26 #include "monitor.hpp"
31 casadi_assert_dev(x.
nnz()>0);
37 return "monitor(" + arg.at(0) +
", " + comment_ +
")";
41 res[0] = arg[0].monitor(comment_);
45 std::vector<std::vector<MX> >& fsens)
const {
46 for (casadi_int d=0; d<fsens.size(); ++d) {
48 ss <<
"fwd(" << d <<
") of " << comment_;
49 fsens[d][0] = fseed[d][0].monitor(ss.str());
54 std::vector<std::vector<MX> >& asens)
const {
55 for (casadi_int d=0; d<aseed.size(); ++d) {
57 ss <<
"adj(" << d <<
") of " << comment_;
58 asens[d][0] += aseed[d][0].monitor(ss.str());
64 std::copy(arg[0], arg[0]+
nnz(), res[0]);
69 int Monitor::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
71 uout() << comment_ <<
":" << std::endl;
74 for (casadi_int i=0; i<n; ++i) {
75 if (i!=0)
uout() <<
", ";
78 uout() <<
"]" << std::endl;
82 std::copy(arg[0], arg[0]+n, res[0]);
89 std::copy(arg[0], arg[0]+
nnz(), res[0]);
99 for (casadi_int i=0; i<n; ++i) {
108 const std::vector<casadi_int>& arg,
109 const std::vector<casadi_int>& res,
110 const std::vector<bool>& arg_is_ref,
111 std::vector<bool>& res_is_ref)
const {
113 g.
local(
"cr",
"const casadi_real",
"*");
114 g.
local(
"i",
"casadi_int");
115 g << g.
printf(comment_ +
"\\n[") <<
"\n"
116 <<
" for (i=0, cr=" << g.
work(arg[0],
dep(0).
nnz(), arg_is_ref[0])
117 <<
"; i!=" <<
nnz() <<
"; ++i) {\n"
118 <<
" if (i!=0) " << g.
printf(
", ") <<
"\n"
119 <<
" " << g.
printf(
"%g",
"*cr++") <<
"\n"
121 <<
" " << g.
printf(
"]\\n") <<
"\n";
128 s.
pack(
"Monitor::comment", comment_);
132 s.
unpack(
"Monitor::comment", comment_);
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string printf(const std::string &str, const std::vector< std::string > &arg=std::vector< std::string >())
Printf.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
Node class for MX objects.
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
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 serialize_body(SerializingStream &s) const
Serialize an object without type information.
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.
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 ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
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 override
Evaluate symbolically (MX)
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Monitor(const MX &x, const std::string &comment)
Constructor.
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 sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
unsigned long long bvec_t