MyraMath
transpose


Source: tests/sparse/transpose.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.
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 template<class Number> void test(int I, int J, int N, typename ReflectPrecision<Number>::type tolerance)
32  {
33  myra::out() << typestring<Number>() << std::endl;
34  typedef typename ReflectPrecision<Number>::type Precision;
35  // Make random SparseMatrix A.
36  auto A = SparseMatrix<Number>::random(I,J,N);
37  // Compare sparse transpose() against dense transpose()
38  Precision error = frobenius( transpose(A).make_Matrix() - transpose(A.make_Matrix()) );
39  myra::out() << "|A'(sparse) - A'(dense)| = " << error << std::endl;
40  REQUIRE(error < tolerance);
41  }
42 
43 } // namespace
44 
45 ADD_TEST("transpose","[sparse]")
46  {
47  test<NumberS>(20,30,150,1.0e-4f);
48  test<NumberD>(20,30,150,1.0e-12);
49  test<NumberC>(20,30,150,1.0e-4f);
50  test<NumberZ>(20,30,150,1.0e-12);
51  }
52 
53 ADD_TEST("transpose_Pattern","[sparse]")
54  {
55  auto A = Pattern::random(20,30,150);
56  auto At = transpose(A);
57  bool ok = true;
58  for (auto iterator = A.begin(); iterator != A.end(); ++iterator)
59  {
60  int i = iterator.i();
61  int j = iterator.j();
62  if (!At.test(j,i))
63  ok = false;
64  }
65  REQUIRE(ok);
66  }
Returns a transposed copy of a SparseMatrix.
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
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
static Pattern random(int I, int J, int N)
Generates a random Pattern with size IxJ and (approximately) N nonzeros.
Definition: Pattern.cpp:300
General purpose dense matrix container, O(i*j) storage.
Range/Iterator types associated with Pattern.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Container class for a sparse nonzero pattern, used in reordering/symbolic analysis.
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.