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"
56 #include "casadi_find.hpp"
57 #include "casadi_low.hpp"
58 #include "einstein.hpp"
59 #include "io_instruction.hpp"
60 #include "symbolic_mx.hpp"
61 #include "constant_mx.hpp"
63 #include "bspline.hpp"
64 #include "convexify.hpp"
65 #include "logsumexp.hpp"
68 #include "setnonzeros_impl.hpp"
69 #include "setnonzeros_param_impl.hpp"
70 #include "solve_impl.hpp"
71 #include "binary_mx_impl.hpp"
73 #include "serializing_stream.hpp"
87 for (std::vector<MX>::iterator cc=
dep_.begin(); cc!=
dep_.end(); ++cc) {
89 if (cc->is_constant())
continue;
92 if (cc->getCount()!= 1) {
99 std::stack<MX> deletion_stack;
102 deletion_stack.push(*cc);
106 while (!deletion_stack.empty()) {
109 MX t = deletion_stack.top();
112 bool found_dep =
false;
115 while (!t->
dep_.empty()) {
116 const MX& ii = t->
dep_.back();
126 deletion_stack.push(ii);
137 deletion_stack.pop();
149 casadi_error(
"'has_duplicates' not defined for class " +
class_name());
153 casadi_error(
"'reset_input' not defined for class " +
class_name());
157 *it++ = shared_from_this<MX>();
175 if (ret.size()==
size()) {
178 casadi_assert_dev(ret.is_empty(
true));
184 return join_primitives_gen<MX>(it);
188 return join_primitives_gen<DM>(it);
192 return join_primitives_gen<SX>(it);
196 casadi_error(
"'name' not defined for class " +
class_name());
201 return typeid(*this).name();
205 casadi_error(
"Can only determine truth value of a numeric MX.");
213 casadi_error(
"'ind' not defined for class " +
class_name());
217 casadi_error(
"'segment' not defined for class " +
class_name());
221 casadi_error(
"'offset' not defined for class " +
class_name());
255 for (
const MX& e :
dep_) {
256 if (e->has_output()) {
258 "You cannot build an expression out of a MultipleOutput node. "
259 "You must select a concrete output by making a get_output() call.");
265 casadi_assert(oind==0,
"Index out of bounds");
271 std::map<const MXNode*, casadi_int> nodeind;
275 std::vector<std::string> intermed;
279 for (casadi_int i=0; i<intermed.size(); ++i)
280 stream <<
"@" << (i+1) <<
"=" << intermed[i] <<
", ";
288 std::map<const MXNode*, casadi_int>::iterator it=nodeind.find(
this);
289 if (it==nodeind.end()) {
291 nodeind.insert(it, std::make_pair(
this, 0));
294 for (casadi_int i=0; i<
n_dep(); ++i) {
304 std::vector<std::string>& intermed)
const {
306 casadi_int&
ind = nodeind[
this];
312 std::vector<std::string> arg(
n_dep());
313 for (casadi_int i=0; i<arg.size(); ++i) {
318 std::string s =
disp(arg);
326 intermed.push_back(s);
327 ind = intermed.size();
333 casadi_error(
"'which_function' not defined for class " +
class_name());
337 casadi_error(
"'which_output' not defined for class " +
class_name());
340 int MXNode::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
341 casadi_error(
"'eval' not defined for class " +
class_name());
346 casadi_error(
"'eval_sx' not defined for class " +
class_name());
351 const std::vector<bool>& unique)
const {
352 casadi_error(
"'eval_mx' not defined for class " +
class_name());
356 std::vector<std::array<MX, 3> >& res)
const {
357 std::vector<MX> arg_sum(arg.size());
358 for (casadi_int i=0; i<arg.size(); ++i) {
359 arg_sum[i] = arg[i][0] + arg[i][1] + arg[i][2];
361 std::vector<MX> res_nonlin(res.size());
363 for (casadi_int i=0; i<res.size(); ++i) {
366 res[i][2] = res_nonlin[i];
371 std::vector<std::array<MX, 3> >& res)
const {
373 for (casadi_int i=0; i<3; ++i) {
375 std::vector<MX> eval_arg(
n_dep());
376 for (casadi_int j=0; j<
n_dep(); ++j) {
377 eval_arg[j] = arg[j][i];
379 std::vector<MX> eval_res(
nout());
383 for (casadi_int j=0; j<
nout(); ++j) {
384 res[j][i] = eval_res[j];
390 std::vector<std::vector<MX> >& fsens)
const {
391 casadi_error(
"'ad_forward' not defined for class " +
class_name());
395 std::vector<std::vector<MX> >& asens)
const {
396 casadi_error(
"'ad_reverse' not defined for class " +
class_name());
404 for (casadi_int k=0; k<
n_dep(); ++k) {
406 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
412 for (casadi_int k=0; k<
nout(); ++k) {
426 for (casadi_int k=0; k<
nout(); ++k) {
435 for (casadi_int k=0; k<
n_dep(); ++k) {
437 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
445 casadi_assert(oind==0,
"Output index out of bounds");
446 return shared_from_this<MX>();
450 const std::vector<casadi_int>& arg,
451 const std::vector<casadi_int>& res,
452 const std::vector<bool>& arg_is_ref,
453 std::vector<bool>& res_is_ref)
const {
454 casadi_warning(
"Cannot code generate MX nodes of type " +
class_name() +
455 "The generation will proceed, but compilation of the code will "
457 g <<
"#error " <<
class_name() <<
": " << arg <<
" => " << res <<
'\n';
461 const std::vector<casadi_int>& arg,
462 const std::vector<casadi_int>& res,
463 const std::vector<bool>& arg_is_ref,
464 std::vector<bool>& res_is_ref,
465 casadi_int i)
const {
466 res_is_ref[i] = arg_is_ref[i];
467 if (arg[i]==res[i])
return;
469 g << g.
workel(res[i]) <<
" = " << g.
workel(arg[i]) <<
";\n";
470 }
else if (arg_is_ref[i]) {
471 g << g.
work(res[i],
nnz(),
true) <<
" = " << g.
work(arg[i],
nnz(),
true) <<
";\n";
480 casadi_error(
"'to_double' not defined for class " +
class_name());
484 casadi_error(
"'to_int' not defined for class " +
class_name());
488 casadi_error(
"'get_DM' not defined for class " +
class_name());
493 return shared_from_this<MX>();
494 }
else if (
sparsity().is_vector()) {
506 return shared_from_this<MX>();
513 casadi_assert_dev(sp.
nnz()==
nnz());
515 return shared_from_this<MX>();
536 s.
pack(
"MXNode::op",
static_cast<int>(
op()));
561 return it->second(s);
574 MX x = shared_from_this<MX>();
577 "Dimension error x.mac(z). Got y=" +
str(y.
size2()) +
" and z=" + z.
dim() +
".");
579 "Dimension error x.mac(z). Got x=" + x.
dim() +
" and z=" + z.
dim() +
".");
581 "Dimension error x.mac(z). Got y=" +
str(y.
size1()) +
" and x" + x.
dim() +
".");
586 const std::vector<casadi_int>& dim_c,
const std::vector<casadi_int>& dim_a,
587 const std::vector<casadi_int>& dim_b,
588 const std::vector<casadi_int>& c,
const std::vector<casadi_int>& a,
589 const std::vector<casadi_int>& b)
const {
592 return shared_from_this<MX>();
594 MX C = densify(shared_from_this<MX>());
601 return einstein(vec(densify(Ac)), vec(densify(Bc)), vec(densify(Cc)),
602 dim_a, dim_b, dim_c, a, b, c);
662 return sparsity_cast(shared_from_this<MX>(), sp);
672 if (outer.
all()==std::vector<casadi_int>{0}) {
680 if (inner.
all()==std::vector<casadi_int>{0}) {
693 bool set_any =
false;
694 for (
auto i=nz.begin(); i!=nz.end() && !set_any; ++i) {
697 if (!set_any)
return y;
761 return shared_from_this<MX>();
762 }
else if (sp.
nnz()==0) {
782 if (operation_checker<F0XChecker>(
op) &&
is_zero()) {
842 operation_checker<FX0Checker>(
op));
845 MX xx = project(shared_from_this<MX>(), r_sp);
846 MX yy = project(y, r_sp);
847 return xx->
_get_binary(
op, yy,
false,
false, unique_x, unique_y);
853 bool unique_x,
bool unique_y)
const {
859 if ((operation_checker<F0XChecker>(
op) &&
nnz()==0) ||
860 (operation_checker<FX0Checker>(
op) && y->
nnz()==0)) {
864 if ((operation_checker<F0XChecker>(
op) &&
is_zero()) ||
865 (operation_checker<FX0Checker>(
op) && y->
is_zero())) {
873 [](casadi_int
op,
const MX& a,
const MX& b) {
909 if (this->
op()!=
OP_CONST && operation_checker<CommChecker>(
op)) {
918 else if (y->
is_value(1))
return shared_from_this<MX>();
924 return scX ? repmat(shared_from_this<MX>(), y.
size()) : shared_from_this<MX>();
927 if (y->
is_value(1))
return shared_from_this<MX>();
930 if (y->
is_value(1))
return shared_from_this<MX>();
962 if (y.
is_dense() || operation_checker<FX0Checker>(
op) ||
963 (
is_zero() && operation_checker<F00Checker>(
op))) {
972 if (
sparsity().is_dense() || operation_checker<F0XChecker>(
op) ||
973 (y.
is_zero() && operation_checker<F00Checker>(
op)) ||
979 return densify(shared_from_this<MX>())->_get_binary(
op, y,
false,
true);
986 if (!rr.
is_dense() && !operation_checker<F00Checker>(
op)) {
990 rr = densify(rr, fcn_0);
997 casadi_error(
"'mapping' not defined for class " +
class_name());
1003 for (casadi_int i=0; i<
n_dep(); ++i) {
1016 return shared_from_this<MX>();
1024 return shared_from_this<MX>();
1026 std::string dir =
".";
1027 std::string format =
"mtx";
1028 bool verbose =
false;
1029 for (
auto&&
op : opts) {
1030 if (
op.first==
"dir") {
1031 dir =
op.second.to_string();
1032 }
else if (
op.first==
"format") {
1033 format =
op.second.to_string();
1034 }
else if (
op.first==
"verbose") {
1035 verbose =
op.second.to_bool();
1037 casadi_error(
"Unknown option '" +
op.first +
"' for dump. "
1038 "Allowed options: 'dir', 'format', 'verbose'.");
1041 return MX::create(
new Dump(shared_from_this<MX>(), base_filename,
1042 dir, format, verbose));
1047 MX x = shared_from_this<MX>();
1048 casadi_assert(x.
is_vector(),
"Argument must be vector, got " + x.
dim() +
".");
1057 return MX::create(
new Low(v, shared_from_this<MX>(), options));
1061 const std::vector<casadi_int>& offset,
1062 const std::vector<double>& coeffs,
1063 const std::vector<casadi_int>& degree,
1065 const std::vector<casadi_int>& lookup_mode)
const {
1066 MX x = shared_from_this<MX>();
1071 const std::vector<double>& knots,
1072 const std::vector<casadi_int>& offset,
1073 const std::vector<casadi_int>& degree,
1075 const std::vector<casadi_int>& lookup_mode)
const {
1076 MX x = shared_from_this<MX>();
1096 "MXNode::dot: Dimension mismatch. dot requires its "
1097 "two arguments to have equal shapes, but got ("
1103 }
else if (
sparsity().is_scalar()) {
1112 MX xx = project(shared_from_this<MX>(), sp);
1113 MX yy = project(y, sp);
1146 for (
auto i=x.begin(); i!=x.end(); ++i) {
1149 std::vector<MX> x_split(x.begin(), i);
1150 for (; i!=x.end(); ++i) {
1152 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1154 x_split.push_back(*i);
1157 return horzcat(x_split);
1172 for (
auto i=x.begin(); i!=x.end(); ++i) {
1175 std::vector<MX> x_split(x.begin(), i);
1176 for (; i!=x.end(); ++i) {
1178 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1180 x_split.push_back(*i);
1183 return vertcat(x_split);
1192 std::vector<MX> ret =
1194 for (casadi_int i=0;i<ret.size();++i) {
1199 std::vector<MX> ret =
1205 casadi_int offset_deps = 0;
1207 for (casadi_int i=0;i<output_offset.size();++i) {
1208 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size2();++j; }
1210 if (output_offset[i]==offset_deps &&
1211 (i+1<output_offset.size()?output_offset[i+1]:
size2()) ==
1241 if (
nnz() == 0 || b.
nnz() == 0) {
1248 if (
nnz() == 0 || x.
nnz() == 0) {
1255 const std::vector<casadi_int>& offset2)
const {
1257 std::vector<MX> ret =
1259 for (casadi_int i=0;i<ret.size();++i) {
1264 std::vector<MX> ret =
1272 std::vector<MX> ret =
1274 for (casadi_int i=0;i<ret.size();++i) {
1279 std::vector<MX> ret =
1285 casadi_int offset_deps = 0;
1287 for (casadi_int i=0;i<output_offset.size();++i) {
1288 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size1();++j; }
1290 if (output_offset[i]==offset_deps &&
1291 (i+1<output_offset.size()?output_offset[i+1]:
size1()) ==
1304 std::copy(arg, arg+len, res);
1310 for (casadi_int k=0; k<len; ++k) {
1320 }
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.
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.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
An MX atomic for an Einstein product,.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
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.
static MX create(const MX &m, const MX &x, bool inner)
Factory: dispatch to the most specific subclass for the given operands.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MX create(const MX &a, const MX &b)
Factory: dispatch to the most specific subclass for the given operands.
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 MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz, bool unique=false) const
Get the nonzeros of matrix.
virtual void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const
Evaluate symbolically (MX)
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.
virtual MX get_unary(casadi_int op, bool unique=false) const
Get a unary operation.
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_solve_tril_unity(const MX &r, bool tr) const
Solve a system of linear equations, lower triangular A, unity diagnal.
virtual MX get_kron(const MX &b) const
Create a Kronecker-product node.
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.
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_binary(casadi_int op, const MX &y, bool scX, bool scY, bool unique_x=false, bool unique_y=false) const
Get a binary operation operation (matrix-matrix)
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 casadi_int to_int() const
Get the value (only for scalar constant nodes)
static std::map< casadi_int, MXNode *(*)(DeserializingStream &)> deserialize_map
const Sparsity & sparsity() const
Get the sparsity.
casadi_int nnz(casadi_int i=0) const
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
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
MX get_binary(casadi_int op, const MX &y, bool unique_x=false, bool unique_y=false) const
Get a binary operation operation.
MX get_dump(const std::string &base_filename, const Dict &opts) const
Dump.
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.
virtual MX get_det(const Linsol &linear_solver) const
Determinant.
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 MX get_project(const Sparsity &sp, bool unique=false) const
Create set sparse.
virtual casadi_int op() const =0
Get the operation.
virtual MX get_mac(const MX &y, const MX &z, const std::string &blas="reference") const
Matrix multiplication and addition.
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_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_kron_contract(const MX &x, bool inner) const
Create a Kronecker-contraction node.
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.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MX create(const MX &z, const MX &x, const MX &y, const std::string &blas="reference")
Factory: dispatch to the most specific subclass for the given operands.
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.
static Sparsity kron(const Sparsity &a, const Sparsity &b)
Enlarge matrix.
static Sparsity kron_contract(const Sparsity &sp_m, const Sparsity &sp_x, bool inner)
Output sparsity of casadi::KronContract.
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.
T common_simp_binary(casadi_int op, const T &x, const T &y, casadi_int depth, SU &&gen_unary, SB &&gen_binary, bool unique_x, bool unique_y, bool &hit)
T common_simp_unary(casadi_int op, const T &x, casadi_int depth, SU &&gen_unary, bool unique, bool &hit)
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)