List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
casadi::Importer Class Reference

Importer. More...

#include <importer.hpp>

Detailed Description

Just-in-time compilation of code

General information

List of plugins

- clang

- shell

Note: some of the plugins in this list might not be available on your system. Also, there might be extra plugins available to you that are not listed here. You can obtain their documentation with Importer.doc("myextraplugin")


clang

Interface to the JIT compiler CLANG

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


List of available options
IdTypeDescription
flagsOT_STRINGVECTORCompile flags for the JIT compiler. Default: None
include_pathOT_STRINGInclude paths for the JIT compiler. The include directory shipped with CasADi will be automatically appended.

shell

Interface to the JIT compiler SHELL

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


List of available options
IdTypeDescription
cleanupOT_BOOLCleanup temporary files when unloading. Default: true
compilerOT_STRINGCompiler command
compiler_flagsOT_STRINGVECTORAlias for 'compiler_flags'
compiler_output_flagOT_STRINGCompiler flag to denote object output. Default: '-o '
compiler_setupOT_STRINGCompiler setup command. Intended to be fixed. The 'flag' option is the prefered way to set custom flags.
directoryOT_STRINGDirectory to put temporary objects in. Must end with a file separator.
extra_suffixesOT_STRINGVECTORList of suffixes for extra files that the compiler may generate. Default: None
flagsOT_STRINGVECTORCompile flags for the JIT compiler. Default: None
linkerOT_STRINGLinker command
linker_flagsOT_STRINGVECTORLinker flags for the JIT compiler. Default: None
linker_output_flagOT_STRINGLinker flag to denote shared library output. Default: '-o '
linker_setupOT_STRINGLinker setup command. Intended to be fixed. The 'flag' option is the prefered way to set custom flags.
nameOT_STRINGThe file name used to write out compiled objects/libraries. The actual file names used depend on 'temp_suffix' and include extensions. Default: 'tmp_casadi_compiler_shell'
temp_suffixOT_BOOLUse a temporary (seemingly random) filename suffix for file names. This is desired for thread-safety. This behaviour may defeat caching compiler wrappers. Default: true
Author
Joris Gillis
Date
2015

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

Definition at line 84 of file importer.hpp.

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

Public Types

using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

 Importer ()
 Default constructor. More...
 
 Importer (const std::string &name, const std::string &compiler, const Dict &opts=Dict())
 Importer factory. More...
 
ImporterInternaloperator-> ()
 Access functions of the node. More...
 
const ImporterInternaloperator-> () const
 
std::string plugin_name () const
 Query plugin name. More...
 
bool has_function (const std::string &symname) const
 
signal_t get_function (const std::string &symname)
 Get a function pointer for numerical evaluation. More...
 
bool has_meta (const std::string &cmd, casadi_int ind=-1) const
 Does a meta entry exist? More...
 
std::string get_meta (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a text. More...
 
bool inlined (const std::string &symname) const
 Check if a function is inlined. More...
 
std::string body (const std::string &symname) const
 Get the function body, if inlined. More...
 
std::string library () const
 Get library name. More...
 
template<typename T >
to (const std::string &cmd, casadi_int ind=-1) const
 Convert to a type. More...
 
std::string meta_string (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a string. More...
 
template<typename T >
std::vector< T > meta_vector (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a vector. More...
 
template<typename T >
std::set< T > meta_set (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a set. More...
 
casadi_int meta_int (const std::string &cmd, casadi_int ind=-1) const
 Get entry as an integer. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
SharedObjectInternalget () const
 Get a const pointer to the node. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 

Static Public Member Functions

static std::string type_name ()
 Get type name. More...
 
static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 
static bool has_plugin (const std::string &name)
 Check if a plugin is available. More...
 
static void load_plugin (const std::string &name)
 Explicitly load a plugin dynamically. More...
 
static std::string doc (const std::string &name)
 Get solver specific documentation. More...
 
static Importer create (ImporterInternal *node)
 Create from node. More...
 
static Importer create (ImporterInternal *node, const Dict &opts)
 Create from node and initialize. More...
 
static std::string indexed (const std::string &cmd, casadi_int ind)
 
static Importer deserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ Importer() [1/2]

casadi::Importer::Importer ( )

Definition at line 31 of file importer.cpp.

31  {
32  }

◆ Importer() [2/2]

casadi::Importer::Importer ( const std::string &  name,
const std::string &  compiler,
const Dict opts = Dict() 
)
explicit

Definition at line 34 of file importer.cpp.

36  {
37  if (compiler=="none") {
38  own(new ImporterInternal(name));
39  } else if (compiler=="dll") {
40  own(new DllLibrary(name));
41  } else {
42  own(ImporterInternal::getPlugin(compiler).creator(name));
43  }
44  (*this)->construct(opts);
45  }
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

References casadi::PluginInterface< ImporterInternal >::getPlugin(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

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

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

Definition at line 124 of file generic_shared_impl.hpp.

137  {
138  return reinterpret_cast<casadi_int>(get());
139  }

◆ assign()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

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

Definition at line 97 of file generic_shared_impl.hpp.

75  {
76  node = node_;
77  }

◆ body()

std::string casadi::Importer::body ( const std::string &  symname) const

Definition at line 95 of file importer.cpp.

95  {
96  return (*this)->body(symname);
97  }

Referenced by casadi::External::codegen_body().

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 134 of file generic_shared_impl.hpp.

42  {
43 #ifdef WITH_EXTRA_CHECKS
44  casadi_assert_dev(Function::call_depth_==0);
45 #endif // WITH_EXTRA_CHECKS
46  if (!node) return;
47  if (node->weak_ref_) {
48 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
49  auto mutex = node->weak_ref_->get_mutex();
50  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
51  std::lock_guard<std::mutex> lock(*mutex);
52  // Could it be that this mutex is destroyed when the lock goes out of scope?
53 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
54 
55  if (--static_cast<Internal*>(node)->count == 0) {
56  delete node;
57  node = nullptr;
58  }
59  } else {
60  if (--static_cast<Internal*>(node)->count == 0) {
61  delete node;
62  node = nullptr;
63  }
64  }
65  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

32  {
33 #ifdef WITH_EXTRA_CHECKS
34  casadi_assert_dev(Function::call_depth_==0);
35 #endif // WITH_EXTRA_CHECKS
36 
37  if (node) static_cast<Internal*>(node)->count++;
38 
39  }

◆ create() [1/2]

Importer casadi::Importer::create ( ImporterInternal node)
static

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

Definition at line 111 of file importer.cpp.

111  {
112  Importer ret;
113  ret.own(node);
114  return ret;
115  }
Importer()
Default constructor.
Definition: importer.cpp:31

References casadi::GenericShared< Shared, Internal >::own().

Referenced by create(), and deserialize().

◆ create() [2/2]

Importer casadi::Importer::create ( ImporterInternal node,
const Dict opts 
)
static

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

Definition at line 117 of file importer.cpp.

117  {
118  Importer ret = create(node);
119  ret->construct(opts);
120  return ret;
121  }
static Importer create(ImporterInternal *node)
Create from node.
Definition: importer.cpp:111

References casadi::ImporterInternal::construct(), and create().

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 113 of file generic_shared_impl.hpp.

80  {
81  if (node) {
82  return node->debug_repr(node);
83  } else {
84  return "NULL";
85  }
86  }
std::string debug_repr(const Internal *) const

◆ deserialize()

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

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

Definition at line 107 of file importer.cpp.

107  {
109  }
static ImporterInternal * deserialize(DeserializingStream &s)

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

◆ disp()

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

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ doc()

std::string casadi::Importer::doc ( const std::string &  name)
static

Definition at line 67 of file importer.cpp.

67  {
68  return ImporterInternal::getPlugin(name).doc;
69  }

References casadi::PluginInterface< ImporterInternal >::getPlugin().

◆ get()

Definition at line 100 of file generic_shared_impl.hpp.

104  {
105  return node;
106  }

◆ get_function()

signal_t casadi::Importer::get_function ( const std::string &  symname)

◆ get_meta()

std::string casadi::Importer::get_meta ( const std::string &  cmd,
casadi_int  ind = -1 
) const

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

Definition at line 87 of file importer.cpp.

87  {
88  return (*this)->get_meta(cmd, ind);
89  }

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 103 of file generic_shared_impl.hpp.

127  {
128  return (*this)->getCount();
129  }

◆ has_function()

bool casadi::Importer::has_function ( const std::string &  symname) const

Definition at line 75 of file importer.cpp.

75  {
76  return (*this)->has_function(symname);
77  }

Referenced by casadi::External::factory(), casadi::External::has_forward(), casadi::External::has_jacobian(), casadi::External::has_reverse(), and casadi::External::init().

◆ has_meta()

bool casadi::Importer::has_meta ( const std::string &  cmd,
casadi_int  ind = -1 
) const

◆ has_plugin()

bool casadi::Importer::has_plugin ( const std::string &  name)
static

Definition at line 59 of file importer.cpp.

59  {
60  return ImporterInternal::has_plugin(name);
61  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.

References casadi::PluginInterface< ImporterInternal >::has_plugin().

◆ indexed()

static std::string casadi::Importer::indexed ( const std::string &  cmd,
casadi_int  ind 
)
inlinestatic

Convert indexed command

Definition at line 163 of file importer.hpp.

163  {
164  std::stringstream ss;
165  ss << cmd << "[" << ind << "]";
166  return ss.str();
167  }

◆ inlined()

bool casadi::Importer::inlined ( const std::string &  symname) const

Definition at line 91 of file importer.cpp.

91  {
92  return (*this)->inlined(symname);
93  }

Referenced by casadi::External::codegen_body(), and casadi::External::codegen_declarations().

◆ is_null()

Definition at line 117 of file generic_shared_impl.hpp.

109  {
110  return node==nullptr;
111  }

◆ library()

std::string casadi::Importer::library ( ) const

Definition at line 99 of file importer.cpp.

99  {
100  return (*this)->library();
101  }

Referenced by casadi::external(), casadi::External::External(), and casadi::FunctionInternal::serialize_body().

◆ load_plugin()

void casadi::Importer::load_plugin ( const std::string &  name)
static

Definition at line 63 of file importer.cpp.

63  {
65  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

References casadi::PluginInterface< ImporterInternal >::load_plugin().

◆ meta_int()

casadi_int casadi::Importer::meta_int ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inline

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

Definition at line 203 of file importer.hpp.

203  {
204  return to<casadi_int>(cmd, ind);
205  }

Referenced by casadi::External::get_n_in(), and casadi::External::get_n_out().

◆ meta_set()

template<typename T >
std::set<T> casadi::Importer::meta_set ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inline

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

Definition at line 196 of file importer.hpp.

196  {
197  return text2set<T>(get_meta(cmd, ind));
198  }
std::string get_meta(const std::string &cmd, casadi_int ind=-1) const
Get entry as a text.
Definition: importer.cpp:87

◆ meta_string()

std::string casadi::Importer::meta_string ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inline

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

Definition at line 180 of file importer.hpp.

180  {
181  return to<std::string>(cmd, ind);
182  }

Referenced by casadi::External::get_name_in(), and casadi::External::get_name_out().

◆ meta_vector()

template<typename T >
std::vector<T> casadi::Importer::meta_vector ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inline

◆ operator->() [1/2]

ImporterInternal * casadi::Importer::operator-> ( )

Definition at line 47 of file importer.cpp.

47  {
48  return static_cast<ImporterInternal*>(SharedObject::operator->());
49  }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const ImporterInternal * casadi::Importer::operator-> ( ) const

Definition at line 51 of file importer.cpp.

51  {
52  return static_cast<const ImporterInternal*>(SharedObject::operator->());
53  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 90 of file generic_shared_impl.hpp.

◆ plugin_name()

std::string casadi::Importer::plugin_name ( ) const

Definition at line 71 of file importer.cpp.

71  {
72  return (*this)->plugin_name();
73  }

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ serialize()

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

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

Definition at line 103 of file importer.cpp.

103  {
104  return (*this)->serialize(s);
105  }

◆ swap()

Definition at line 106 of file generic_shared_impl.hpp.

120  {
121  GenericShared<Shared, Internal> temp = *this;
122  *this = other;
123  other = temp;
124  }

◆ test_cast()

bool casadi::Importer::test_cast ( const SharedObjectInternal ptr)
static

Definition at line 55 of file importer.cpp.

55  {
56  return dynamic_cast<const ImporterInternal*>(ptr)!=nullptr;
57  }

◆ to()

template<typename T >
T casadi::Importer::to ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inline

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

Definition at line 173 of file importer.hpp.

173  {
174  return text2type<T>(get_meta(cmd, ind));
175  }

References casadi::T.

◆ type_name()

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

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

Definition at line 91 of file importer.hpp.

91 {return "Importer";}

◆ weak()

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

Definition at line 131 of file generic_shared_impl.hpp.

132  {
133  return (*this)->weak();
134  }

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