MyraMath
alias_Vector


Source: tests/dense/alias.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.
13 #include <myramath/dense/Vector.h>
14 #include <myramath/dense/Matrix.h>
16 
17 // Ranges.
21 
22 // Algorithms.
24 
25 // Reporting.
26 #include <tests/myratest.h>
27 
28 using namespace myra;
29 
30 namespace {
31 
32 // Alias test for Vector.
33 template<class Number> void test1(typename ReflectPrecision<Number>::type tolerance)
34  {
35  auto x = Vector<Number>::random(10);
36  Vector<Number> y(x.first(5));
37  x = x.first(5);
38  REQUIRE( frobenius(x-y) < tolerance);
39  }
40 
41 // Alias test for Matrix.
42 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
43  {
44  auto A = Matrix<Number>::random(10,10);
45  Matrix<Number> B(A.top(5));
46  A = A.top(5);
47  REQUIRE( frobenius(A-B) < tolerance);
48  }
49 
50 // Alias test for DiagonalMatrix.
51 template<class Number> void test3(typename ReflectPrecision<Number>::type tolerance)
52  {
53  auto A = DiagonalMatrix<Number>::random(10);
54  DiagonalMatrix<Number> B(A.first(5));
55  A = A.first(5);
56  REQUIRE( frobenius(A-B) < tolerance);
57  }
58 
59 } // namespace
60 
61 ADD_TEST("alias_Vector","[dense]")
62  {
63  test1<NumberS>(1.0e-4f);
64  test1<NumberD>(1.0e-8);
65  test1<NumberC>(1.0e-4f);
66  test1<NumberZ>(1.0e-8);
67  }
68 
69 ADD_TEST("alias_Matrix","[dense]")
70  {
71  test2<NumberS>(1.0e-4f);
72  test2<NumberD>(1.0e-8);
73  test2<NumberC>(1.0e-4f);
74  test2<NumberZ>(1.0e-8);
75  }
76 
77 ADD_TEST("alias_DiagonalMatrix","[dense]")
78  {
79  test2<NumberS>(1.0e-4f);
80  test2<NumberD>(1.0e-8);
81  test2<NumberC>(1.0e-4f);
82  test2<NumberZ>(1.0e-8);
83  }
Interface class for representing subranges of DiagonalMatrix&#39;s.
Tabulates the values of a square NxN diagonal matrix. Allows random access, but only on the diagonal...
Definition: conjugate.h:23
Interface class for representing subranges of dense Matrix&#39;s.
Interface class for representing subranges of dense Vector&#39;s.
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
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Definition: syntax.dox:1
CVectorRange< Number > first(int n) const
Returns a VectorRange over the first n entries, this(0:n)
Definition: Vector.cpp:192
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
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) ...
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
const CDiagonalMatrixRange< Number > first(int n) const
Returns a DiagonalMatrixRange over the first n entries, this(0:n,0:n)
Definition: DiagonalMatrix.cpp:153
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
CMatrixRange< Number > top(int i) const
Returns a MatrixRange over the i topmost rows, this(0:i,:)
Definition: Matrix.cpp:207


Results: [PASS]


Go back to Summary of /test programs.