26 #ifndef CASADI_MATRIX_DECL_HPP
27 #define CASADI_MATRIX_DECL_HPP
29 #include "matrix_fwd.hpp"
30 #include "exception.hpp"
31 #include "casadi_limits.hpp"
32 #include "runtime/casadi_runtime.hpp"
33 #include "generic_matrix.hpp"
34 #include "generic_expression.hpp"
35 #include "printable.hpp"
40 #include <initializer_list>
41 #ifdef CASADI_WITH_THREAD
42 #ifdef CASADI_WITH_THREAD_MINGW
43 #include <mingw.mutex.h>
63 template <
typename Scalar>
inline std::string
matrixName()
64 {
return std::string(
"Matrix<") +
typeid(Scalar).name() + std::string(
">");}
142 template<
typename Scalar>
145 public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<Matrix<Scalar> >),
147 public SWIG_IF_ELSE(PrintableCommon, Printable<Matrix<Scalar> >) {
233 Matrix(casadi_int nrow, casadi_int ncol);
239 explicit Matrix(
const std::pair<casadi_int, casadi_int>& rc);
244 std::vector<Scalar>* operator->();
249 const std::vector<Scalar>* operator->()
const;
353 #if !(defined(SWIG) && defined(SWIGMATLAB))
387 explicit Matrix(
const std::vector< std::vector<double> >& m);
410 nonzeros_(
std::vector<Scalar>(x.size())) {
411 auto x_it = x.begin();
412 for (
auto&& d : nonzeros_) d =
static_cast<Scalar
>(*x_it++);
460 auto x_it = x->begin();
461 for (
auto&& d : nonzeros_) d =
static_cast<Scalar
>(*x_it++);
466 Matrix(
const std::vector<Scalar>& x);
542 bool has_nz(casadi_int rr, casadi_int cc)
const;
576 bool __nonzero__()
const;
1109 static std::vector< Scalar >
call(
const Function& f,
const std::vector< Scalar > &x);
1127 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
1131 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
1143 static std::vector<Matrix<Scalar> >
1153 const std::string& lsolver,
const Dict& opts);
1158 const std::string& lsolver,
const Dict& opts);
1161 const std::string& lsolver,
const Dict& opts);
1165 const std::vector<std::string>& args);
1171 const std::string& v_prefix,
1172 const std::string& v_suffix);
1183 bool short_circuit=
false);
1187 bool short_circuit=
false);
1214 const Sparsity& sp,
bool intersect=
false);
1220 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
1221 const std::vector<casadi_int>& dim_c,
1222 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
1223 const std::vector<casadi_int>& c);
1226 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
1227 const std::vector<casadi_int>& dim_c,
1228 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
1229 const std::vector<casadi_int>& c);
1239 static std::vector<Matrix<Scalar> >
1241 const std::vector<casadi_int>& offset);
1243 static std::vector< Matrix<Scalar> >
1245 const std::vector<casadi_int>& offset);
1246 static std::vector< Matrix<Scalar> >
1248 const std::vector<casadi_int>& offset1,
1249 const std::vector<casadi_int>& offset2);
1255 const std::string& blas =
"reference");
1259 const std::string& blas =
"reference");
1292 static std::vector<std::vector<Matrix<Scalar> > >
1297 static std::vector<std::vector<Matrix<Scalar> > >
1303 casadi_int order=1,
bool tr=
false);
1311 const std::vector<casadi_int>& order_contributions);
1318 std::vector<casadi_int>& pc,
bool amd=
true);
1321 const std::vector<casadi_int>& prinv,
1322 const std::vector<casadi_int>& pc,
bool tr=
false);
1325 std::vector<casadi_int>& p,
bool amd=
true);
1361 #if !defined(SWIG) || defined(DOXYGEN)
1640 std::vector<casadi_int>& pc,
bool amd=
true) {
1690 const std::vector<casadi_int>& prinv,
1691 const std::vector<casadi_int>& pc,
bool tr=
false) {
1824 std::vector<casadi_int>& p,
bool amd=
true) {
1872 const std::vector<casadi_int>& p) {
2386 casadi_int order=5) {
2551 const std::vector<casadi_int>& order_contributions) {
2834 static void set_max_depth(casadi_int eq_depth=1);
2841 static casadi_int get_max_depth();
2877 static std::vector<Matrix<Scalar> > get_input(
const Function& f);
2912 static std::vector<Matrix<Scalar> > get_free(
const Function& f);
2938 static std::string type_name();
2984 void print_split(std::vector<std::string>& SWIG_OUTPUT(nz),
2985 std::vector<std::string>& SWIG_OUTPUT(inter))
const;
2994 void disp(std::ostream& stream,
bool more=
false)
const;
3022 void print_scalar(std::ostream &stream)
const;
3045 void print_vector(std::ostream &stream,
bool truncate=
true)
const;
3073 void print_dense(std::ostream &stream,
bool truncate=
true)
const;
3104 void print_sparse(std::ostream &stream,
bool truncate=
true)
const;
3108 static void print_default(std::ostream &stream,
const Sparsity& sp,
const Scalar* nonzeros,
3109 bool truncate=
true);
3112 static void print_scalar(std::ostream &stream,
const Scalar& e);
3115 static void print_vector(std::ostream &stream,
const Sparsity& sp,
const Scalar* nonzeros,
3116 bool truncate=
true);
3119 static void print_canonical(std::ostream &stream,
const Sparsity& sp,
const Scalar* nonzeros,
3120 bool truncate=
true);
3123 static void print_sparse(std::ostream &stream,
const Sparsity& sp,
const Scalar* nonzeros,
3124 bool truncate=
true);
3127 static void print_split(casadi_int nnz,
const Scalar* nonzeros, std::vector<std::string>& nz,
3128 std::vector<std::string>& inter);
3131 static void print_dense(std::ostream &stream,
const Sparsity& sp,
const Scalar* nonzeros,
3132 bool truncate=
true);
3189 void resize(casadi_int nrow, casadi_int ncol);
3246 void erase(
const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
3286 void erase(
const std::vector<casadi_int>& rr,
bool ind1=
false);
3322 void remove(
const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc);
3382 const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
3515 const std::vector<casadi_int>& col,
3518 const std::vector<casadi_int>& col,
3521 const std::vector<casadi_int>& col,
3523 const std::pair<casadi_int, casadi_int>& rc);
3686 casadi_int element_hash()
const;
3774 bool is_smooth()
const;
3781 bool is_leaf()
const;
3788 bool is_commutative()
const;
3804 bool is_symbolic()
const;
3817 bool is_valid_input()
const;
3867 bool has_duplicates()
const;
3872 void reset_input()
const;
3919 bool is_call()
const;
3924 bool is_output()
const;
3929 bool has_output()
const;
3934 casadi_int which_output()
const;
3998 casadi_int op()
const;
4001 bool is_op(casadi_int op)
const;
4129 template<
typename A>
4166 explicit operator double()
const;
4192 explicit operator casadi_int()
const;
4198 template<
typename A>
4199 explicit operator std::vector<A>()
const;
4231 std::string name()
const;
4279 casadi_int n_dep()
const;
4323 static void set_precision(casadi_int precision);
4324 static void set_width(casadi_int width);
4325 static void set_scientific(
bool scientific);
4330 static casadi_int get_precision();
4331 static casadi_int get_width();
4332 static bool get_scientific();
4370 static void rng(casadi_int seed);
4418 const std::pair<casadi_int, casadi_int>& rc);
4600 const Scalar* nonzeros,
const std::string& format=
"");
4674 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
4675 static std::mutex& get_mutex_temp();
4683 std::vector<Scalar> nonzeros_;
4686 static casadi_int stream_precision_;
4687 static casadi_int stream_width_;
4688 static bool stream_scientific_;
4691 static std::default_random_engine rng_;
4697 template<
typename Scalar>
4698 template<
typename A>
4700 std::vector<A> ret(nnz());
4701 auto r = ret.begin();
4702 for (
auto&& e : nonzeros()) *r++ =
static_cast<A
>(e);
4707 template<
typename Scalar>
4708 template<
typename A>
4711 casadi_int size1 = this->size1(), size2 = this->size2();
4712 const casadi_int *colind = this->colind(), *row = this->row();
4714 auto it = nonzeros().begin();
4715 std::vector<A> ret(numel(), 0);
4716 for (casadi_int cc=0; cc<size2; ++cc) {
4717 for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
4718 ret[row[el] + cc*size1] =
static_cast<A
>(*it++);
Helper class for Serialization.
Sparse matrix class. SX and DM are specializations.
static Matrix< Scalar > minor(const Matrix< Scalar > &x, casadi_int i, casadi_int j)
static std::string print_operator(const Matrix< Scalar > &x, const std::vector< std::string > &args)
std::vector< Scalar > & nonzeros()
static Matrix< Scalar > qr_solve(const Matrix< Scalar > &b, const Matrix< Scalar > &v, const Matrix< Scalar > &r, const Matrix< Scalar > &beta, const std::vector< casadi_int > &prinv, const std::vector< casadi_int > &pc, bool tr=false)
static Matrix< Scalar > mtaylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order, const std::vector< casadi_int > &order_contributions)
static std::vector< Matrix< Scalar > > transform(const std::vector< Matrix< Scalar > > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
static void qr(const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R)
static Matrix< Scalar > chol(const Matrix< Scalar > &A)
static Matrix< Scalar > transform(const Matrix< Scalar > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
static std::vector< std::vector< Matrix< Scalar > > > reverse(const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &arg, const std::vector< std::vector< Matrix< Scalar > > > &v, const Dict &opts=Dict())
static Matrix< Scalar > simplify(const Matrix< Scalar > &x)
Matrix(const Matrix< A > &x)
Create a matrix from another matrix with a different entry type.
static Matrix< Scalar > sparsity_cast(const Matrix< Scalar > &x, const Sparsity &sp)
bool is_inf() const
check if the matrix is inf (note that false negative answers are possible)
static void extract_parametric(const Matrix< Scalar > &expr, const Matrix< Scalar > &par, Matrix< Scalar > &expr_ret, std::vector< Matrix< Scalar > > &symbols, std::vector< Matrix< Scalar >> ¶metric, const Dict &opts)
static Matrix< Scalar > nan(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with every nonzero equal to nan.
bool has_zeros() const
Check if any structural nonzero is known to be numerically zero.
static Matrix< Scalar > deserialize(const std::string &s)
Build a matrix from a string produced by serialize.
static Matrix< Scalar > if_else(const Matrix< Scalar > &x, const Matrix< Scalar > &if_true, const Matrix< Scalar > &if_false, bool short_circuit=false)
static std::vector< bool > which_depends(const Matrix< Scalar > &expr, const Matrix< Scalar > &var, casadi_int order=1, bool tr=false)
static Matrix< Scalar > rectangle(const Matrix< Scalar > &x)
static Matrix< Scalar > gauss_quadrature(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order, const Matrix< Scalar > &w)
void serialize(std::ostream &stream) const
Serialize an object.
bool is_one() const
check if the matrix is 1 (note that false negative answers are possible)
void remove(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc)
Delete rows and columns, shrinking the matrix in place.
static Matrix< Scalar > unite(const Matrix< Scalar > &A, const Matrix< Scalar > &B)
Matrix(double val)
Dense 1-by-1 matrix holding a number; enables implicit conversion from a numeric type.
Matrix< Scalar > T() const
Transpose the matrix.
static void separate_linear(const Matrix< Scalar > &expr, const Matrix< Scalar > &sym_lin, const Matrix< Scalar > &sym_const, Matrix< Scalar > &expr_const, Matrix< Scalar > &expr_lin, Matrix< Scalar > &expr_nonlin)
static Matrix< Scalar > det(const Matrix< Scalar > &x)
static Matrix< Scalar > conditional(const Matrix< Scalar > &ind, const std::vector< Matrix< Scalar > > &x, const Matrix< Scalar > &x_default, bool short_circuit=false)
static Matrix< Scalar > solve(const Matrix< Scalar > &A, const Matrix< Scalar > &b, const std::string &lsolver, const Dict &opts)
static Matrix< Scalar > diagcat(const std::vector< Matrix< Scalar > > &A)
static Matrix< Scalar > reshape(const Matrix< Scalar > &x, casadi_int nrow, casadi_int ncol)
static std::vector< Matrix< Scalar > > call(const Function &f, const std::vector< Matrix< Scalar > > &x)
Create nodes by their ID.
static Matrix< Scalar > scalar_matrix(casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Create nodes by their ID.
Scalar ScalarType
Scalar type.
static Matrix< Scalar > pinv(const Matrix< Scalar > &A, const std::string &lsolver, const Dict &opts)
static Matrix< Scalar > _rank1(const Matrix< Scalar > &A, const Matrix< Scalar > &alpha, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
static Matrix< Scalar > diag(const Matrix< Scalar > &x)
static Matrix< Scalar > rand(const Sparsity &sp)
Create a matrix with uniformly distributed random numbers in [0, 1)
static Matrix< Scalar > sum1(const Matrix< Scalar > &x)
void resize(casadi_int nrow, casadi_int ncol)
Change the shape in place, keeping nonzeros that remain inside the new bounds.
friend Scalar * get_ptr(Matrix< Scalar > &v)
Sparsity get_sparsity() const
Get the sparsity pattern (Python: sparsity())
static Matrix< Scalar > expm_const(const Matrix< Scalar > &A, const Matrix< Scalar > &t)
static Matrix< Scalar > mac(const Matrix< Scalar > &x, const Matrix< Scalar > &y, const Matrix< Scalar > &z, const std::string &blas="reference")
static std::vector< Matrix< Scalar > > transform(const std::vector< Matrix< Scalar > > &x, const Dict &opts=Dict())
static Matrix< Scalar > deserialize(std::istream &stream)
Build a matrix from a serialization stream.
static Matrix< Scalar > mrdivide(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
void erase(const std::vector< casadi_int > &rr, bool ind1=false)
Erase the elements at the given linear indices, leaving structural zeros.
static Matrix< Scalar > transform(const Matrix< Scalar > &x, const Dict &opts=Dict())
void clear()
Reset to an empty 0-by-0 matrix, in place.
static std::vector< Matrix< Scalar > > symvar(const Matrix< Scalar > &x)
bool is_value(double val) const
check if the matrix is value
void export_code(const std::string &lang, std::ostream &stream=casadi::uout(), const Dict &options=Dict()) const
Export matrix in specific language.
static void ldl(const Matrix< Scalar > &A, Matrix< Scalar > &D, Matrix< Scalar > <, std::vector< casadi_int > &p, bool amd=true)
static Matrix< Scalar > ramp(const Matrix< Scalar > &x)
const Sparsity & sparsity() const
Const access the sparsity - reference to data member.
static Matrix< Scalar > expm(const Matrix< Scalar > &A)
void serialize(SerializingStream &s) const
Serialize an object.
static Matrix< Scalar > mmax(const Matrix< Scalar > &x)
static Matrix< Scalar > inv(const Matrix< Scalar > &A)
static Matrix< Scalar > hessian(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Dict &opts=Dict())
static void shared(std::vector< Matrix< Scalar > > &ex, std::vector< Matrix< Scalar > > &v, std::vector< Matrix< Scalar > > &vdef, const std::string &v_prefix, const std::string &v_suffix)
static std::vector< Matrix< Scalar > > substitute(const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &vdef)
static Matrix< Scalar > inv_minor(const Matrix< Scalar > &x)
Matrix(const Sparsity &sp)
Create a matrix with the given sparsity pattern and all nonzeros equal to one.
static Matrix< Scalar > matrix_matrix(casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Create nodes by their ID.
Matrix(casadi_int nrow, casadi_int ncol)
Create a matrix of the given shape with all structural zeros (no nonzeros)
static Matrix< Scalar > heaviside(const Matrix< Scalar > &x)
static casadi_int n_nodes(const Matrix< Scalar > &x)
static std::vector< Matrix< Scalar > > diagsplit(const Matrix< Scalar > &x, const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2)
Matrix< Scalar > operator+() const
static Matrix< Scalar > hessian(const Matrix< Scalar > &f, const Matrix< Scalar > &x, Matrix< Scalar > &g, const Dict &opts=Dict())
Matrix(const std::pair< casadi_int, casadi_int > &rc)
Create a sparse matrix with all structural zeros.
static std::vector< Matrix< Scalar > > horzsplit(const Matrix< Scalar > &x, const std::vector< casadi_int > &offset)
static Matrix< Scalar > nan(const Sparsity &sp)
Create a matrix with every nonzero equal to nan.
static Matrix< Scalar > gauss_quadrature(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order=5)
static Matrix< Scalar > mtimes(const Matrix< Scalar > &x, const Matrix< Scalar > &y, const std::string &blas="reference")
static Matrix< Scalar > pw_lin(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
static Matrix< Scalar > taylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order)
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, casadi_int nrow, casadi_int ncol)
Construct a sparse matrix from triplet form (row indices, column indices, values)
static Matrix< Scalar > mldivide(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
bool is_minus_one() const
check if the matrix is -1 (note that false negative answers are possible)
static Matrix< Scalar > all(const Matrix< Scalar > &x)
static Matrix< Scalar > binary(casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Create nodes by their ID.
friend const Scalar * get_ptr(const Matrix< Scalar > &v)
void to_file(const std::string &filename, const std::string &format="") const
Write a numerical matrix to a text file (DM only)
static Matrix< Scalar > norm_2(const Matrix< Scalar > &x)
static std::vector< std::vector< Matrix< Scalar > > > forward(const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &arg, const std::vector< std::vector< Matrix< Scalar > > > &v, const Dict &opts=Dict())
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d)
Construct a sparse matrix from triplet form (row indices, column indices, values)
static void expand(const Matrix< Scalar > &x, Matrix< Scalar > &weights, Matrix< Scalar > &terms)
static Matrix< Scalar > adj(const Matrix< Scalar > &x)
bool is_half() const
check if the matrix is 0.5 (note that false negative answers are possible)
static Matrix< Scalar > det(const Matrix< Scalar > &x, const std::string &lsolver, const Dict &dict=Dict())
static Matrix< Scalar > matrix_scalar(casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Create nodes by their ID.
static Matrix< Scalar > _logsumexp(const Matrix< Scalar > &x)
static bool simplify_const_folding(std::vector< Matrix< Scalar > > &arg, std::vector< Matrix< Scalar > > &res, const Dict &opts=Dict())
static bool depends_on(const Matrix< Scalar > &x, const Matrix< Scalar > &arg)
static Matrix< Scalar > unary(casadi_int op, const Matrix< Scalar > &x)
Create nodes by their ID.
void disp(std::ostream &stream, bool more=false) const
Print a representation of the object to a stream.
static Matrix< Scalar > rand(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with uniformly distributed random numbers in [0, 1)
static Matrix< Scalar > inv(const Matrix< Scalar > &A, const std::string &lsolver, const Dict &opts)
Matrix(const Sparsity &sp, const Scalar &val, bool dummy)
Sparse matrix with a given sparsity with all values same.
bool is_eye() const
check if the matrix is an identity matrix (note that false negative answers
static Matrix< Scalar > solve(const Matrix< Scalar > &A, const Matrix< Scalar > &b)
static void substitute_inplace(const std::vector< Matrix< Scalar > > &v, std::vector< Matrix< Scalar > > &vdef, std::vector< Matrix< Scalar > > &ex, bool revers)
static Matrix< Scalar > ldl_solve(const Matrix< Scalar > &b, const Matrix< Scalar > &D, const Matrix< Scalar > <, const std::vector< casadi_int > &p)
static Matrix< Scalar > mmin(const Matrix< Scalar > &x)
static Matrix< Scalar > any(const Matrix< Scalar > &x)
static Matrix< Scalar > sparsify(const Matrix< Scalar > &x, double tol=0)
const std::vector< Scalar > & nonzeros() const
bool is_minus_inf() const
check if the matrix is -inf (note that false negative answers are possible)
void erase(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Erase the block at the given rows and columns, leaving structural zeros.
static Matrix< Scalar > polyval(const Matrix< Scalar > &p, const Matrix< Scalar > &x)
static Matrix< Scalar > norm_1(const Matrix< Scalar > &x)
static Matrix< Scalar > nullspace(const Matrix< Scalar > &x)
static Matrix< Scalar > inf(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with every nonzero equal to +inf.
const Scalar * ptr() const
static Matrix< Scalar > _bilin(const Matrix< Scalar > &A, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
static Matrix< Scalar > cofactor(const Matrix< Scalar > &A, casadi_int i, casadi_int j)
static Matrix< Scalar > blockcat(const std::vector< std::vector< Matrix< Scalar > > > &v)
std::vector< Scalar > get_elements() const
Get all elements as a flat list in column-major order (Python: elements())
static bool simplify_combine_terms(std::vector< Matrix< Scalar > > &arg, std::vector< Matrix< Scalar > > &res, const Dict &opts=Dict())
static bool contains_any(const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &n)
static Matrix< Scalar > substitute(const Matrix< Scalar > &ex, const Matrix< Scalar > &v, const Matrix< Scalar > &vdef)
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, const std::pair< casadi_int, casadi_int > &rc)
Construct a sparse matrix from triplet form (row indices, column indices, values)
static Matrix< Scalar > eig_symbolic(const Matrix< Scalar > &m)
Matrix(const std::vector< std::vector< double > > &m)
Dense matrix from a list of rows.
static bool contains(const std::vector< Matrix< Scalar > > &v, const Matrix< Scalar > &n)
bool is_zero() const
check if the matrix is 0 (note that false negative answers are possible)
static Matrix< Scalar > dot(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
static Matrix< Scalar > norm_fro(const Matrix< Scalar > &x)
static Matrix< Scalar > vertcat(const std::vector< Matrix< Scalar > > &v)
static Matrix< Scalar > inf(const Sparsity &sp)
Create a matrix with every nonzero equal to +inf.
Matrix(std::initializer_list< Scalar > x)
Construct from initializer list.
static bool contains_all(const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &n)
static Matrix< double > from_file(const std::string &filename, const std::string &format_hint="")
Read a numerical matrix from a text file written by to_file (DM only)
static void extract(std::vector< Matrix< Scalar >> &ex, std::vector< Matrix< Scalar >> &v, std::vector< Matrix< Scalar >> &vdef, const Dict &opts=Dict())
std::string serialize() const
Serialize to a string.
void enlarge(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Enlarge the matrix in place, moving the existing rows and columns to new positions.
static std::vector< Matrix< Scalar > > cse(const std::vector< Matrix< Scalar > > &e)
static Matrix< Scalar > deserialize(DeserializingStream &s)
static Matrix< Scalar > reshape(const Matrix< Scalar > &x, const Sparsity &sp)
static Matrix< Scalar > norm_inf_mul(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
bool is_constant() const
Check if every entry is a numerical constant (no symbols)
static Matrix< Scalar > horzcat(const std::vector< Matrix< Scalar > > &v)
GenericMatrix< Matrix< Scalar > > B
Base class.
static Matrix< Scalar > sum2(const Matrix< Scalar > &x)
static Matrix< double > evalf(const Matrix< Scalar > &m)
bool is_nonnegative() const
check if the matrix is not negative
Matrix(const std::vector< A > &x)
Dense column vector from a flat list of numbers.
void reserve(casadi_int nnz)
Reserve storage for the given number of nonzeros (performance hint, no visible effect)
static Matrix< Scalar > norm_inf(const Matrix< Scalar > &x)
std::vector< A > get_nonzeros() const
Get all nonzeros.
static Matrix< Scalar > trace(const Matrix< Scalar > &x)
static std::vector< Scalar > call(const Function &f, const std::vector< Scalar > &x)
Create nodes by their ID.
void reserve(casadi_int nnz, casadi_int ncol)
static Matrix< Scalar > eye(casadi_int n)
Create an n-by-n identity matrix.
static Matrix< Scalar > jacobian(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Dict &opts=Dict())
static Matrix< Scalar > mtaylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order)
Matrix(const Sparsity &sp, const Matrix< Scalar > &d)
Create a matrix with a given sparsity pattern and given nonzeros.
static Matrix< Scalar > rand(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with uniformly distributed random numbers in [0, 1)
bool is_integer() const
Check if the matrix is integer-valued.
static bool is_equal(const Matrix< Scalar > &x, const Matrix< Scalar > &y, casadi_int depth=0)
Matrix< Scalar > operator-() const
static Matrix< Scalar > triangle(const Matrix< Scalar > &x)
static Sparsity jacobian_sparsity(const Matrix< Scalar > &f, const Matrix< Scalar > &x)
static Matrix< Scalar > project(const Matrix< Scalar > &x, const Sparsity &sp, bool intersect=false)
static void qr_sparse(const Matrix< Scalar > &A, Matrix< Scalar > &V, Matrix< Scalar > &R, Matrix< Scalar > &beta, std::vector< casadi_int > &prinv, std::vector< casadi_int > &pc, bool amd=true)
static Matrix< Scalar > pw_const(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
static Matrix< Scalar > poly_coeff(const Matrix< Scalar > &ex, const Matrix< Scalar > &x)
static std::vector< Matrix< Scalar > > vertsplit(const Matrix< Scalar > &x, const std::vector< casadi_int > &offset)
Matrix(const Sparsity &sp, const std::vector< Scalar > &d, bool dummy)
Sparse matrix with a given sparsity and non-zero elements.
static Matrix< Scalar > nan(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with every nonzero equal to nan.
static Matrix< Scalar > poly_roots(const Matrix< Scalar > &p)
static Matrix< Scalar > inf(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with every nonzero equal to +inf.
std::string get_str(bool more=false) const
Get the string representation that disp prints.
Matrix< Scalar > printme(const Matrix< Scalar > &y) const
const Scalar scalar() const
Convert to scalar type.
std::vector< Scalar > get_nonzeros() const
Get all structural nonzeros as a flat list in column-major order (Python: nonzeros())
static Matrix< Scalar > pinv(const Matrix< Scalar > &x)
static bool simplify_ref_count(std::vector< Matrix< Scalar > > &arg, std::vector< Matrix< Scalar > > &res, const Dict &opts=Dict())
static Matrix< Scalar > kron(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
static void to_file(const std::string &filename, const Sparsity &sp, const Scalar *nonzeros, const std::string &format="")
Helper class for Serialization.
Class representing a Slice.
std::string matrixName()
Get typename.
std::string matrixName< casadi_int >()
Get typename.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::vector< T > cumsum(const std::vector< T > &values)
cumulative sum
bool is_regular(const std::vector< T > &v)
Checks if array does not contain NaN or Inf.
std::string matrixName< double >()
Get typename.
std::string filename(const std::string &path)