MyraMath
dsymmLower


Source: tests/dense/symm3.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>
16 
17 // Algorithms.
19 #include <myramath/dense/gemm.h>
20 #include <myramath/dense/symm.h>
21 #include <myramath/dense/tril.h>
24 
25 // Reporting.
26 #include <tests/myratest.h>
27 
28 using namespace myra;
29 
30 namespace {
31 
32 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
33  {
34  typedef typename ReflectPrecision<Number>::type Precision;
35  myra::out() << typestring<Number>() << std::endl;
36  // Make random symmetric matrix A.
37  auto A = Matrix<Number>::random(I,I);
38  A = A + transpose(A);
39  Number alpha = random<Number>();
40  Number beta = random<Number>();
41  // Extract A into LowerMatrix
42  LowerMatrix<Number> L(tril(A));
43  // Check symm('L')
44  {
45  auto B = Matrix<Number>::random(I,J);
46  auto C1 = Matrix<Number>::random(I,J);
47  Matrix<Number> C2 = C1;
48  gemm_inplace(C1, A, 'N', B, 'N', alpha, beta);
49  symm_inplace('L', C2, L, B, alpha, beta);
50  Precision error = frobenius(C1-C2);
51  myra::out() << " |symm('L')-gemm()| = " << error << std::endl;
52  REQUIRE(error < tolerance);
53  }
54  // Check symm('R')
55  {
56  auto B = Matrix<Number>::random(J,I);
57  auto C1 = Matrix<Number>::random(J,I);
58  Matrix<Number> C2 = C1;
59  gemm_inplace(C1, B, 'N', A, 'N', alpha, beta);
60  symm_inplace('R', C2, L, B, alpha, beta);
61  Precision error = frobenius(C1-C2);
62  myra::out() << " |symm('R')-gemm()| = " << error << std::endl;
63  REQUIRE(error < tolerance);
64  }
65  }
66 
67 } // namespace
68 
69 ADD_TEST("ssymmLower","[dense][blas]")
70  { test<NumberS>(51,32, 1.0e-4f); }
71 
72 ADD_TEST("dsymmLower","[dense][blas]")
73  { test<NumberD>(51,32, 1.0e-8); }
74 
75 ADD_TEST("csymmLower","[dense][blas]")
76  { test<NumberC>(51,32, 1.0e-4f); }
77 
78 ADD_TEST("zsymmLower","[dense][blas]")
79  { test<NumberZ>(51,32, 1.0e-8); }
80 
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
Range construct for a lower triangular matrix stored in rectangular packed format.
Definition: syntax.dox:1
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
Returns the lower triangle of a dense Matrix.
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
Simplistic random number functions.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Routines for symmetric Matrix * dense Matrix multiplication.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

double
|symm('L')-gemm()| = 3.66206e-15
|symm('R')-gemm()| = 4.77173e-15


Go back to Summary of /test programs.