26 #include "unary_mx.hpp"
27 #include "casadi_misc.hpp"
28 #include "global_options.hpp"
29 #include "serializing_stream.hpp"
37 if (!operation_checker<F00Checker>(
op_)) {
49 int UnaryMX::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
50 double dummy = std::numeric_limits<double>::quiet_NaN();
67 std::vector<std::array<MX, 3> >& res)
const {
73 std::vector<std::vector<MX> >& fsens)
const {
80 for (casadi_int d=0; d<fsens.size(); ++d) {
81 fsens[d][0] = pd[0]*fseed[d][0];
86 std::vector<std::vector<MX> >& asens)
const {
93 for (casadi_int d=0; d<aseed.size(); ++d) {
94 asens[d][0] += pd[0]*aseed[d][0];
109 const std::vector<casadi_int>& arg,
110 const std::vector<casadi_int>& res,
111 const std::vector<bool>& arg_is_ref,
112 std::vector<bool>& res_is_ref)
const {
120 g.
local(
"cs",
"const casadi_real",
"*");
121 g.
local(
"rr",
"casadi_real",
"*");
122 g.
local(
"i",
"casadi_int");
123 g <<
"for (i=0, rr=" << g.
work(res[0],
nnz(),
false) <<
", cs="
124 << g.
work(arg[0],
nnz(), arg_is_ref[0])
131 g << r <<
" = " << g.
print_op(
op_,
" " + x +
" ") <<
";\n";
146 else if (
op==
OP_FABS)
return shared_from_this<MX>();
150 else if (
op==
OP_FABS)
return shared_from_this<MX>();
154 else if (
op==
OP_FABS)
return shared_from_this<MX>();
160 if (
op==
OP_FABS)
return shared_from_this<MX>();
203 s.
pack(
"UnaryMX::op",
static_cast<int>(
op_));
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string print_op(casadi_int op, const std::string &a0)
Print an operation to a c file.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
std::string workel(casadi_int n) const
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
static MX ones(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries one.
static bool simplification_on_the_fly
Indicates whether simplifications should be made on the fly.
Node class for MX objects.
static void copy_fwd(const bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities forward through a copy operation.
static bool maxDepth()
Get equality checking depth.
static void copy_rev(bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities backwards through a copy operation.
virtual MX get_unary(casadi_int op) const
Get a unary operation.
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.
virtual casadi_int op() const =0
Get the operation.
void set_dep(const MX &dep)
Set unary dependency.
virtual MX _get_binary(casadi_int op, const MX &y, bool scX, bool scY) const
Get a binary operation operation (matrix-matrix)
const Sparsity & sparsity() const
Get the sparsity pattern.
static bool is_equal(const MX &x, const MX &y, casadi_int depth=0)
casadi_int op() const
Get operation type.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
casadi_int nnz() const
Get the number of (structural) non-zeros.
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
MX _get_binary(casadi_int op, const MX &y, bool scX, bool scY) const override
Get a binary operation operation.
void eval_linear(const std::vector< std::array< MX, 3 > > &arg, std::vector< std::array< MX, 3 > > &res) const override
Evaluate the MX node on a const/linear/nonlinear partition.
casadi_int op() const override
Get the operation.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const override
Evaluate symbolically (MX)
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 serialize_body(SerializingStream &s) const override
Serialize an object without type information.
MX get_unary(casadi_int op) const override
Get a unary operation.
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.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
UnaryMX(Operation op, MX x)
Constructor is private, use "create" below.
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
unsigned long long bvec_t
Operation
Enum for quick access to any node.
static void der(unsigned char op, const T &x, const T &y, const T &f, T *d)
Evaluate a built in derivative function.
static void fun_linear(unsigned char op, const T *x, const T *y, T *f)
Evaluate function on a const/linear/nonlinear partition.
static std::string print(unsigned char op, const std::string &x, const std::string &y)
Print.
static void fun(unsigned char op, const T &x, const T &y, T &f)
Evaluate a built in function (scalar-scalar)