26 #include "io_instruction.hpp"
27 #include "serializing_stream.hpp"
35 std::string
Input::disp(
const std::vector<std::string>& arg)
const {
42 const std::vector<casadi_int>& arg,
43 const std::vector<casadi_int>& res,
44 const std::vector<bool>& arg_is_ref,
45 std::vector<bool>& res_is_ref)
const {
46 casadi_int
nnz = this->
nnz();
49 casadi_int i = res.front();
51 g << g.
workel(i) <<
" = " << a <<
" ? " << a <<
"[" <<
offset_ <<
"] : 0;\n";
54 g << g.
work(i,
nnz,
true) <<
" = " << a <<
" ? " << a <<
" : " << g.
zeros(
nnz) <<
";\n";
76 std::string
Output::disp(
const std::vector<std::string>& arg)
const {
83 const std::vector<casadi_int>& arg,
84 const std::vector<casadi_int>& res,
85 const std::vector<bool>& arg_is_ref,
86 std::vector<bool>& res_is_ref)
const {
89 casadi_int i = arg.front();
92 g <<
"if (" << r <<
") " << r <<
"[" <<
offset_ <<
"] = " << g.
workel(i) <<
";\n";
96 g <<
"if (" << r <<
") "
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string arg(casadi_int i) const
Refer to argument.
std::string copy(const std::string &arg, std::size_t n, const std::string &res)
Create a copy operation.
std::string workel(casadi_int n) const
std::string res(casadi_int i) const
Refer to resuly.
bool elide_copy(casadi_int sz)
std::string zeros(casadi_int sz)
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
An input or output instruction.
IOInstruction(casadi_int ind, casadi_int segment, casadi_int offset)
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Dict info() const override
Node class for MX objects.
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.
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.
Output(const MX &x, casadi_int ind, casadi_int segment, casadi_int offset)
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.