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 const std::vector<bool>& unique)
const {
62 bool unique_arg0 = !unique.empty() && unique[0];
63 res[0] = arg[0]->get_project(
sparsity(), unique_arg0);
80 std::vector<unsigned char>
mapping;
84 std::vector<casadi_int> dnz;
104 std::vector<std::vector<MX> >& fsens)
const {
105 casadi_int nfwd = fsens.size();
106 for (casadi_int d=0; d<nfwd; ++d) {
112 std::vector<std::vector<MX> >& asens)
const {
113 casadi_int nadj = aseed.size();
114 for (casadi_int d=0; d<nadj; ++d) {
126 std::fill(res[0], res[0]+
nnz(), 0);
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 {
141 s.
pack(
"Project::type",
'n');
146 s.
pack(
"Project::type",
'd');
151 s.
pack(
"Project::type",
's');
156 s.
unpack(
"Project::type", t);
165 casadi_assert_dev(
false);
170 const std::vector<casadi_int>& arg,
171 const std::vector<casadi_int>& res,
172 const std::vector<bool>& arg_is_ref,
173 std::vector<bool>& res_is_ref)
const {
175 g.
work(res.front(),
nnz(),
false)) <<
"\n";
179 const std::vector<casadi_int>& arg,
180 const std::vector<casadi_int>& res,
181 const std::vector<bool>& arg_is_ref,
182 std::vector<bool>& res_is_ref)
const {
199 int Densify::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
200 return eval_gen<double>(arg, res, iw, w);
204 return eval_gen<SXElem>(arg, res, iw, w);
207 int Sparsify::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
208 return eval_gen<double>(arg, res, iw, w);
212 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 MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz, bool unique=false) const
Get the nonzeros of matrix.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual Matrix< casadi_int > mapping() const
Get an IM representation of a GetNonzeros or SetNonzeros node.
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.
virtual MX get_project(const Sparsity &sp, bool unique=false) const
Create set sparse.
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)
MX get_project(const Sparsity &sp, bool unique=false) const override
Create set sparse.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz, bool unique=false) const override
Get the nonzeros of matrix.
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.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
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.
bool is_subset(const Sparsity &rhs) const
Is subset?
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.
Sparsity intersect(const Sparsity &y, std::vector< unsigned char > &mapping) const
Intersection of two sparsity patterns.
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.