TEST(Join, JoinLargeDim) { using af::constant; using af::deviceGC; using af::span; // const int nx = 32; const int nx = 1; const int ny = 4 * 1024 * 1024; const int nw = 4 * 1024 * 1024; deviceGC(); { array in = randu(nx, ny, u8); array joined = join(0, in, in); dim4 in_dims = in.dims(); dim4 joined_dims = joined.dims(); ASSERT_EQ(2 * in_dims[0], joined_dims[0]); ASSERT_EQ(0.f, sum<float>((joined(0, span) - joined(1, span)).as(f32))); array in2 = constant(1, (dim_t)nx, (dim_t)ny, (dim_t)2, (dim_t)nw, u8); joined = join(3, in, in); in_dims = in.dims(); joined_dims = joined.dims(); ASSERT_EQ(2 * in_dims[3], joined_dims[3]); } }
void sparseArithTesterMul(const int m, const int n, int factor, const double eps) { deviceGC(); if (noDoubleTests<T>()) return; #if 1 array A = cpu_randu<T>(dim4(m, n)); array B = cpu_randu<T>(dim4(m, n)); #else array A = randu(m, n, (dtype)dtype_traits<T>::af_type); array B = randu(m, n, (dtype)dtype_traits<T>::af_type); #endif A = makeSparse<T>(A, factor); array RA = sparse(A, AF_STORAGE_CSR); array OA = sparse(A, AF_STORAGE_COO); // Forward { // Arith Op array resR = arith_op<af_mul_t>()(RA, B); array resO = arith_op<af_mul_t>()(OA, B); // We will test this by converting the COO to CSR and CSR to COO and // comparing them. In essense, we are comparing the resR and resO // TODO: Make a better comparison using dense // Check resR against conR array conR = sparseConvertTo(resR, AF_STORAGE_CSR); sparseCompare<T>(resR, conR, eps); // Check resO against conO array conO = sparseConvertTo(resR, AF_STORAGE_COO); sparseCompare<T>(resO, conO, eps); } // Reverse { // Arith Op array resR = arith_op<af_mul_t>()(B, RA); array resO = arith_op<af_mul_t>()(B, OA); // We will test this by converting the COO to CSR and CSR to COO and // comparing them. In essense, we are comparing the resR and resO // TODO: Make a better comparison using dense // Check resR against conR array conR = sparseConvertTo(resR, AF_STORAGE_CSR); sparseCompare<T>(resR, conR, eps); // Check resO against conO array conO = sparseConvertTo(resR, AF_STORAGE_COO); sparseCompare<T>(resO, conO, eps); } }
void sparseArithTesterDiv(const int m, const int n, int factor, const double eps) { deviceGC(); if (noDoubleTests<T>()) return; #if 1 array A = cpu_randu<T>(dim4(m, n)); array B = cpu_randu<T>(dim4(m, n)); #else array A = randu(m, n, (dtype)dtype_traits<T>::af_type); array B = randu(m, n, (dtype)dtype_traits<T>::af_type); #endif A = makeSparse<T>(A, factor); array RA = sparse(A, AF_STORAGE_CSR); array OA = sparse(A, AF_STORAGE_COO); // Arith Op array resR = arith_op<af_div_t>()(RA, B); array resO = arith_op<af_div_t>()(OA, B); // Assert division by sparse is not allowed af_array out_temp = 0; ASSERT_EQ(AF_ERR_NOT_SUPPORTED, af_div(&out_temp, B.get(), RA.get(), false)); ASSERT_EQ(AF_ERR_NOT_SUPPORTED, af_div(&out_temp, B.get(), OA.get(), false)); if(out_temp != 0) af_release_array(out_temp); // We will test this by converting the COO to CSR and CSR to COO and // comparing them. In essense, we are comparing the resR and resO // TODO: Make a better comparison using dense // Check resR against conR array conR = sparseConvertTo(resR, AF_STORAGE_CSR); sparseCompare<T>(resR, conR, eps); // Check resO against conO array conO = sparseConvertTo(resR, AF_STORAGE_COO); sparseCompare<T>(resO, conO, eps); }
void sparseArithTester(const int m, const int n, int factor, const double eps) { deviceGC(); if (noDoubleTests<T>()) return; #if 1 array A = cpu_randu<T>(dim4(m, n)); array B = cpu_randu<T>(dim4(m, n)); #else array A = randu(m, n, (dtype)dtype_traits<T>::af_type); array B = randu(m, n, (dtype)dtype_traits<T>::af_type); #endif A = makeSparse<T>(A, factor); array RA = sparse(A, AF_STORAGE_CSR); array OA = sparse(A, AF_STORAGE_COO); // Arith Op array resR = arith_op<op>()(RA, B); array resO = arith_op<op>()(OA, B); array resD = arith_op<op>()( A, B); array revR = arith_op<op>()(B, RA); array revO = arith_op<op>()(B, OA); array revD = arith_op<op>()(B, A); ASSERT_NEAR(0, sum<double>(abs(real(resR - resD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(imag(resR - resD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(real(resO - resD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(imag(resO - resD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(real(revR - revD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(imag(revR - revD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(real(revO - revD))) / (m * n), eps); ASSERT_NEAR(0, sum<double>(abs(imag(revO - revD))) / (m * n), eps); }