26 #include "monitor.hpp"
27 #include "function_internal.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;
76 std::copy(arg[0], arg[0]+
nnz(), res[0]);
83 std::copy(arg[0], arg[0]+
nnz(), res[0]);
93 for (casadi_int i=0; i<n; ++i) {
102 const std::vector<casadi_int>& arg,
103 const std::vector<casadi_int>& res,
104 const std::vector<bool>& arg_is_ref,
105 std::vector<bool>& res_is_ref)
const {
107 std::string a = g.
work(arg[0],
dep(0).
nnz(), arg_is_ref[0]);
108 g << g.
printf(comment_ +
":\\n") <<
"\n";
110 g << g.
printf(
"\\n") <<
"\n";
116 s.
pack(
"Monitor::comment", comment_);
120 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.
std::string print_canonical(const Sparsity &sp, const std::string &arg)
Print canonical representaion of a matrix.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
static void print_canonical(std::ostream &stream, const Sparsity &sp, const double *nz)
Print canonical representation of a numeric matrix.
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
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 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