MyraMath
psymm2


Source: tests/pdense/psymm2.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 
12 // Containers.
14 #include <myramath/dense/Matrix.h>
18 
19 // Serial algorithms.
22 #include <myramath/dense/tril.h>
23 #include <myramath/dense/triu.h>
24 #include <myramath/dense/symm.h>
26 
27 // Parallel algorithms.
28 #include <myramath/pdense/psymm.h>
30 
31 // Reporting.
32 #include <tests/myratest.h>
33 
34 using namespace myra;
35 typedef pdense::Options Options;
36 
37 namespace {
38 
39 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
40  {
41  typedef typename ReflectPrecision<Number>::type Precision;
42  myra::out() << typestring<Number>() << std::endl;
43  // Make random symmetric matrix A.
44  auto A = Matrix<Number>::random(I,I);
45  A = A + transpose(A);
46  Number alpha = random<Number>();
47  Number beta = random<Number>();
48  // Grab A's lower triangle into L.
50  // Initialize options.
51  auto options = Options::create().set_nthreads(4).set_blocksize(128);
52  // Check psymm('L'eft)
53  {
54  auto B = Matrix<Number>::random(I,J);
55  auto C1 = Matrix<Number>::random(I,J);
56  auto C2 = C1;
57  symm_inplace('L', C1, L, B, alpha, beta);
58  psymm_inplace('L', C2, L, B, alpha, beta, options);
59  Precision error = frobenius(C1-C2)/frobenius(C1);
60  myra::out() << " |symm('L')-psymm('L')| = " << error << std::endl;
61  REQUIRE(error < tolerance);
62  }
63  // Check psymm('R'ight)
64  {
65  auto B = Matrix<Number>::random(J,I);
66  auto C1 = Matrix<Number>::random(J,I);
67  auto C2 = C1;
68  symm_inplace('R', C1, L, B, alpha, beta);
69  psymm_inplace('R', C2, L, B, alpha, beta, options);
70  Precision error = frobenius(C1-C2)/frobenius(C1);
71  myra::out() << " |symm('R')-psymm('R')| = " << error << std::endl;
72  REQUIRE(error < tolerance);
73  }
74  }
75 
76 } // namespace
77 
78 ADD_TEST("psymm2","[pdense][parallel]")
79  {
80  int I = 512;
81  int J = 256;
82  test<NumberS> (I,J,1.0e-4f);
83  test<NumberD> (I,J,1.0e-8);
84  test<NumberC> (I,J,1.0e-4f);
85  test<NumberZ> (I,J,1.0e-8);
86  }
Interface class for representing subranges of dense Matrix&#39;s.
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
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.
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.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Routines for symmetric Matrix * dense Matrix multiplication.
Thread-parallel symmetric Matrix * dense Matrix multiplication.


Results: [PASS]

float
|symm('L')-psymm('L')| = 2.40123e-07
|symm('R')-psymm('R')| = 3.21969e-07
double
|symm('L')-psymm('L')| = 3.53979e-16
|symm('R')-psymm('R')| = 4.73187e-16
std::complex<float>
|symm('L')-psymm('L')| = 2.28176e-07
|symm('R')-psymm('R')| = 2.73029e-07
std::complex<double>
|symm('L')-psymm('L')| = 4.08115e-16
|symm('R')-psymm('R')| = 4.92408e-16


Go back to Summary of /test programs.