MyraMath
sparse_dimm


Source: tests/sparse/dimm.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>
18 
19 // Algorithms.
20 #include <myramath/dense/dimm.h>
22 #include <myramath/sparse/dimm.h>
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 // Make random D and X, try all dimm('L',op) variations.
32 template<class Number> void test1(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
33  {
34  typedef typename ReflectPrecision<Number>::type Precision;
36  auto X = SparseMatrix<Number>::random(I,J,N);
37  Precision errorN = frobenius(dimm('L','N',D,X).make_Matrix()-dimm('L','N',D,X.make_Matrix()));
38  Precision errorT = frobenius(dimm('L','T',D,X).make_Matrix()-dimm('L','T',D,X.make_Matrix()));
39  Precision errorH = frobenius(dimm('L','H',D,X).make_Matrix()-dimm('L','H',D,X.make_Matrix()));
40  Precision errorC = frobenius(dimm('L','C',D,X).make_Matrix()-dimm('L','C',D,X.make_Matrix()));
41  myra::out() << "error |D^N * X| = " << errorN << std::endl;
42  myra::out() << "error |D^T * X| = " << errorT << std::endl;
43  myra::out() << "error |D^H * X| = " << errorH << std::endl;
44  myra::out() << "error |D^C * X| = " << errorC << std::endl;
45  REQUIRE(errorN < tolerance);
46  REQUIRE(errorT < tolerance);
47  REQUIRE(errorH < tolerance);
48  REQUIRE(errorC < tolerance);
49  }
50 
51 // Make random D and X, try all dimm('R',op) variations.
52 template<class Number> void test2(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
53  {
54  typedef typename ReflectPrecision<Number>::type Precision;
56  auto X = SparseMatrix<Number>::random(I,J,N);
57  Precision errorN = frobenius(dimm('R','N',D,X).make_Matrix()-dimm('R','N',D,X.make_Matrix()));
58  Precision errorT = frobenius(dimm('R','T',D,X).make_Matrix()-dimm('R','T',D,X.make_Matrix()));
59  Precision errorH = frobenius(dimm('R','H',D,X).make_Matrix()-dimm('R','H',D,X.make_Matrix()));
60  Precision errorC = frobenius(dimm('R','C',D,X).make_Matrix()-dimm('R','C',D,X.make_Matrix()));
61  myra::out() << "error |X * D^N| = " << errorN << std::endl;
62  myra::out() << "error |X * D^T| = " << errorT << std::endl;
63  myra::out() << "error |X * D^H| = " << errorH << std::endl;
64  myra::out() << "error |X * D^C| = " << errorC << std::endl;
65  REQUIRE(errorN < tolerance);
66  REQUIRE(errorT < tolerance);
67  REQUIRE(errorH < tolerance);
68  REQUIRE(errorC < tolerance);
69  }
70 
71 } // namespace
72 
73 ADD_TEST("sparse_dimm","[sparse]")
74  {
75  test1<NumberS>(100,50,500,1.0e-4f);
76  test1<NumberD>(100,50,500,1.0e-10);
77  test1<NumberC>(100,50,500,1.0e-4f);
78  test1<NumberZ>(100,50,500,1.0e-10);
79  test2<NumberS>(100,50,500,1.0e-4f);
80  test2<NumberD>(100,50,500,1.0e-10);
81  test2<NumberC>(100,50,500,1.0e-4f);
82  test2<NumberZ>(100,50,500,1.0e-10);
83  };
Interface class for representing subranges of DiagonalMatrix&#39;s.
Interface class for representing subranges of dense Matrix&#39;s.
Routines for computing Frobenius norms of various algebraic containers.
Routines for multiplying by a DiagonalMatrix.
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 multiplying by a DiagonalMatrix.
static DiagonalMatrix< Number > random(int N)
Generates a random DiagonalMatrix of specified size.
Definition: DiagonalMatrix.cpp:217
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
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

error |D^N * X| = 0
error |D^T * X| = 0
error |D^H * X| = 0
error |D^C * X| = 0
error |D^N * X| = 0
error |D^T * X| = 0
error |D^H * X| = 0
error |D^C * X| = 0
error |D^N * X| = 0
error |D^T * X| = 0
error |D^H * X| = 0
error |D^C * X| = 0
error |D^N * X| = 0
error |D^T * X| = 0
error |D^H * X| = 0
error |D^C * X| = 0
error |X * D^N| = 0
error |X * D^T| = 0
error |X * D^H| = 0
error |X * D^C| = 0
error |X * D^N| = 0
error |X * D^T| = 0
error |X * D^H| = 0
error |X * D^C| = 0
error |X * D^N| = 0
error |X * D^T| = 0
error |X * D^H| = 0
error |X * D^C| = 0
error |X * D^N| = 0
error |X * D^T| = 0
error |X * D^H| = 0
error |X * D^C| = 0


Go back to Summary of /test programs.