MyraMath
zgesvd_tallskinny


Source: tests/dense/gesvd.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/gesvd.h>
21 #include <myramath/dense/dimm.h>
22 #include <myramath/dense/gemm.h>
24 
25 // Reporting.
26 #include <tests/myratest.h>
27 
28 using namespace myra;
29 
30 namespace {
31 
32 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
33  {
34  myra::out() << typestring<Number>() << std::endl;
35  typedef typename ReflectPrecision<Number>::type Precision;
36  // Construct random input.
37  auto A = Matrix<Number>::random(I,J);
38  int K = I < J ? I : J;
39  // Perform SVD and grab references to components.
40  auto USV = gesvd(A);
41  const auto& U = USV.U;
42  const auto& S = USV.S;
43  const auto& V = USV.V;
44  // Check U*S*V-A
45  Precision decomposition_error = frobenius(U*S*V-A);
46  myra::out() << " |U*S*V-A| = " << decomposition_error << std::endl;
47  REQUIRE(decomposition_error < tolerance);
48  // Check orthogonality of U
49  Precision unitary_u = frobenius( gemm(U,'H',U) - Matrix<Number>::identity(K) );
50  myra::out() << " |U'U-I| = " << unitary_u << std::endl;
51  REQUIRE(unitary_u < tolerance);
52  // Check orthogonality of V.
53  Precision unitary_v = frobenius( gemm(V,V,'H') - Matrix<Number>::identity(K) );
54  myra::out() << " |VV'-I| = " << unitary_v << std::endl;
55  REQUIRE(unitary_u < tolerance);
56  }
57 
58 } // namespace
59 
60 // Tall-skinny tests.
61 ADD_TEST("sgesvd_tallskinny","[dense][lapack]")
62  { test<NumberS>(47,23,1.0e-4f); }
63 
64 ADD_TEST("dgesvd_tallskinny","[dense][lapack]")
65  { test<NumberD>(47,23,1.0e-12); }
66 
67 ADD_TEST("cgesvd_tallskinny","[dense][lapack]")
68  { test<NumberC>(47,23,1.0e-4f); }
69 
70 ADD_TEST("zgesvd_tallskinny","[dense][lapack]")
71  { test<NumberZ>(47,23,1.0e-12); }
72 
73 // Short-fat tests.
74 ADD_TEST("sgesvd_shortfat","[dense][lapack]")
75  { test<NumberS>(13,33,1.0e-4f); }
76 
77 ADD_TEST("dgesvd_shortfat","[dense][lapack]")
78  { test<NumberD>(13,33,1.0e-12); }
79 
80 ADD_TEST("cgesvd_shortfat","[dense][lapack]")
81  { test<NumberC>(13,33,1.0e-4f); }
82 
83 ADD_TEST("zgesvd_shortfat","[dense][lapack]")
84  { test<NumberZ>(13,33,1.0e-12); }
85 
86 // Square tests.
87 ADD_TEST("sgesvd_square","[dense][lapack]")
88  { test<NumberS>(25,25,1.0e-4f); }
89 
90 ADD_TEST("dgesvd_square","[dense][lapack]")
91  { test<NumberD>(25,25,1.0e-12); }
92 
93 ADD_TEST("cgesvd_square","[dense][lapack]")
94  { test<NumberC>(25,25,1.0e-4f); }
95 
96 ADD_TEST("zgesvd_square","[dense][lapack]")
97  { test<NumberZ>(25,25,1.0e-12); }
98 
99 // Stress tests.
100 ADD_TEST("sgesvd_stress","[dense][lapack][.]")
101  {
102  int T = 100;
103  for (int t = 0; t < T; ++t)
104  test<NumberS>( random_int(1,50), random_int(1,50), 1.0e-4f );
105  }
106 
107 ADD_TEST("dgesvd_stress","[dense][lapack][.]")
108  {
109  int T = 100;
110  for (int t = 0; t < T; ++t)
111  test<NumberD>( random_int(1,50), random_int(1,50), 1.0e-12 );
112  }
113 
114 ADD_TEST("cgesvd_stress","[dense][lapack][.]")
115  {
116  int T = 100;
117  for (int t = 0; t < T; ++t)
118  test<NumberC>( random_int(1,50), random_int(1,50), 1.0e-4f );
119  }
120 
121 ADD_TEST("zgesvd_stress","[dense][lapack][.]")
122  {
123  int T = 100;
124  for (int t = 0; t < T; ++t)
125  test<NumberZ>( random_int(1,50), random_int(1,50), 1.0e-12 );
126  }
127 
Interface class for representing subranges of DiagonalMatrix&#39;s.
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
Routines for multiplying by a DiagonalMatrix.
Definition: syntax.dox:1
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 for computing singular value decompositions.
Simplistic random number functions.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

std::complex<double>
|U*S*V-A| = 1.32584e-13
|U'U-I| = 7.33825e-15
|VV'-I| = 7.26709e-15


Go back to Summary of /test programs.