-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixSolver.cpp
53 lines (50 loc) · 1.14 KB
/
MatrixSolver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "MatrixSolver.h"
#include <iostream>
using namespace std;
using namespace Eigen;
MatrixSolverLLT::MatrixSolverLLT()
: MatrixSolver()
{}
void MatrixSolverLLT::decomp(const MatrixXd& x)
{
_solver.compute(x);
}
MatrixXd MatrixSolverLLT::solve(const MatrixXd& ys) const
{
return _solver.solve(ys);
}
bool MatrixSolverLLT::check_SPD() const
{
return _solver.info() == Eigen::Success;
}
double MatrixSolverLLT::log_det() const
{
return 2*_solver.matrixL().toDenseMatrix().diagonal().array().log().sum();
}
MatrixXd MatrixSolverLLT::inverse() const
{
return _solver.solve(MatrixXd::Identity(_solver.rows(), _solver.cols()));
}
MatrixSolverQR::MatrixSolverQR()
: MatrixSolver(), _solver()
{}
void MatrixSolverQR::decomp(const MatrixXd& x)
{
_solver.compute(x);
}
MatrixXd MatrixSolverQR::solve(const MatrixXd& ys) const
{
return _solver.solve(ys);
}
bool MatrixSolverQR::check_SPD() const
{
return (_solver.info() == Eigen::Success) and (_solver.isInvertible());
}
double MatrixSolverQR::log_det() const
{
return _solver.logAbsDeterminant();
}
MatrixXd MatrixSolverQR::inverse() const
{
return _solver.inverse();
}