MyraMath
sparse_flip


Source: tests/sparse/flip.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.
18 #include <myramath/dense/flip.h>
20 #include <myramath/sparse/flip.h>
21 
22 // Reporting.
23 #include <tests/myratest.h>
24 
25 using namespace myra;
26 
27 namespace {
28 
29 // Make random A, test flip_ud() and flip_lr() against their dense equivalents.
30 template<class Number> void test(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
31  {
32  auto A = SparseMatrix<Number>::random(I,J,N);
33  typedef typename ReflectPrecision<Number>::type Precision;
34  Precision error_ud = frobenius( flip_ud(A).make_Matrix() - flip_ud(A.make_Matrix()) );
35  Precision error_lr = frobenius( flip_lr(A).make_Matrix() - flip_lr(A.make_Matrix()) );
36  myra::out() << "error(flip_ud()) = " << error_ud << std::endl;
37  myra::out() << "error(flip_lr()) = " << error_lr << std::endl;
38  REQUIRE(error_ud < tolerance);
39  REQUIRE(error_lr < tolerance);
40  }
41 
42 } // namespace
43 
44 ADD_TEST("sparse_flip","[sparse]")
45  {
46  test<NumberS>(100,50,500,1.0e-4f);
47  test<NumberD>(100,50,500,1.0e-10);
48  test<NumberC>(100,50,500,1.0e-4f);
49  test<NumberZ>(100,50,500,1.0e-10);
50  test<NumberD>(1,10,5,1.0e-10);
51  test<NumberD>(10,1,5,1.0e-10);
52  test<NumberD>(1,1,1,1.0e-10);
53  test<NumberD>(0,0,1,1.0e-10);
54  };
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
Routines for flipping (reversing) dense Vector&#39;s, Matrix&#39;s, etc.
General purpose dense matrix container, O(i*j) storage.
Routines for flipping (reversing) SparseMatrix&#39;s.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0
error(flip_ud()) = 0
error(flip_lr()) = 0


Go back to Summary of /test programs.