Skip to content

Commit

Permalink
Sparse-Sparse arithmetic tests using MTX files
Browse files Browse the repository at this point in the history
  • Loading branch information
9prady9 committed Nov 30, 2018
1 parent 6ce7ed5 commit 3fdd452
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/sparse_arith.cpp
Expand Up @@ -384,3 +384,57 @@ SP_SP_ARITH_TESTS(float , 1e-6)
SP_SP_ARITH_TESTS(double , 1e-6)
SP_SP_ARITH_TESTS(cfloat , 1e-4) // This is mostly for complex division in OpenCL
SP_SP_ARITH_TESTS(cdouble, 1e-6)

#if defined(USE_MTX)

// Sparse-Sparse Arithmetic testing function using mtx files
template<af_op_t op>
void ssArithmeticMTX(const char* op1, const char* op2)
{
deviceGC();

//Re-enable when double is enabled if (noDoubleTests<T>()) return;

array cooA, cooB;
ASSERT_TRUE(mtxReadSparseMatrix(cooA, op1));
ASSERT_TRUE(mtxReadSparseMatrix(cooB, op2));

array spA = sparseConvertTo(cooA, AF_STORAGE_CSR);
array spB = sparseConvertTo(cooB, AF_STORAGE_CSR);

array A = dense(spA);
array B = dense(spB);

arith_op<op> binOp;

// Arith Op
array resS = binOp(spA, spB);
array resD = binOp(A, B);
array revS = binOp(spB, spA);
array revD = binOp(B, A);

ASSERT_ARRAYS_NEAR(resD, dense(resS), 1e-4);
ASSERT_ARRAYS_NEAR(revD, dense(revS), 1e-4);
}

TEST(SparseSparseArith, LinearProgrammingData)
{
std::string file1(TEST_DIR "/matrixmarket/LPnetlib/lpi_vol1/lpi_vol1.mtx");
std::string file2(TEST_DIR "/matrixmarket/LPnetlib/lpi_qual/lpi_qual.mtx");
ssArithmeticMTX<af_add_t>(file1.c_str(), file2.c_str());
}

TEST(SparseSparseArith, SubsequentCircuitSimData)
{
std::string file1(TEST_DIR "/matrixmarket/Sandia/oscil_dcop_12/oscil_dcop_12.mtx");
std::string file2(TEST_DIR "/matrixmarket/Sandia/oscil_dcop_42/oscil_dcop_42.mtx");
ssArithmeticMTX<af_sub_t>(file1.c_str(), file2.c_str());
}

TEST(SparseSparseArith, QuantumChemistryData)
{
std::string file1(TEST_DIR "/matrixmarket/QCD/conf6_0-4x4-20/conf6_0-4x4-20.mtx");
std::string file2(TEST_DIR "/matrixmarket/QCD/conf6_0-4x4-30/conf6_0-4x4-30.mtx");
ssArithmeticMTX<af_add_t>(file1.c_str(), file2.c_str());
}
#endif

0 comments on commit 3fdd452

Please sign in to comment.