graph_builder.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_GRAPH_BUILDER_HPP
27 #define CASADI_GRAPH_BUILDER_HPP
28 
29 #include "function.hpp"
30 
31 namespace casadi {
32 
33  class GraphBuilderInternal;
34 
51  class CASADI_EXPORT GraphBuilder
52  : public SharedObject,
53  public SWIG_IF_ELSE(PrintableCommon, Printable<GraphBuilder>) {
54  public:
56  std::string type_name() const { return "GraphBuilder"; }
57 
59  GraphBuilder();
60 
62  explicit GraphBuilder(const std::string& model_path, const Dict& opts = Dict());
63 
65  explicit GraphBuilder(const Function& f, const Dict& opts = Dict());
66 
67 #ifndef SWIG
69  GraphBuilder(const std::string& name, const std::vector<uint8_t>& model_data,
70  const std::string& format, const Dict& opts = Dict());
71 #endif // SWIG
72 
74  const std::string& name() const;
75 
77 
78  casadi_int n_in() const;
79  casadi_int n_out() const;
80  std::vector<std::string> name_in() const;
81  std::vector<std::string> name_out() const;
83  std::vector<casadi_int> dimension(const std::string& name) const;
85  std::string dtype(const std::string& name) const;
87  std::vector<std::string> dimension_param(const std::string& name) const;
89  std::vector<std::string> dynamic_params() const;
91 
93 
95  void bind_dim(const std::string& param, casadi_int value);
97  void bind_shape(const std::string& input_name, const std::vector<casadi_int>& shape);
99  void set(const std::string& input_name, const std::vector<double>& value);
101  void set(const std::string& input_name, double value);
103 
124  Function create(const std::string& name,
125  const std::vector<std::string>& name_in,
126  const std::vector<std::string>& name_out,
127  const Dict& opts = Dict()) const;
128 
135  Function create(const std::string& name, const Dict& opts = Dict()) const;
136 
140  Function create() const { return create(name() + "_graph"); }
141 
145  void export_onnx(const std::string& filename, const Dict& opts = Dict());
146 
147 #ifndef SWIG
150  GraphBuilderInternal* operator->();
151  const GraphBuilderInternal* operator->() const;
152  GraphBuilderInternal* get() const;
154 #endif // SWIG
155  };
156 
157 } // namespace casadi
158 
159 #endif // CASADI_GRAPH_BUILDER_HPP
Function object.
Definition: function.hpp:126
Internal class for GraphBuilder.
A mutable, format-neutral interface to a computational-graph model.
std::string type_name() const
Readable name of the class.
Function create() const
Freeze into an evaluable Function, default naming.
GenericShared implements a reference counting framework similar for efficient and.
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::string filename(const std::string &path)
Definition: ghc.cpp:55