MyraMath
NegateAction


Source: tests/iterative/NegateAction.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.
18 #include <myramath/dense/gemm.h>
20 
21 // Iterative solve/action stuff.
25 
26 // Reporting.
27 #include <tests/myratest.h>
28 
29 using namespace myra;
30 
31 namespace {
32 
33 // Test negate_action().
34 template<class Number> void test1(int I, int J, int K, typename ReflectPrecision<Number>::type tolerance)
35  {
36  myra::out() << typestring<Number>() << std::endl;
37  typedef typename ReflectPrecision<Number>::type Precision;
38  // Form A.
39  auto A = Matrix<Number>::random(I,J);
40  auto action = -make_GemmAction(A);
41  // Check action.make_Matrix()
42  {
43  Precision error = frobenius(-A-action.make_Matrix());
44  myra::out() << " |A(action) - A(dense)| = " << error << std::endl;
45  REQUIRE(error < tolerance);
46  }
47  // Check A_action.multiply(X,B)
48  {
49  auto X = Matrix<Number>::random(J,K);
50  auto B = Matrix<Number>::zeros(I,K);
51  action.multiply(X,B);
52  Precision error = frobenius(-A*X-B);
53  myra::out() << " |A*X - B| = " << error << std::endl;
54  REQUIRE(error < tolerance);
55  }
56  // Check A_action.multiply(X,B,alpha,beta)
57  {
58  auto X = Matrix<Number>::random(J,K);
59  auto B = Matrix<Number>::random(I,K);
60  auto alpha = random<Number>();
61  auto beta = random<Number>();
62  auto C = -alpha*A*X + beta*B;
63  action.multiply(X,B,alpha,beta);
64  Precision error = frobenius(B-C);
65  myra::out() << " | (alpha*A*X+beta*B)[action] - (alpha*A*X+beta*B)[dense] | = " << error << std::endl;
66  REQUIRE(error < tolerance);
67  }
68  }
69 
70 } // namespace
71 
72 ADD_TEST("NegateAction","[iterative]")
73  {
74  // Test dense make_TrsmAction()
75  int I = 10;
76  int J = 7;
77  int K = 4;
78  test1<NumberS>(I,J,K,1.0e-4f);
79  test1<NumberD>(I,J,K,1.0e-10);
80  test1<NumberC>(I,J,K,1.0e-4f);
81  test1<NumberZ>(I,J,K,1.0e-10);
82  }
Interface class for representing subranges of dense Matrix&#39;s.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
static Matrix< Number > zeros(int I, int J)
Generates a zeros Matrix of specified size.
Definition: Matrix.cpp:357
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
Returns the negation of an Action A.
Various utility functions/classes related to scalar Number types.
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
Matrix< Number > make_Matrix() const
Tabulates *this into a dense Matrix.
Definition: Action.cpp:71
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Simplistic random number functions.
void multiply(const CMatrixRange< Number > &X, const MatrixRange< Number > &B, Number alpha, Number beta) const
Assigns B = alpha*A*X + beta*B.
Definition: Action.cpp:55
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

float
|A(action) - A(dense)| = 0
|A*X - B| = 0
| (alpha*A*X+beta*B)[action] - (alpha*A*X+beta*B)[dense] | = 0
double
|A(action) - A(dense)| = 0
|A*X - B| = 0
| (alpha*A*X+beta*B)[action] - (alpha*A*X+beta*B)[dense] | = 0
std::complex<float>
|A(action) - A(dense)| = 0
|A*X - B| = 0
| (alpha*A*X+beta*B)[action] - (alpha*A*X+beta*B)[dense] | = 6.51404e-07
std::complex<double>
|A(action) - A(dense)| = 0
|A*X - B| = 0
| (alpha*A*X+beta*B)[action] - (alpha*A*X+beta*B)[dense] | = 1.07295e-15


Go back to Summary of /test programs.