MyraMath
convert_czc


Source: tests/dense/convert.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.
20 
21 // Reporting.
22 #include <tests/myratest.h>
23 
24 using namespace myra;
25 
26 ADD_TEST("convert_sds","[dense]")
27  {
28  // Verify that you can convert real float->double->float, without loss.
29  int I = 10;
30  int J = 12;
31  auto S1 = Matrix<NumberS>::random(I,J);
32  auto S2 = lower_precision(raise_precision(S1));
33  NumberS S_error = frobenius(S1-S2);
34  myra::out() << " |S - float(double(S))| = " << S_error << std::endl;
35  REQUIRE(S_error == 0.0f);
36  }
37 
38 ADD_TEST("convert_czc","[dense]")
39  {
40  // Verify that you can convert complex float->double->float, without loss.
41  int I = 10;
42  int J = 12;
43  auto C1 = Matrix<NumberC>::random(I,J);
44  auto C2 = lower_precision(raise_precision(C1));
45  NumberS C_error = frobenius(C1-C2);
46  myra::out() << " |C - float(double(C))| = " << C_error << std::endl;
47  REQUIRE(C_error == 0.0f);
48  }
49 
50 ADD_TEST("convert_dsd","[dense]")
51  {
52  // Converting a real double->float->double implies some loss.
53  int I = 10;
54  int J = 12;
55  auto D1 = Matrix<NumberD>::random(I,J);
56  auto D2 = raise_precision(lower_precision(D1));
57  NumberD D_error = frobenius(D1-D2);
58  myra::out() << " |D - double(float(D))| = " << D_error << std::endl;
59  REQUIRE(D_error < 1.0e-6);
60  }
61 
62 ADD_TEST("convert_zcz","[dense]")
63  {
64  // Converting a complex double->float->double implies some loss.
65  int I = 10;
66  int J = 12;
67  auto Z1 = Matrix<NumberZ>::random(I,J);
68  auto Z2 = raise_precision(lower_precision(Z1));
69  NumberD Z_error = frobenius(Z1-Z2);
70  myra::out() << " |Z - double(float(Z))| = " << Z_error << std::endl;
71  REQUIRE(Z_error < 1.0e-6);
72  }
73 
Interface class for representing subranges of dense Matrix&#39;s.
Routines for copying and lowering the precision of a container.
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
Definition: syntax.dox:1
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Routines for copying and raising the precision of a container.
float NumberS
Useful typedefs.
Definition: Number.h:21


Results: [PASS]

|C - float(double(C))| = 0


Go back to Summary of /test programs.