Ocean
TestLinearAlgebra.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_LINEAR_ALGEBRA_H
9 #define META_OCEAN_TEST_TESTMATH_LINEAR_ALGEBRA_H
10 
12 
14 #include "ocean/math/Matrix.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Test
20 {
21 
22 namespace TestMath
23 {
24 
25 /**
26  * This class implements linear algebra tests.
27  * @ingroup testmath
28  */
29 class OCEAN_TEST_MATH_EXPORT TestLinearAlgebra
30 {
31  public:
32 
33  /**
34  * Tests all linear algebra functions.
35  * @param testDuration Number of seconds for each test, with range (0, infinity)
36  * @return True, if succeeded
37  */
38  static bool test(const double testDuration);
39 
40  /**
41  * Tests the Eigen system of a 3x3 square matrix.
42  * @param testDuration Number of seconds for each test, with range (0, infinity)
43  * @return True, if succeeded
44  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
45  */
46  template <typename T>
47  static bool testEigenSystemSquareMatrix3(const double testDuration);
48 
49  /**
50  * Tests the Eigen system of the matrix.
51  * @param testDuration Number of seconds for each test, with range (0, infinity)
52  * @return True, if succeeded
53  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
54  */
55  template <typename T>
56  static bool testEigenSystemMatrix(const double testDuration);
57 
58  /**
59  * Tests the singular value decomposition of a matrix.
60  * @param testDuration Number of seconds for each test, with range (0, infinity)
61  * @return True, if succeeded
62  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
63  */
64  template <typename T>
65  static bool testSingularValueDecomposition(const double testDuration);
66 
67  /**
68  * Tests the QR decomposition of a matrix.
69  * @param testDuration Number of seconds for each test, with range (0, infinity)
70  * @return True, if succeeded
71  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
72  */
73  template <typename T>
74  static bool testQrDecomposition(const double testDuration);
75 
76  /**
77  * Tests the Cholesky decomposition of a square matrix.
78  * @param testDuration Number of seconds for each test, with range (0, infinity)
79  * @return True, if succeeded
80  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
81  */
82  template <typename T>
83  static bool testCholeskyDecomposition(const double testDuration);
84 
85  /**
86  * Tests solving a system of linear equations.
87  * @param testDuration Number of seconds for each test, with range (0, infinity)
88  * @return True, if succeeded
89  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
90  */
91  template <typename T>
92  static bool testSolve(const double testDuration);
93 
94  private:
95 
96  /**
97  * Tests the singular value decomposition of static and known matrix.
98  * @param testDuration Number of seconds for each test, with range (0, infinity)
99  * @return True, if succeeded
100  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
101  */
102  template <typename T>
103  static bool testSingularValueDecompositionStatic(const double testDuration);
104 
105  /**
106  * Tests the singular value decomposition of dynamic random matrices.
107  * @param testDuration Number of seconds for each test, with range (0, infinity)
108  * @return True, if succeeded
109  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
110  */
111  template <typename T>
112  static bool testSingularValueDecompositionDynamic(const double testDuration);
113 
114  /**
115  * Tests the QR decomposition of static and known matrix.
116  * @param testDuration Number of seconds for each test, with range (0, infinity)
117  * @return True, if succeeded
118  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
119  */
120  template <typename T>
121  static bool testQrDecompositionStatic(const double testDuration);
122 
123  /**
124  * Tests the QR decomposition of dynamic random matrices.
125  * @param testDuration Number of seconds for each test, with range (0, infinity)
126  * @return True, if succeeded
127  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
128  */
129  template <typename T>
130  static bool testQrDecompositionDynamic(const double testDuration);
131 
132  /**
133  * Validates the Eigen system of a static and known 3x3 square matrix.
134  * @param matrix The matrix to test
135  * @param expectedEigenValues The expected Eigen values
136  * @return True, if succeeded
137  * @tparam T The data type of the scalar to use, ether 'float' or 'double'
138  */
139  template <typename T>
140  static bool validateEigenSystem(const SquareMatrixT3<T>& matrix, const VectorT3<T>& expectedEigenValues);
141 
142  /**
143  * Validate singular value decomposition of a matrix M = U * diag(W) * V^T.
144  * @param matrix The matrix M for which the singular value decomposition has been computed
145  * @param uMatrix Matrix U obtained from the SVD
146  * @param wVector Vector W obtained from the SVD holding the singular values of diagonal matrix D
147  * @param vMatrix Matrix V obtained from the SVD
148  * @return True, if succeeded
149  */
150  template <typename T>
151  static bool validateSingularValueDecomposition(const MatrixT<T>& matrix, const MatrixT<T>& uMatrix, const MatrixT<T>& wVector, const MatrixT<T>& vMatrix);
152 };
153 
154 }
155 
156 }
157 
158 }
159 
160 #endif // META_OCEAN_TEST_TESTMATH_LINEAR_ALGEBRA_H
This class implements a matrix with arbitrary size.
Definition: Matrix.h:63
This class implements a 3x3 square matrix.
Definition: SquareMatrix3.h:88
This class implements linear algebra tests.
Definition: TestLinearAlgebra.h:30
static bool testQrDecomposition(const double testDuration)
Tests the QR decomposition of a matrix.
static bool testQrDecompositionDynamic(const double testDuration)
Tests the QR decomposition of dynamic random matrices.
static bool testSingularValueDecompositionStatic(const double testDuration)
Tests the singular value decomposition of static and known matrix.
static bool test(const double testDuration)
Tests all linear algebra functions.
static bool testQrDecompositionStatic(const double testDuration)
Tests the QR decomposition of static and known matrix.
static bool testEigenSystemMatrix(const double testDuration)
Tests the Eigen system of the matrix.
static bool testSolve(const double testDuration)
Tests solving a system of linear equations.
static bool testEigenSystemSquareMatrix3(const double testDuration)
Tests the Eigen system of a 3x3 square matrix.
static bool validateSingularValueDecomposition(const MatrixT< T > &matrix, const MatrixT< T > &uMatrix, const MatrixT< T > &wVector, const MatrixT< T > &vMatrix)
Validate singular value decomposition of a matrix M = U * diag(W) * V^T.
static bool testCholeskyDecomposition(const double testDuration)
Tests the Cholesky decomposition of a square matrix.
static bool testSingularValueDecompositionDynamic(const double testDuration)
Tests the singular value decomposition of dynamic random matrices.
static bool testSingularValueDecomposition(const double testDuration)
Tests the singular value decomposition of a matrix.
static bool validateEigenSystem(const SquareMatrixT3< T > &matrix, const VectorT3< T > &expectedEigenValues)
Validates the Eigen system of a static and known 3x3 square matrix.
This class implements a vector with three elements.
Definition: Vector3.h:97
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15