MyraMath
zswizzle


Source: tests/dense/swizzle.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/Matrix.h>
15 
16 // Algorithms.
17 #include <myramath/dense/gemm.h>
18 #include <myramath/dense/swizzle.h>
20 
21 // Real solver type for A.
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 template<class Precision> void test(int I, int J, Precision tolerance)
32  {
33  myra::out() << typestring<Precision>() << std::endl;
34  // Make random real A, and generate a solver for it.
35  const auto A = Matrix<Precision>::random(I,I);
36  LUSolver<Precision> solver(A);
37  // Make random complex X, and multiply it into B=A*X using make_complex(A)
38  typedef std::complex<Precision> Number;
39  auto X = Matrix<Number>::random(I,J);
41  // Use solver.solve() and swizzle()/unswizzle() to solve A*X=B.
42  auto RI = swizzle(B);
43  solver.solve(RI.first);
44  solver.solve(RI.second);
45  unswizzle(B);
46  // Verify B=X.
47  Precision error = frobenius(X-B)/frobenius(X);
48  myra::out() << "inv(A) [real] * B [complex] - X [complex] == " << error << std::endl;
49  REQUIRE(error < tolerance);
50  }
51 
52 } // namespace
53 
54 ADD_TEST("cswizzle","[dense][solver]")
55  { test<float>(53,21,1.0e-3f); }
56 
57 ADD_TEST("zswizzle","[dense][solver]")
58  { test<double>(48,18,1.0e-10); }
59 
Interface class for representing subranges of dense Matrix&#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
Definition: syntax.dox:1
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Wonkish routines for rearranging a complex Range into two real Range&#39;s, and back again.
General purpose linear solver, no symmetry/definiteness assumptions upon A (just square) ...
Factors a square matrix A into L*U, presents solve methods.
Definition: LUSolver.h:30
Expression< 1, NumberC > make_complex(const Expression< 1, NumberS > &A)
Promotes a real Expression into a complex one.
Definition: functions_complex.cpp:122
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

double
inv(A) [real] * B [complex] - X [complex] == 5.30887e-15


Go back to Summary of /test programs.