MyraMath
chemmL


Source: tests/dense/hemm1.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>
14 
15 // Algorithms.
17 #include <myramath/dense/gemm.h>
18 #include <myramath/dense/hemm.h>
19 #include <myramath/dense/tril.h>
22 
23 // Reporting.
24 #include <tests/myratest.h>
25 
26 using namespace myra;
27 
28 namespace {
29 
30 template<class Precision> void test(int I, int J, Precision tolerance)
31  {
32  typedef std::complex<Precision> Number;
33  myra::out() << typestring<Number>() << std::endl;
34  // Make random hermitian matrix A.
35  auto A = Matrix<Number>::random(I,I);
36  A = A + hermitian(A);
37  Number alpha = random<Number>();
38  Number beta = random<Number>();
39  // Extract lower triangle, fill upper triangle with random data.
40  Matrix<Number> L = tril(A);
41  for (int j = 0; j < I; ++j)
42  for (int i = 0; i < j; ++i)
43  L(i,j) = random<Number>();
44  // Check hemm('L','L')
45  {
46  auto B = Matrix<Number>::random(I,J);
47  auto C1 = Matrix<Number>::random(I,J);
48  Matrix<Number> C2 = C1;
49  gemm_inplace(C1, A, 'N', B, 'N', alpha, beta);
50  hemm_inplace('L', 'L', C2, L, B, alpha, beta);
51  Precision error = frobenius(C1-C2);
52  myra::out() << " |hemm('L','L')-gemm()| = " << error << std::endl;
53  REQUIRE(error < tolerance);
54  }
55  // Check hemm('R','L')
56  {
57  auto B = Matrix<Number>::random(J,I);
58  auto C1 = Matrix<Number>::random(J,I);
59  Matrix<Number> C2 = C1;
60  gemm_inplace(C1, B, 'N', A, 'N', alpha, beta);
61  hemm_inplace('R', 'L', C2, L, B, alpha, beta);
62  Precision error = frobenius(C1-C2);
63  myra::out() << " |hemm('R','L')-gemm()| = " << error << std::endl;
64  REQUIRE(error < tolerance);
65  }
66  }
67 
68 } // namespace
69 
70 ADD_TEST("chemmL","[dense][blas]")
71  { test<float> (53,28, 1.0e-4f); }
72 
73 ADD_TEST("zhemmL","[dense][blas]")
74  { test<double> (53,28, 1.0e-8); }
75 
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
Routines for hermitian Matrix * dense Matrix multiplication.
Definition: syntax.dox:1
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.
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
Simplistic random number functions.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

std::complex<float>
|hemm('L','L')-gemm()| = 3.16296e-05
|hemm('R','L')-gemm()| = 3.38861e-05


Go back to Summary of /test programs.