MyraMath
zherkL


Source: tests/dense/herk1.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/herk.h>
23 #include <myramath/dense/tril.h>
24 #include <myramath/dense/triu.h>
26 
27 // Reporting.
28 #include <tests/myratest.h>
29 
30 using namespace myra;
31 
32 namespace {
33 
34 template<class Precision> void test(int I, int J, Precision tolerance)
35  {
36  // Useful typedef.
37  typedef std::complex<Precision> Number;
38  myra::out() << typestring<Number>() << std::endl;
39 
40  // Make random nonsquare matrix A.
41  auto A = Matrix<Number>::random(I,J);
42  Precision alpha = random<Precision>();
43  Precision beta = random<Precision>();
44 
45  // Compare herk_inplace('N') to gemm_inplace(A,'N',A,'H')
46  {
47  auto C1 = Matrix<Number>::random(I,I);
48  for (int i = 0; i < I; ++i)
49  C1(i,i) = std::real(C1(i,i));
50  Matrix<Number> C2 = C1;
51  gemm_inplace(C1,A,'N',A,'H',Number(alpha),Number(beta));
52  herk_inplace(C2,'L',A,'N',alpha,beta);
53  Precision error = frobenius(tril(C1-C2));
54  myra::out() << " |herk('N')-gemm('N','H')| = " << error << std::endl;
55  REQUIRE(error < tolerance);
56  }
57 
58  // Compare herk_inplace('T') to gemm_inplace(A,'T',A,'C')
59  {
60  auto C1 = Matrix<Number>::random(J,J);
61  for (int j = 0; j < J; ++j)
62  C1(j,j) = std::real(C1(j,j));
63  Matrix<Number> C2 = C1;
64  gemm_inplace(C1,A,'T',A,'C',Number(alpha),Number(beta));
65  herk_inplace(C2,'L',A,'T',alpha,beta);
66  Precision error = frobenius(tril(C1-C2));
67  myra::out() << " |herk('T')-gemm('T','C')| = " << error << std::endl;
68  REQUIRE(error < tolerance);
69  }
70 
71  // Compare herk_inplace('H') to gemm_inplace(A,'H',A,'N')
72  {
73  auto C1 = Matrix<Number>::random(J,J);
74  for (int j = 0; j < J; ++j)
75  C1(j,j) = std::real(C1(j,j));
76  Matrix<Number> C2 = C1;
77  gemm_inplace(C1,A,'H',A,'N',Number(alpha),Number(beta));
78  herk_inplace(C2,'L',A,'H',alpha,beta);
79  Precision error = frobenius(tril(C1-C2));
80  myra::out() << " |herk('H')-gemm('H','N')| = " << error << std::endl;
81  REQUIRE(error < tolerance);
82  }
83 
84  // Compare herk_inplace('C') to gemm(A,'C',A,'T')
85  {
86  auto C1 = Matrix<Number>::random(I,I);
87  for (int i = 0; i < I; ++i)
88  C1(i,i) = std::real(C1(i,i));
89  Matrix<Number> C2 = C1;
90  gemm_inplace(C1,A,'C',A,'T',Number(alpha),Number(beta));
91  herk_inplace(C2,'L',A,'C',alpha,beta);
92  Precision error = frobenius(tril(C1-C2));
93  myra::out() << " |herk('C')-gemm('C','T')| = " << error << std::endl;
94  REQUIRE(error < tolerance);
95  }
96 
97  }
98 
99 } // namespace
100 
101 ADD_TEST("cherkL","[dense][blas]")
102  { test<float>(54,37,1.0e-4f); }
103 
104 ADD_TEST("zherkL","[dense][blas]")
105  { test<double>(54,37,1.0e-8); }
106 
Returns a conjugated copy of a Matrix or Vector. Or, conjugate one inplace.
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Routines for hermitian rank-k updates, a specialized form of Matrix*Matrix multiplication.
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
Replaces small values with explicit zeros.
Definition: syntax.dox:1
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
Returns the lower triangle of a dense Matrix.
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<double>
|herk('N')-gemm('N','H')| = 1.97599e-15
|herk('T')-gemm('T','C')| = 2.2676e-15
|herk('H')-gemm('H','N')| = 2.2676e-15
|herk('C')-gemm('C','T')| = 1.97599e-15


Go back to Summary of /test programs.