MyraMath
vectorcat_cpp11


Source: tests/dense/vectorcat.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/Vector.h>
16 
17 // Algorithms.
20 
21 // Reporting.
22 #include <tests/myratest.h>
23 
24 using namespace myra;
25 
26 namespace {
27 
28 // Test vectorcat(a,b)
29 template<class Number> void test1(typename ReflectPrecision<Number>::type tolerance)
30  {
31  typedef typename ReflectPrecision<Number>::type Precision;
32  auto a = Vector<Number>::random(6);
33  auto b = vectorcat( a.first(2), a.last(4) );
34  Precision error = euclidean(a-b);
35  myra::out() << " |a - vectorcat(a,a)| = " << error << std::endl;
36  REQUIRE(error < tolerance);
37  }
38 
39 #ifdef MYRAMATH_ENABLE_CPP11
40 
41 // Test vectorcat({a,b,c})
42 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
43  {
44  typedef typename ReflectPrecision<Number>::type Precision;
45  auto a = Vector<NumberS>::random(7);
46  auto b = vectorcat( a.add_const().windows({2,3,2}) );
47  Precision error = euclidean(a-b);
48  myra::out() << " |a - vectorcat(...)| = " << error << std::endl;
49  REQUIRE(error < tolerance);
50  }
51 
52 #endif
53 
54 } // namespace
55 
56 ADD_TEST("vectorcat","[dense]")
57  {
58  test1<NumberS>(1.0e-5f);
59  test1<NumberD>(1.0e-10);
60  test1<NumberC>(1.0e-5f);
61  test1<NumberZ>(1.0e-10);
62  }
63 
64 #ifdef MYRAMATH_ENABLE_CPP11
65 
66 ADD_TEST("vectorcat_cpp11","[dense]")
67  {
68  test2<NumberS>(1.0e-5f);
69  test2<NumberD>(1.0e-10);
70  test2<NumberC>(1.0e-5f);
71  test2<NumberZ>(1.0e-10);
72  }
73 
74 #endif
75 
Routines to concatenate Vector&#39;s.
Routines for computing euclidean norm of a Vector/VectorRange, or normalizing a Vector/VectorRange to...
Container of values, allows random (i) access.
Interface class for representing subranges of dense Vector&#39;s.
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Definition: syntax.dox:1
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
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

|a - vectorcat(...)| = 0
|a - vectorcat(...)| = 0
|a - vectorcat(...)| = 0
|a - vectorcat(...)| = 0


Go back to Summary of /test programs.