26 #ifndef CASADI_CONSTANT_SX_HPP
27 #define CASADI_CONSTANT_SX_HPP
29 #include "sx_node.hpp"
30 #include "serializing_stream.hpp"
31 #include "matrix_decl.hpp"
37 #include <unordered_map>
38 #define CACHING_MAP std::unordered_map
55 std::string
class_name()
const override {
return "ConstantSX";}
94 std::string
print(
const std::string& arg1,
const std::string& arg2)
const override {
99 ss.setf(std::ios::scientific);
101 ss.unsetf(std::ios::scientific);
128 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
130 std::lock_guard<std::mutex> lock(mutex_cached_constants);
133 assert(num_erased==1);
139 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
141 std::lock_guard<std::mutex> lock(mutex_cached_constants);
166 casadi_int
to_int()
const override {
return static_cast<casadi_int
>(
value);}
172 s.
pack(
"ConstantSX::type",
'r');
184 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
185 static std::mutex mutex_cached_constants;
205 casadi_assert(
value<=std::numeric_limits<int>::max() &&
206 value>=std::numeric_limits<int>::min(),
"Integer overflow");
213 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
215 std::lock_guard<std::mutex> lock(mutex_cached_constants);
218 assert(num_erased==1);
224 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
226 std::lock_guard<std::mutex> lock(mutex_cached_constants);
251 casadi_int
to_int()
const override {
return static_cast<casadi_int
>(
value); }
260 s.
pack(
"ConstantSX::type",
'i');
273 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
274 static std::mutex mutex_cached_constants;
306 casadi_int
to_int()
const override {
return 0;}
314 bool is_zero()
const override {
return true; }
319 s.
pack(
"ConstantSX::type",
'0');
337 static OneSX instance;
346 casadi_int
to_int()
const override {
return 1;}
352 bool is_one()
const override {
return true; }
355 s.
pack(
"ConstantSX::type",
'1');
385 casadi_int
to_int()
const override {
return -1;}
397 s.
pack(
"ConstantSX::type",
'm');
416 static InfSX instance;
424 double to_double()
const override {
return std::numeric_limits<double>::infinity();}
429 bool is_inf()
const override {
return true; }
432 s.
pack(
"ConstantSX::type",
'F');
460 double to_double()
const override {
return -std::numeric_limits<double>::infinity();}
468 s.
pack(
"ConstantSX::type",
'f');
485 static NanSX instance;
493 double to_double()
const override {
return std::numeric_limits<double>::quiet_NaN();}
498 bool is_nan()
const override {
return true; }
501 s.
pack(
"ConstantSX::type",
'n');
508 s.
unpack(
"ConstantSX::type", type);
514 s.
unpack(
"ConstantSX::value", value);
519 s.
unpack(
"ConstantSX::value", value);
527 default: casadi_error(
"ConstantSX::deserialize error");
Represents a constant SX.
casadi_int op() const override
Get the operation.
std::string class_name() const override
Get type name.
bool is_integer() const override
check properties of a node
bool is_value(double v) const override
Properties.
std::string print(const std::string &arg1, const std::string &arg2) const override
Print expression.
bool is_half() const override
check properties of a node
bool is_equal(const SXNode *node, casadi_int depth) const override
Check if two nodes are equivalent up to a given depth.
bool is_constant() const override
Properties.
double to_double() const override=0
Get the value must be defined.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
Represents an infinity SX.
double to_double() const override
Get the value.
static InfSX * singleton()
void serialize_node(SerializingStream &s) const override
bool is_inf() const override
Properties.
Represents a constant integer SX.
static CACHING_MAP< casadi_int, IntegerSX * > cached_constants_
Hash map of all constants currently allocated.
static IntegerSX * create(casadi_int value)
Static creator function (use instead of constructor)
casadi_int to_int() const override
evaluate function
void serialize_node(SerializingStream &s) const override
~IntegerSX() override
Destructor.
double to_double() const override
evaluate function
bool is_integer() const override
Properties.
Sparse matrix class. SX and DM are specializations.
Represents a minus infinity SX.
bool is_minus_inf() const override
Properties.
void serialize_node(SerializingStream &s) const override
double to_double() const override
Get the value.
static MinusInfSX * singleton()
Represents a minus one SX.
double to_double() const override
Get the value.
bool is_minus_one() const override
Properties.
bool is_integer() const override
Properties.
static MinusOneSX * singleton()
void serialize_node(SerializingStream &s) const override
casadi_int to_int() const override
Get the value.
Represents a not-a-number SX.
bool is_nan() const override
Properties.
static NanSX * singleton()
double to_double() const override
Get the value.
void serialize_node(SerializingStream &s) const override
double to_double() const override
Get the value.
void serialize_node(SerializingStream &s) const override
bool is_integer() const override
Properties.
casadi_int to_int() const override
Get value of a constant node.
static OneSX * singleton()
bool is_one() const override
check properties of a node
static CACHING_MAP< double, RealtypeSX * > cached_constants_
Hash map of all constants currently allocated.
double value
Data members.
bool is_almost_zero(double tol) const override
check properties of a node
~RealtypeSX() override
Destructor.
double to_double() const override
Get the value.
static RealtypeSX * create(double value)
Static creator function (use instead of constructor)
void serialize_node(SerializingStream &s) const override
casadi_int to_int() const override
Get the value.
Internal node class for SX.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
void serialize_node(SerializingStream &s) const override
casadi_int to_int() const override
Get the value.
double to_double() const override
Get the value.
bool is_almost_zero(double tol) const override
Properties.
bool is_integer() const override
Properties.
static ZeroSX * singleton()
bool is_zero() const override
Properties.
static bool is_half(const T &val)
static bool is_integer(const T &val)
static bool is_value(const T &val, T v)
SXNode * ConstantSX_deserialize(DeserializingStream &s)