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