alpaqa 1.0.0a15
Nonconvex constrained optimization
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TypeErasedProblem< Conf, Allocator > Class Template Reference

#include <alpaqa/problem/type-erased-problem.hpp>

Detailed Description

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
class alpaqa::TypeErasedProblem< Conf, Allocator >

The main polymorphic minimization problem interface.

This class wraps the actual problem implementation class, filling in the missing member functions with sensible defaults, and providing a uniform interface that is used by the solvers.

The problem implementations do not inherit from an abstract base class. Instead, structural typing is used. The ProblemVTable constructor uses reflection to discover which member functions are provided by the problem implementation. See Problem formulations for more information, and C++/CustomCppProblem/main.cpp for an example.

Definition at line 216 of file type-erased-problem.hpp.

+ Inheritance diagram for TypeErasedProblem< Conf, Allocator >:
+ Collaboration diagram for TypeErasedProblem< Conf, Allocator >:

Problem dimensions

length_t get_n () const
 [Required] Number of decision variables.
 
length_t get_m () const
 [Required] Number of constraints.
 

Required cost and constraint functions

real_t eval_f (crvec x) const
 [Required] Function that evaluates the cost, \( f(x) \)
 
void eval_grad_f (crvec x, rvec grad_fx) const
 [Required] Function that evaluates the gradient of the cost, \( \nabla f(x) \)
 
void eval_g (crvec x, rvec gx) const
 [Required] Function that evaluates the constraints, \( g(x) \)
 
void eval_grad_g_prod (crvec x, crvec y, rvec grad_gxy) const
 [Required] Function that evaluates the gradient of the constraints times a vector, \( \nabla g(x)\,y = \tp{\jac_g(x)}y \)
 

Projections onto constraint sets and proximal mappings

void eval_proj_diff_g (crvec z, rvec e) const
 [Required] Function that evaluates the difference between the given point \( z \) and its projection onto the constraint set \( D \).
 
void eval_proj_multipliers (rvec y, real_t M) const
 [Required] Function that projects the Lagrange multipliers for ALM.
 
real_t eval_prox_grad_step (real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
 [Required] Function that computes a proximal gradient step.
 
index_t eval_inactive_indices_res_lna (real_t γ, crvec x, crvec grad_ψ, rindexvec J) const
 [Optional] Function that computes the inactive indices \( \mathcal J(x) \) for the evaluation of the linear Newton approximation of the residual, as in [4].
 

Constraint sets

const Boxget_box_C () const
 [Optional] Get the rectangular constraint set of the decision variables, \( x \in C \).
 
const Boxget_box_D () const
 [Optional] Get the rectangular constraint set of the general constraint function, \( g(x) \in D \).
 

Functions for second-order solvers

void eval_jac_g (crvec x, rvec J_values) const
 [Optional] Function that evaluates the nonzero values of the Jacobian matrix of the constraints, \( \jac_g(x) \)
 
Sparsity get_jac_g_sparsity () const
 [Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the constraints.
 
void eval_grad_gi (crvec x, index_t i, rvec grad_gi) const
 [Optional] Function that evaluates the gradient of one specific constraint, \( \nabla g_i(x) \)
 
void eval_hess_L_prod (crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
 [Optional] Function that evaluates the Hessian of the Lagrangian multiplied by a vector, \( \nabla_{xx}^2L(x, y)\,v \)
 
void eval_hess_L (crvec x, crvec y, real_t scale, rvec H_values) const
 [Optional] Function that evaluates the nonzero values of the Hessian of the Lagrangian, \( \nabla_{xx}^2L(x, y) \)
 
Sparsity get_hess_L_sparsity () const
 [Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
 
void eval_hess_ψ_prod (crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
 [Optional] Function that evaluates the Hessian of the augmented Lagrangian multiplied by a vector, \( \nabla_{xx}^2L_\Sigma(x, y)\,v \)
 
void eval_hess_ψ (crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
 [Optional] Function that evaluates the nonzero values of the Hessian of the augmented Lagrangian, \( \nabla_{xx}^2L_\Sigma(x, y) \)
 
Sparsity get_hess_ψ_sparsity () const
 [Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lagrangian.
 

Combined evaluations

real_t eval_f_grad_f (crvec x, rvec grad_fx) const
 [Optional] Evaluate both \( f(x) \) and its gradient, \( \nabla f(x) \).
 
real_t eval_f_g (crvec x, rvec g) const
 [Optional] Evaluate both \( f(x) \) and \( g(x) \).
 
void eval_grad_f_grad_g_prod (crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
 [Optional] Evaluate both \( \nabla f(x) \) and \( \nabla g(x)\,y \).
 
void eval_grad_L (crvec x, crvec y, rvec grad_L, rvec work_n) const
 [Optional] Evaluate the gradient of the Lagrangian \( \nabla_x L(x, y) = \nabla f(x) + \nabla g(x)\,y \)
 

Augmented Lagrangian

real_t eval_ψ (crvec x, crvec y, crvec Σ, rvec ŷ) const
 [Optional] Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.
 
void eval_grad_ψ (crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
 [Optional] Calculate the gradient ∇ψ(x).
 
real_t eval_ψ_grad_ψ (crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
 [Optional] Calculate both ψ(x) and its gradient ∇ψ(x).
 

Checks

void check () const
 [Optional] Check that the problem formulation is well-defined, the dimensions match, etc.
 

Querying specialized implementations

bool provides_eval_inactive_indices_res_lna () const
 Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.
 
bool provides_eval_jac_g () const
 Returns true if the problem provides an implementation of eval_jac_g.
 
bool provides_get_jac_g_sparsity () const
 Returns true if the problem provides an implementation of get_jac_g_sparsity.
 
bool provides_eval_grad_gi () const
 Returns true if the problem provides an implementation of eval_grad_gi.
 
bool provides_eval_hess_L_prod () const
 Returns true if the problem provides an implementation of eval_hess_L_prod.
 
bool provides_eval_hess_L () const
 Returns true if the problem provides an implementation of eval_hess_L.
 
bool provides_get_hess_L_sparsity () const
 Returns true if the problem provides an implementation of get_hess_L_sparsity.
 
bool provides_eval_hess_ψ_prod () const
 Returns true if the problem provides an implementation of eval_hess_ψ_prod.
 
bool provides_eval_hess_ψ () const
 Returns true if the problem provides an implementation of eval_hess_ψ.
 
bool provides_get_hess_ψ_sparsity () const
 Returns true if the problem provides an implementation of get_hess_ψ_sparsity.
 
bool provides_eval_f_grad_f () const
 Returns true if the problem provides a specialized implementation of eval_f_grad_f, false if it uses the default implementation.
 
bool provides_eval_f_g () const
 Returns true if the problem provides a specialized implementation of eval_f_g, false if it uses the default implementation.
 
bool provides_eval_grad_f_grad_g_prod () const
 Returns true if the problem provides a specialized implementation of eval_grad_f_grad_g_prod, false if it uses the default implementation.
 
bool provides_eval_grad_L () const
 Returns true if the problem provides a specialized implementation of eval_grad_L, false if it uses the default implementation.
 
bool provides_eval_ψ () const
 Returns true if the problem provides a specialized implementation of eval_ψ, false if it uses the default implementation.
 
bool provides_eval_grad_ψ () const
 Returns true if the problem provides a specialized implementation of eval_grad_ψ, false if it uses the default implementation.
 
bool provides_eval_ψ_grad_ψ () const
 Returns true if the problem provides a specialized implementation of eval_ψ_grad_ψ, false if it uses the default implementation.
 
bool provides_get_box_C () const
 Returns true if the problem provides an implementation of get_box_C.
 
bool provides_get_box_D () const
 Returns true if the problem provides an implementation of get_box_D.
 
bool provides_check () const
 Returns true if the problem provides an implementation of check.
 

Helpers

real_t calc_ŷ_dᵀŷ (rvec g_ŷ, crvec y, crvec Σ) const
 Given g(x), compute the intermediate results ŷ and dᵀŷ that can later be used to compute ψ(x) and ∇ψ(x).
 

Public Types

using Sparsity = alpaqa::Sparsity< config_t >
 
using Box = alpaqa::Box< config_t >
 
using VTable = ProblemVTable< config_t >
 
using allocator_type = Allocator
 
using TypeErased = util::TypeErased< VTable, allocator_type >
 

Public Member Functions

 TypeErased () noexcept(noexcept(allocator_type()))=default
 Default constructor.
 
template<class Alloc >
 TypeErased (std::allocator_arg_t, const Alloc &alloc)
 Default constructor (allocator aware).
 
 TypeErased (const TypeErased &other)
 Copy constructor.
 
 TypeErased (const TypeErased &other, allocator_type alloc)
 Copy constructor (allocator aware).
 
 TypeErased (TypeErased &&other) noexcept
 Move constructor.
 
 TypeErased (TypeErased &&other, const allocator_type &alloc) noexcept
 Move constructor (allocator aware).
 
template<class T , class Alloc >
 TypeErased (std::allocator_arg_t, const Alloc &alloc, T &&d)
 Main constructor that type-erases the given argument.
 
template<class T , class Alloc , class... Args>
 TypeErased (std::allocator_arg_t, const Alloc &alloc, te_in_place_t< T >, Args &&...args)
 Main constructor that type-erases the object constructed from the given argument.
 
template<class T >
requires no_child_of_ours<T>
 TypeErased (T &&d)
 
template<class T , class... Args>
 TypeErased (te_in_place_t< T >, Args &&...args)
 Main constructor that type-erases the object constructed from the given argument.
 
 operator bool () const noexcept
 Check if this wrapper wraps an object.
 
bool owns_referenced_object () const noexcept
 Check if this wrapper owns the storage of the wrapped object, or whether it simply stores a reference to an object that was allocated elsewhere.
 
bool referenced_object_is_const () const noexcept
 Check if the wrapped object is const.
 
allocator_type get_allocator () const noexcept
 Get a copy of the allocator.
 
const std::type_info & type () const noexcept
 Query the contained type.
 
template<class T >
Tas () &
 Convert the type-erased object to the given type.
 
template<class T >
const Tas () const &
 Convert the type-erased object to the given type.
 
template<class T >
const T && as () &&
 Convert the type-erased object to the given type.
 
voidget_pointer () const
 Get a type-erased pointer to the wrapped object.
 
const voidget_const_pointer () const
 Get a type-erased pointer to the wrapped object.
 

Static Public Member Functions

template<class T , class... Args>
static TypeErasedProblem make (Args &&...args)
 
template<class Ret , class T , class Alloc , class... Args>
requires std::is_base_of_v<TypeErased, Ret>
static Ret make (std::allocator_arg_t tag, const Alloc &alloc, Args &&...args)
 Construct a type-erased wrapper of type Ret for an object of type T, initialized in-place with the given arguments.
 

Static Public Attributes

static constexpr size_t small_buffer_size = SmallBufferSize
 

Protected Member Functions

template<class Ret , class... FArgs, class... Args>
decltype(autocall (Ret(*f)(const void *, FArgs...), Args &&...args) const
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret , class... FArgs, class... Args>
decltype(autocall (Ret(*f)(void *, FArgs...), Args &&...args)
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret >
decltype(autocall (Ret(*f)(const void *)) const
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret >
decltype(autocall (Ret(*f)(void *))
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret >
decltype(autocall (Ret(*f)(const void *, const VTable &)) const
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret >
decltype(autocall (Ret(*f)(void *, const VTable &))
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class T , class... Args>
void construct_inplace (Args &&...args)
 Ensure storage and construct the type-erased object of type T in-place.
 
template<class Ret >
decltype(autocall (Ret(*f)(const void *, const VTable &)) const
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 
template<class Ret >
decltype(autocall (Ret(*f)(void *, const VTable &))
 Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.
 

Static Protected Member Functions

static bool size_indicates_ownership (size_t size)
 
static bool size_indicates_const (size_t size)
 

Protected Attributes

voidself
 Pointer to the stored object.
 
VTable vtable
 
size_t size = invalid_size
 Size required to store the object.
 

Static Protected Attributes

static constexpr size_t invalid_size
 
static constexpr size_t mut_ref_size
 
static constexpr size_t const_ref_size
 

Private Types

using allocator_traits = std::allocator_traits< allocator_type >
 
using buffer_type = std::array< std::byte, small_buffer_size >
 

Private Member Functions

Deallocator allocate (size_t size)
 Ensure that storage is available, either by using the small buffer if it is large enough, or by calling the allocator.
 
void deallocate ()
 Deallocate the memory without invoking the destructor.
 
void cleanup ()
 Destroy the type-erased object (if not empty), and deallocate the memory if necessary.
 
template<bool CopyAllocator>
void do_copy_assign (const TypeErased &other)
 

Private Attributes

buffer_type small_buffer
 
allocator_type allocator
 

Static Private Attributes

template<class T >
static constexpr auto no_child_of_ours
 True if T is not a child class of TypeErased.
 

Member Typedef Documentation

◆ Sparsity

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
using Sparsity = alpaqa::Sparsity<config_t>

Definition at line 219 of file type-erased-problem.hpp.

◆ Box

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
using Box = alpaqa::Box<config_t>

Definition at line 220 of file type-erased-problem.hpp.

◆ VTable

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
using VTable = ProblemVTable<config_t>

Definition at line 221 of file type-erased-problem.hpp.

◆ allocator_type

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
using allocator_type = Allocator

Definition at line 222 of file type-erased-problem.hpp.

◆ TypeErased

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
using TypeErased = util::TypeErased<VTable, allocator_type>

Definition at line 223 of file type-erased-problem.hpp.

◆ allocator_traits

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
using allocator_traits = std::allocator_traits<allocator_type>
privateinherited

Definition at line 199 of file type-erasure.hpp.

◆ buffer_type

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
using buffer_type = std::array<std::byte, small_buffer_size>
privateinherited

Definition at line 200 of file type-erasure.hpp.

Member Function Documentation

◆ make() [1/2]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class T , class... Args>
static TypeErasedProblem make ( Args &&...  args)
inlinestatic

Definition at line 233 of file type-erased-problem.hpp.

◆ get_n()

template<Config Conf, class Allocator >
auto get_n ( ) const

[Required] Number of decision variables.

Definition at line 697 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_m()

template<Config Conf, class Allocator >
auto get_m ( ) const

[Required] Number of constraints.

Definition at line 701 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_f()

template<Config Conf, class Allocator >
auto eval_f ( crvec  x) const

[Required] Function that evaluates the cost, \( f(x) \)

Parameters
[in]xDecision variable \( x \in \R^n \)

Definition at line 726 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_grad_f()

template<Config Conf, class Allocator >
void eval_grad_f ( crvec  x,
rvec  grad_fx 
) const

[Required] Function that evaluates the gradient of the cost, \( \nabla f(x) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[out]grad_fxGradient of cost function \( \nabla f(x) \in \R^n \)

Definition at line 730 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_g()

template<Config Conf, class Allocator >
void eval_g ( crvec  x,
rvec  gx 
) const

[Required] Function that evaluates the constraints, \( g(x) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[out]gxValue of the constraints \( g(x) \in \R^m \)

Definition at line 734 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_grad_g_prod()

template<Config Conf, class Allocator >
void eval_grad_g_prod ( crvec  x,
crvec  y,
rvec  grad_gxy 
) const

[Required] Function that evaluates the gradient of the constraints times a vector, \( \nabla g(x)\,y = \tp{\jac_g(x)}y \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]yVector \( y \in \R^m \) to multiply the gradient by
[out]grad_gxyGradient of the constraints \( \nabla g(x)\,y \in \R^n \)

Definition at line 738 of file type-erased-problem.hpp.

◆ eval_proj_diff_g()

template<Config Conf, class Allocator >
void eval_proj_diff_g ( crvec  z,
rvec  e 
) const

[Required] Function that evaluates the difference between the given point \( z \) and its projection onto the constraint set \( D \).

Parameters
[in]zSlack variable, \( z \in \R^m \)
[out]eThe difference relative to its projection, \( e = z - \Pi_D(z) \in \R^m \)
Note
z and e can refer to the same vector.

Definition at line 706 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_proj_multipliers()

template<Config Conf, class Allocator >
void eval_proj_multipliers ( rvec  y,
real_t  M 
) const

[Required] Function that projects the Lagrange multipliers for ALM.

Parameters
[in,out]yMultipliers, \( y \leftarrow \Pi_Y(y) \in \R^m \)
[in]MThe radius/size of the set \( Y \). See ALMParams::max_multiplier.

Definition at line 710 of file type-erased-problem.hpp.

◆ eval_prox_grad_step()

template<Config Conf, class Allocator >
auto eval_prox_grad_step ( real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
) const

[Required] Function that computes a proximal gradient step.

Parameters
[in]γStep size, \( \gamma \in \R_{>0} \)
[in]xDecision variable \( x \in \R^n \)
[in]grad_ψGradient of the subproblem cost, \( \nabla\psi(x) \in \R^n \)
[out]Next proximal gradient iterate, \( \hat x = T_\gamma(x) = \prox_{\gamma h}(x - \gamma\nabla\psi(x)) \in \R^n \)
[out]pThe proximal gradient step, \( p = \hat x - x \in \R^n \)
Returns
The nonsmooth function evaluated at x̂, \( h(\hat x) \).
Note
The vector \( p \) is often used in stopping criteria, so its numerical accuracy is more important than that of \( \hat x \).

Definition at line 714 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_inactive_indices_res_lna()

template<Config Conf, class Allocator >
auto eval_inactive_indices_res_lna ( real_t  γ,
crvec  x,
crvec  grad_ψ,
rindexvec  J 
) const

[Optional] Function that computes the inactive indices \( \mathcal J(x) \) for the evaluation of the linear Newton approximation of the residual, as in [4].

Parameters
[in]γStep size, \( \gamma \in \R_{>0} \)
[in]xDecision variable \( x \in \R^n \)
[in]grad_ψGradient of the subproblem cost, \( \nabla\psi(x) \in \R^n \)
[out]JThe indices of the components of \( x \) that are in the index set \( \mathcal J(x) \). In ascending order, at most n.
Returns
The number of inactive constraints, \( \# \mathcal J(x) \).

For example, in the case of box constraints, we have

\[ \mathcal J(x) \defeq \defset{i \in \N_{[0, n-1]}}{\underline x_i \lt x_i - \gamma\nabla_{\!x_i}\psi(x) \lt \overline x_i}. \]

Definition at line 719 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_box_C()

template<Config Conf, class Allocator >
auto get_box_C ( ) const

[Optional] Get the rectangular constraint set of the decision variables, \( x \in C \).

Definition at line 818 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_box_D()

template<Config Conf, class Allocator >
auto get_box_D ( ) const

[Optional] Get the rectangular constraint set of the general constraint function, \( g(x) \in D \).

Definition at line 822 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_jac_g()

template<Config Conf, class Allocator >
void eval_jac_g ( crvec  x,
rvec  J_values 
) const

[Optional] Function that evaluates the nonzero values of the Jacobian matrix of the constraints, \( \jac_g(x) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[out]J_valuesNonzero values of the Jacobian \( \jac_g(x) \in \R^{m\times n} \)

Required for second-order solvers only.

Definition at line 746 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_jac_g_sparsity()

template<Config Conf, class Allocator >
auto get_jac_g_sparsity ( ) const

[Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the constraints.

Required for second-order solvers only.

Definition at line 750 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_grad_gi()

template<Config Conf, class Allocator >
void eval_grad_gi ( crvec  x,
index_t  i,
rvec  grad_gi 
) const

[Optional] Function that evaluates the gradient of one specific constraint, \( \nabla g_i(x) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]iWhich constraint \( 0 \le i \lt m \)
[out]grad_giGradient of the constraint \( \nabla g_i(x) \in \R^n \)

Required for second-order solvers only.

Definition at line 742 of file type-erased-problem.hpp.

◆ eval_hess_L_prod()

template<Config Conf, class Allocator >
void eval_hess_L_prod ( crvec  x,
crvec  y,
real_t  scale,
crvec  v,
rvec  Hv 
) const

[Optional] Function that evaluates the Hessian of the Lagrangian multiplied by a vector, \( \nabla_{xx}^2L(x, y)\,v \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]yLagrange multipliers \( y \in \R^m \)
[in]scaleScale factor for the cost function.
[in]vVector to multiply by \( v \in \R^n \)
[out]HvHessian-vector product \( \nabla_{xx}^2 L(x, y)\,v \in \R^{n} \)

Required for second-order solvers only.

Definition at line 754 of file type-erased-problem.hpp.

◆ eval_hess_L()

template<Config Conf, class Allocator >
void eval_hess_L ( crvec  x,
crvec  y,
real_t  scale,
rvec  H_values 
) const

[Optional] Function that evaluates the nonzero values of the Hessian of the Lagrangian, \( \nabla_{xx}^2L(x, y) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]yLagrange multipliers \( y \in \R^m \)
[in]scaleScale factor for the cost function.
[out]H_valuesNonzero values of the Hessian \( \nabla_{xx}^2 L(x, y) \in \R^{n\times n} \).

Required for second-order solvers only.

Definition at line 759 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_hess_L_sparsity()

template<Config Conf, class Allocator >
auto get_hess_L_sparsity ( ) const

[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.

Required for second-order solvers only.

Definition at line 764 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_hess_ψ_prod()

template<Config Conf, class Allocator >
void eval_hess_ψ_prod ( crvec  x,
crvec  y,
crvec  Σ,
real_t  scale,
crvec  v,
rvec  Hv 
) const

[Optional] Function that evaluates the Hessian of the augmented Lagrangian multiplied by a vector, \( \nabla_{xx}^2L_\Sigma(x, y)\,v \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]yLagrange multipliers \( y \in \R^m \)
[in]ΣPenalty weights \( \Sigma \)
[in]scaleScale factor for the cost function.
[in]vVector to multiply by \( v \in \R^n \)
[out]HvHessian-vector product \( \nabla_{xx}^2 L_\Sigma(x, y)\,v \in \R^{n} \)

Required for second-order solvers only.

Definition at line 768 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_hess_ψ()

template<Config Conf, class Allocator >
void eval_hess_ψ ( crvec  x,
crvec  y,
crvec  Σ,
real_t  scale,
rvec  H_values 
) const

[Optional] Function that evaluates the nonzero values of the Hessian of the augmented Lagrangian, \( \nabla_{xx}^2L_\Sigma(x, y) \)

Parameters
[in]xDecision variable \( x \in \R^n \)
[in]yLagrange multipliers \( y \in \R^m \)
[in]ΣPenalty weights \( \Sigma \)
[in]scaleScale factor for the cost function.
[out]H_valuesNonzero values of the Hessian \( \nabla_{xx}^2 L_\Sigma(x, y) \in \R^{n\times n} \)

Required for second-order solvers only.

Definition at line 773 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ get_hess_ψ_sparsity()

template<Config Conf, class Allocator >
auto get_hess_ψ_sparsity ( ) const

[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lagrangian.

Required for second-order solvers only.

Definition at line 778 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_f_grad_f()

template<Config Conf, class Allocator >
auto eval_f_grad_f ( crvec  x,
rvec  grad_fx 
) const

[Optional] Evaluate both \( f(x) \) and its gradient, \( \nabla f(x) \).

Default implementation:
ProblemVTable::default_eval_f_grad_f

Definition at line 782 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_f_g()

template<Config Conf, class Allocator >
auto eval_f_g ( crvec  x,
rvec  g 
) const

[Optional] Evaluate both \( f(x) \) and \( g(x) \).

Default implementation:
ProblemVTable::default_eval_f_g

Definition at line 786 of file type-erased-problem.hpp.

◆ eval_grad_f_grad_g_prod()

template<Config Conf, class Allocator >
void eval_grad_f_grad_g_prod ( crvec  x,
crvec  y,
rvec  grad_f,
rvec  grad_gxy 
) const

[Optional] Evaluate both \( \nabla f(x) \) and \( \nabla g(x)\,y \).

Default implementation:
ProblemVTable::default_eval_grad_f_grad_g_prod

Definition at line 790 of file type-erased-problem.hpp.

◆ eval_grad_L()

template<Config Conf, class Allocator >
void eval_grad_L ( crvec  x,
crvec  y,
rvec  grad_L,
rvec  work_n 
) const

[Optional] Evaluate the gradient of the Lagrangian \( \nabla_x L(x, y) = \nabla f(x) + \nabla g(x)\,y \)

Default implementation:
ProblemVTable::default_eval_grad_L

Definition at line 795 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_ψ()

template<Config Conf, class Allocator >
auto eval_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  ŷ 
) const

[Optional] Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.

\[ \psi(x) = f(x) + \tfrac{1}{2} \text{dist}_\Sigma^2\left(g(x) + \Sigma^{-1}y,\;D\right) \]

\[ \hat y = \Sigma\, \left(g(x) + \Sigma^{-1}y - \Pi_D\left(g(x) + \Sigma^{-1}y\right)\right) \]

Default implementation:
ProblemVTable::default_eval_ψ
Parameters
[in]xDecision variable \( x \)
[in]yLagrange multipliers \( y \)
[in]ΣPenalty weights \( \Sigma \)
[out]ŷ\( \hat y \)

Definition at line 800 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_grad_ψ()

template<Config Conf, class Allocator >
void eval_grad_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  grad_ψ,
rvec  work_n,
rvec  work_m 
) const

[Optional] Calculate the gradient ∇ψ(x).

\[ \nabla \psi(x) = \nabla f(x) + \nabla g(x)\,\hat y(x) \]

Default implementation:
ProblemVTable::default_eval_grad_ψ
Parameters
[in]xDecision variable \( x \)
[in]yLagrange multipliers \( y \)
[in]ΣPenalty weights \( \Sigma \)
[out]grad_ψ\( \nabla \psi(x) \)
work_nDimension \( n \)
work_mDimension \( m \)

Definition at line 804 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_ψ_grad_ψ()

template<Config Conf, class Allocator >
auto eval_ψ_grad_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  grad_ψ,
rvec  work_n,
rvec  work_m 
) const

[Optional] Calculate both ψ(x) and its gradient ∇ψ(x).

\[ \psi(x) = f(x) + \tfrac{1}{2} \text{dist}_\Sigma^2\left(g(x) + \Sigma^{-1}y,\;D\right) \]

\[ \nabla \psi(x) = \nabla f(x) + \nabla g(x)\,\hat y(x) \]

Default implementation:
ProblemVTable::default_eval_ψ_grad_ψ
Parameters
[in]xDecision variable \( x \)
[in]yLagrange multipliers \( y \)
[in]ΣPenalty weights \( \Sigma \)
[out]grad_ψ\( \nabla \psi(x) \)
work_nDimension \( n \)
work_mDimension \( m \)

Definition at line 809 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ check()

template<Config Conf, class Allocator >
void check ( ) const

[Optional] Check that the problem formulation is well-defined, the dimensions match, etc.

Throws an exception if this is not the case.

Definition at line 826 of file type-erased-problem.hpp.

◆ provides_eval_inactive_indices_res_lna()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_inactive_indices_res_lna ( ) const
inline

Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.

Definition at line 561 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_jac_g()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_jac_g ( ) const
inline

Returns true if the problem provides an implementation of eval_jac_g.

Definition at line 566 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_get_jac_g_sparsity()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_get_jac_g_sparsity ( ) const
inline

Returns true if the problem provides an implementation of get_jac_g_sparsity.

Definition at line 571 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_grad_gi()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_grad_gi ( ) const
inline

Returns true if the problem provides an implementation of eval_grad_gi.

Definition at line 576 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_hess_L_prod()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_hess_L_prod ( ) const
inline

Returns true if the problem provides an implementation of eval_hess_L_prod.

Definition at line 581 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_hess_L()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_hess_L ( ) const
inline

Returns true if the problem provides an implementation of eval_hess_L.

Definition at line 586 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_get_hess_L_sparsity()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_get_hess_L_sparsity ( ) const
inline

Returns true if the problem provides an implementation of get_hess_L_sparsity.

Definition at line 591 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_hess_ψ_prod()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_hess_ψ_prod ( ) const
inline

Returns true if the problem provides an implementation of eval_hess_ψ_prod.

Definition at line 596 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_hess_ψ()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_hess_ψ ( ) const
inline

Returns true if the problem provides an implementation of eval_hess_ψ.

Definition at line 601 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_get_hess_ψ_sparsity()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_get_hess_ψ_sparsity ( ) const
inline

Returns true if the problem provides an implementation of get_hess_ψ_sparsity.

Definition at line 606 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_f_grad_f()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_f_grad_f ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_f_grad_f, false if it uses the default implementation.

Definition at line 611 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_f_g()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_f_g ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_f_g, false if it uses the default implementation.

Definition at line 616 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_grad_f_grad_g_prod()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_grad_f_grad_g_prod ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_grad_f_grad_g_prod, false if it uses the default implementation.

Definition at line 621 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_grad_L()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_grad_L ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_grad_L, false if it uses the default implementation.

Definition at line 626 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_ψ()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_ψ ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_ψ, false if it uses the default implementation.

Definition at line 631 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_grad_ψ()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_grad_ψ ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_grad_ψ, false if it uses the default implementation.

Definition at line 634 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_eval_ψ_grad_ψ()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_eval_ψ_grad_ψ ( ) const
inline

Returns true if the problem provides a specialized implementation of eval_ψ_grad_ψ, false if it uses the default implementation.

Definition at line 639 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_get_box_C()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_get_box_C ( ) const
inline

Returns true if the problem provides an implementation of get_box_C.

Definition at line 644 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_get_box_D()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_get_box_D ( ) const
inline

Returns true if the problem provides an implementation of get_box_D.

Definition at line 649 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ provides_check()

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
bool provides_check ( ) const
inline

Returns true if the problem provides an implementation of check.

Definition at line 653 of file type-erased-problem.hpp.

+ Here is the caller graph for this function:

◆ calc_ŷ_dᵀŷ()

template<Config Conf, class Allocator >
auto calc_ŷ_dᵀŷ ( rvec  g_ŷ,
crvec  y,
crvec  Σ 
) const

Given g(x), compute the intermediate results ŷ and dᵀŷ that can later be used to compute ψ(x) and ∇ψ(x).

Computes the result using the following algorithm:

\[ \begin{aligned} \zeta &= g(x) + \Sigma^{-1} y \\[] d &= \zeta - \Pi_D(\zeta) = \operatorname{eval\_proj\_diff\_g}(\zeta, \zeta) \\[] \hat y &= \Sigma d \\[] \end{aligned} \]

See also
page_math
Parameters
[in,out]g_ŷInput \( g(x) \), outputs \( \hat y \)
[in]yLagrange multipliers \( y \)
[in]ΣPenalty weights \( \Sigma \)
Returns
The inner product \( d^\top \hat y \)

Definition at line 814 of file type-erased-problem.hpp.

◆ TypeErased() [1/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
TypeErased ( )
defaultnoexcept

Default constructor.

◆ TypeErased() [2/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Alloc >
TypeErased ( std::allocator_arg_t  ,
const Alloc alloc 
)
inline

Default constructor (allocator aware).

Definition at line 235 of file type-erasure.hpp.

◆ TypeErased() [3/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
TypeErased ( const TypeErased other)
inline

Copy constructor.

Definition at line 237 of file type-erasure.hpp.

◆ TypeErased() [4/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
TypeErased ( const TypeErased other,
allocator_type  alloc 
)
inline

Copy constructor (allocator aware).

Definition at line 243 of file type-erasure.hpp.

◆ TypeErased() [5/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
TypeErased ( TypeErased &&  other)
inlinenoexcept

Move constructor.

Definition at line 259 of file type-erasure.hpp.

◆ TypeErased() [6/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
TypeErased ( TypeErased &&  other,
const allocator_type alloc 
)
inlinenoexcept

Move constructor (allocator aware).

Definition at line 278 of file type-erasure.hpp.

◆ TypeErased() [7/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class T , class Alloc >
TypeErased ( std::allocator_arg_t  ,
const Alloc alloc,
T &&  d 
)
inlineexplicit

Main constructor that type-erases the given argument.

Definition at line 373 of file type-erasure.hpp.

◆ TypeErased() [8/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class T , class Alloc , class... Args>
TypeErased ( std::allocator_arg_t  ,
const Alloc alloc,
te_in_place_t< T ,
Args &&...  args 
)
inlineexplicit

Main constructor that type-erases the object constructed from the given argument.

Definition at line 380 of file type-erasure.hpp.

◆ TypeErased() [9/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class T >
requires no_child_of_ours<T>
TypeErased ( T &&  d)
inlineexplicit

Requirement prevents this constructor from taking precedence over the copy and move constructors.

Definition at line 390 of file type-erasure.hpp.

◆ TypeErased() [10/10]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class T , class... Args>
TypeErased ( te_in_place_t< T ,
Args &&...  args 
)
inlineexplicit

Main constructor that type-erases the object constructed from the given argument.

Definition at line 396 of file type-erasure.hpp.

◆ call() [1/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret , class... FArgs, class... Args>
decltype(auto) call ( Ret(*)(const void *, FArgs...)  f,
Args &&...  args 
) const
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 586 of file type-erasure.hpp.

◆ call() [2/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret , class... FArgs, class... Args>
decltype(auto) call ( Ret(*)(void *, FArgs...)  f,
Args &&...  args 
)
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 598 of file type-erasure.hpp.

◆ call() [3/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret >
decltype(auto) call ( Ret(*)(const void *)  f) const
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 612 of file type-erasure.hpp.

◆ call() [4/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret >
decltype(auto) call ( Ret(*)(void *)  f)
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 619 of file type-erasure.hpp.

◆ call() [5/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret >
decltype(auto) call ( Ret(*)(const void *, const VTable &)  f) const
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 628 of file type-erasure.hpp.

◆ call() [6/8]

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
template<class Ret >
decltype(auto) call ( Ret(*)(void *, const VTable &)  f)
inlineprotected

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 636 of file type-erasure.hpp.

◆ size_indicates_ownership()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
static bool size_indicates_ownership ( size_t  size)
inlinestaticprotectedinherited

Definition at line 217 of file type-erasure.hpp.

+ Here is the caller graph for this function:

◆ size_indicates_const()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
static bool size_indicates_const ( size_t  size)
inlinestaticprotectedinherited

Definition at line 220 of file type-erasure.hpp.

+ Here is the caller graph for this function:

◆ make() [2/2]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class Ret , class T , class Alloc , class... Args>
requires std::is_base_of_v<TypeErased, Ret>
static Ret make ( std::allocator_arg_t  tag,
const Alloc alloc,
Args &&...  args 
)
inlinestaticinherited

Construct a type-erased wrapper of type Ret for an object of type T, initialized in-place with the given arguments.

Definition at line 404 of file type-erasure.hpp.

◆ operator bool()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
operator bool ( ) const
inlineexplicitnoexceptinherited

Check if this wrapper wraps an object.

False for default-constructed objects.

Definition at line 421 of file type-erasure.hpp.

◆ owns_referenced_object()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
bool owns_referenced_object ( ) const
inlinenoexceptinherited

Check if this wrapper owns the storage of the wrapped object, or whether it simply stores a reference to an object that was allocated elsewhere.

Definition at line 426 of file type-erasure.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ referenced_object_is_const()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
bool referenced_object_is_const ( ) const
inlinenoexceptinherited

Check if the wrapped object is const.

Definition at line 431 of file type-erasure.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_allocator()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
allocator_type get_allocator ( ) const
inlinenoexceptinherited

Get a copy of the allocator.

Definition at line 436 of file type-erasure.hpp.

◆ type()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
const std::type_info & type ( ) const
inlinenoexceptinherited

Query the contained type.

Definition at line 439 of file type-erasure.hpp.

+ Here is the caller graph for this function:

◆ as() [1/3]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class T >
T & as ( ) &
inlineinherited

Convert the type-erased object to the given type.

The type is checked in debug builds only, use with caution.

Definition at line 446 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ as() [2/3]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class T >
const T & as ( ) const &
inlineinherited

Convert the type-erased object to the given type.

The type is checked in debug builds only, use with caution.

Definition at line 453 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ as() [3/3]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class T >
const T && as ( ) &&
inlineinherited

Convert the type-erased object to the given type.

The type is checked in debug builds only, use with caution.

Definition at line 460 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ get_pointer()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
void * get_pointer ( ) const
inlineinherited

Get a type-erased pointer to the wrapped object.

Exceptions
alpaqa::util::bad_type_erased_constnessIf the wrapped object is const.
See also
get_const_pointer()

Definition at line 470 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ get_const_pointer()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
const void * get_const_pointer ( ) const
inlineinherited

Get a type-erased pointer to the wrapped object.

Definition at line 476 of file type-erasure.hpp.

◆ allocate()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
Deallocator allocate ( size_t  size)
inlineprivateinherited

Ensure that storage is available, either by using the small buffer if it is large enough, or by calling the allocator.

Returns a RAII wrapper that deallocates the storage unless released.

Definition at line 502 of file type-erasure.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deallocate()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
void deallocate ( )
inlineprivateinherited

Deallocate the memory without invoking the destructor.

Definition at line 514 of file type-erasure.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanup()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
void cleanup ( )
inlineprivateinherited

Destroy the type-erased object (if not empty), and deallocate the memory if necessary.

Definition at line 526 of file type-erasure.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_copy_assign()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<bool CopyAllocator>
void do_copy_assign ( const TypeErased< VTable, Allocator, SmallBufferSize > &  other)
inlineprivateinherited

Definition at line 536 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ construct_inplace()

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class T , class... Args>
void construct_inplace ( Args &&...  args)
inlineprotectedinherited

Ensure storage and construct the type-erased object of type T in-place.

Definition at line 562 of file type-erasure.hpp.

+ Here is the call graph for this function:

◆ call() [7/8]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class Ret >
decltype(auto) call ( Ret(*)(const void *, const VTable &)  f) const
inlineprotectedinherited

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 628 of file type-erasure.hpp.

◆ call() [8/8]

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class Ret >
decltype(auto) call ( Ret(*)(void *, const VTable &)  f)
inlineprotectedinherited

Call the vtable function f with the given arguments args, implicitly passing the self pointer and vtable reference if necessary.

Definition at line 636 of file type-erasure.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ self

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
void* self
protected

Pointer to the stored object.

Definition at line 225 of file type-erasure.hpp.

◆ vtable

template<Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
VTable vtable
protected

Definition at line 228 of file type-erasure.hpp.

◆ small_buffer_size

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
constexpr size_t small_buffer_size = SmallBufferSize
staticconstexprinherited

Definition at line 195 of file type-erasure.hpp.

◆ small_buffer

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
buffer_type small_buffer
privateinherited

Definition at line 201 of file type-erasure.hpp.

◆ allocator

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
allocator_type allocator
privateinherited

Definition at line 202 of file type-erasure.hpp.

◆ no_child_of_ours

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
template<class T >
constexpr auto no_child_of_ours
staticconstexprprivateinherited
Initial value:
=
!std::is_base_of_v<TypeErased, std::remove_cvref_t<T>>

True if T is not a child class of TypeErased.

Definition at line 207 of file type-erasure.hpp.

◆ invalid_size

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
constexpr size_t invalid_size
staticconstexprprotectedinherited
Initial value:
=
static_cast<size_t>(0xDEAD'BEEF'DEAD'BEEF)

Definition at line 211 of file type-erasure.hpp.

◆ mut_ref_size

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
constexpr size_t mut_ref_size
staticconstexprprotectedinherited
Initial value:
=
static_cast<size_t>(0xFFFF'FFFF'FFFF'FFFF)

Definition at line 213 of file type-erasure.hpp.

◆ const_ref_size

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
constexpr size_t const_ref_size
staticconstexprprotectedinherited
Initial value:
=
static_cast<size_t>(0xFFFF'FFFF'FFFF'FFFE)

Definition at line 215 of file type-erasure.hpp.

◆ size

template<class VTable = BasicVTable, class Allocator = std::allocator<std::byte>, size_t SmallBufferSize = default_te_buffer_size<VTable, Allocator>()>
size_t size = invalid_size
protectedinherited

Size required to store the object.

Definition at line 227 of file type-erasure.hpp.


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