MyraMath
dher2kLower


Source: tests/dense/her2k3.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/her2k.h>
25 #include <myramath/dense/tril.h>
26 #include <myramath/dense/triu.h>
27 
28 // Reporting.
29 #include <tests/myratest.h>
30 
31 using namespace myra;
32 
33 namespace {
34 
35 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
36  {
37  // Useful typedef.
38  typedef typename ReflectPrecision<Number>::type Precision;
39  myra::out() << typestring<Number>() << std::endl;
40  // Make random nonsquare matrix A and B.
41  auto A = Matrix<Number>::random(I,J);
42  auto B = Matrix<Number>::random(I,J);
43  Number alpha = random<Number>();
44  Precision beta = random<Precision>();
45  Number one(1);
46  // Compare her2k('N') to gemm(A,'N',B,'H')+gemm(B,'N',A,'H')
47  {
48  auto C1 = Matrix<Number>::random(I,I);
49  C1 = C1 + hermitian(C1);
50  LowerMatrix<Number> C2(C1);
51  gemm_inplace(C1,A,'N',B,'H',alpha,beta);
52  gemm_inplace(C1,B,'N',A,'H',conjugate(alpha),one);
53  her2k_inplace(C2,A,B,'N',alpha,beta);
54  Precision error = frobenius(C2.make_Matrix('H')-C1);
55  myra::out() << " |her2k('N')-gemm('N','H')| = " << error << std::endl;
56  REQUIRE(error < tolerance);
57  }
58  // Compare her2k('T') to gemm(A,'T',B,'C')+gemm(B,'T',A,'C')
59  {
60  auto C1 = Matrix<Number>::random(J,J);
61  C1 = C1 + hermitian(C1);
62  LowerMatrix<Number> C2(C1);
63  gemm_inplace(C1,A,'T',B,'C',alpha,beta);
64  gemm_inplace(C1,B,'T',A,'C',conjugate(alpha),one);
65  her2k_inplace(C2,A,B,'T',alpha,beta);
66  Precision error = frobenius(C2.make_Matrix('H')-C1);
67  myra::out() << " |her2k('T')-gemm('T','C')| = " << error << std::endl;
68  REQUIRE(error < tolerance);
69  }
70  // Compare her2k('H') to gemm(A,'H',B,'N')+gemm(B,'H',A,'N')
71  {
72  auto C1 = Matrix<Number>::random(J,J);
73  C1 = C1 + hermitian(C1);
74  LowerMatrix<Number> C2(C1);
75  gemm_inplace(C1,A,'H',B,'N',alpha,beta);
76  gemm_inplace(C1,B,'H',A,'N',conjugate(alpha),one);
77  her2k_inplace(C2,A,B,'H',alpha,beta);
78  Precision error = frobenius(C2.make_Matrix('H')-C1);
79  myra::out() << " |her2k('H')-gemm('H','N')| = " << error << std::endl;
80  REQUIRE(error < tolerance);
81  }
82  // Compare her2k('C') to gemm(A,'C',B,'T')+gemm(B,'C',A,'T')
83  {
84  auto C1 = Matrix<Number>::random(I,I);
85  C1 = C1 + hermitian(C1);
86  LowerMatrix<Number> C2(C1);
87  gemm_inplace(C1,A,'C',B,'T',alpha,beta);
88  gemm_inplace(C1,B,'C',A,'T',conjugate(alpha),one);
89  her2k_inplace(C2,A,B,'C',alpha,beta);
90  Precision error = frobenius(C2.make_Matrix('H')-C1);
91  myra::out() << " |her2k('C')-gemm('C','T')| = " << error << std::endl;
92  REQUIRE(error < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("sher2kLower","[dense][blas]")
99  { test<NumberS>(57,24,1.0e-4f); }
100 
101 ADD_TEST("dher2kLower","[dense][blas]")
102  { test<NumberD>(57,24,1.0e-8); }
103 
104 ADD_TEST("cher2kLower","[dense][blas]")
105  { test<NumberC>(57,24,1.0e-4f); }
106 
107 ADD_TEST("zher2kLower","[dense][blas]")
108  { test<NumberZ>(57,24,1.0e-8); }
109 
Returns a conjugated copy of a Matrix or Vector. Or, conjugate one inplace.
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 rank-2k updates, a specialized form of Matrix*Matrix multiplication.
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.
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.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
Simplistic random number functions.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

double
|her2k('N')-gemm('N','H')| = 7.15325e-15
|her2k('T')-gemm('T','C')| = 4.8503e-15
|her2k('H')-gemm('H','N')| = 4.98993e-15
|her2k('C')-gemm('C','T')| = 7.15488e-15


Go back to Summary of /test programs.