Added an SVD passthrough to matrix.cpp
Merge-Checker / build_and_test (pull_request) Failing after 20m35s
Merge-Checker / build_and_test (pull_request) Failing after 20m35s
This commit is contained in:
@@ -20,6 +20,20 @@ void EigenQR(Matrix<N, N> &matrixToDecompose, Matrix<N, N> &eigenVectors,
|
||||
#include "QR.hpp"
|
||||
#endif
|
||||
|
||||
// Forward-declare SVD::SVD so the Matrix::SVD implementation below can call
|
||||
// it even when Matrix.cpp is pulled in through SVD.hpp's own include chain
|
||||
// (SVD.hpp -> Matrix.hpp -> Matrix.cpp), where the SVD namespace has not
|
||||
// been declared yet at this point. If we are not already inside that chain,
|
||||
// pull in the full SVD library so its template definition is available.
|
||||
namespace SVD {
|
||||
template <uint8_t rows, uint8_t columns>
|
||||
void SVD(Matrix<rows, columns> &matrixToDecompose, Matrix<rows, columns> &U,
|
||||
Matrix<columns, 1> &sigma, Matrix<columns, columns> &Vt);
|
||||
}
|
||||
#ifndef SVD_H_
|
||||
#include "SVD.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef MATRIX_H_ // since the .cpp file has to be included by the .hpp file this
|
||||
// will evaluate to true
|
||||
#include "Matrix.hpp"
|
||||
@@ -592,4 +606,18 @@ void Matrix<rows, columns>::EigenQR(Matrix<rows, rows> &eigenVectors,
|
||||
QR::EigenQR(A, eigenVectors, eigenValues, maxIterations, tolerance);
|
||||
}
|
||||
|
||||
template <uint8_t rows, uint8_t columns>
|
||||
void Matrix<rows, columns>::SVD(Matrix<rows, columns> &U,
|
||||
Matrix<columns, 1> &sigma,
|
||||
Matrix<columns, columns> &Vt) const {
|
||||
// Delegate to the SVD library (see src/SVD.hpp for the algorithm and
|
||||
// conventions). NB: the fully-qualified ::SVD is required here — inside
|
||||
// this member the unqualified name SVD refers to this method, which
|
||||
// would shadow the namespace in a qualified lookup. SVD::SVD takes its
|
||||
// input by non-const reference but does not modify it; pass a copy so
|
||||
// the const-ness of *this is preserved.
|
||||
Matrix<rows, columns> A = *this;
|
||||
::SVD::SVD<rows, columns>(A, U, sigma, Vt);
|
||||
}
|
||||
|
||||
#endif // MATRIX_H_
|
||||
Reference in New Issue
Block a user