15#include "proxsuite-nlp/python/polymorphic.hpp"
26template <
class FunctionBase = context::StageFunction>
29 proxsuite::nlp::python::PolymorphicWrapper<PyStageFunction<FunctionBase>,
31 using Scalar =
typename FunctionBase::Scalar;
33 using FunctionBase::FunctionBase;
36 void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
37 Data &data)
const override {
42 Data &data)
const override {
48 const ConstVectorRef &u,
49 const ConstVectorRef &lbda,
50 Data &data)
const override {
52 x, u, lbda, boost::ref(data));
60 return FunctionBase::createData();
64template <
typename UFunction = context::UnaryFunction>
67 proxsuite::nlp::python::PolymorphicWrapper<PyUnaryFunction<UFunction>,
69 using Scalar =
typename UFunction::Scalar;
71 std::is_base_of_v<UnaryFunctionTpl<Scalar>, UFunction>,
72 "Template parameter UFunction must derive from UnaryFunctionTpl<>.");
77 using UFunction::UFunction;
79 void evaluate(
const ConstVectorRef &x,
Data &data)
const override {
89 const ConstVectorRef &lbda,
90 Data &data)
const override {
92 lbda, boost::ref(data));
96 const ConstVectorRef &lbda,
98 UFunction::computeVectorHessianProducts(x, lbda, data);
106 return UFunction::createData();
110template <
typename Class>
115 template <
typename Iterator,
typename Fn>
117 while (range.start != range.stop) {
119 std::advance(range.start, range.step);
124 static auto get_slice(xyz::polymorphic<Class>
const &fn,
125 bp::slice slice_obj) {
126 std::vector<int> indices((
unsigned)fn->nr);
127 std::iota(indices.begin(), indices.end(), 0);
128 auto bounds = slice_obj.get_indices(indices.cbegin(), indices.cend());
129 std::vector<int> out{};
140 std::vector<int>
const &indices) {
144 template <
typename... Args>
void visit(bp::class_<Args...> &cl)
const {
147 .def(
"__getitem__", &
get_slice, bp::args(
"self",
"sl"));
157struct value_holder<
aligator::python::PyStageFunction<>>
158 : proxsuite::nlp::python::OwningNonOwningHolder<
159 aligator::python::PyStageFunction<>> {
160 using OwningNonOwningHolder::OwningNonOwningHolder;
164struct value_holder<
aligator::python::PyUnaryFunction<>>
165 : proxsuite::nlp::python::OwningNonOwningHolder<
166 aligator::python::PyUnaryFunction<>> {
167 using OwningNonOwningHolder::OwningNonOwningHolder;
#define ALIGATOR_PYTHON_OVERRIDE(ret_type, cname, fname,...)
Define the body of a virtual function override. This is meant to reduce boilerplate code when exposin...
#define ALIGATOR_PYTHON_OVERRIDE_PURE(ret_type, pyname,...)
Define the body of a virtual function override. This is meant to reduce boilerplate code when exposin...
Base definitions for ternary functions.
Base definitions for numerical integrators.
Represents a function of which the output is a subset of another function, for instance where is gi...
Base struct for function data.
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
void computeJacobians(const ConstVectorRef &x, const ConstVectorRef &u, Data &data) const override
Compute Jacobians of this function.
shared_ptr< Data > default_createData() const
typename FunctionBase::Scalar Scalar
shared_ptr< Data > createData() const override
Instantiate a Data object.
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, Data &data) const override
Evaluate the function.
void computeVectorHessianProducts(const ConstVectorRef &x, const ConstVectorRef &u, const ConstVectorRef &lbda, Data &data) const override
Compute the vector-hessian products of this function.
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
void evaluate(const ConstVectorRef &x, Data &data) const override
ALIGATOR_UNARY_FUNCTION_INTERFACE(Scalar)
shared_ptr< Data > default_createData() const
typename UFunction::Scalar Scalar
shared_ptr< Data > createData() const override
Instantiate a Data object.
void default_computeVectorHessianProducts(const ConstVectorRef &x, const ConstVectorRef &lbda, Data &data) const
void computeVectorHessianProducts(const ConstVectorRef &x, const ConstVectorRef &lbda, Data &data) const override
void computeJacobians(const ConstVectorRef &x, Data &data) const override
static auto get_from_index(xyz::polymorphic< Class > const &fn, const int idx)
FunctionSliceXprTpl< Scalar, Class > SliceType
static auto get_from_indices(xyz::polymorphic< Class > const &fn, std::vector< int > const &indices)
void visit(bp::class_< Args... > &cl) const
static auto get_slice(xyz::polymorphic< Class > const &fn, bp::slice slice_obj)
static auto do_with_slice(Fn &&fun, bp::slice::range< Iterator > &range)
typename Class::Scalar Scalar