18 #include <tests/myratest.h> 22 #ifdef MYRAMATH_ENABLE_CPP11 24 ADD_TEST(
"expr_arithmetic",
"[expression]")
27 auto E = expr({1.0,2.0,3.0});
29 REQUIRE( frobenius( (E+E) - expr({2.0,4.0,6.0}) ) < tol );
30 REQUIRE( frobenius( (E+2.0) - expr({3.0,4.0,5.0}) ) < tol );
31 REQUIRE( frobenius( (3.0+E) - expr({4.0,5.0,6.0}) ) < tol );
33 REQUIRE( frobenius( (E-E) - expr({0.0,0.0,0.0}) ) < tol );
34 REQUIRE( frobenius( (E-2.0) - expr({-1.0,0.0,1.0}) ) < tol );
35 REQUIRE( frobenius( (3.0-E) - expr({2.0,1.0,0.0}) ) < tol );
37 REQUIRE( frobenius( (E*E) - expr({1.0,4.0,9.0}) ) < tol );
38 REQUIRE( frobenius( (E*2.0) - expr({2.0,4.0,6.0}) ) < tol );
39 REQUIRE( frobenius( (3.0*E) - expr({3.0,6.0,9.0}) ) < tol );
41 REQUIRE( frobenius( (E/E) - expr({1.0,1.0,1.0}) ) < tol );
42 REQUIRE( frobenius( (E/2.0) - expr({0.5,1.0,1.5}) ) < tol );
43 REQUIRE( frobenius( (3.0/E) - expr({3.0,1.5,1.0}) ) < tol );
45 REQUIRE( frobenius( (-E) - expr({-1.0,-2.0,-3.0}) ) < tol );
48 ADD_TEST(
"expr_tensor",
"[expression]")
51 std::vector<double> v1({1.0,2.0,3.0});
52 std::vector<double> v2({4.0,5.0,6.0});
53 auto E = expr(v1) ^ expr(v2);
54 for (
int i = 0; i < 3; ++i)
55 for (
int j = 0; j < 3; ++j)
56 REQUIRE( std::abs(E.evaluate({i,j})-v1[i]*v2[j]) < tol );
Overloads expr() for std::vector<Number> and (C++11 only) std::initializer_list<Number> ...
An interface used to fill containers from Expression's (see Matrix::evaluate(), for example)...
Arithmetic operators (+,-,*,/) for Expression's.
Routines for computing Frobenius norms of Expression's.