MyraMath
ctrsmLower


Source: tests/dense/trsm3.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>
17 
18 // Algorithms.
20 #include <myramath/dense/potrf.h>
21 #include <myramath/dense/tril.h>
22 #include <myramath/dense/gemm.h>
23 #include <myramath/dense/trsm.h>
28 
29 // Reporting.
30 #include <tests/myratest.h>
31 
32 using namespace myra;
33 
34 namespace {
35 
36 template<class Number> void test(typename ReflectPrecision<Number>::type tolerance)
37  {
38  typedef typename ReflectPrecision<Number>::type Precision;
39  myra::out() << typestring<Number>() << std::endl;
40  int I = 27;
41  int J = 34;
42  // Compute the cholesky triangle of a random SPD matrix to get a suitably conditioned L.
43  auto G = Matrix<Number>::random(I,I);
44  Matrix<Number> A = G * hermitian(G);
45  potrf_inplace('L','R',A);
46  A = tril(A);
48  char diag = 'N';
49  Number alpha = random<Number>();
50  Number one(1);
51  // Case 1: solving L*X=B
52  {
53  auto X = Matrix<Number>::random(I,J);
54  Matrix<Number> B = (one/alpha)*A*X;
55  trsm_inplace('L','N',L,B,diag,alpha);
56  Precision error = frobenius(B-X);
57  myra::out() << " |L\\B-X| = " << error << std::endl;
58  REQUIRE(error < tolerance);
59  }
60  // Case 2: solving transpose(L)*X = B
61  {
62  auto X = Matrix<Number>::random(I,J);
63  Matrix<Number> B = (one/alpha)*transpose(A)*X;
64  trsm_inplace('L','T',L,B,diag,alpha);
65  Precision error = frobenius(B-X);
66  myra::out() << " |transpose(L)\\B-X| = " << error << std::endl;
67  REQUIRE(error < tolerance);
68  }
69  // Case 3: solving hermitian(L)*X = B
70  {
71  auto X = Matrix<Number>::random(I,J);
72  Matrix<Number> B = (one/alpha)*hermitian(A)*X;
73  trsm_inplace('L','H',L,B,diag,alpha);
74  Precision error = frobenius(B-X);
75  myra::out() << " |hermitian(L)\\B-X| = " << error << std::endl;
76  REQUIRE(error < tolerance);
77  }
78  // Case 4: solving conjugate(L)*X = B
79  {
80  auto X = Matrix<Number>::random(I,J);
81  Matrix<Number> B = (one/alpha)*conjugate(A)*X;
82  trsm_inplace('L','C',L,B,diag,alpha);
83  Precision error = frobenius(B-X);
84  myra::out() << " |conjugate(L)\\B-X| = " << error << std::endl;
85  REQUIRE(error < tolerance);
86  }
87  // Case 5: solving X*L = B
88  {
89  auto X = Matrix<Number>::random(J,I);
90  Matrix<Number> B = (one/alpha)*X*A;
91  trsm_inplace('R','N',L,B,diag,alpha);
92  Precision error = frobenius(B-X);
93  myra::out() << " |B/L-X| = " << error << std::endl;
94  REQUIRE(error < tolerance);
95  }
96  // Case 6: solving X*transpose(L) = B
97  {
98  auto X = Matrix<Number>::random(J,I);
99  Matrix<Number> B = (one/alpha)*X*transpose(A);
100  trsm_inplace('R','T',L,B,diag,alpha);
101  Precision error = frobenius(B-X);
102  myra::out() << " |B/transpose(L)-X| = " << error << std::endl;
103  REQUIRE(error < tolerance);
104  }
105  // Case 7: solving X*hermitian(L) = B
106  {
107  auto X = Matrix<Number>::random(J,I);
108  Matrix<Number> B = (one/alpha)*X*hermitian(A);
109  trsm_inplace('R','H',L,B,diag,alpha);
110  Precision error = frobenius(B-X);
111  myra::out() << " |B/hermitian(L)-X| = " << error << std::endl;
112  REQUIRE(error < tolerance);
113  }
114  // Case 8: solving X*conjugate(L) = B
115  {
116  auto X = Matrix<Number>::random(J,I);
117  Matrix<Number> B = (one/alpha)*X*conjugate(A);
118  trsm_inplace('R','C',L,B,diag,alpha);
119  Precision error = frobenius(B-X);
120  myra::out() << " |B/conjugate(L)-X| = " << error << std::endl;
121  REQUIRE(error < tolerance);
122  }
123  }
124 
125 } // namespace
126 
127 ADD_TEST("strsmLower","[dense][lapack]")
128  { test<NumberS>(1.0e-2f); }
129 
130 ADD_TEST("dtrsmLower","[dense][lapack]")
131  { test<NumberD>(1.0e-10); }
132 
133 ADD_TEST("ctrsmLower","[dense][lapack]")
134  { test<NumberC>(1.0e-2f); }
135 
136 ADD_TEST("ztrsmLower","[dense][lapack]")
137  { test<NumberZ>(1.0e-10); }
Returns a conjugated copy of a Matrix or Vector. Or, conjugate one inplace.
Cholesky factorization routines for positive definite matrices.
Interface class for representing subranges of dense Matrix&#39;s.
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
Routines for backsolving by a triangular Matrix or LowerMatrix.
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
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]

std::complex<float>
|L\B-X| = 2.5539e-05
|transpose(L)\B-X| = 5.80269e-06
|hermitian(L)\B-X| = 5.66601e-06
|conjugate(L)\B-X| = 2.53304e-05
|B/L-X| = 6.02365e-06
|B/transpose(L)-X| = 2.33278e-05
|B/hermitian(L)-X| = 2.41674e-05
|B/conjugate(L)-X| = 5.51361e-06


Go back to Summary of /test programs.