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(ret.is_empty(
true),
179 "Expected a primitive of dimension " +
sparsity().dim() +
", but got " + ret.
dim() +
".");
185 return join_primitives_gen<MX>(it);
189 return join_primitives_gen<DM>(it);
193 return join_primitives_gen<SX>(it);
197 casadi_error(
"'name' not defined for class " +
class_name());
202 return typeid(*this).name();
206 casadi_error(
"Can only determine truth value of a numeric MX.");
214 casadi_error(
"'ind' not defined for class " +
class_name());
218 casadi_error(
"'segment' not defined for class " +
class_name());
222 casadi_error(
"'offset' not defined for class " +
class_name());
256 for (
const MX& e :
dep_) {
257 if (e->has_output()) {
259 "You cannot build an expression out of a MultipleOutput node. "
260 "You must select a concrete output by making a get_output() call.");
266 casadi_assert(oind==0,
"Index out of bounds");
272 std::map<const MXNode*, casadi_int> nodeind;
276 std::vector<std::string> intermed;
280 for (casadi_int i=0; i<intermed.size(); ++i)
281 stream <<
"@" << (i+1) <<
"=" << intermed[i] <<
", ";
289 std::map<const MXNode*, casadi_int>::iterator it=nodeind.find(
this);
290 if (it==nodeind.end()) {
292 nodeind.insert(it, std::make_pair(
this, 0));
295 for (casadi_int i=0; i<
n_dep(); ++i) {
305 std::vector<std::string>& intermed)
const {
307 casadi_int&
ind = nodeind[
this];
313 std::vector<std::string> arg(
n_dep());
314 for (casadi_int i=0; i<arg.size(); ++i) {
319 std::string s =
disp(arg);
327 intermed.push_back(s);
328 ind = intermed.size();
334 casadi_error(
"'which_function' not defined for class " +
class_name());
338 casadi_error(
"'which_output' not defined for class " +
class_name());
341 int MXNode::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
342 casadi_error(
"'eval' not defined for class " +
class_name());
347 casadi_error(
"'eval_sx' not defined for class " +
class_name());
352 const std::vector<bool>& unique)
const {
353 casadi_error(
"'eval_mx' not defined for class " +
class_name());
357 std::vector<std::array<MX, 3> >& res)
const {
358 std::vector<MX> arg_sum(arg.size());
359 for (casadi_int i=0; i<arg.size(); ++i) {
360 arg_sum[i] = arg[i][0] + arg[i][1] + arg[i][2];
362 std::vector<MX> res_nonlin(res.size());
364 for (casadi_int i=0; i<res.size(); ++i) {
367 res[i][2] = res_nonlin[i];
372 std::vector<std::array<MX, 3> >& res)
const {
374 for (casadi_int i=0; i<3; ++i) {
376 std::vector<MX> eval_arg(
n_dep());
377 for (casadi_int j=0; j<
n_dep(); ++j) {
378 eval_arg[j] = arg[j][i];
380 std::vector<MX> eval_res(
nout());
384 for (casadi_int j=0; j<
nout(); ++j) {
385 res[j][i] = eval_res[j];
391 std::vector<std::vector<MX> >& fsens)
const {
392 casadi_error(
"'ad_forward' not defined for class " +
class_name());
396 std::vector<std::vector<MX> >& asens)
const {
397 casadi_error(
"'ad_reverse' not defined for class " +
class_name());
405 for (casadi_int k=0; k<
n_dep(); ++k) {
407 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
413 for (casadi_int k=0; k<
nout(); ++k) {
427 for (casadi_int k=0; k<
nout(); ++k) {
436 for (casadi_int k=0; k<
n_dep(); ++k) {
438 for (casadi_int i=0; i<
dep(k).
nnz(); ++i) {
446 casadi_assert(oind==0,
"Output index out of bounds");
447 return shared_from_this<MX>();
451 const std::vector<casadi_int>& arg,
452 const std::vector<casadi_int>& res,
453 const std::vector<bool>& arg_is_ref,
454 std::vector<bool>& res_is_ref)
const {
455 casadi_warning(
"Cannot code generate MX nodes of type " +
class_name() +
456 "The generation will proceed, but compilation of the code will "
458 g <<
"#error " <<
class_name() <<
": " << arg <<
" => " << res <<
'\n';
462 const std::vector<casadi_int>& arg,
463 const std::vector<casadi_int>& res,
464 const std::vector<bool>& arg_is_ref,
465 std::vector<bool>& res_is_ref,
466 casadi_int i)
const {
467 res_is_ref[i] = arg_is_ref[i];
468 if (arg[i]==res[i])
return;
470 g << g.
workel(res[i]) <<
" = " << g.
workel(arg[i]) <<
";\n";
471 }
else if (arg_is_ref[i]) {
472 g << g.
work(res[i],
nnz(),
true) <<
" = " << g.
work(arg[i],
nnz(),
true) <<
";\n";
481 casadi_error(
"'to_double' not defined for class " +
class_name());
485 casadi_error(
"'to_int' not defined for class " +
class_name());
489 casadi_error(
"'get_DM' not defined for class " +
class_name());
494 return shared_from_this<MX>();
495 }
else if (
sparsity().is_vector()) {
507 return shared_from_this<MX>();
514 casadi_assert_dev(sp.
nnz()==
nnz());
516 return shared_from_this<MX>();
537 s.
pack(
"MXNode::op",
static_cast<int>(
op()));
562 return it->second(s);
575 MX x = shared_from_this<MX>();
578 "Dimension error x.mac(z). Got y=" +
str(y.
size2()) +
" and z=" + z.
dim() +
".");
580 "Dimension error x.mac(z). Got x=" + x.
dim() +
" and z=" + z.
dim() +
".");
582 "Dimension error x.mac(z). Got y=" +
str(y.
size1()) +
" and x" + x.
dim() +
".");
587 const std::vector<casadi_int>& dim_c,
const std::vector<casadi_int>& dim_a,
588 const std::vector<casadi_int>& dim_b,
589 const std::vector<casadi_int>& c,
const std::vector<casadi_int>& a,
590 const std::vector<casadi_int>& b)
const {
593 return shared_from_this<MX>();
595 MX C = densify(shared_from_this<MX>());
602 return einstein(vec(densify(Ac)), vec(densify(Bc)), vec(densify(Cc)),
603 dim_a, dim_b, dim_c, a, b, c);
663 return sparsity_cast(shared_from_this<MX>(), sp);
673 if (outer.
all()==std::vector<casadi_int>{0}) {
681 if (inner.
all()==std::vector<casadi_int>{0}) {
694 bool set_any =
false;
695 for (
auto i=nz.begin(); i!=nz.end() && !set_any; ++i) {
698 if (!set_any)
return y;
762 return shared_from_this<MX>();
763 }
else if (sp.
nnz()==0) {
783 if (operation_checker<F0XChecker>(
op) &&
is_zero()) {
843 operation_checker<FX0Checker>(
op));
846 MX xx = project(shared_from_this<MX>(), r_sp);
847 MX yy = project(y, r_sp);
848 return xx->
_get_binary(
op, yy,
false,
false, unique_x, unique_y);
854 bool unique_x,
bool unique_y)
const {
860 if ((operation_checker<F0XChecker>(
op) &&
nnz()==0) ||
861 (operation_checker<FX0Checker>(
op) && y->
nnz()==0)) {
865 if ((operation_checker<F0XChecker>(
op) &&
is_zero()) ||
866 (operation_checker<FX0Checker>(
op) && y->
is_zero())) {
874 [](casadi_int
op,
const MX& a,
const MX& b) {
910 if (this->
op()!=
OP_CONST && operation_checker<CommChecker>(
op)) {
919 else if (y->
is_value(1))
return shared_from_this<MX>();
925 return scX ? repmat(shared_from_this<MX>(), y.
size()) : shared_from_this<MX>();
928 if (y->
is_value(1))
return shared_from_this<MX>();
931 if (y->
is_value(1))
return shared_from_this<MX>();
963 if (y.
is_dense() || operation_checker<FX0Checker>(
op) ||
964 (
is_zero() && operation_checker<F00Checker>(
op))) {
973 if (
sparsity().is_dense() || operation_checker<F0XChecker>(
op) ||
974 (y.
is_zero() && operation_checker<F00Checker>(
op)) ||
980 return densify(shared_from_this<MX>())->_get_binary(
op, y,
false,
true);
987 if (!rr.
is_dense() && !operation_checker<F00Checker>(
op)) {
991 rr = densify(rr, fcn_0);
998 casadi_error(
"'mapping' not defined for class " +
class_name());
1004 for (casadi_int i=0; i<
n_dep(); ++i) {
1017 return shared_from_this<MX>();
1025 return shared_from_this<MX>();
1027 std::string dir =
".";
1028 std::string format =
"mtx";
1029 bool verbose =
false;
1030 for (
auto&&
op : opts) {
1031 if (
op.first==
"dir") {
1032 dir =
op.second.to_string();
1033 }
else if (
op.first==
"format") {
1034 format =
op.second.to_string();
1035 }
else if (
op.first==
"verbose") {
1036 verbose =
op.second.to_bool();
1038 casadi_error(
"Unknown option '" +
op.first +
"' for dump. "
1039 "Allowed options: 'dir', 'format', 'verbose'.");
1042 return MX::create(
new Dump(shared_from_this<MX>(), base_filename,
1043 dir, format, verbose));
1048 MX x = shared_from_this<MX>();
1049 casadi_assert(x.
is_vector(),
"Argument must be vector, got " + x.
dim() +
".");
1058 return MX::create(
new Low(v, shared_from_this<MX>(), options));
1062 const std::vector<casadi_int>& offset,
1063 const std::vector<double>& coeffs,
1064 const std::vector<casadi_int>& degree,
1066 const std::vector<casadi_int>& lookup_mode)
const {
1067 MX x = shared_from_this<MX>();
1072 const std::vector<double>& knots,
1073 const std::vector<casadi_int>& offset,
1074 const std::vector<casadi_int>& degree,
1076 const std::vector<casadi_int>& lookup_mode)
const {
1077 MX x = shared_from_this<MX>();
1097 "MXNode::dot: Dimension mismatch. dot requires its "
1098 "two arguments to have equal shapes, but got ("
1104 }
else if (
sparsity().is_scalar()) {
1113 MX xx = project(shared_from_this<MX>(), sp);
1114 MX yy = project(y, sp);
1147 for (
auto i=x.begin(); i!=x.end(); ++i) {
1150 std::vector<MX> x_split(x.begin(), i);
1151 for (; i!=x.end(); ++i) {
1153 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1155 x_split.push_back(*i);
1158 return horzcat(x_split);
1173 for (
auto i=x.begin(); i!=x.end(); ++i) {
1176 std::vector<MX> x_split(x.begin(), i);
1177 for (; i!=x.end(); ++i) {
1179 x_split.insert(x_split.end(), (*i)->dep_.begin(), (*i)->dep_.end());
1181 x_split.push_back(*i);
1184 return vertcat(x_split);
1193 std::vector<MX> ret =
1195 for (casadi_int i=0;i<ret.size();++i) {
1200 std::vector<MX> ret =
1206 casadi_int offset_deps = 0;
1208 for (casadi_int i=0;i<output_offset.size();++i) {
1209 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size2();++j; }
1211 if (output_offset[i]==offset_deps &&
1212 (i+1<output_offset.size()?output_offset[i+1]:
size2()) ==
1242 if (
nnz() == 0 || b.nnz() == 0) {
1249 if (
nnz() == 0 || x.
nnz() == 0) {
1256 const std::vector<casadi_int>& offset2)
const {
1258 std::vector<MX> ret =
1260 for (casadi_int i=0;i<ret.size();++i) {
1265 std::vector<MX> ret =
1273 std::vector<MX> ret =
1275 for (casadi_int i=0;i<ret.size();++i) {
1280 std::vector<MX> ret =
1286 casadi_int offset_deps = 0;
1288 for (casadi_int i=0;i<output_offset.size();++i) {
1289 while (offset_deps<output_offset[i]) { offset_deps+=
dep(j).
size1();++j; }
1291 if (output_offset[i]==offset_deps &&
1292 (i+1<output_offset.size()?output_offset[i+1]:
size1()) ==
1305 std::copy(arg, arg+len, res);
1311 for (casadi_int k=0; k<len; ++k) {
1321 }
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 is dense, i.e. nnz() equals numel()
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 matrix is empty, i.e. if one of the dimensions is zero.
std::pair< casadi_int, casadi_int > size() const
Get the shape as a pair (number of rows, number of columns)
bool is_vector() const
Check if the matrix is a row or column vector.
casadi_int nnz() const
Get the number of structural nonzeros.
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 is scalar, i.e. 1-by-1.
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 the node is a 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 constant with all nonzeros NaN.
MX dep(casadi_int ch=0) const
Get the ch-th dependency (child node) of this node.
bool is_zero() const
Check if the node is a constant zero (false negatives are possible)
casadi_int op() const
Get the operation type of the node.
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 of the same shape (also the * operator)
const std::vector< casadi_int > permutation_vector(bool invert=false) const
Recover the permutation vector p from the pattern of a permutation matrix.
std::string dim(bool with_nz=false) const
Dimensions as a string "nrow x ncol", optionally with the number of nonzeros.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern.
bool is_reshape(const Sparsity &y) const
Check whether y is a reshape of this pattern.
Sparsity combine(const Sparsity &y, bool f0x_is_zero, bool function0_is_zero, std::vector< unsigned char > &mapping) const
Combine two patterns of the same shape, as the result of a binary operation.
casadi_int nnz() const
Number of structural nonzeros.
std::pair< casadi_int, casadi_int > size() const
Shape as a pair (number of rows, number of columns)
bool is_empty(bool both=false) const
Check whether the pattern has a zero dimension.
static Sparsity kron(const Sparsity &a, const Sparsity &b)
Accessed by SparsityInterface.
static Sparsity kron_contract(const Sparsity &sp_m, const Sparsity &sp_x, bool inner)
Output sparsity of casadi::KronContract.
bool is_dense() const
Check whether every entry is a structural nonzero, i.e. nnz() == numel()
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)