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