MyraMath
dense_io1


Source: tests/dense/io1.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 // Container types.
13 #include <myramath/dense/Matrix.h>
14 #include <myramath/dense/Vector.h>
17 
18 // Algorithms.
20 
21 // Serialization backend.
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 template<class Number> void roundtrip_Matrix()
32  {
33  // Make original.
34  auto A1 = Matrix<Number>::random(5,7);
35  // Write it out, read back into a copy.
36  VectorStream inout;
37  A1.write(inout);
38  Matrix<Number> A2(inout);
39  // Check errors.
40  auto error = frobenius(A1-A2);
41  myra::out() << "|A1-A2| = " << error << " (" << typestring<Number>() << ")" << std::endl;
42  REQUIRE(error == 0);
43  }
44 
45 template<class Number> void roundtrip_LowerMatrix()
46  {
47  // Make original.
48  auto L1 = LowerMatrix<Number>::random(5);
49  // Write it out, read back into a copy.
50  VectorStream inout;
51  L1.write(inout);
52  LowerMatrix<Number> L2(inout);
53  // Check errors.
54  auto error = frobenius(L1-L2);
55  myra::out() << "|L1-L2| = " << error << " (" << typestring<Number>() << ")" << std::endl;
56  REQUIRE(error == 0);
57  }
58 
59 template<class Number> void roundtrip_DiagonalMatrix()
60  {
61  // Make original.
62  auto D1 = DiagonalMatrix<Number>::random(5);
63  // Write it out, read back into a copy.
64  VectorStream inout;
65  D1.write(inout);
66  DiagonalMatrix<Number> D2(inout);
67  // Check errors.
68  auto error = frobenius(D1-D2);
69  myra::out() << "|D1-D2| = " << error << " (" << typestring<Number>() << ")" << std::endl;
70  REQUIRE(error == 0);
71  }
72 
73 
74 template<class Number> void roundtrip_Vector()
75  {
76  // Make original.
77  auto V1 = Vector<Number>::random(5);
78  // Write it out, read back into a copy.
79  VectorStream inout;
80  V1.write(inout);
81  Vector<Number> V2(inout);
82  // Check errors.
83  auto error = frobenius(V1-V2);
84  myra::out() << "|V1-V2| = " << error << " (" << typestring<Number>() << ")" << std::endl;
85  REQUIRE(error == 0);
86  }
87 
88 } // namespace
89 
90 ADD_TEST("dense_io1","[dense]")
91  {
92  // Test serialization for Matrix<>
93  roundtrip_Matrix<NumberS> ();
94  roundtrip_Matrix<NumberD> ();
95  roundtrip_Matrix<NumberC> ();
96  roundtrip_Matrix<NumberZ> ();
97  // Test serialization for LowerMatrix<>
98  roundtrip_LowerMatrix<NumberS> ();
99  roundtrip_LowerMatrix<NumberD> ();
100  roundtrip_LowerMatrix<NumberC> ();
101  roundtrip_LowerMatrix<NumberZ> ();
102  // Test serialization for DiagonalMatrix<>
103  roundtrip_DiagonalMatrix<NumberS> ();
104  roundtrip_DiagonalMatrix<NumberD> ();
105  roundtrip_DiagonalMatrix<NumberC> ();
106  roundtrip_DiagonalMatrix<NumberZ> ();
107  // Test serialization for Vector<>
108  roundtrip_Vector<NumberS> ();
109  roundtrip_Vector<NumberD> ();
110  roundtrip_Vector<NumberC> ();
111  roundtrip_Vector<NumberZ> ();
112  }
Tabulates the values of a square NxN diagonal matrix. Allows random access, but only on the diagonal...
Definition: conjugate.h:23
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Routines for computing Frobenius norms of various algebraic containers.
static Matrix< Number > random(int I, int J)
Generates a random Matrix of specified size.
Definition: Matrix.cpp:353
Wraps a std::vector<char>, presents it as both an InputStream and OutputStream. Useful for hygienic u...
Definition: VectorStream.h:22
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Definition: syntax.dox:1
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
Various utility functions/classes related to scalar Number types.
static DiagonalMatrix< Number > random(int N)
Generates a random DiagonalMatrix of specified size.
Definition: DiagonalMatrix.cpp:217
A stream that serialize/deserializes to std::vector<char> buffer.
General purpose dense matrix container, O(i*j) storage.
Tabulates a vector of length N, allows random access.
Definition: conjugate.h:21
Container for either a column vector or row vector (depends upon the usage context) ...
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
void write(OutputStream &out) const
Writes to OutputStream, complements InputStream constructor.
Definition: DiagonalMatrix.cpp:83
static LowerMatrix< Number > random(int N)
Generates a random LowerMatrix of specified size.
Definition: LowerMatrix.cpp:249


Results: [PASS]

|A1-A2| = 0 (float)
|A1-A2| = 0 (double)
|A1-A2| = 0 (std::complex<float>)
|A1-A2| = 0 (std::complex<double>)
|L1-L2| = 0 (float)
|L1-L2| = 0 (double)
|L1-L2| = 0 (std::complex<float>)
|L1-L2| = 0 (std::complex<double>)
|D1-D2| = 0 (float)
|D1-D2| = 0 (double)
|D1-D2| = 0 (std::complex<float>)
|D1-D2| = 0 (std::complex<double>)
|V1-V2| = 0 (float)
|V1-V2| = 0 (double)
|V1-V2| = 0 (std::complex<float>)
|V1-V2| = 0 (std::complex<double>)


Go back to Summary of /test programs.