26 #include "project.hpp"
27 #include "casadi_misc.hpp"
40 return "dense(" + arg.at(0) +
")";
42 return "project(" + arg.at(0) +
")";
52 int Project::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
53 return eval_gen<double>(arg, res, iw, w);
57 return eval_gen<SXElem>(arg, res, iw, w);
61 res[0] = project(arg[0],
sparsity());
65 std::vector<std::vector<MX> >& fsens)
const {
66 casadi_int nfwd = fsens.size();
67 for (casadi_int d=0; d<nfwd; ++d) {
73 std::vector<std::vector<MX> >& asens)
const {
74 casadi_int nadj = aseed.size();
75 for (casadi_int d=0; d<nadj; ++d) {
87 std::fill(res[0], res[0]+
nnz(), 0);
92 const std::vector<casadi_int>& arg,
93 const std::vector<casadi_int>& res,
94 const std::vector<bool>& arg_is_ref,
95 std::vector<bool>& res_is_ref)
const {
102 s.
pack(
"Project::type",
'n');
107 s.
pack(
"Project::type",
'd');
112 s.
pack(
"Project::type",
's');
117 s.
unpack(
"Project::type", t);
126 casadi_assert_dev(
false);
131 const std::vector<casadi_int>& arg,
132 const std::vector<casadi_int>& res,
133 const std::vector<bool>& arg_is_ref,
134 std::vector<bool>& res_is_ref)
const {
136 g.
work(res.front(),
nnz(),
false)) <<
"\n";
140 const std::vector<casadi_int>& arg,
141 const std::vector<casadi_int>& res,
142 const std::vector<bool>& arg_is_ref,
143 std::vector<bool>& res_is_ref)
const {
160 int Densify::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
161 return eval_gen<double>(arg, res, iw, w);
165 return eval_gen<SXElem>(arg, res, iw, w);
168 int Sparsify::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
169 return eval_gen<double>(arg, res, iw, w);
173 return eval_gen<SXElem>(arg, res, iw, w);
Helper class for C code generation.
std::string project(const std::string &arg, const Sparsity &sp_arg, const std::string &res, const Sparsity &sp_res, const std::string &w)
Sparse assignment.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string sparsify(const std::string &arg, const std::string &res, const Sparsity &sp_res, bool tr=false)
Sparsify.
std::string densify(const std::string &arg, const Sparsity &sp_arg, const std::string &res, bool tr=false)
Densify.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void serialize_type(SerializingStream &s) const override
Serialize type information.
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.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
Node class for MX objects.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
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
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
void set_dep(const MX &dep)
Set unary dependency.
const Sparsity & sparsity() const
Get the sparsity pattern.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const override
Evaluate symbolically (MX)
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
Project(const MX &x, const Sparsity &sp)
Constructor.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
void serialize_type(SerializingStream &s) const override
Serialize type information.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
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 ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
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.
void serialize_type(SerializingStream &s) const override
Serialize type information.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
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 bor(T *data, const T *val_data, const Sparsity &val_sp) const
Bitwise or of the nonzero entries of one sparsity pattern and the nonzero.
void set(T *data, const T *val_data, const Sparsity &val_sp) const
Assign the nonzero entries of one sparsity pattern to the nonzero.
unsigned long long bvec_t
void casadi_sparsify(const T1 *x, T2 *y, const casadi_int *sp_y, casadi_int tr)
Convert dense to sparse.
void casadi_project(const T1 *x, const casadi_int *sp_x, T1 *y, const casadi_int *sp_y, T1 *w)
Sparse copy: y <- x, w work vector (length >= number of rows)
void casadi_densify(const T1 *x, const casadi_int *sp_x, T2 *y, casadi_int tr)
Convert sparse to dense.