Skip to content

Commit

Permalink
overload ldl_solve to perform the LDL^T factorization and solve in on…
Browse files Browse the repository at this point in the history
…e all
  • Loading branch information
roryhubbard committed Dec 5, 2022
1 parent e9ce0b6 commit db703ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions casadi/core/matrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ namespace casadi {
std::vector<casadi_int>& p, bool amd=true);
static Matrix<Scalar> ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D,
const Matrix<Scalar>& LT, const std::vector<casadi_int>& p);
static Matrix<Scalar> ldl_solve(const Matrix<Scalar>& A, const Matrix<Scalar>& b);
static Matrix<Scalar> all(const Matrix<Scalar>& x);
static Matrix<Scalar> any(const Matrix<Scalar>& x);
static Matrix<Scalar> adj(const Matrix<Scalar>& x);
Expand Down Expand Up @@ -584,6 +585,12 @@ namespace casadi {
return Matrix<Scalar>::ldl_solve(b, D, LT, p);
}

/** \brief Perform LDL^T factorization of A and then solve Ax=b for x */
friend inline Matrix<Scalar>
ldl_solve(const Matrix<Scalar>& A, const Matrix<Scalar>& b) {
return Matrix<Scalar>::ldl_solve(A, b);
}

/** \brief Returns true only if any element in the matrix is true
\identifier{18y} */
Expand Down
10 changes: 10 additions & 0 deletions casadi/core/matrix_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,16 @@ namespace casadi {
return x;
}

template<typename Scalar>
Matrix<Scalar> Matrix<Scalar>::
ldl_solve(const Matrix<Scalar>& A, const Matrix<Scalar>& b) {
// Perform an LDL transformation
Matrix<Scalar> D, LT;
std::vector<casadi_int> p;
ldl(A, D, LT, p, false);
return ldl_solve(b, D, LT, p);
}

template<typename Scalar>
Matrix<Scalar> Matrix<Scalar>::nullspace(const Matrix<Scalar>& A) {
Matrix<Scalar> X = A;
Expand Down

0 comments on commit db703ce

Please sign in to comment.