MyraMath
dqrt


Source: tests/dense/qrt.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>
15 
16 // Algorithms.
17 #include <myramath/dense/qrt.h>
18 #include <myramath/dense/gemm.h>
19 #include <myramath/dense/trmm.h>
20 #include <myramath/dense/geqrf.h>
21 #include <myramath/dense/ormqr.h>
24 
25 // Reporting.
26 #include <tests/myratest.h>
27 
28 using namespace myra;
29 
30 namespace {
31 
32 // Tests qrt() on a tall/skinny A.
33 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
34  {
35  // Useful typedefs/constants.
36  typedef typename ReflectPrecision<Number>::type Precision;
37  Number one(1);
38  int K = I < J ? I : J;
39  myra::out() << typestring<Number>() << std::endl;
40  // Form random A/B, factor A=QR, form T in triu(A)
41  auto A = Matrix<Number>::random(I,J);
42  auto B1 = Matrix<Number>::random(I,J);
43  auto B2 = B1;
44  auto tau = geqrf_inplace(A);
45  qrt_inplace(A,tau);
46  // Apply scalar reflections, B1 = (I-tau*v*v')*B1, using ormqr_inplace() ..
47  ormqr_inplace(A,tau,B1,'L','N');
48  // Apply block reflection, B2 = (I-V*T*V')*B2, using qrt() ..
49  // .. partition V and B.
50  auto VtVb = A.split_top(K);
51  auto Vt = VtVb.first;
52  auto Vb = VtVb.second;
53  auto BtBb = B2.split_top(K);
54  auto Bt = BtBb.first;
55  auto Bb = BtBb.second;
56  // .. form W = V'*B
57  Matrix<Number> W(Bt);
58  trmm_inplace('L','L','H',Vt,W,'U');
59  gemm_inplace(W,Vb,'H',Bb,'N',one,one);
60  // .. update W = T*W
61  trmm_inplace('L','U','N',Vt,W,'N',one);
62  // .. update B -= V*W
63  gemm_inplace(Bb,Vb,'N',W,'N',-one,one);
64  trmm_inplace('L','L','N',Vt,W,'U');
65  Bt -= W;
66  // Check answers.
67  Precision error = frobenius(B1-B2) / frobenius(B1);
68  myra::out() << "|Q*B1(ormqr) - Q*B2(qrt)| = " << error << std::endl;
69  REQUIRE(error < tolerance);
70  }
71 
72 } // namespace
73 
74 ADD_TEST("sqrt","[dense][lapack]")
75  { test<NumberS>(178,159,1.0e-4f); }
76 
77 ADD_TEST("dqrt","[dense][lapack]")
78  { test<NumberD>(178,159,1.0e-10); }
79 
80 ADD_TEST("cqrt","[dense][lapack]")
81  { test<NumberC>(178,159,1.0e-4f); }
82 
83 ADD_TEST("zqrt","[dense][lapack]")
84  { test<NumberZ>(178,159,1.0e-10); }
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
CPair split_top(int i) const
Splits by rows, returns [this->top(i), this->cut_top(i)].
Definition: Matrix.cpp:219
Routines to compute a Householder QR decomposition.
Definition: syntax.dox:1
Routines for multiplying by a triangular Matrix or LowerMatrix.
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
Routines to apply a Householder Q, as previously factored via geqrf_inplace()
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
Given the scalar reflectors [V,tau] from geqrf(), forms the T of the equivalent block reflector I-V*T...
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

double
|Q*B1(ormqr) - Q*B2(qrt)| = 1.36386e-15


Go back to Summary of /test programs.