MyraMath
sparse_threshold


Source: tests/sparse/threshold.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.
20 
21 // Reporting.
22 #include <tests/myratest.h>
23 
24 using namespace myra;
25 
26 namespace {
27 
28 template<class Number> void test(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
29  {
30  myra::out() << typestring<Number>() << std::endl;
31  // Make random A.
32  auto A = SparseMatrix<Number>::random(I,J,N);
33  // Make a dense Matrix from A, then threshold it back to a SparseMatrix.
34  auto B = dense2sparse_threshold(A.make_Matrix());
35  // Verify A == B
36  typedef typename ReflectPrecision<Number>::type Precision;
37  Precision error = frobenius(A-B);
38  myra::out() << " |A-threshold(A.make_Matrix())| = " << error << std::endl;
39  REQUIRE(error < tolerance);
40  }
41 
42 } // namespace
43 
44 ADD_TEST("sparse_threshold","[sparse]")
45  {
46  test<NumberS>(15,10,40,1.0e-4f);
47  test<NumberD>(15,10,40,1.0e-9);
48  test<NumberC>(15,10,40,1.0e-4f);
49  test<NumberZ>(15,10,40,1.0e-9);
50  }
Interface class for representing subranges of dense Matrix&#39;s.
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.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Generates a SparseMatrix by thresholding a dense Matrix, or another SparseMatrix. ...
Returns frobenius norm of a SparseMatrix.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

float
|A-threshold(A.make_Matrix())| = 0
double
|A-threshold(A.make_Matrix())| = 0
std::complex<float>
|A-threshold(A.make_Matrix())| = 0
std::complex<double>
|A-threshold(A.make_Matrix())| = 0


Go back to Summary of /test programs.