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();
62 const std::vector<bool>& unique)
const {
63 bool unique_arg0 = !unique.empty() && unique[0];
68 std::vector<std::array<MX, 3> >& res)
const {
74 std::vector<std::vector<MX> >& fsens)
const {
81 for (casadi_int d=0; d<fsens.size(); ++d) {
82 fsens[d][0] = pd[0]*fseed[d][0];
87 std::vector<std::vector<MX> >& asens)
const {
94 for (casadi_int d=0; d<aseed.size(); ++d) {
95 asens[d][0] += pd[0]*aseed[d][0];
105 const bvec_t zero_out = operation_checker<F0XChecker>(
op_) ? 0 : ~static_cast<bvec_t>(0);
108 for (casadi_int i=0; i<nnz(); ++i) r[i] = a[i] ? ~static_cast<bvec_t>(0) : zero_out;
118 const std::vector<casadi_int>& arg,
119 const std::vector<casadi_int>& res,
120 const std::vector<bool>& arg_is_ref,
121 std::vector<bool>& res_is_ref)
const {
129 g.
local(
"cs",
"const casadi_real",
"*");
130 g.
local(
"rr",
"casadi_real",
"*");
131 g.
local(
"i",
"casadi_int");
132 g <<
"for (i=0, rr=" << g.
work(res[0],
nnz(),
false) <<
", cs="
133 << g.
work(arg[0],
nnz(), arg_is_ref[0])
140 g << r <<
" = " << g.
print_op(
op_,
" " + x +
" ") <<
";\n";
144 return operation_checker<NonnegativeChecker>(
op_);
148 bool unique_x,
bool unique_y)
const {
177 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.
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_binary(casadi_int op, const MX &y, bool scX, bool scY, bool unique_x=false, bool unique_y=false) const
Get a binary operation operation (matrix-matrix)
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.
static MX unary(casadi_int op, const MX &x, bool unique=false)
Create nodes by their ID.
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.
bool is_nonnegative() const override
Check if not negative.
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_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.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique=std::vector< bool >()) const override
Evaluate symbolically (MX)
int eval_activity(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate signal activity forward.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
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_binary(casadi_int op, const MX &y, bool scX, bool scY, bool unique_x=false, bool unique_y=false) const override
Get a binary operation 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)