Ocean
TestSquareMatrix3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_3_H
9 #define META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_3_H
10 
12 
13 #include "ocean/base/Worker.h"
14 
16 #include "ocean/math/Vector4.h"
17 
18 namespace Ocean
19 {
20 
21 namespace Test
22 {
23 
24 namespace TestMath
25 {
26 
27 /**
28  * This class implements a test for 3x3 square matrices.
29  * @ingroup testmath
30  */
31 class OCEAN_TEST_MATH_EXPORT TestSquareMatrix3
32 {
33  public:
34 
35  /**
36  * Tests all square matrix 3x3 functions.
37  * @param testDuration Number of seconds for each test, with range (0, infinity)
38  * @param worker The worker object allowing to distribute computations
39  * @return True, if succeeded
40  */
41  static bool test(const double testDuration, Worker& worker);
42 
43  /**
44  * Tests the messenger function.
45  * @return True, if succeeded
46  */
47  static bool testWriteToMessenger();
48 
49  /**
50  * Tests the element-based constructor.
51  * @param testDuration The number of seconds for each test, with range (0, infinity)
52  * @return True, if succeeded
53  */
54  static bool testElementConstructor(const double testDuration);
55 
56  /**
57  * Tests the quaternion-based constructor.
58  * @param testDuration The number of seconds for each test, with range (0, infinity)
59  * @return True, if succeeded
60  * @tparam T The data type of a scalar values
61  */
62  template <typename T>
63  static bool testQuaternionConstructor(const double testDuration);
64 
65  /**
66  * Tests the 2D vector multiplication operator and function.
67  * @param testDuration The number of seconds for each test, with range (0, infinity)
68  * @return True, if succeeded
69  * @tparam T The data type of a scalar value
70  */
71  template <typename T>
72  static bool testVectorMultiplication2(const double testDuration);
73 
74  /**
75  * Tests the 3D vector multiplication operator.
76  * @param testDuration The number of seconds for each test, with range (0, infinity)
77  * @param worker The worker object allowing to distribute computations
78  * @return True, if succeeded
79  * @tparam T The data type of a scalar value
80  */
81  template <typename T>
82  static bool testVectorMultiplication3(const double testDuration, Worker& worker);
83 
84  /**
85  * Tests the invert functions.
86  * @param testDuration Number of seconds for each test, with range (0, infinity)
87  * @return True, if succeeded
88  */
89  static bool testInvert(const double testDuration);
90 
91  /**
92  * Tests the matrix conversion functions.
93  * @param testDuration Number of seconds for each test, with range (0, infinity)
94  * @return True, if succeeded
95  */
96  static bool testMatrixConversion(const double testDuration);
97 
98  /**
99  * Test for solver of linear systems of equations.
100  * @param testDuration Number of seconds for each test, with range (0, infinity)
101  * @return True, if the test was successful
102  */
103  static bool testSolve(const double testDuration);
104 
105  protected:
106 
107  /**
108  * Standard implementation of a multiplication between a 4x4 matrix and a 4x1 vector.
109  * @param matrix The matrix to be used for multiplication
110  * @param vector The vector to be used for multiplication
111  * @return The multiplication result
112  * @tparam T The data type of the elements
113  */
114  template <typename T>
115  static OCEAN_FORCE_INLINE VectorT3<T> standardVectorMultiplication(const SquareMatrixT3<T>& matrix, const VectorT3<T>& vector);
116 
117  /**
118  * Test for solver of linear systems of equations.
119  * @param containsSignular True, to create test data containing singular matrices
120  * @param testDuration Number of seconds for each test, with range (0, infinity)
121  * @return True, if the test was successful
122  */
123  static bool testSolve(const bool containsSignular, const double testDuration);
124 
125  /**
126  * Gauss algorithm for 3x3 systems of linear equations, Ax = b.
127  * @param A The coefficients matrix
128  * @param b The right-hand side vector
129  * @param x The solution vector
130  * @return True if a solution has been found; False, otherwise (e.g. when A is singular)
131  * @tparam T Data type, can be either float or double
132  */
133  template <typename T>
134  static bool solveGauss(const SquareMatrixT3<T>& A, const VectorT3<T>& b, VectorT3<T>& x);
135 };
136 
137 template <typename T>
139 {
140  return VectorT3<T>(matrix[0] * vector[0] + matrix[3] * vector[1] + matrix[6] * vector[2],
141  matrix[1] * vector[0] + matrix[4] * vector[1] + matrix[7] * vector[2],
142  matrix[2] * vector[0] + matrix[5] * vector[1] + matrix[8] * vector[2]);
143 }
144 
145 }
146 
147 }
148 
149 }
150 
151 #endif // META_OCEAN_TEST_TESTMATH_TEST_SQUARE_MATRIX_3_H
This class implements a 3x3 square matrix.
Definition: SquareMatrix3.h:88
This class implements a test for 3x3 square matrices.
Definition: TestSquareMatrix3.h:32
static bool testSolve(const bool containsSignular, const double testDuration)
Test for solver of linear systems of equations.
static bool solveGauss(const SquareMatrixT3< T > &A, const VectorT3< T > &b, VectorT3< T > &x)
Gauss algorithm for 3x3 systems of linear equations, Ax = b.
static bool testVectorMultiplication3(const double testDuration, Worker &worker)
Tests the 3D vector multiplication operator.
static bool test(const double testDuration, Worker &worker)
Tests all square matrix 3x3 functions.
static bool testVectorMultiplication2(const double testDuration)
Tests the 2D vector multiplication operator and function.
static bool testWriteToMessenger()
Tests the messenger function.
static bool testMatrixConversion(const double testDuration)
Tests the matrix conversion functions.
static OCEAN_FORCE_INLINE VectorT3< T > standardVectorMultiplication(const SquareMatrixT3< T > &matrix, const VectorT3< T > &vector)
Standard implementation of a multiplication between a 4x4 matrix and a 4x1 vector.
Definition: TestSquareMatrix3.h:138
static bool testSolve(const double testDuration)
Test for solver of linear systems of equations.
static bool testInvert(const double testDuration)
Tests the invert functions.
static bool testElementConstructor(const double testDuration)
Tests the element-based constructor.
static bool testQuaternionConstructor(const double testDuration)
Tests the quaternion-based constructor.
This class implements a vector with three elements.
Definition: Vector3.h:97
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15