MyraMath
psymm1


Source: tests/pdense/psymm1.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 // Serial algorithms.
19 #include <myramath/dense/tril.h>
20 #include <myramath/dense/triu.h>
21 #include <myramath/dense/symm.h>
23 
24 // Parallel algorithms.
25 #include <myramath/pdense/psymm.h>
27 
28 // Reporting.
29 #include <tests/myratest.h>
30 
31 using namespace myra;
32 typedef pdense::Options Options;
33 
34 namespace {
35 
36 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
37  {
38  typedef typename ReflectPrecision<Number>::type Precision;
39  myra::out() << typestring<Number>() << std::endl;
40  // Make random symmetric matrix A.
41  auto A = Matrix<Number>::random(I,I);
42  A = A + transpose(A);
43  Number alpha = random<Number>();
44  Number beta = random<Number>();
45  // Make upper/lower triangles of it.
46  Matrix<Number> L = tril(A);
47  Matrix<Number> U = triu(A);
48  // Initialize options.
49  auto options = Options::create().set_nthreads(4).set_blocksize(128);
50  // Check psymm('L','L')
51  {
52  auto B = Matrix<Number>::random(I,J);
53  auto C1 = Matrix<Number>::random(I,J);
54  auto C2 = C1;
55  symm_inplace('L', 'L', C1, L, B, alpha, beta);
56  psymm_inplace('L', 'L', C2, L, B, alpha, beta, options);
57  Precision error = frobenius(C1-C2)/frobenius(C1);
58  myra::out() << " |symm('L','L')-psymm('L','L')| = " << error << std::endl;
59  REQUIRE(error < tolerance);
60  }
61  // Check psymm('L','U')
62  {
63  auto B = Matrix<Number>::random(I,J);
64  auto C1 = Matrix<Number>::random(I,J);
65  auto C2 = C1;
66  symm_inplace('L', 'U', C1, U, B, alpha, beta);
67  psymm_inplace('L', 'U', C2, U, B, alpha, beta, options);
68  Precision error = frobenius(C1-C2)/frobenius(C1);
69  myra::out() << " |symm('L','U')-psymm('L','U')| = " << error << std::endl;
70  REQUIRE(error < tolerance);
71  }
72  // Check psymm('R','L')
73  {
74  auto B = Matrix<Number>::random(J,I);
75  auto C1 = Matrix<Number>::random(J,I);
76  auto C2 = C1;
77  symm_inplace('R', 'L', C1, L, B, alpha, beta);
78  psymm_inplace('R', 'L', C2, L, B, alpha, beta, options);
79  Precision error = frobenius(C1-C2)/frobenius(C1);
80  myra::out() << " |symm('R','L')-psymm('R','L')| = " << error << std::endl;
81  REQUIRE(error < tolerance);
82  }
83  // Check psymm('R','U')
84  {
85  auto B = Matrix<Number>::random(J,I);
86  auto C1 = Matrix<Number>::random(J,I);
87  auto C2 = C1;
88  symm_inplace('R', 'U', C1, U, B, alpha, beta);
89  psymm_inplace('R', 'U', C2, U, B, alpha, beta, options);
90  Precision error = frobenius(C1-C2)/frobenius(C1);
91  myra::out() << " |symm('R','U')-psymm('R','U')| = " << error << std::endl;
92  REQUIRE(error < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("psymm1","[pdense][parallel]")
99  {
100  int I = 512;
101  int J = 256;
102  test<NumberS> (I,J,1.0e-4f);
103  test<NumberD> (I,J,1.0e-8);
104  test<NumberC> (I,J,1.0e-4f);
105  test<NumberZ> (I,J,1.0e-8);
106  }
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
Options pack for routines in /pdense.
Definition: Options.h:24
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.
Options pack for routines in /pdense.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Simplistic random number functions.
Routines for symmetric Matrix * dense Matrix multiplication.
Thread-parallel symmetric Matrix * dense Matrix multiplication.


Results: [PASS]

float
|symm('L','L')-psymm('L','L')| = 2.58582e-07
|symm('L','U')-psymm('L','U')| = 3.31749e-07
|symm('R','L')-psymm('R','L')| = 3.79184e-07
|symm('R','U')-psymm('R','U')| = 3.78143e-07
double
|symm('L','L')-psymm('L','L')| = 4.82599e-16
|symm('L','U')-psymm('L','U')| = 6.09224e-16
|symm('R','L')-psymm('R','L')| = 7.00946e-16
|symm('R','U')-psymm('R','U')| = 6.97612e-16
std::complex<float>
|symm('L','L')-psymm('L','L')| = 2.99332e-07
|symm('L','U')-psymm('L','U')| = 3.5593e-07
|symm('R','L')-psymm('R','L')| = 4.04806e-07
|symm('R','U')-psymm('R','U')| = 4.05293e-07
std::complex<double>
|symm('L','L')-psymm('L','L')| = 5.51966e-16
|symm('L','U')-psymm('L','U')| = 6.58328e-16
|symm('R','L')-psymm('R','L')| = 7.21684e-16
|symm('R','U')-psymm('R','U')| = 7.19744e-16


Go back to Summary of /test programs.