alpaqa 1.0.0a19
Nonconvex constrained optimization
Loading...
Searching...
No Matches
casadi-external-function.cpp
Go to the documentation of this file.
3#include <alpaqa/util/dl.hpp>
4
5namespace alpaqa {
7namespace casadi {
8
27
29 if (work)
30 return;
32 functions.init_mem(mem); // TODO: what to do upon failure?
35 auto &w = work.emplace();
36 w.arg.resize(static_cast<size_t>(sz_arg));
37 w.res.resize(static_cast<size_t>(sz_res));
38 w.iw.resize(static_cast<size_t>(sz_iw));
39 w.w.resize(static_cast<size_t>(sz_w));
40}
41
42Function::Function(std::shared_ptr<void> so_handle,
43 const std::string &func_name)
44 : so_handle{std::move(so_handle)} {
45 load(this->so_handle.get(), func_name);
46}
48 : so_handle{o.so_handle}, functions{o.functions} {
50}
52 : so_handle{std::move(o.so_handle)}, functions{o.functions},
53 work{std::move(o.work)}, mem{std::exchange(o.mem, nullptr)} {}
55 if (so_handle) {
56 if (mem)
59 }
60}
61
64std::pair<casadi_int, casadi_int> Function::size_in(casadi_int n) const {
65 return sparsity_in(n).size();
66}
67std::pair<casadi_int, casadi_int> Function::size_out(casadi_int n) const {
68 return sparsity_out(n).size();
69}
88
89Function external(const std::string &name, const std::string &bin_name) {
90 return Function{util::load_lib(std::filesystem::path{bin_name}), name};
91}
92
93} // namespace casadi
95} // namespace alpaqa
#define BEGIN_ALPAQA_CASADI_LOADER_NAMESPACE
#define END_ALPAQA_CASADI_LOADER_NAMESPACE
std::pair< casadi_int, casadi_int > size() const
Class that loads and calls pre-compiled CasADi functions in a DLL/SO file.
struct alpaqa::casadi::Function::Functions functions
casadi_int size1_out(casadi_int) const
std::pair< casadi_int, casadi_int > size_in(casadi_int) const
fname_sparsity_in::signature_t * sparsity_in
void load(void *so_handle, const std::string &func_name)
std::pair< casadi_int, casadi_int > size_out(casadi_int) const
fname_sparsity_out::signature_t * sparsity_out
Sparsity sparsity_in(casadi_int) const
std::shared_ptr< void > so_handle
casadi_int size2_out(casadi_int) const
Function(std::shared_ptr< void > so_handle, const std::string &func_name)
Sparsity sparsity_out(casadi_int) const
casadi_int size1_in(casadi_int) const
casadi_int size2_in(casadi_int) const
Function external(const std::string &name, const std::string &bin_name)
Load the given CasADi function from the given DLL/SO file.
std::shared_ptr< void > load_lib(const std::filesystem::path &so_filename)
Definition dl.cpp:51
constexpr const auto inf
Definition config.hpp:112
long long int casadi_int
static signature_t * load(void *handle, std::string fname)