MyraMath


Source: tests/sparse/SparseMatrixBuilder.cpp

1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
11 // Containers.
12 #include <myramath/dense/Matrix.h>
16 
17 // Algorithms.
19 
20 // Reporting.
21 #include <tests/myratest.h>
22 
23 using namespace myra;
24 
25 ADD_TEST("SparseMatrixBuilder","[sparse]")
26  {
27  auto A = SparseMatrix<double>::random(10,10,25);
28  auto B = SparseMatrix<double>::random(10,10,25);
29  double error_p = frobenius( (A+B).make_Matrix()-(A.make_Matrix()+B.make_Matrix()) );
30  double error_m = frobenius( (A-B).make_Matrix()-(A.make_Matrix()-B.make_Matrix()) );
31  myra::out() << "| A+B(sparse) - A+B(dense) | = " << error_p << std::endl;
32  myra::out() << "| A-B(sparse) - A-B(dense) | = " << error_m << std::endl;
33  double tolerance = 1.0e-12;
34  REQUIRE(error_p < tolerance);
35  REQUIRE(error_m < tolerance);
36  }
Interface class for representing subranges of dense Matrix&#39;s.
Routines for computing Frobenius norms of various algebraic containers.
static SparseMatrix< Number > random(int I, int J, int N)
Generates a random SparseMatrix with size IxJ and (approximately) N nonzeros.
Definition: SparseMatrix.cpp:493
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
General purpose dense matrix container, O(i*j) storage.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

| A+B(sparse) - A+B(dense) | = 0
| A-B(sparse) - A-B(dense) | = 0


Go back to Summary of /test programs.