RavEngine
Loading...
Searching...
No Matches
pseudoinverse.h
1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
18#define RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
19
20#include "Eigen/Dense"
21
22namespace vraudio {
23
24// Computes the Moore-Penrose pseudoinverse of |matrix|.
25//
26// @tparam MatrixType The type of the input matrix (an Eigen::Matrix).
27// @param matrix The input matrix to compute the pseudoinverse of.
28// @return The Moore-Penrose pseudoinverse of |matrix|.
29template <typename MatrixType>
30Eigen::Matrix<typename MatrixType::Scalar, MatrixType::ColsAtCompileTime,
31 MatrixType::RowsAtCompileTime>
32Pseudoinverse(const MatrixType& matrix) {
33 Eigen::JacobiSVD<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic,
34 Eigen::Dynamic>> svd(matrix,
37 return svd.solve(
38 Eigen::Matrix<typename MatrixType::Scalar, MatrixType::RowsAtCompileTime,
39 MatrixType::RowsAtCompileTime>::Identity(matrix.rows(),
40 matrix.rows()));
41}
42
43} // namespace vraudio
44
45#endif // RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition JacobiSVD.h:490
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
@ ComputeThinV
Definition Constants.h:399
@ ComputeThinU
Definition Constants.h:395
const int Dynamic
Definition Constants.h:22