27 #include "determinant.hpp"
28 #include "linsol_internal.hpp"
33 casadi_assert(x.
is_square(),
"Dimension mismatch. Matrix must be square, "
34 "but got " + x.
dim() +
" instead.");
40 return "det(" + arg.at(0) +
")";
68 std::copy(arg[0], arg[0]+
dep(0).
nnz(), A.
ptr());
69 *res[0] = det(A,
"symbolicqr").scalar();
78 const std::vector<casadi_int>& arg,
79 const std::vector<casadi_int>& res,
80 const std::vector<bool>& arg_is_ref,
81 std::vector<bool>& res_is_ref)
const {
87 const std::vector<bool>& unique)
const {
92 std::vector<std::vector<MX> >& fsens)
const {
94 MX det_X = shared_from_this<MX>();
95 MX trans_inv_X = inv(
X).
T();
96 for (casadi_int d=0; d<fsens.size(); ++d) {
97 fsens[d][0] = det_X *
dot(trans_inv_X, fseed[d][0]);
102 std::vector<std::vector<MX> >& asens)
const {
104 MX det_X = shared_from_this<MX>();
105 MX trans_inv_X = inv(
X).
T();
106 for (casadi_int d=0; d<aseed.size(); ++d) {
107 asens[d][0] += aseed[d][0]*det_X * trans_inv_X;
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string workel(casadi_int n) const
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res, const std::vector< bool > &arg_is_ref, std::vector< bool > &res_is_ref) const override
Generate code for the operation.
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
Determinant(const MX &x, const Linsol &linsol)
Constructor.
size_t codegen_sz_w() const override
Length of w the generated code needs (eval uses Linsol memory)
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
std::string dim(bool with_nz=false) const
Get string representation of dimensions.
bool is_square() const
Check if the matrix expression is square.
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
virtual void generate_det(CodeGenerator &g, const std::string &A, const std::string &d) const
Generate C code that computes the determinant into scalar d.
virtual size_t sz_w_fact() const
void nfact(const DM &A) const
Numeric factorization of the linear system.
double det(const DM &A) const
Matrix determinant.
void sfact(const DM &A) const
Symbolic factorization of the linear system, e.g. selecting pivots.
Node class for MX objects.
const Sparsity & sparsity() const
Get the sparsity.
casadi_int nnz(casadi_int i=0) const
const MX & dep(casadi_int ind=0) const
dependencies - functions that have to be evaluated before this one
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
void set_dep(const MX &dep)
Set unary dependency.
MX T() const
Transpose the matrix.
Sparse matrix class. SX and DM are specializations.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
T dot(const std::vector< T > &a, const std::vector< T > &b)