MyraMath
hermitian


Source: tests/sparse/hermitian.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.
21 
22 // Reporting.
23 #include <tests/myratest.h>
24 
25 using namespace myra;
26 
27 namespace {
28 
29 template<class Number> void test(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
30  {
31  myra::out() << typestring<Number>() << std::endl;
32  typedef typename ReflectPrecision<Number>::type Precision;
33  // Make random SparseMatrix A.
34  auto A = SparseMatrix<Number>::random(I,J,N);
35  // Compare sparse hermitian() against dense hermitian()
36  Precision error = frobenius( hermitian(A).make_Matrix() - hermitian(A.make_Matrix()) );
37  myra::out() << "|A'(sparse) - A'(dense)| = " << error << std::endl;
38  REQUIRE(error < tolerance);
39  }
40 
41 } // namespace
42 
43 ADD_TEST("hermitian","[sparse]")
44  {
45  test<NumberS>(20,30,150,1.0e-4f);
46  test<NumberD>(20,30,150,1.0e-12);
47  test<NumberC>(20,30,150,1.0e-4f);
48  test<NumberZ>(20,30,150,1.0e-12);
49  }
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
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
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
Returns a hermitian copy of a SparseMatrix.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

float
|A'(sparse) - A'(dense)| = 0
double
|A'(sparse) - A'(dense)| = 0
std::complex<float>
|A'(sparse) - A'(dense)| = 0
std::complex<double>
|A'(sparse) - A'(dense)| = 0


Go back to Summary of /test programs.