MyraMath
drotate1


Source: tests/dense/rotate1.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>
14 #include <myramath/dense/Vector.h>
17 
18 // Algorithms.
19 #include <myramath/dense/gemv.h>
20 #include <myramath/dense/gemm.h>
21 #include <myramath/dense/rotate.h>
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 template<class Number> void test(typename ReflectPrecision<Number>::type tolerance)
32  {
33  // Form random vector x, then compute a givens1() rotation to zero x(1).
34  typedef typename ReflectPrecision<Number>::type Precision;
35  auto x = Vector<Number>::random(2);
36  std::pair<Number,Number> cs = rotate1(x(0),x(1));
37  Number c = cs.first;
38  Number s = cs.second;
39  // Form G = [c s; -s' c], apply rotation y=G*x.
40  auto G = Matrix<Number>::fill_rmajor(2,2, {c,s,-conjugate(s),c});
41  auto I = Matrix<Number>::identity(2);
42  auto y = G*x;
43  // Verify G'G is identity.
44  Precision G_error = frobenius(gemm(G,'H',G)-I);
45  myra::out() << "|G'G-I| = " << G_error << std::endl;
46  REQUIRE(G_error < tolerance);
47  // Verify y(1) is zero.
48  Precision y_error = scalar_norm1(y(1));
49  myra::out() << "|(G*x)(1)| = " << y_error << std::endl;
50  REQUIRE(y_error < tolerance);
51  }
52 
53 } // namespace
54 
55 ADD_TEST("srotate1","[dense][lapack]")
56  { test<NumberS>(1.0e-5f); }
57 
58 ADD_TEST("drotate1","[dense][lapack]")
59  { test<NumberD>(1.0e-10); }
60 
61 ADD_TEST("crotate1","[dense][lapack]")
62  { test<NumberC>(1.0e-5f); }
63 
64 ADD_TEST("zrotate1","[dense][lapack]")
65  { test<NumberZ>(1.0e-10); }
66 
Interface class for representing subranges of dense Matrix&#39;s.
Interface class for representing subranges of dense Vector&#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.
Variety of routines all for dense Matrix*Vector multiplies. All just delegate to gemm() ...
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Definition: syntax.dox:1
Various utility functions/classes related to scalar Number types.
static Matrix< Number > identity(int IJ)
Generates an identity Matrix of specified size.
Definition: Matrix.cpp:349
General purpose dense matrix container, O(i*j) storage.
Container for either a column vector or row vector (depends upon the usage context) ...
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Computes a plane rotation, either single sided (rotate1) or double sided (rotate2).


Results: [PASS]

|G'G-I| = 1.58456e-16
|(G*x)(1)| = 5.24662e-17


Go back to Summary of /test programs.