MyraMath
chemmU


Source: tests/dense/hemm2.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/triu.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 upper triangle, fill lower triangle with random data.
40  Matrix<Number> U = triu(A);
41  for (int j = 0; j < I; ++j)
42  for (int i = j+1; i < I; ++i)
43  U(i,j) = random<Number>();
44  // Check hemm('L','U')
45  {
46  auto B = Matrix<Number>::random(I,J);
47  auto C1 = Matrix<Number>::random(I,J);
48  Matrix<Number> C2 = C1;
49  Matrix<Number> U = triu(A);
50  gemm_inplace(C1, A, 'N', B, 'N', alpha, beta);
51  hemm_inplace('L', 'U', C2, U, B, alpha, beta);
52  Precision error = frobenius(C1-C2);
53  myra::out() << " |hemm('L','U')-gemm()| = " << error << std::endl;
54  REQUIRE(error < tolerance);
55  }
56  // Check hemm('R','U')
57  {
58  auto B = Matrix<Number>::random(J,I);
59  auto C1 = Matrix<Number>::random(J,I);
60  Matrix<Number> C2 = C1;
61  Matrix<Number> U = triu(A);
62  gemm_inplace(C1, B, 'N', A, 'N', alpha, beta);
63  hemm_inplace('R', 'U', C2, U, B, alpha, beta);
64  Precision error = frobenius(C1-C2);
65  myra::out() << " |hemm('R','U')-gemm()| = " << error << std::endl;
66  REQUIRE(error < tolerance);
67  }
68  }
69 
70 } // namespace
71 
72 ADD_TEST("chemmU","[dense][blas]")
73  { test<float> (53,28, 1.0e-4f); }
74 
75 ADD_TEST("zhemmU","[dense][blas]")
76  { test<double> (53,28, 1.0e-8); }
77 
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 upper 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','U')-gemm()| = 2.18314e-05
|hemm('R','U')-gemm()| = 2.35195e-05


Go back to Summary of /test programs.