List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
casadi::SXElem Class Reference

The basic scalar symbolic class of CasADi. More...

#include <sx_elem.hpp>

Detailed Description

SXElem is exposed only as an empty struct to SWIG

Author
Joel Andersson
Date
2010-2014

Extra doc: https://github.com/casadi/casadi/wiki/L_10i

Definition at line 74 of file sx_elem.hpp.

Inheritance diagram for casadi::SXElem:
Inheritance graph
[legend]
Collaboration diagram for casadi::SXElem:
Collaboration graph
[legend]

Public Member Functions

 SXElem ()
 Default constructor (not-a-number) More...
 
 SXElem (double val)
 Numerical constant constructor. More...
 
 SXElem (SXNode *node, bool dummy)
 
 SXElem (const SXElem &scalar)
 Copy constructor. More...
 
 ~SXElem ()
 Destructor. More...
 
SXElemoperator= (const SXElem &scalar)
 Assignment. More...
 
SXElemoperator= (double scalar)
 
 operator Matrix< SXElem > () const
 Convert to a 1-by-1 Matrix. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
SXNodeget () const
 Get a pointer to the node. More...
 
const SXNodeoperator-> () const
 Access functions of the node. More...
 
SXNodeoperator-> ()
 
bool __nonzero__ () const
 Check the truth value of this node. More...
 
bool is_leaf () const
 check if this SXElem is a leaf of the SX graph More...
 
bool is_constant () const
 
bool is_integer () const
 
bool is_symbolic () const
 
bool is_commutative () const
 Check whether a binary SXElem is commutative. More...
 
bool is_zero () const
 
bool is_almost_zero (double tol) const
 
bool is_one () const
 
bool is_minus_one () const
 
bool is_half () const
 
bool is_value (double val) const
 
bool is_nan () const
 
bool is_inf () const
 
bool is_minus_inf () const
 
const std::string & name () const
 
casadi_int op () const
 
bool is_op (casadi_int op) const
 
bool is_call () const
 
bool is_output () const
 
bool has_output () const
 
Function which_function () const
 
casadi_int which_output () const
 
bool is_regular () const
 Checks if expression does not contain NaN or Inf. More...
 
bool is_nonnegative () const
 Check if a value is always nonnegative (false negatives are allowed) More...
 
SXElem dep (casadi_int ch=0) const
 
 operator double () const
 Type conversion to double. More...
 
 operator casadi_int () const
 Type conversion to casadi_int. More...
 
bool is_doubled () const
 Check if the node is the sum of two equal expressions. More...
 
casadi_int n_dep () const
 Get the number of dependencies of a binary SXElem. More...
 
SXElem get_output (casadi_int oind) const
 Get an output. More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given SXNode. More...
 
SXElem operator- () const
 Negation. More...
 
SXElem inv () const
 Element-wise inverse. More...
 
int get_temp () const
 
void set_temp (int t) const
 Set the temporary variable. More...
 
bool marked () const
 Check if marked (i.e. temporary is negative) More...
 
void mark () const
 Mark by flipping the sign of the temporary and decreasing by one. More...
 
void assignIfDuplicate (const SXElem &scalar, casadi_int depth=1)
 Assign to another expression, if a duplicate. More...
 
SXNodeassignNoDelete (const SXElem &scalar)
 Assign the node to something, without invoking the deletion of the node,. More...
 
bool is_null ()
 SXElem nodes are not allowed to be null. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
SXElemoperator+= (const SXElem &y)
 

Static Public Member Functions

static SXElem sym (const std::string &name)
 Create a symbolic primitive. More...
 
static SXElem create (SXNode *node)
 
static std::string type_name ()
 Type name. More...
 
static SXElem binary (casadi_int op, const SXElem &x, const SXElem &y, bool unique_x=false, bool unique_y=false)
 Perform operations by ID. More...
 
static SXElem unary (casadi_int op, const SXElem &x, bool unique=false)
 
static std::vector< SXElemcall (const Function &f, const std::vector< SXElem > &deps)
 
static bool is_equal (const SXElem &x, const SXElem &y, casadi_int depth=0)
 Check equality up to a given depth. More...
 
static SXElem deserialize (DeserializingStream &s)
 
static SXElem plus (const SXElem &x, const SXElem &y)
 Addition: (x,y) -> x + y. More...
 
static SXElem lt (const SXElem &x, const SXElem &y)
 Logical less than: (x,y) -> x < y. More...
 
static SXElem le (const SXElem &x, const SXElem &y)
 Logical less or equal to: (x,y) -> x <= y. More...
 
static SXElem gt (const SXElem &x, const SXElem &y)
 Logical greater than: (x,y) -> x > y. More...
 
static SXElem ge (const SXElem &x, const SXElem &y)
 Logical greater or equal to: (x,y) -> x >= y. More...
 
static SXElem eq (const SXElem &x, const SXElem &y)
 Logical equal to: (x,y) -> x == y. More...
 
static SXElem ne (const SXElem &x, const SXElem &y)
 Logical not equal to: (x,y) -> x != y. More...
 
static SXElem logic_and (const SXElem &x, const SXElem &y)
 Logical and More...
 
static SXElem logic_or (const SXElem &x, const SXElem &y)
 Logical or More...
 
static SXElem abs (const SXElem &x)
 Absolute value: x -> abs(x) More...
 
static SXElem sqrt (const SXElem &x)
 Square root: x -> sqrt(x) More...
 
static SXElem sq (const SXElem &x)
 Square: x -> x^2. More...
 
static SXElem sin (const SXElem &x)
 Sine: x -> sin(x) More...
 
static SXElem cos (const SXElem &x)
 Cosine: x -> cos(x) More...
 
static SXElem tan (const SXElem &x)
 Tangent: x -> tan(x) More...
 
static SXElem atan (const SXElem &x)
 Arc tangent: x -> atan(x) More...
 
static SXElem asin (const SXElem &x)
 Arc sine: x -> asin(x) More...
 
static SXElem acos (const SXElem &x)
 Arc cosine: x -> acos(x) More...
 
static SXElem tanh (const SXElem &x)
 Hyperbolic tangent: x -> tanh(x) More...
 
static SXElem sinh (const SXElem &x)
 Hyperbolic sin: x -> sinh(x) More...
 
static SXElem cosh (const SXElem &x)
 Hyperbolic cosine: x -> cosh(x) More...
 
static SXElem atanh (const SXElem &x)
 Inverse hyperbolic tangent: x -> atanh(x) More...
 
static SXElem asinh (const SXElem &x)
 Inverse hyperbolic sin: x -> asinh(x) More...
 
static SXElem acosh (const SXElem &x)
 Inverse hyperbolic cosine: x -> acosh(x) More...
 
static SXElem exp (const SXElem &x)
 Elementwise exponential: x -> exp(x) More...
 
static SXElem log (const SXElem &x)
 Natural logarithm: x -> log(x) More...
 
static SXElem log10 (const SXElem &x)
 Base-10 logarithm: x -> log10(x) More...
 
static SXElem log1p (const SXElem &x)
 Precision variant for natural logarithm: x -> log(x+1) More...
 
static SXElem expm1 (const SXElem &x)
 Precision variant for elementwise exponential: x -> exp(x)-1. More...
 
static SXElem floor (const SXElem &x)
 Round down to nearest integer: x -> floor(x) More...
 
static SXElem ceil (const SXElem &x)
 Round up to nearest integer: x -> ceil(x) More...
 
static SXElem erf (const SXElem &x)
 Error function: x -> erf(x) More...
 
static SXElem erfinv (const SXElem &x)
 Inverse error function: x -> erfinv(x) More...
 
static SXElem sign (const SXElem &x)
 Sign function: More...
 
static SXElem pow (const SXElem &x, const SXElem &y)
 Elementwise power: (x,y) -> x.^y. More...
 
static SXElem mod (const SXElem &x, const SXElem &y)
 Remainder after division: (x,y) -> fmod(x,y) More...
 
static SXElem remainder (const SXElem &x, const SXElem &y)
 Remainder after division: (x,y) -> remainder(x,y) More...
 
static SXElem atan2 (const SXElem &y, const SXElem &x)
 Two argument arc tangent: (y,x) -> atan2(y,x) More...
 
static SXElem if_else_zero (const SXElem &x, const SXElem &y)
 Conditional assignment: (x,y) -> x ? y : 0. More...
 
static SXElem fmin (const SXElem &x, const SXElem &y)
 Smallest of two values: (x,y) -> min(x,y) More...
 
static SXElem fmax (const SXElem &x, const SXElem &y)
 Largest of two values: (x,y) -> max(x,y) More...
 
static SXElem copysign (const SXElem &x, const SXElem &y)
 
static SXElem constpow (const SXElem &x, const SXElem &y)
 
static SXElem printme (const SXElem &x, const SXElem &y)
 
static SXElem hypot (const SXElem &x, const SXElem &y)
 Precision variant for 2 norm: (x,y) -> sqrt(x^2+y^2) More...
 

Protected Member Functions

const SXElemself () const
 
SXElemself ()
 

Friends

class SXNode
 
class BinarySXNode
 
class Matrix< SXElem >
 
SXElem if_else (const SXElem &x, const SXElem &y, const SXElem &z)
 Ternary if_else: x ? y : z. More...
 
SXElemoperator-= (const SXElem &y)
 Subtraction: (x,y) -> x - y. More...
 
static SXElem minus (const SXElem &x, const SXElem &y)
 Subtraction: (x,y) -> x - y. More...
 
SXElemoperator*= (const SXElem &y)
 Elementwise multiplication: (x,y) -> x .* y. More...
 
static SXElem times (const SXElem &x, const SXElem &y)
 Elementwise multiplication: (x,y) -> x .* y. More...
 
SXElemoperator/= (const SXElem &y)
 Elementwise division: (x,y) -> x ./ y. More...
 
static SXElem rdivide (const SXElem &x, const SXElem &y)
 Elementwise division: (x,y) -> x ./ y. More...
 
SXElem operator! () const
 Logical not x -> !x. More...
 
static SXElem logic_not (const SXElem &x)
 Logical not x -> !x. More...
 

Constructor & Destructor Documentation

◆ SXElem() [1/4]

casadi::SXElem::SXElem ( )

Object is initialized as not-a-number.

Extra doc: https://github.com/casadi/casadi/wiki/L_10j

Definition at line 53 of file sx_elem.cpp.

53  {
54  node = casadi_limits<SXElem>::nan.node;
55  node->count++;
56  }
unsigned int count
Definition: sx_node.hpp:199
casadi_limits class

References casadi::SXNode::count.

Referenced by create(), and operator=().

◆ SXElem() [2/4]

casadi::SXElem::SXElem ( double  val)
Parameters
valNumerical value

Extra doc: https://github.com/casadi/casadi/wiki/L_10k

Definition at line 71 of file sx_elem.cpp.

71  {
72  // Check for nan/inf first to avoid undefined behavior from static_cast<int>
73  if (isnan(val)) {
74  node = casadi_limits<SXElem>::nan.node;
75  } else if (isinf(val)) {
76  node = val > 0 ? casadi_limits<SXElem>::inf.node :
78  } else {
79  // Only ints fit here, not casadi_int
80  int intval = static_cast<int>(val);
81  if (val-static_cast<double>(intval) == 0) { // check if integer
82  if (intval == 0) node = casadi_limits<SXElem>::zero.node;
83  else if (intval == 1) node = casadi_limits<SXElem>::one.node;
84  else if (intval == 2) node = casadi_limits<SXElem>::two.node;
85  else if (intval == -1) node = casadi_limits<SXElem>::minus_one.node;
86  else node = IntegerSX::create(intval);
87  } else {
88  node = RealtypeSX::create(val);
89  }
90  }
91  node->count++;
92  }
static IntegerSX * create(casadi_int value)
Static creator function (use instead of constructor)
static RealtypeSX * create(double value)
Static creator function (use instead of constructor)

References casadi::SXNode::count, casadi::IntegerSX::create(), and casadi::RealtypeSX::create().

◆ SXElem() [3/4]

casadi::SXElem::SXElem ( SXNode node,
bool  dummy 
)

Create an expression from a node: extra dummy argument to avoid ambiguity for 0/NULL

Definition at line 58 of file sx_elem.cpp.

58  : node(node_) {
59  node->count++;
60  }

References casadi::SXNode::count.

◆ SXElem() [4/4]

casadi::SXElem::SXElem ( const SXElem scalar)

Extra doc: https://github.com/casadi/casadi/wiki/L_10m

Definition at line 66 of file sx_elem.cpp.

66  {
67  node = scalar.node;
68  node->count++;
69  }

References casadi::SXNode::count.

◆ ~SXElem()

casadi::SXElem::~SXElem ( )

Definition at line 98 of file sx_elem.cpp.

98  {
99  if (--node->count == 0) delete node;
100  }

References casadi::SXNode::count.

Member Function Documentation

◆ __hash__()

casadi_int casadi::SXElem::__hash__ ( ) const

If the SXElem does not point to any node, 0 is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_10w

Definition at line 397 of file sx_elem.cpp.

397  {
398  return reinterpret_cast<casadi_int>(node);
399  }

◆ __nonzero__()

bool casadi::SXElem::__nonzero__ ( ) const

Introduced to catch bool(x) situations in python

Extra doc: https://github.com/casadi/casadi/wiki/L_10q

Definition at line 163 of file sx_elem.cpp.

163  {
164  if (is_constant()) return !is_zero();
165  casadi_error("Cannot compute the truth value of a CasADi SXElem symbolic expression.");
166  }
bool is_zero() const
Definition: sx_elem.cpp:307
bool is_constant() const
Definition: sx_elem.cpp:275

References is_constant(), and is_zero().

◆ abs()

static SXElem casadi::GenericExpression< SXElem >::abs ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p0

Definition at line 275 of file generic_expression.hpp.

275  {
276  return ExType::unary(OP_FABS, x);
277  }

◆ acos()

static SXElem casadi::GenericExpression< SXElem >::acos ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p8

Definition at line 374 of file generic_expression.hpp.

374  {
375  return ExType::unary(OP_ACOS, x);
376  }

◆ acosh()

static SXElem casadi::GenericExpression< SXElem >::acosh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pe

Definition at line 446 of file generic_expression.hpp.

446  {
447  return ExType::unary(OP_ACOSH, x);
448  }

◆ asin()

static SXElem casadi::GenericExpression< SXElem >::asin ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p7

Definition at line 362 of file generic_expression.hpp.

362  {
363  return ExType::unary(OP_ASIN, x);
364  }

◆ asinh()

static SXElem casadi::GenericExpression< SXElem >::asinh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pd

Definition at line 434 of file generic_expression.hpp.

434  {
435  return ExType::unary(OP_ASINH, x);
436  }

◆ assignIfDuplicate()

void casadi::SXElem::assignIfDuplicate ( const SXElem scalar,
casadi_int  depth = 1 
)

Check for equality up to a given depth

Extra doc: https://github.com/casadi/casadi/wiki/L_110

Definition at line 117 of file sx_elem.cpp.

117  {
118  casadi_assert_dev(depth>=1);
119  if (!is_equal(*this, scalar, 0) && is_equal(*this, scalar, depth)) {
120  *this = scalar;
121  }
122  }
static bool is_equal(const SXElem &x, const SXElem &y, casadi_int depth=0)
Check equality up to a given depth.
Definition: sx_elem.cpp:355

References is_equal().

Referenced by casadi::SXFunction::eval_sx().

◆ assignNoDelete()

SXNode * casadi::SXElem::assignNoDelete ( const SXElem scalar)

if the count reaches 0

Extra doc: https://github.com/casadi/casadi/wiki/L_111

Definition at line 124 of file sx_elem.cpp.

124  {
125  // Return value
126  SXNode* ret = node;
127 
128  // quick return if the old and new pointers point to the same object
129  if (node == scalar.node) return ret;
130 
131  // decrease the counter but do not delete if this was the last pointer
132  --node->count;
133 
134  // save the new pointer
135  node = scalar.node;
136  node->count++;
137 
138  // Return a pointer to the old node
139  return ret;
140  }
Internal node class for SX.
Definition: sx_node.hpp:49

References casadi::SXNode::count.

Referenced by casadi::SXNode::safe_delete(), casadi::BinarySX::~BinarySX(), and casadi::UnarySX::~UnarySX().

◆ atan()

static SXElem casadi::GenericExpression< SXElem >::atan ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p6

Definition at line 350 of file generic_expression.hpp.

350  {
351  return ExType::unary(OP_ATAN, x);
352  }

◆ atan2()

static SXElem casadi::GenericExpression< SXElem >::atan2 ( const SXElem y,
const SXElem x 
)
inlinestaticinherited

theta = atan2(y,x) corresponds to x = r cos(theta), y = r sin(theta)

Extra doc: https://github.com/casadi/casadi/wiki/L_pr

Definition at line 648 of file generic_expression.hpp.

648  {
649  return ExType::binary(OP_ATAN2, y, x);
650  }

◆ atanh()

static SXElem casadi::GenericExpression< SXElem >::atanh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pc

Definition at line 422 of file generic_expression.hpp.

422  {
423  return ExType::unary(OP_ATANH, x);
424  }

◆ binary()

SXElem casadi::SXElem::binary ( casadi_int  op,
const SXElem x,
const SXElem y,
bool  unique_x = false,
bool  unique_y = false 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_10p

Definition at line 189 of file sx_elem.cpp.

190  {
191  // If-else-zero nodes are always simplified at top level to avoid NaN propagation
192  if (y.op() == OP_IF_ELSE_ZERO) {
193  if (op == OP_MUL) {
194  // (Rule 1.) x * if_else_zero(c, y), simplified to if_else_zero(c, x * y)
195  // Background: x is often a partial derivative and may evaluate to INF or NAN.
196  // The simplification ensures that the zero seed corresponding to an inactive branch does
197  // not give rise to any NaN contribution to the derivative due to NaN * 0 == NaN.
198  return if_else_zero(y.dep(0), x * y.dep(1));
199  } else if (op == OP_ADD && x.op() == OP_IF_ELSE_ZERO && is_equal(x.dep(0), y.dep(0))) {
200  // (Rule 2.) if_else_zero(c, x) + if_else_zero(c, y) is simplified to if_else_zero(c, x + y)
201  // Background: During the backward propagation, seeds are added together. Without this rule,
202  // the addition node can prevent rule (1.) from working in subsequent steps.
203  return if_else_zero(y.dep(0), x.dep(1) + y.dep(1));
204  }
205  } else if (x.op() == OP_IF_ELSE_ZERO && op == OP_MUL) {
206  // Same as Rule 1. above, but with factors swapped. For symmetry.
207  return if_else_zero(x.dep(0), x.dep(1) * y);
208  }
209  // Simplifications
211  bool hit;
213  [](casadi_int op, const SXElem& a) { return unary(op, a);},
214  [](casadi_int op, const SXElem& a, const SXElem& b) { return binary(op, a, b);},
215  unique_x,
216  unique_y,
217  hit);
218  if (hit) return ret;
219  switch (op) {
220  case OP_MUL:
221  if (x.is_constant() && y.is_op(OP_TWICE))
222  return (x*2)*y.dep(); // a*(2*x) -> (a*2)*x
223  else if (y.is_constant() && x.is_op(OP_TWICE))
224  return (2*y)*x.dep(); // (2*x)*b -> (2*b)*x
225  break;
226  }
227 
228  }
229  return BinarySX::create(Operation(op), x, y);
230  }
static SXElem create(unsigned char op, const SXElem &dep0, const SXElem &dep1)
Create a binary expression.
Definition: binary_sx.hpp:55
static bool simplification_on_the_fly
Indicates whether simplifications should be made on the fly.
The basic scalar symbolic class of CasADi.
Definition: sx_elem.hpp:75
SXElem dep(casadi_int ch=0) const
Definition: sx_elem.cpp:384
static SXElem unary(casadi_int op, const SXElem &x, bool unique=false)
Definition: sx_elem.cpp:237
casadi_int op() const
Definition: sx_elem.cpp:347
bool is_op(casadi_int op) const
Definition: sx_elem.cpp:351
static SXElem binary(casadi_int op, const SXElem &x, const SXElem &y, bool unique_x=false, bool unique_y=false)
Perform operations by ID.
Definition: sx_elem.cpp:189
static casadi_int eq_depth_
Definition: sx_node.hpp:181
static SXElem if_else_zero(const SXElem &x, const SXElem &y)
Conditional assignment: (x,y) -> x ? y : 0.
T common_simp_binary(casadi_int op, const T &x, const T &y, casadi_int depth, SU &&gen_unary, SB &&gen_binary, bool unique_x, bool unique_y, bool &hit)
Definition: calculus.hpp:1871
Operation
Enum for quick access to any node.
Definition: calculus.hpp:60
@ OP_IF_ELSE_ZERO
Definition: calculus.hpp:71
@ OP_TWICE
Definition: calculus.hpp:67
@ OP_ADD
Definition: calculus.hpp:65
@ OP_MUL
Definition: calculus.hpp:65

References casadi::common_simp_binary(), casadi::BinarySX::create(), dep(), casadi::SXNode::eq_depth_, casadi::GenericExpression< SXElem >::if_else_zero(), is_constant(), is_equal(), is_op(), op(), casadi::OP_ADD, casadi::OP_IF_ELSE_ZERO, casadi::OP_MUL, casadi::OP_TWICE, casadi::GlobalOptions::simplification_on_the_fly, and unary().

◆ call()

std::vector< SXElem > casadi::SXElem::call ( const Function f,
const std::vector< SXElem > &  deps 
)
static

Definition at line 232 of file sx_elem.cpp.

232  {
233  SXElem c = CallSX::create(f, deps);
234  return OutputSX::split(c, f.nnz_out());
235  }
static SXElem create(const Function &f, const std::vector< SXElem > &dep)
Create a binary expression.
Definition: call_sx.hpp:57
casadi_int nnz_out() const
Get number of output nonzeros.
Definition: function.cpp:1007
static std::vector< SXElem > split(const SXElem &e, casadi_int n)
Definition: output_sx.hpp:139

References casadi::CallSX::create(), casadi::Function::nnz_out(), and casadi::OutputSX::split().

Referenced by casadi::SXFunction::ad_forward(), casadi::SXFunction::ad_reverse(), casadi::CallSX::eval_sx(), and casadi::SXFunction::eval_sx().

◆ ceil()

static SXElem casadi::GenericExpression< SXElem >::ceil ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pl

Definition at line 530 of file generic_expression.hpp.

530  {
531  return ExType::unary(OP_CEIL, x);
532  }

◆ constpow()

static SXElem casadi::GenericExpression< SXElem >::constpow ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Elementwise power with const power

Definition at line 720 of file generic_expression.hpp.

720  {
721  return ExType::binary(OP_CONSTPOW, x, y);
722  }

◆ copysign()

static SXElem casadi::GenericExpression< SXElem >::copysign ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Copy sign

Definition at line 710 of file generic_expression.hpp.

710  {
711  return ExType::binary(OP_COPYSIGN, x, y);
712  }

◆ cos()

static SXElem casadi::GenericExpression< SXElem >::cos ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p4

Definition at line 326 of file generic_expression.hpp.

326  {
327  return ExType::unary(OP_COS, x);
328  }

◆ cosh()

static SXElem casadi::GenericExpression< SXElem >::cosh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pb

Definition at line 410 of file generic_expression.hpp.

410  {
411  return ExType::unary(OP_COSH, x);
412  }

◆ create()

SXElem casadi::SXElem::create ( SXNode node)
static

Create an object given a node

Definition at line 62 of file sx_elem.cpp.

62  {
63  return SXElem(node, false);
64  }
SXElem()
Default constructor (not-a-number)
Definition: sx_elem.cpp:53

References SXElem().

Referenced by casadi::CallSX::create(), casadi::UnarySX::create(), casadi::BinarySX::create(), deserialize(), casadi::CallSX::get_output(), casadi::SXFunction::init(), casadi::SXFunction::order(), and sym().

◆ dep()

SXElem casadi::SXElem::dep ( casadi_int  ch = 0) const

Definition at line 384 of file sx_elem.cpp.

384  {
385  casadi_assert_dev(ch >= 0 || ch < n_dep());
386  return node->dep(ch);
387  }
casadi_int n_dep() const
Get the number of dependencies of a binary SXElem.
Definition: sx_elem.cpp:389
virtual const SXElem & dep(casadi_int i) const
get the reference of a child
Definition: sx_node.cpp:80

References casadi::SXNode::dep(), and n_dep().

Referenced by binary(), is_doubled(), operator-(), and unary().

◆ deserialize()

SXElem casadi::SXElem::deserialize ( DeserializingStream s)
static

Definition at line 497 of file sx_elem.cpp.

497  {
499  }
static SXElem create(SXNode *node)
Definition: sx_elem.cpp:62
static SXNode * deserialize(DeserializingStream &s)
Definition: sx_node.cpp:243

References create(), and casadi::SXNode::deserialize().

◆ disp()

void casadi::SXElem::disp ( std::ostream &  stream,
bool  more = false 
) const

Definition at line 146 of file sx_elem.cpp.

146  {
147  node->disp(stream, more);
148  }
virtual void disp(std::ostream &stream, bool more) const
print
Definition: sx_node.cpp:88

References casadi::SXNode::disp().

◆ eq()

static SXElem casadi::GenericExpression< SXElem >::eq ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ov

Definition at line 191 of file generic_expression.hpp.

191  {
192  return ExType::binary(OP_EQ, x, y);
193  }

◆ erf()

static SXElem casadi::GenericExpression< SXElem >::erf ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pm

Definition at line 542 of file generic_expression.hpp.

542  {
543  return ExType::unary(OP_ERF, x);
544  }

◆ erfinv()

static SXElem casadi::GenericExpression< SXElem >::erfinv ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pn

Definition at line 554 of file generic_expression.hpp.

554  {
555  return ExType::unary(OP_ERFINV, x);
556  }

◆ exp()

static SXElem casadi::GenericExpression< SXElem >::exp ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pf

Definition at line 458 of file generic_expression.hpp.

458  {
459  return ExType::unary(OP_EXP, x);
460  }

◆ expm1()

static SXElem casadi::GenericExpression< SXElem >::expm1 ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pj

Definition at line 506 of file generic_expression.hpp.

506  {
507  return ExType::unary(OP_EXPM1, x);
508  }

◆ floor()

static SXElem casadi::GenericExpression< SXElem >::floor ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pk

Definition at line 518 of file generic_expression.hpp.

518  {
519  return ExType::unary(OP_FLOOR, x);
520  }

◆ fmax()

static SXElem casadi::GenericExpression< SXElem >::fmax ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pu

Definition at line 684 of file generic_expression.hpp.

684  {
685  return ExType::binary(OP_FMAX, x, y);
686  }

◆ fmin()

static SXElem casadi::GenericExpression< SXElem >::fmin ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pt

Definition at line 672 of file generic_expression.hpp.

672  {
673  return ExType::binary(OP_FMIN, x, y);
674  }

◆ ge()

static SXElem casadi::GenericExpression< SXElem >::ge ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ou

Definition at line 176 of file generic_expression.hpp.

176  {
177  return ExType::le(y, x);
178  }

◆ get()

SXNode * casadi::SXElem::get ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10n

Definition at line 177 of file sx_elem.cpp.

177  {
178  return node;
179  }

Referenced by casadi::SXFunction::init(), is_equal(), and casadi::register_symbol().

◆ get_output()

SXElem casadi::SXElem::get_output ( casadi_int  oind) const

Extra doc: https://github.com/casadi/casadi/wiki/L_29f

Definition at line 393 of file sx_elem.cpp.

393  {
394  return node->get_output(oind);
395  }
virtual SXElem get_output(casadi_int oind) const
Get an output.
Definition: sx_node.cpp:227

References casadi::SXNode::get_output().

Referenced by casadi::Matrix< double >::is_leaf(), and casadi::OutputSX::split().

◆ get_temp()

int casadi::SXElem::get_temp ( ) const

Get the temporary variable

Definition at line 469 of file sx_elem.cpp.

469  {
470  return (*this)->temp;
471  }

◆ gt()

static SXElem casadi::GenericExpression< SXElem >::gt ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ot

Definition at line 161 of file generic_expression.hpp.

161  {
162  return ExType::lt(y, x);
163  }

◆ has_output()

bool casadi::SXElem::has_output ( ) const

Definition at line 287 of file sx_elem.cpp.

287  {
288  return node->has_output();
289  }
virtual bool has_output() const
check properties of a node
Definition: sx_node.hpp:84

References casadi::SXNode::has_output().

◆ hypot()

static SXElem casadi::GenericExpression< SXElem >::hypot ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pw

Definition at line 742 of file generic_expression.hpp.

742  {
743  return ExType::binary(OP_HYPOT, x, y);
744  }

◆ if_else_zero()

static SXElem casadi::GenericExpression< SXElem >::if_else_zero ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ps

Definition at line 660 of file generic_expression.hpp.

660  {
661  return ExType::binary(OP_IF_ELSE_ZERO, x, y);
662  }

◆ inv()

SXElem casadi::SXElem::inv ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10y

Definition at line 173 of file sx_elem.cpp.

173  {
174  return unary(OP_INV, *this);
175  }
@ OP_INV
Definition: calculus.hpp:73

References casadi::OP_INV, and unary().

◆ is_almost_zero()

bool casadi::SXElem::is_almost_zero ( double  tol) const

Definition at line 311 of file sx_elem.cpp.

311  {
312  return node->is_almost_zero(tol);
313  }
virtual bool is_almost_zero(double tol) const
check properties of a node
Definition: sx_node.hpp:74

References casadi::SXNode::is_almost_zero().

Referenced by casadi::casadi_limits< SXElem >::is_almost_zero().

◆ is_call()

bool casadi::SXElem::is_call ( ) const

Definition at line 279 of file sx_elem.cpp.

279  {
280  return node->is_call();
281  }
virtual bool is_call() const
check properties of a node
Definition: sx_node.hpp:82

References casadi::SXNode::is_call().

◆ is_commutative()

bool casadi::SXElem::is_commutative ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10s

Definition at line 270 of file sx_elem.cpp.

270  {
271  casadi_assert(n_dep(), "SX::is_commutative: must be binary");
272  return operation_checker<CommChecker>(op());
273  }

References n_dep(), and op().

◆ is_constant()

bool casadi::SXElem::is_constant ( ) const

◆ is_doubled()

bool casadi::SXElem::is_doubled ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10u

Definition at line 168 of file sx_elem.cpp.

168  {
169  return (is_op(OP_ADD) && is_equal(dep(0), dep(1), SXNode::eq_depth_)) ||
170  (is_op(OP_TWICE));
171  }

References dep(), casadi::SXNode::eq_depth_, is_equal(), is_op(), casadi::OP_ADD, and casadi::OP_TWICE.

◆ is_equal()

bool casadi::SXElem::is_equal ( const SXElem x,
const SXElem y,
casadi_int  depth = 0 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_10z

Definition at line 355 of file sx_elem.cpp.

355  {
356  SXNode *x_node = x.get(), *y_node = y.get();
357  if (x_node==y_node) {
358  return true;
359  } else if (depth>0) {
360  return x_node->is_equal(y_node, depth);
361  } else {
362  return false;
363  }
364  }
SXNode * get() const
Get a pointer to the node.
Definition: sx_elem.cpp:177
virtual bool is_equal(const SXNode *node, casadi_int depth) const
Check if two nodes are equivalent up to a given depth.
Definition: sx_node.cpp:72

References get(), and casadi::SXNode::is_equal().

Referenced by assignIfDuplicate(), binary(), casadi::SXFunction::eval_sx(), is_doubled(), casadi::casadi_limits< SXElem >::is_equal(), casadi::BinarySX::is_equal(), and casadi::UnarySX::is_equal().

◆ is_half()

bool casadi::SXElem::is_half ( ) const

Definition at line 323 of file sx_elem.cpp.

323  {
324  return node->is_half();
325  }
virtual bool is_half() const
check properties of a node
Definition: sx_node.hpp:77

References casadi::SXNode::is_half().

Referenced by casadi::casadi_limits< SXElem >::is_half().

◆ is_inf()

bool casadi::SXElem::is_inf ( ) const

Definition at line 335 of file sx_elem.cpp.

335  {
336  return node->is_inf();
337  }
virtual bool is_inf() const
check properties of a node
Definition: sx_node.hpp:80

References casadi::SXNode::is_inf().

Referenced by casadi::casadi_limits< SXElem >::is_inf(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_integer()

bool casadi::SXElem::is_integer ( ) const

Definition at line 299 of file sx_elem.cpp.

299  {
300  return node->is_integer();
301  }
virtual bool is_integer() const
check properties of a node
Definition: sx_node.hpp:70

References casadi::SXNode::is_integer().

Referenced by casadi::casadi_limits< SXElem >::is_integer().

◆ is_leaf()

bool casadi::SXElem::is_leaf ( ) const

An SXElem qualifies as leaf when it has no dependencies.

Extra doc: https://github.com/casadi/casadi/wiki/L_10r

Definition at line 265 of file sx_elem.cpp.

265  {
266  if (!node) return true;
267  return is_constant() || is_symbolic();
268  }
bool is_symbolic() const
Definition: sx_elem.cpp:303

References is_constant(), and is_symbolic().

◆ is_minus_inf()

bool casadi::SXElem::is_minus_inf ( ) const

Definition at line 339 of file sx_elem.cpp.

339  {
340  return node->is_minus_inf();
341  }
virtual bool is_minus_inf() const
check properties of a node
Definition: sx_node.hpp:81

References casadi::SXNode::is_minus_inf().

Referenced by casadi::casadi_limits< SXElem >::is_minus_inf(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_minus_one()

bool casadi::SXElem::is_minus_one ( ) const

Definition at line 319 of file sx_elem.cpp.

319  {
320  return node->is_minus_one();
321  }
virtual bool is_minus_one() const
check properties of a node
Definition: sx_node.hpp:76

References casadi::SXNode::is_minus_one().

Referenced by casadi::casadi_limits< SXElem >::is_minus_one(), and operator-().

◆ is_nan()

bool casadi::SXElem::is_nan ( ) const

Definition at line 331 of file sx_elem.cpp.

331  {
332  return node->is_nan();
333  }
virtual bool is_nan() const
check properties of a node
Definition: sx_node.hpp:79

References casadi::SXNode::is_nan().

Referenced by casadi::casadi_limits< SXElem >::is_nan(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_nonnegative()

bool casadi::SXElem::is_nonnegative ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10t

Definition at line 366 of file sx_elem.cpp.

366  {
367  if (is_constant()) {
368  return static_cast<double>(*this)>=0;
369  } else if (casadi_math<SXElem>::is_unary(node->op())) {
370  return operation_checker<NonnegativeChecker>(node->op());
371  } else {
372  return false;
373  }
374  }
virtual casadi_int op() const =0
get the operation
Easy access to all the functions for a particular type.
Definition: calculus.hpp:1135

References is_constant(), and casadi::SXNode::op().

Referenced by casadi::casadi_limits< SXElem >::is_nonnegative().

◆ is_null()

bool casadi::SXElem::is_null ( )
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_112

Definition at line 283 of file sx_elem.hpp.

283 {return false;}

◆ is_one()

bool casadi::SXElem::is_one ( ) const

Definition at line 315 of file sx_elem.cpp.

315  {
316  return node->is_one();
317  }
virtual bool is_one() const
check properties of a node
Definition: sx_node.hpp:75

References casadi::SXNode::is_one().

Referenced by casadi::casadi_limits< SXElem >::is_one(), and operator-().

◆ is_op()

bool casadi::SXElem::is_op ( casadi_int  op) const

Definition at line 351 of file sx_elem.cpp.

351  {
352  return node->is_op(op);
353  }
virtual bool is_op(casadi_int op) const
check properties of a node
Definition: sx_node.hpp:73

References casadi::SXNode::is_op(), and op().

Referenced by binary(), is_doubled(), operator-(), and unary().

◆ is_output()

bool casadi::SXElem::is_output ( ) const

Definition at line 283 of file sx_elem.cpp.

283  {
284  return node->is_output();
285  }
virtual bool is_output() const
check properties of a node
Definition: sx_node.hpp:83

References casadi::SXNode::is_output().

◆ is_regular()

bool casadi::SXElem::is_regular ( ) const

Definition at line 485 of file sx_elem.cpp.

485  {
486  if (is_constant()) {
487  return !(is_nan() || is_inf() || is_minus_inf());
488  } else {
489  casadi_error("Cannot check regularity for symbolic SXElem");
490  }
491  }
bool is_nan() const
Definition: sx_elem.cpp:331
bool is_minus_inf() const
Definition: sx_elem.cpp:339
bool is_inf() const
Definition: sx_elem.cpp:335

References is_constant(), is_inf(), is_minus_inf(), and is_nan().

◆ is_symbolic()

bool casadi::SXElem::is_symbolic ( ) const

Definition at line 303 of file sx_elem.cpp.

303  {
304  return node->is_symbolic();
305  }
virtual bool is_symbolic() const
check properties of a node
Definition: sx_node.hpp:71

References casadi::SXNode::is_symbolic().

Referenced by is_leaf(), and casadi::register_symbol().

◆ is_value()

bool casadi::SXElem::is_value ( double  val) const

Definition at line 327 of file sx_elem.cpp.

327  {
328  return node->is_value(val);
329  }
virtual bool is_value(double val) const
check properties of a node
Definition: sx_node.hpp:78

References casadi::SXNode::is_value().

Referenced by casadi::casadi_limits< SXElem >::is_value().

◆ is_zero()

bool casadi::SXElem::is_zero ( ) const

Definition at line 307 of file sx_elem.cpp.

307  {
308  return node->is_zero();
309  }
virtual bool is_zero() const
check properties of a node
Definition: sx_node.hpp:72

References casadi::SXNode::is_zero().

Referenced by __nonzero__(), casadi::casadi_limits< SXElem >::is_zero(), and operator-().

◆ le()

static SXElem casadi::GenericExpression< SXElem >::le ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_os

Definition at line 146 of file generic_expression.hpp.

146  {
147  return ExType::binary(OP_LE, x, y);
148  }

◆ log()

static SXElem casadi::GenericExpression< SXElem >::log ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pg

Definition at line 470 of file generic_expression.hpp.

470  {
471  return ExType::unary(OP_LOG, x);
472  }

◆ log10()

static SXElem casadi::GenericExpression< SXElem >::log10 ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ph

Definition at line 482 of file generic_expression.hpp.

482  {
483  return log(x)*(1/std::log(10.));
484  }
static SXElem log(const SXElem &x)
Natural logarithm: x -> log(x)

◆ log1p()

static SXElem casadi::GenericExpression< SXElem >::log1p ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pi

Definition at line 494 of file generic_expression.hpp.

494  {
495  return ExType::unary(OP_LOG1P, x);
496  }

◆ logic_and()

static SXElem casadi::GenericExpression< SXElem >::logic_and ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Returns (an expression evaluating to) 1 if both expressions are nonzero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_ox

Definition at line 224 of file generic_expression.hpp.

224  {
225  return ExType::binary(OP_AND, x, y);
226  }

◆ logic_not()

static SXElem casadi::GenericExpression< SXElem >::logic_not ( const SXElem x)
inlinestaticinherited

Returns (an expression evaluating to) 1 if expression is zero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oz

Definition at line 260 of file generic_expression.hpp.

260  {
261  return ExType::unary(OP_NOT, x);
262  }

◆ logic_or()

static SXElem casadi::GenericExpression< SXElem >::logic_or ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

returns (an expression evaluating to) 1 if at least one expression is nonzero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oy

Definition at line 242 of file generic_expression.hpp.

242  {
243  return ExType::binary(OP_OR, x, y);
244  }

◆ lt()

static SXElem casadi::GenericExpression< SXElem >::lt ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_or

Definition at line 131 of file generic_expression.hpp.

131  {
132  return ExType::binary(OP_LT, x, y);
133  }

◆ mark()

void casadi::SXElem::mark ( ) const

Definition at line 481 of file sx_elem.cpp.

481  {
482  (*this)->mark();
483  }

◆ marked()

bool casadi::SXElem::marked ( ) const

Definition at line 477 of file sx_elem.cpp.

477  {
478  return (*this)->marked();
479  }

◆ minus()

static SXElem casadi::GenericExpression< SXElem >::minus ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oo

Definition at line 83 of file generic_expression.hpp.

83  {
84  return ExType::binary(OP_SUB, x, y);
85  }

◆ mod()

static SXElem casadi::GenericExpression< SXElem >::mod ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/fmod

Notably:

  • fmod(5,3) -> 2
  • fmod(5,-3) -> 2
  • fmod(-5,3) -> -2
  • fmod(-5,-3) -> -2

This is equivalent to Python's numpy.fmod and Matlab's rem.

\seealso remainder

Extra doc: https://github.com/casadi/casadi/wiki/L_pq 

Definition at line 607 of file generic_expression.hpp.

607  {
608  return ExType::binary(OP_FMOD, x, y);
609  }

◆ n_dep()

casadi_int casadi::SXElem::n_dep ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10v

Definition at line 389 of file sx_elem.cpp.

389  {
390  return node->n_dep();
391  }
virtual casadi_int n_dep() const
Number of dependencies.
Definition: sx_node.hpp:126

References casadi::SXNode::n_dep().

Referenced by dep(), and is_commutative().

◆ name()

const std::string & casadi::SXElem::name ( ) const

Definition at line 343 of file sx_elem.cpp.

343  {
344  return node->name();
345  }
virtual const std::string & name() const
Definition: sx_node.cpp:76

References casadi::SXNode::name().

Referenced by sym().

◆ ne()

static SXElem casadi::GenericExpression< SXElem >::ne ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ow

Definition at line 206 of file generic_expression.hpp.

206  {
207  return ExType::binary(OP_NE, x, y);
208  }

◆ op()

casadi_int casadi::SXElem::op ( ) const

Definition at line 347 of file sx_elem.cpp.

347  {
348  return node->op();
349  }

References casadi::SXNode::op().

Referenced by binary(), is_commutative(), is_op(), and unary().

◆ operator casadi_int()

casadi::SXElem::operator casadi_int ( ) const
explicit

Definition at line 380 of file sx_elem.cpp.

380  {
381  return node->to_int();
382  }
virtual casadi_int to_int() const
Get value of a constant node.
Definition: sx_node.cpp:60

◆ operator double()

casadi::SXElem::operator double ( ) const
explicit

Definition at line 376 of file sx_elem.cpp.

376  {
377  return node->to_double();
378  }
virtual double to_double() const
Get value of a constant node.
Definition: sx_node.cpp:56

◆ operator Matrix< SXElem >()

casadi::SXElem::operator Matrix< SXElem > ( ) const

◆ operator!()

SXElem casadi::GenericExpression< SXElem >::operator! ( ) const
inlineinherited

Returns (an expression evaluating to) 1 if expression is zero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oz

Definition at line 266 of file generic_expression.hpp.

266  {
267  return logic_not(self());
268  }
static SXElem logic_not(const SXElem &x)
Logical not x -> !x.

◆ operator*=()

SXElem & casadi::GenericExpression< SXElem >::operator*= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_op

Definition at line 108 of file generic_expression.hpp.

108 {return self() = self() * y;}

◆ operator+=()

SXElem & casadi::GenericExpression< SXElem >::operator+= ( const SXElem y)
inlineinherited

Definition at line 76 of file generic_expression.hpp.

76 { return self() = self() + y; }

◆ operator-()

SXElem casadi::SXElem::operator- ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10x

Definition at line 150 of file sx_elem.cpp.

150  {
151  if (is_op(OP_NEG))
152  return dep();
153  else if (is_zero())
154  return 0;
155  else if (is_minus_one())
156  return 1;
157  else if (is_one())
158  return -1;
159  else
160  return unary(OP_NEG, *this);
161  }
bool is_minus_one() const
Definition: sx_elem.cpp:319
bool is_one() const
Definition: sx_elem.cpp:315
@ OP_NEG
Definition: calculus.hpp:66

References dep(), is_minus_one(), is_one(), is_op(), is_zero(), casadi::OP_NEG, and unary().

◆ operator-=()

SXElem & casadi::GenericExpression< SXElem >::operator-= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oo

Definition at line 92 of file generic_expression.hpp.

92 { return self() = self() - y; }

◆ operator->() [1/2]

SXNode * casadi::SXElem::operator-> ( )

Definition at line 185 of file sx_elem.cpp.

185  {
186  return node;
187  }

◆ operator->() [2/2]

const SXNode * casadi::SXElem::operator-> ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10o

Definition at line 181 of file sx_elem.cpp.

181  {
182  return node;
183  }

◆ operator/=()

SXElem & casadi::GenericExpression< SXElem >::operator/= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oq

Definition at line 124 of file generic_expression.hpp.

124 {return self() = self() / y;}

◆ operator=() [1/2]

SXElem & casadi::SXElem::operator= ( const SXElem scalar)

Definition at line 102 of file sx_elem.cpp.

102  {
103  if (this == &scalar) return *this;
104 
105  // quick return if the old and new pointers point to the same object
106  if (node == scalar.node) return *this;
107 
108  // decrease the counter and delete if this was the last pointer
109  if (--node->count == 0) delete node;
110 
111  // save the new pointer
112  node = scalar.node;
113  node->count++;
114  return *this;
115  }

References casadi::SXNode::count.

◆ operator=() [2/2]

SXElem & casadi::SXElem::operator= ( double  scalar)

Definition at line 142 of file sx_elem.cpp.

142  {
143  return *this = SXElem(scalar);
144  }

References SXElem().

◆ plus()

static SXElem casadi::GenericExpression< SXElem >::plus ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_on

Definition at line 67 of file generic_expression.hpp.

67  {
68  return ExType::binary(OP_ADD, x, y);
69  }

◆ pow()

static SXElem casadi::GenericExpression< SXElem >::pow ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pp

Definition at line 583 of file generic_expression.hpp.

583  {
584  return ExType::binary(OP_POW, x, y);
585  }

◆ printme()

static SXElem casadi::GenericExpression< SXElem >::printme ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Debug printing

Definition at line 730 of file generic_expression.hpp.

730  {
731  return ExType::binary(OP_PRINTME, x, y);
732  }

◆ rdivide()

static SXElem casadi::GenericExpression< SXElem >::rdivide ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oq

Definition at line 115 of file generic_expression.hpp.

115  {
116  return ExType::binary(OP_DIV, x, y);
117  }

◆ remainder()

static SXElem casadi::GenericExpression< SXElem >::remainder ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/remainder

Notably:

  • remainder(5,3) -> -1
  • remainder(5,-3) -> -1
  • remainder(-5,3) -> 1
  • remainder(-5,-3) -> 1

This is equivalent to Python's math.remainder. There is no equivalence in Matlab.

\seealso fmod

Extra doc: https://github.com/casadi/casadi/wiki/L_24x 

Definition at line 634 of file generic_expression.hpp.

634  {
635  return ExType::binary(OP_REMAINDER, x, y);
636  }

◆ self() [1/2]

SXElem & casadi::GenericExpression< SXElem >::self ( )
inlineprotectedinherited

Definition at line 55 of file generic_expression.hpp.

55 { return static_cast<ExType&>(*this); }

◆ self() [2/2]

const SXElem & casadi::GenericExpression< SXElem >::self ( ) const
inlineprotectedinherited

Definition at line 54 of file generic_expression.hpp.

54 { return static_cast<const ExType&>(*this); }

◆ serialize()

void casadi::SXElem::serialize ( SerializingStream s) const

Extra doc: https://github.com/casadi/casadi/wiki/L_114

Definition at line 493 of file sx_elem.cpp.

493  {
494  (*this)->serialize(s);
495  }

◆ set_temp()

void casadi::SXElem::set_temp ( int  t) const

Definition at line 473 of file sx_elem.cpp.

473  {
474  (*this)->temp = t;
475  }

◆ sign()

static SXElem casadi::GenericExpression< SXElem >::sign ( const SXElem x)
inlinestaticinherited

sign(x) := -1 for x<0 sign(x) := 1 for x>0, sign(0) := 0 sign(NaN) := NaN

Extra doc: https://github.com/casadi/casadi/wiki/L_po

Definition at line 571 of file generic_expression.hpp.

571  {
572  return ExType::unary(OP_SIGN, x);
573  }

◆ sin()

static SXElem casadi::GenericExpression< SXElem >::sin ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p3

Definition at line 314 of file generic_expression.hpp.

314  {
315  return ExType::unary(OP_SIN, x);
316  }

◆ sinh()

static SXElem casadi::GenericExpression< SXElem >::sinh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pa

Definition at line 398 of file generic_expression.hpp.

398  {
399  return ExType::unary(OP_SINH, x);
400  }

◆ sq()

static SXElem casadi::GenericExpression< SXElem >::sq ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p2

Definition at line 302 of file generic_expression.hpp.

302  {
303  return ExType::unary(OP_SQ, x);
304  }

◆ sqrt()

static SXElem casadi::GenericExpression< SXElem >::sqrt ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p1

Definition at line 290 of file generic_expression.hpp.

290  {
291  return ExType::unary(OP_SQRT, x);
292  }

◆ sym()

SXElem casadi::SXElem::sym ( const std::string &  name)
static
Parameters
nameName of the symbolic primitive

This is the name that will be used by the "operator<<" and "str" methods. The name is not used as identifier; you may construct distinct SXElem objects with non-unique names.

Extra doc: https://github.com/casadi/casadi/wiki/L_10l

Definition at line 94 of file sx_elem.cpp.

94  {
95  return create(new SymbolicSX(name));
96  }
const std::string & name() const
Definition: sx_elem.cpp:343
Represents a scalar symbolic expression.
Definition: symbolic_sx.hpp:42

References create(), and name().

Referenced by casadi::Matrix< Scalar >::_sym(), and casadi::register_symbol().

◆ tan()

static SXElem casadi::GenericExpression< SXElem >::tan ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p5

Definition at line 338 of file generic_expression.hpp.

338  {
339  return ExType::unary(OP_TAN, x);
340  }

◆ tanh()

static SXElem casadi::GenericExpression< SXElem >::tanh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p9

Definition at line 386 of file generic_expression.hpp.

386  {
387  return ExType::unary(OP_TANH, x);
388  }

◆ times()

static SXElem casadi::GenericExpression< SXElem >::times ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_op

Definition at line 99 of file generic_expression.hpp.

99  {
100  return ExType::binary(OP_MUL, x, y);
101  }

◆ type_name()

static std::string casadi::SXElem::type_name ( )
inlinestatic

Definition at line 135 of file sx_elem.hpp.

135 {return "SXElem";}

◆ unary()

SXElem casadi::SXElem::unary ( casadi_int  op,
const SXElem x,
bool  unique = false 
)
static

Definition at line 237 of file sx_elem.cpp.

237  {
238  // Simplifications
240  switch (op) {
241  case OP_NOT:
242  if (x.is_op(OP_NOT))
243  return x.dep(); // This looks problematic
244  break;
245  case OP_TWICE:
246  if (x.is_op(OP_MUL) && x.dep(0).is_constant())
247  return (2*x.dep(0))*x.dep(1); // (2*a)*x = (2*a)*x
248  else if (x.is_op(OP_MUL) && x.dep(1).is_constant())
249  return (2*x.dep(1))*x.dep(0); // x*(2*a) = (2*a)*x
250  else if (x.is_op(OP_TWICE))
251  return 4*x.dep(); // 2*(2*x) = 4*x
252  break;
253  }
254  // Simplifications
255  bool hit;
257  [](casadi_int op, const SXElem& a) { return unary(op, a);},
258  unique,
259  hit);
260  if (hit) return ret;
261  }
262  return UnarySX::create(Operation(op), x);
263  }
static SXElem create(unsigned char op, const SXElem &dep)
Create a unary expression.
Definition: unary_sx.hpp:55
T common_simp_unary(casadi_int op, const T &x, casadi_int depth, SU &&gen_unary, bool unique, bool &hit)
Definition: calculus.hpp:1813
@ OP_NOT
Definition: calculus.hpp:70

References casadi::common_simp_unary(), casadi::UnarySX::create(), dep(), casadi::SXNode::eq_depth_, is_constant(), is_op(), op(), casadi::OP_MUL, casadi::OP_NOT, casadi::OP_TWICE, and casadi::GlobalOptions::simplification_on_the_fly.

Referenced by binary(), inv(), and operator-().

◆ which_function()

Function casadi::SXElem::which_function ( ) const

Definition at line 291 of file sx_elem.cpp.

291  {
292  return node->which_function();
293  }
virtual Function which_function() const
Get called function.
Definition: sx_node.cpp:64

References casadi::SXNode::which_function().

◆ which_output()

casadi_int casadi::SXElem::which_output ( ) const

Definition at line 295 of file sx_elem.cpp.

295  {
296  return node->which_output();
297  }
virtual casadi_int which_output() const
Get function output.
Definition: sx_node.cpp:68

References casadi::SXNode::which_output().

Friends And Related Function Documentation

◆ BinarySXNode

friend class BinarySXNode
friend

Definition at line 77 of file sx_elem.hpp.

◆ if_else

SXElem if_else ( const SXElem x,
const SXElem y,
const SXElem z 
)
friend

Extra doc: https://github.com/casadi/casadi/wiki/L_113

Definition at line 288 of file sx_elem.hpp.

288  {
289  return if_else_zero(x, y) + if_else_zero(!x, z);
290  }

◆ Matrix< SXElem >

friend class Matrix< SXElem >
friend

Definition at line 77 of file sx_elem.hpp.

◆ SXNode

friend class SXNode
friend

Definition at line 76 of file sx_elem.hpp.


The documentation for this class was generated from the following files: