26 #include "mx_node.hpp"
27 #include "casadi_misc.hpp"
28 #include "transpose.hpp"
29 #include "reshape.hpp"
30 #include "sparsity_cast.hpp"
31 #include "multiplication.hpp"
35 #include "subassign.hpp"
36 #include "getnonzeros.hpp"
37 #include "getnonzeros_param.hpp"
38 #include "setnonzeros.hpp"
39 #include "setnonzeros_param.hpp"
40 #include "project.hpp"
42 #include "unary_mx.hpp"
43 #include "binary_mx.hpp"
44 #include "determinant.hpp"
45 #include "inverse.hpp"
51 #include "assertion.hpp"
52 #include "monitor.hpp"
54 #include "casadi_find.hpp"
55 #include "casadi_low.hpp"
56 #include "einstein.hpp"
57 #include "io_instruction.hpp"
58 #include "symbolic_mx.hpp"
59 #include "constant_mx.hpp"
61 #include "bspline.hpp"
62 #include "convexify.hpp"
63 #include "logsumexp.hpp"
66 #include "setnonzeros_impl.hpp"
67 #include "setnonzeros_param_impl.hpp"
68 #include "solve_impl.hpp"
69 #include "binary_mx_impl.hpp"
71 #include "serializing_stream.hpp"
85 for (std::vector<MX>::iterator cc=
dep_.begin(); cc!=
dep_.end(); ++cc) {
87 if (cc->is_constant())
continue;
90 if (cc->getCount()!= 1) {
97 std::stack<MX> deletion_stack;
100 deletion_stack.push(*cc);
104 while (!deletion_stack.empty()) {
107 MX t = deletion_stack.top();
110 bool found_dep =
false;
113 while (!t->
dep_.empty()) {
114 const MX& ii = t->
dep_.back();
124 deletion_stack.push(ii);
135 deletion_stack.pop();
147 casadi_error(
"'has_duplicates' not defined for class " +
class_name());
151 casadi_error(
"'reset_input' not defined for class " +
class_name());
155 *it++ = shared_from_this<MX>();
173 if (ret.size()==
size()) {
176 casadi_assert_dev(ret.is_empty(
true));
182 return join_primitives_gen<MX>(it);
186 return join_primitives_gen<DM>(it);
190 return join_primitives_gen<SX>(it);
194 casadi_error(
"'name' not defined for class " +
class_name());
199 return typeid(*this).name();
203 casadi_error(
"Can only determine truth value of a numeric MX.");
211 casadi_error(
"'ind' not defined for class " +
class_name());
215 casadi_error(
"'segment' not defined for class " +
class_name());
219 casadi_error(
"'offset' not defined for class " +
class_name());
253 for (
const MX& e :
dep_) {
254 if (e->has_output()) {
256 "You cannot build an expression out of a MultipleOutput node. "
257 "You must select a concrete output by making a get_output() call.");
263 casadi_assert(oind==0,
"Index out of bounds");
269 std::map<const MXNode*, casadi_int> nodeind;
273 std::vector<std::string> intermed;
277 for (casadi_int i=0; i<intermed.size(); ++i)
278 stream <<
"@" << (i+1) <<
"=" << intermed[i] <<
", ";
286 std::map<const MXNode*, casadi_int>::iterator it=nodeind.find(
this);
287 if (it==nodeind.end()) {
289 nodeind.insert(it, std::make_pair(
this, 0));
292 for (casadi_int i=0; i<
n_dep(); ++i) {
302 std::vector<std::string>& intermed)
const {
304 casadi_int&
ind = nodeind[
this];
310 std::vector<std::string> arg(
n_dep());
311 for (casadi_int i=0; i<arg.size(); ++i) {
316 std::string s =
disp(arg);
324 intermed.push_back(s);
325 ind = intermed.size();
331 casadi_error(
"'which_function' not defined for class " +
class_name());
335 casadi_error(
"'which_output' not defined for class " +
class_name());
338 int MXNode::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
339 casadi_error(
"'eval' not defined for class " +
class_name());
344 casadi_error(
"'eval_sx' not defined for class " +
class_name());
349 casadi_error(
"'eval_mx' not defined for class " +
class_name());
353 std::vector<std::array<MX, 3> >& res)
const {
354 std::vector<MX> arg_sum(arg.size());
355 for (casadi_int i=0; i<arg.size(); ++i) {
356 arg_sum[i] = arg[i][0] + arg[i][1] + arg[i][2];
358 std::vector<MX> res_nonlin(res.size());
360 for (casadi_int i=0; i<res.size(); ++i) {
363 res[i][2] = res_nonlin[i];
368 std::vector<std::array<MX, 3> >& res)
const {
370 for (casadi_int i=0; i<3; ++i) {
372 std::vector<MX> eval_arg(
n_dep());
373 for (casadi_int j=0; j<
n_dep(); ++j) {
374 eval_arg[j] = arg[j][i];
376 std::vector<MX> eval_res(
nout());
380 for (casadi_int j=0; j<
nout(); ++j) {
381 res[j][i] = eval_res[j];
387 std::vector<std::vector<MX> >& fsens)
const {
388 casadi_error(
"'ad_forward' not defined for class " +
class_name());
392 std::vector<std::vector<MX> >& asens)
const {
393 casadi_error(
"'ad_reverse' not defined for class " +
class_name());
401 for (casadi_int k=0; k<
n_dep(); ++k) {
403 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
409 for (casadi_int k=0; k<
nout(); ++k) {
423 for (casadi_int k=0; k<
nout(); ++k) {
432 for (casadi_int k=0; k<
n_dep(); ++k) {
434 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
442 casadi_assert(oind==0,
"Output index out of bounds");
443 return shared_from_this<MX>();
447 const std::vector<casadi_int>& arg,
448 const std::vector<casadi_int>& res,
449 const std::vector<bool>& arg_is_ref,
450 std::vector<bool>& res_is_ref)
const {
451 casadi_warning(
"Cannot code generate MX nodes of type " +
class_name() +
452 "The generation will proceed, but compilation of the code will "
454 g <<
"#error " <<
class_name() <<
": " << arg <<
" => " << res <<
'\n';
458 const std::vector<casadi_int>& arg,
459 const std::vector<casadi_int>& res,
460 const std::vector<bool>& arg_is_ref,
461 std::vector<bool>& res_is_ref,
462 casadi_int i)
const {
463 res_is_ref[i] = arg_is_ref[i];
464 if (arg[i]==res[i])
return;
466 g << g.
workel(res[i]) <<
" = " << g.
workel(arg[i]) <<
";\n";
467 }
else if (arg_is_ref[i]) {
468 g << g.
work(res[i],
nnz(),
true) <<
" = " << g.
work(arg[i],
nnz(),
true) <<
";\n";
477 casadi_error(
"'to_double' not defined for class " +
class_name());
481 casadi_error(
"'get_DM' not defined for class " +
class_name());
486 return shared_from_this<MX>();
487 }
else if (
sparsity().is_vector()) {
499 return shared_from_this<MX>();
506 casadi_assert_dev(sp.
nnz()==
nnz());
508 return shared_from_this<MX>();
529 s.
pack(
"MXNode::op",
static_cast<int>(
op()));
554 return it->second(s);
567 MX x = shared_from_this<MX>();
570 "Dimension error x.mac(z). Got y=" +
str(y.
size2()) +
" and z=" + z.
dim() +
".");
572 "Dimension error x.mac(z). Got x=" + x.
dim() +
" and z=" + z.
dim() +
".");
574 "Dimension error x.mac(z). Got y=" +
str(y.
size1()) +
" and x" + x.
dim() +
".");
583 const std::vector<casadi_int>& dim_c,
const std::vector<casadi_int>& dim_a,
584 const std::vector<casadi_int>& dim_b,
585 const std::vector<casadi_int>& c,
const std::vector<casadi_int>& a,
586 const std::vector<casadi_int>& b)
const {
589 return shared_from_this<MX>();
591 MX C = densify(shared_from_this<MX>());
598 return einstein(vec(densify(Ac)), vec(densify(Bc)), vec(densify(Cc)),
599 dim_a, dim_b, dim_c, a, b, c);
659 return sparsity_cast(shared_from_this<MX>(), sp);
669 if (outer.
all()==std::vector<casadi_int>{0}) {
677 if (inner.
all()==std::vector<casadi_int>{0}) {
690 bool set_any =
false;
691 for (
auto i=nz.begin(); i!=nz.end() && !set_any; ++i) {
694 if (!set_any)
return y;
758 return shared_from_this<MX>();
759 }
else if (sp.
nnz()==0) {
779 if (operation_checker<F0XChecker>(
op) &&
is_zero()) {
833 operation_checker<FX0Checker>(
op));
836 MX xx = project(shared_from_this<MX>(), r_sp);
837 MX yy = project(y, r_sp);
849 if ((operation_checker<F0XChecker>(
op) &&
nnz()==0) ||
850 (operation_checker<FX0Checker>(
op) && y->
nnz()==0)) {
854 if ((operation_checker<F0XChecker>(
op) &&
is_zero()) ||
855 (operation_checker<FX0Checker>(
op) && y->
is_zero())) {
886 if (this->
op()!=
OP_CONST && operation_checker<CommChecker>(
op)) {
895 else if (y->
is_value(1))
return shared_from_this<MX>();
901 return scX ? repmat(shared_from_this<MX>(), y.
size()) : shared_from_this<MX>();
904 if (y->
is_value(1))
return shared_from_this<MX>();
907 if (y->
is_value(1))
return shared_from_this<MX>();
939 if (y.
is_dense() || operation_checker<FX0Checker>(
op) ||
940 (
is_zero() && operation_checker<F00Checker>(
op))) {
949 if (
sparsity().is_dense() || operation_checker<F0XChecker>(
op) ||
950 (y.
is_zero() && operation_checker<F00Checker>(
op)) ||
956 return densify(shared_from_this<MX>())->_get_binary(
op, y,
false,
true);
963 if (!rr.
is_dense() && !operation_checker<F00Checker>(
op)) {
967 rr = densify(rr, fcn_0);
974 casadi_error(
"'mapping' not defined for class " +
class_name());
980 for (casadi_int i=0; i<
n_dep(); ++i) {
993 return shared_from_this<MX>();
1000 MX x = shared_from_this<MX>();
1001 casadi_assert(x.
is_vector(),
"Argument must be vector, got " + x.
dim() +
".");
1010 return MX::create(
new Low(v, shared_from_this<MX>(), options));
1014 const std::vector<casadi_int>& offset,
1015 const std::vector<double>& coeffs,
1016 const std::vector<casadi_int>& degree,
1018 const std::vector<casadi_int>& lookup_mode)
const {
1019 MX x = shared_from_this<MX>();
1024 const std::vector<double>& knots,
1025 const std::vector<casadi_int>& offset,
1026 const std::vector<casadi_int>& degree,
1028 const std::vector<casadi_int>& lookup_mode)
const {
1029 MX x = shared_from_this<MX>();
1049 "MXNode::dot: Dimension mismatch. dot requires its "
1050 "two arguments to have equal shapes, but got ("
1056 }
else if (
sparsity().is_scalar()) {
1065 MX xx = project(shared_from_this<MX>(), sp);
1066 MX yy = project(y, sp);
1099 for (
auto i=x.begin(); i!=x.end(); ++i) {
1102 std::vector<MX> x_split(x.begin(), i);
1103 for (; i!=x.end(); ++i) {
1105 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1107 x_split.push_back(*i);
1110 return horzcat(x_split);
1125 for (
auto i=x.begin(); i!=x.end(); ++i) {
1128 std::vector<MX> x_split(x.begin(), i);
1129 for (; i!=x.end(); ++i) {
1131 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1133 x_split.push_back(*i);
1136 return vertcat(x_split);
1145 std::vector<MX> ret =
1147 for (casadi_int i=0;i<ret.size();++i) {
1152 std::vector<MX> ret =
1158 casadi_int offset_deps = 0;
1160 for (casadi_int i=0;i<output_offset.size();++i) {
1161 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size2();++j; }
1163 if (output_offset[i]==offset_deps &&
1164 (i+1<output_offset.size()?output_offset[i+1]:
size2()) ==
1194 const std::vector<casadi_int>& offset2)
const {
1196 std::vector<MX> ret =
1198 for (casadi_int i=0;i<ret.size();++i) {
1203 std::vector<MX> ret =
1211 std::vector<MX> ret =
1213 for (casadi_int i=0;i<ret.size();++i) {
1218 std::vector<MX> ret =
1224 casadi_int offset_deps = 0;
1226 for (casadi_int i=0;i<output_offset.size();++i) {
1227 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size1();++j; }
1229 if (output_offset[i]==offset_deps &&
1230 (i+1<output_offset.size()?output_offset[i+1]:
size1()) ==
1243 std::copy(arg, arg+len, res);
1249 for (casadi_int k=0; k<len; ++k) {
1259 }
else if (depth>0) {
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Calculate quadratic form.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Represents any binary operation that involves two matrices.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string copy(const std::string &arg, std::size_t n, const std::string &res)
Create a copy operation.
std::string workel(casadi_int n) const
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Convexify a symmetric matrix.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
An MX atomic for matrix-matrix product,.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Diagonal concatenation of matrices.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Diag split, x -> x0, x1, ...
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
An MX atomic for an Einstein product,.
Finds the first nonzero element in a vector.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
bool is_dense() const
Check if the matrix expression is dense.
bool is_column() const
Check if the matrix is a column vector (i.e. size2()==1)
bool is_empty(bool both=false) const
Check if the sparsity is empty, i.e. if one of the dimensions is zero.
std::pair< casadi_int, casadi_int > size() const
Get the shape.
bool is_vector() const
Check if the matrix is a row or column vector.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
casadi_int size2() const
Get the second dimension (i.e. number of columns)
casadi_int size1() const
Get the first dimension (i.e. number of rows)
std::string dim(bool with_nz=false) const
Get string representation of dimensions.
static MX ones(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries one.
static MatType repsum(const MatType &x, casadi_int n, casadi_int m=1)
Functions called by friend functions defined here.
static MX zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
bool is_scalar(bool scalar_and_dense=false) const
Check if the matrix expression is scalar.
casadi_int getCount() const
Get the reference count.
static MX create(const MX &x, const MX &nz)
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MX create(const Sparsity &sp, const MX &x, const std::vector< casadi_int > &nz)
static bool simplification_on_the_fly
Indicates whether simplifications should be made on the fly.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Horizontal concatenation.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Horizontal split, x -> x0, x1, ...
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Linear solve operation with a linear solver instance.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Calculate logsumexp update.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Lows the first nonzero element in a vector.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Node class for MX objects.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual MX get_logsumexp() const
Logsumexp.
virtual void reset_input() const
Reset the marker for an input expression.
std::string class_name() const override
Get name of public class.
virtual MX get_nzassign(const MX &y, const std::vector< casadi_int > &nz) const
Assign the nonzeros of a matrix to another matrix.
virtual const std::string & name() const
Get the name.
virtual casadi_int n_primitives() const
Get the number of symbolic primitives.
virtual MX get_norm_2() const
Spectral norm.
~MXNode() override=0
Destructor.
virtual MX get_output(casadi_int oind) const
Get an output.
virtual casadi_int offset() const
virtual bool is_zero() const
Check if identically zero.
virtual MX get_sparsity_cast(const Sparsity &sp) const
Sparsity cast.
virtual MX get_mmax() const
Max.
static bool is_equal(const MXNode *x, const MXNode *y, casadi_int depth)
Check if two nodes are equivalent up to a given depth.
static void copy_fwd(const bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities forward through a copy operation.
virtual int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const
Evaluate symbolically (SX)
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
Propagate sparsity forward.
virtual Matrix< casadi_int > mapping() const
Get an IM representation of a GetNonzeros or SetNonzeros node.
virtual MX get_einstein(const MX &A, const MX &B, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b) const
Einstein product and addition.
virtual DM get_DM() const
Get the value (only for constant nodes)
virtual void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const
Calculate reverse mode directional derivatives.
virtual bool has_duplicates() const
Detect duplicate symbolic expressions.
virtual 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
Generate code for the operation.
virtual casadi_int ind() const
virtual MX get_solve(const MX &r, bool tr, const Linsol &linear_solver) const
Solve a system of linear equations.
virtual MX get_solve_triu(const MX &r, bool tr) const
Solve a system of linear equations, upper triangular A.
void can_inline(std::map< const MXNode *, casadi_int > &nodeind) const
Find out which nodes can be inlined.
virtual MX get_mac(const MX &y, const MX &z) const
Matrix multiplication and addition.
virtual MX get_solve_tril_unity(const MX &r, bool tr) const
Solve a system of linear equations, lower triangular A, unity diagnal.
virtual Dict info() const
static bool maxDepth()
Get equality checking depth.
virtual MX join_primitives(std::vector< MX >::const_iterator &it) const
Join an expression along symbolic primitives.
virtual MX get_dot(const MX &y) const
Inner product.
virtual MX get_repmat(casadi_int m, casadi_int n) const
Create a repeated matrix node.
virtual int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
Propagate sparsity backwards.
MX get_bspline(const std::vector< double > &knots, const std::vector< casadi_int > &offset, const std::vector< double > &coeffs, const std::vector< casadi_int > °ree, casadi_int m, const std::vector< casadi_int > &lookup_mode) const
BSpline.
static void copy_rev(bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities backwards through a copy operation.
virtual MX get_diagcat(const std::vector< MX > &x) const
Create a diagonal concatenation node.
MX get_binary(casadi_int op, const MX &y) const
Get a binary operation operation.
virtual MX get_det() const
Determinant.
std::pair< casadi_int, casadi_int > size() const
Sparsity sparsity_
The sparsity pattern.
virtual void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const
Calculate forward mode directional derivatives.
virtual MX get_solve_tril(const MX &r, bool tr) const
Solve a system of linear equations, lower triangular A.
void generate_copy(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, casadi_int i) const
void check_dep() const
Check validatity of dependencies.
virtual MX get_unary(casadi_int op) const
Get a unary operation.
static std::map< casadi_int, MXNode *(*)(DeserializingStream &)> deserialize_map
const Sparsity & sparsity() const
Get the sparsity.
virtual MX get_project(const Sparsity &sp) const
Create set sparse.
casadi_int nnz(casadi_int i=0) const
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const
Evaluate symbolically (MX)
virtual MX get_solve_triu_unity(const MX &r, bool tr) const
Solve a system of linear equations, upper triangular A, unity diagonal.
virtual const Function & which_function() const
Get called function.
virtual casadi_int nout() const
Number of outputs.
virtual bool is_value(double val) const
Check if a certain value.
virtual casadi_int which_output() const
Get function output.
virtual MX get_subref(const Slice &i, const Slice &j) const
Get submatrix reference.
const MX & dep(casadi_int ind=0) const
dependencies - functions that have to be evaluated before this one
std::vector< MX > dep_
dependencies - functions that have to be evaluated before this one
virtual MX get_norm_1() const
1-norm
virtual MX get_nz_ref(const MX &nz) const
Get the nonzeros of matrix, parametrically.
virtual MX get_subassign(const MX &y, const Slice &i, const Slice &j) const
Get submatrix assignment.
MX get_monitor(const std::string &comment) const
Monitor.
casadi_int n_dep() const
Number of dependencies.
virtual MX get_reshape(const Sparsity &sp) const
Reshape.
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.
virtual casadi_int segment() const
virtual void primitives(std::vector< MX >::iterator &it) const
Get symbolic primitives.
MX get_convexify(const Dict &opts) const
Convexify.
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
virtual MX get_horzcat(const std::vector< MX > &x) const
Create a horizontal concatenation node.
virtual casadi_int op() const =0
Get the operation.
virtual MX get_transpose() const
Transpose.
virtual MX get_norm_fro() const
Frobenius norm.
virtual std::vector< MX > get_diagsplit(const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2) const
Create a diagonal split node.
virtual std::vector< MX > get_horzsplit(const std::vector< casadi_int > &output_offset) const
Create a horizontal split node.
virtual MX get_vertcat(const std::vector< MX > &x) const
Create a vertical concatenation node (vectors only)
virtual MX get_repsum(casadi_int m, casadi_int n) const
Create a repeated sum node.
virtual MX get_mmin() const
Min.
virtual MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz) const
Get the nonzeros of matrix.
virtual MX get_nzadd(const MX &y, const std::vector< casadi_int > &nz) const
Add the nonzeros of a matrix to another matrix.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w) const
Evaluate numerically.
virtual MX get_norm_inf() const
Infinity norm.
MX get_low(const MX &v, const Dict &options) const
Find.
virtual MX get_inv() const
Inverse.
bool sameOpAndDeps(const MXNode *node, casadi_int depth) const
Checks if two nodes have the same operation and have.
virtual std::vector< MX > get_vertsplit(const std::vector< casadi_int > &output_offset) const
Create a vertical split node (vectors only)
virtual bool __nonzero__() const
Check the truth value of this node.
virtual MX get_bilin(const MX &x, const MX &y) const
Bilinear form.
void set_dep(const MX &dep)
Set unary dependency.
MX get_assert(const MX &y, const std::string &fail_message) const
Assertion.
virtual MX _get_binary(casadi_int op, const MX &y, bool scX, bool scY) const
Get a binary operation operation (matrix-matrix)
virtual std::string disp(const std::vector< std::string > &arg) const =0
Print expression.
virtual MX get_rank1(const MX &alpha, const MX &x, const MX &y) const
Bilinear form.
virtual bool is_output() const
Check if evaluation output.
virtual void split_primitives(const MX &x, std::vector< MX >::iterator &it) const
Split up an expression along symbolic primitives.
static MX to_matrix(const MX &x, const Sparsity &sp)
Convert scalar to matrix.
void eval_linear_rearrange(const std::vector< std::array< MX, 3 > > &arg, std::vector< std::array< MX, 3 > > &res) const
Evaluate the MX node on a const/linear/nonlinear partition.
T join_primitives_gen(typename std::vector< T >::const_iterator &it) const
Join an expression along symbolic primitives (template)
void serialize(SerializingStream &s) const
Serialize an object.
virtual double to_double() const
Get the value (only for scalar constant nodes)
virtual void eval_linear(const std::vector< std::array< MX, 3 > > &arg, std::vector< std::array< MX, 3 > > &res) const
Evaluate the MX node on a const/linear/nonlinear partition.
std::string print_compact(std::map< const MXNode *, casadi_int > &nodeind, std::vector< std::string > &intermed) const
Print compact.
static MX create(MXNode *node)
Create from node.
const Sparsity & sparsity() const
Get the sparsity pattern.
bool is_constant() const
Check if constant.
MXNode * get() const
Get a const pointer to the node.
static bool is_equal(const MX &x, const MX &y, casadi_int depth=0)
MX T() const
Transpose the matrix.
static std::vector< MX > createMultipleOutput(MXNode *node)
Create from node (multiple-outputs)
static MX nan(const Sparsity &sp)
create a matrix with all nan
MX dep(casadi_int ch=0) const
Get the nth dependency as MX.
bool is_zero() const
check if zero (note that false negative answers are possible)
casadi_int op() const
Get operation type.
Sparse matrix class. SX and DM are specializations.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
An MX atomic for matrix-matrix product,.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Represents a 2-norm (spectral norm)
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Represents a Frobenius norm.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Represents an infinity-norm operation on a MX.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Change the sparsity of an expression.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MX create(const MX &y, const MX &x, const MX &nz)
Create functions.
static MX create(const MX &y, const MX &x, const std::vector< casadi_int > &nz)
Create functions.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Class representing a Slice.
bool is_empty() const
Check if slice is empty.
std::vector< casadi_int > all() const
Get a vector of indices.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MatType repmat(const MatType &x, casadi_int n, casadi_int m=1)
Sparsity intersect(const Sparsity &y, std::vector< unsigned char > &mapping) const
Intersection of two sparsity patterns.
const std::vector< casadi_int > permutation_vector(bool invert=false) const
Construct permutation vector from permutation matrix.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
bool is_reshape(const Sparsity &y) const
Check if the sparsity is a reshape of another.
Sparsity combine(const Sparsity &y, bool f0x_is_zero, bool function0_is_zero, std::vector< unsigned char > &mapping) const
Combine two sparsity patterns.
casadi_int nnz() const
Get the number of (structural) non-zeros.
std::pair< casadi_int, casadi_int > size() const
Get the shape.
bool is_empty(bool both=false) const
Check if the sparsity is empty.
bool is_dense() const
Is dense?
Reference to a submatrix.
Reference to a submatrix.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Linear solve with an upper triangular matrix.
Linear solve with an upper triangular matrix.
Linear solve with an upper triangular matrix, unity diagonal.
Linear solve with an upper triangular matrix.
Represents a general unary operation on an MX.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Vertical concatenation of vectors.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Vertical split of vectors, x -> x0, x1, ...
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
double if_else_zero(double x, double y)
Conditional assignment.
unsigned long long bvec_t
bool is_range(const std::vector< casadi_int > &v, casadi_int start, casadi_int stop, casadi_int step)
Check if a vector matches a range.
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
Operation
Enum for quick access to any node.
Easy access to all the functions for a particular type.
static void fun(unsigned char op, const T &x, const T &y, T &f)
Evaluate a built in function (scalar-scalar)