26 #include "reshape.hpp"
27 #include "casadi_misc.hpp"
32 casadi_assert_dev(x.
nnz()==sp.
nnz());
37 int Reshape::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
38 return eval_gen<double>(arg, res, iw, w);
42 return eval_gen<SXElem>(arg, res, iw, w);
47 if (arg[0]!=res[0]) std::copy(arg[0], arg[0]+
nnz(), res[0]);
65 return arg.at(0) +
"'";
69 return "vec(" + arg.at(0) +
")";
71 return "reshape(" + arg.at(0) +
")";
77 res[0] = reshape(arg[0],
size());
81 std::vector<std::vector<MX> >& fsens)
const {
82 for (casadi_int d = 0; d<fsens.size(); ++d) {
83 fsens[d][0] = reshape(fseed[d][0],
size());
88 std::vector<std::vector<MX> >& asens)
const {
89 for (casadi_int d=0; d<aseed.size(); ++d) {
90 asens[d][0] += reshape(aseed[d][0],
dep().
size());
95 const std::vector<casadi_int>& arg,
96 const std::vector<casadi_int>& res,
97 const std::vector<bool>& arg_is_ref,
98 std::vector<bool>& res_is_ref)
const {
103 return reshape(
dep(0), sp);
133 split_primitives_gen<MX>(x, it);
137 split_primitives_gen<SX>(x, it);
141 split_primitives_gen<DM>(x, it);
150 return join_primitives_gen<MX>(it);
154 return join_primitives_gen<SX>(it);
158 return join_primitives_gen<DM>(it);
Helper class for C code generation.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
virtual void reset_input() const
Reset the marker for an input expression.
virtual casadi_int n_primitives() const
Get the number of symbolic primitives.
static void copy_fwd(const bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities forward through a copy operation.
virtual bool has_duplicates() const
Detect duplicate symbolic expressions.
virtual bool is_valid_input() const
Check if valid function input.
static void copy_rev(bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities backwards through a copy operation.
std::pair< casadi_int, casadi_int > size() const
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
const Sparsity & sparsity() const
Get the sparsity.
casadi_int nnz(casadi_int i=0) const
const MX & dep(casadi_int ind=0) const
dependencies - functions that have to be evaluated before this one
virtual void primitives(std::vector< MX >::iterator &it) const
Get symbolic primitives.
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
virtual MX get_transpose() const
Transpose.
void set_dep(const MX &dep)
Set unary dependency.
virtual void split_primitives(const MX &x, std::vector< MX >::iterator &it) const
Split up an expression along symbolic primitives.
Sparse matrix class. SX and DM are specializations.
MX get_reshape(const Sparsity &sp) const override
Reshape.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
bool has_duplicates() const override
Detect duplicate symbolic expressions.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
T join_primitives_gen(typename std::vector< T >::const_iterator &it) const
Join an expression along symbolic primitives (template)
MX join_primitives(std::vector< MX >::const_iterator &it) const override
Join an expression along symbolic primitives.
void split_primitives_gen(const T &x, typename std::vector< T >::iterator &it) const
Split up an expression along primitives (template)
void primitives(std::vector< MX >::iterator &it) const override
Get symbolic primitives.
void reset_input() const override
Reset the marker for an input expression.
Reshape(const MX &x, Sparsity sp)
Constructor.
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
MX get_transpose() const override
Transpose (if a dimension is one)
bool is_valid_input() const override
Check if valid function input.
casadi_int n_primitives() const override
Get the number of symbolic primitives.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
void split_primitives(const MX &x, std::vector< MX >::iterator &it) const override
Split up an expression along symbolic primitives.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res, const std::vector< bool > &arg_is_ref, std::vector< bool > &res_is_ref) const override
Generate code for the operation.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const override
Evaluate symbolically (MX)
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
The basic scalar symbolic class of CasADi.
casadi_int nnz() const
Get the number of (structural) non-zeros.
unsigned long long bvec_t