MCPcopy Create free account
hub / github.com/avaxman/Directional / basicStuff

Function basicStuff

external/eigen/test/basicstuff.cpp:24–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22check_index(const MatrixType& /*unused*/) {}
23
24template<typename MatrixType> void basicStuff(const MatrixType& m)
25{
26 typedef typename MatrixType::Scalar Scalar;
27 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
28 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
29
30 Index rows = m.rows();
31 Index cols = m.cols();
32
33 // this test relies a lot on Random.h, and there's not much more that we can do
34 // to test it, hence I consider that we will have tested Random.h
35 MatrixType m1 = MatrixType::Random(rows, cols),
36 m2 = MatrixType::Random(rows, cols),
37 m3(rows, cols),
38 mzero = MatrixType::Zero(rows, cols),
39 square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows);
40 VectorType v1 = VectorType::Random(rows),
41 vzero = VectorType::Zero(rows);
42 SquareMatrixType sm1 = SquareMatrixType::Random(rows,rows), sm2(rows,rows);
43
44 Scalar x = 0;
45 while(x == Scalar(0)) x = internal::random<Scalar>();
46
47 Index r = internal::random<Index>(0, rows-1),
48 c = internal::random<Index>(0, cols-1);
49
50 m1.coeffRef(r,c) = x;
51 VERIFY_IS_APPROX(x, m1.coeff(r,c));
52 m1(r,c) = x;
53 VERIFY_IS_APPROX(x, m1(r,c));
54 v1.coeffRef(r) = x;
55 VERIFY_IS_APPROX(x, v1.coeff(r));
56 v1(r) = x;
57 VERIFY_IS_APPROX(x, v1(r));
58 v1[r] = x;
59 VERIFY_IS_APPROX(x, v1[r]);
60
61 // test fetching with various index types.
62 Index r1 = internal::random<Index>(0, numext::mini(Index(127),rows-1));
63 x = v1(static_cast<char>(r1));
64 x = v1(static_cast<signed char>(r1));
65 x = v1(static_cast<unsigned char>(r1));
66 x = v1(static_cast<signed short>(r1));
67 x = v1(static_cast<unsigned short>(r1));
68 x = v1(static_cast<signed int>(r1));
69 x = v1(static_cast<unsigned int>(r1));
70 x = v1(static_cast<signed long>(r1));
71 x = v1(static_cast<unsigned long>(r1));
72 if(sizeof(Index) >= sizeof(long long int))
73 x = v1(static_cast<long long int>(r1));
74 if(sizeof(Index) >= sizeof(unsigned long long int))
75 x = v1(static_cast<unsigned long long int>(r1));
76
77 VERIFY_IS_APPROX( v1, v1);
78 VERIFY_IS_NOT_APPROX( v1, 2*v1);
79 VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1);
80 VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1.squaredNorm());
81 VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1, v1);

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 15

miniFunction · 0.85
check_indexFunction · 0.85
realMethod · 0.80
noaliasMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
coeffRefMethod · 0.45
coeffMethod · 0.45
squaredNormMethod · 0.45
colMethod · 0.45
evalMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected