io_instruction.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_IO_INSTRUCTION_HPP
27 #define CASADI_IO_INSTRUCTION_HPP
28 
29 #include "mx_node.hpp"
30 
31 namespace casadi {
38  class CASADI_EXPORT IOInstruction : public MXNode {
39  protected:
40  // Input/output index
41  casadi_int ind_;
42 
43  // Segment number
44  casadi_int segment_;
45 
46  // Nonzero offset
47  casadi_int offset_;
48 
49  // Constructor (called from derived classes)
50  IOInstruction(casadi_int ind, casadi_int segment, casadi_int offset)
51  : ind_(ind), segment_(segment), offset_(offset) {}
52 
53  public:
55  ~IOInstruction() override {}
56 
57  // Get IO index
58  casadi_int ind() const override { return ind_;}
59 
60  // Get IO segment
61  casadi_int segment() const override { return segment_;}
62 
63  // Get IO offset
64  casadi_int offset() const override { return offset_;}
65 
67  Dict info() const override;
68 
72  void serialize_body(SerializingStream& s) const override;
73 
74  protected:
79  };
80 
84  class CASADI_EXPORT Input : public IOInstruction {
85  public:
86  // Constructor (called from derived classes)
87  Input(const Sparsity& sp, casadi_int ind, casadi_int segment, casadi_int offset);
88 
90  ~Input() override {}
91 
95  casadi_int op() const override { return OP_INPUT;}
96 
100  std::string disp(const std::vector<std::string>& arg) const override;
101 
106  const std::vector<casadi_int>& arg,
107  const std::vector<casadi_int>& res) const override;
108 
112  static MXNode* deserialize(DeserializingStream& s) { return new Input(s); }
113 
114  protected:
119  };
120 
124  class CASADI_EXPORT Output : public IOInstruction {
125  public:
126  // Constructor (called from derived classes)
127  Output(const MX& x, casadi_int ind, casadi_int segment, casadi_int offset);
128 
130  ~Output() override {}
131 
135  casadi_int nout() const override { return 0;}
136 
140  casadi_int op() const override { return OP_OUTPUT;}
141 
145  std::string disp(const std::vector<std::string>& arg) const override;
146 
151  const std::vector<casadi_int>& arg,
152  const std::vector<casadi_int>& res) const override;
153 
157  static MXNode* deserialize(DeserializingStream& s) { return new Output(s); }
158  protected:
163  };
164 
165 
167 } // namespace casadi
168 
169 #endif // CASADI_IO_INSTRUCTION_HPP
Helper class for C code generation.
Helper class for Serialization.
An input or output instruction.
IOInstruction(DeserializingStream &s)
Deserializing constructor.
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
casadi_int segment() const override
casadi_int ind() const override
~IOInstruction() override
Destructor.
casadi_int offset() const override
Input instruction.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
casadi_int op() const override
Get the operation.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Input(const Sparsity &sp, casadi_int ind, casadi_int segment, casadi_int offset)
Input(DeserializingStream &s)
Deserializing constructor.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res) const override
Generate code for the operation.
~Input() override
Destructor.
Node class for MX objects.
Definition: mx_node.hpp:50
MX - Matrix expression.
Definition: mx.hpp:84
Input instruction.
Output(DeserializingStream &s)
Deserializing constructor.
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
casadi_int nout() const override
Number of outputs.
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.
casadi_int op() const override
Get the operation.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res) const override
Generate code for the operation.
~Output() override
Destructor.
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:99
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.