8 #include "sopt/config.h"
15 template <
typename FUNCTION,
typename DERIVED>
16 class AppliedFunction :
public Eigen::ReturnByValue<AppliedFunction<FUNCTION, DERIVED>> {
19 using Index =
typename DERIVED::Index;
22 : func(func), x(x), rows_(
rows) {}
27 template <
typename DESTINATION>
28 void evalTo(DESTINATION &destination)
const {
45 template <
typename VECTOR>
57 : func(func), sizes_(
sizes) {
59 assert(sizes_[1] != 0);
68 func = std::move(c.func);
69 sizes_ = std::move(c.sizes_);
73 template <
typename T0>
75 Eigen::ArrayBase<T0>
const &x)
const {
80 template <
typename T0>
82 Eigen::ArrayBase<T0>
const &x)
const {
87 template <
typename T0>
89 Eigen::MatrixBase<T0>
const &x)
const {
94 template <
typename T0>
96 Eigen::MatrixBase<T0>
const &x)
const {
106 std::array<t_int, 3>
const &
sizes()
const {
return sizes_; }
109 template <
typename T>
110 typename std::enable_if<std::is_integral<T>::value, T>::type
rows(T xsize)
const {
111 auto const result = (
static_cast<t_int>(xsize) * sizes_[0]) / sizes_[1] + sizes_[2];
113 return static_cast<T
>(result);
117 template <
typename T>
118 t_uint rows(Eigen::DenseBase<T>
const &x)
const {
119 return rows(x.size());
126 std::array<t_int, 3> sizes_;
130 template <
typename VECTOR>
132 std::array<t_int, 3> sizes = {{1, 1, 0}}) {
133 return WrapFunction<VECTOR>(func, sizes);
138 template <
typename FUNCTION,
typename VECTOR>
139 struct traits<
sopt::details::AppliedFunction<FUNCTION, VECTOR>> {
Expression referencing the result of a function call.
typename DERIVED::PlainObject PlainObject
void evalTo(DESTINATION &destination) const
AppliedFunction(AppliedFunction const &c)
AppliedFunction(FUNCTION const &func, DERIVED const &x, Index rows)
AppliedFunction(FUNCTION const &func, DERIVED const &x)
typename DERIVED::Index Index
AppliedFunction(AppliedFunction &&c)
Wraps an std::function to return an expression.
std::enable_if< std::is_integral< T >::value, T >::type rows(T xsize) const
Output vector size for a input with xsize elements.
OperatorFunction< VECTOR > t_Function
Type of function wrapped here.
void operator=(WrapFunction const &c)
AppliedFunction< t_Function const &, Eigen::MatrixBase< T0 > > operator()(Eigen::MatrixBase< T0 > const &x) const
Function application form.
WrapFunction(t_Function const &func, std::array< t_int, 3 > sizes={{1, 1, 0}})
std::array< t_int, 3 > const & sizes() const
Defines relation-ship between input and output sizes.
WrapFunction(WrapFunction const &&c)
AppliedFunction< t_Function const &, Eigen::ArrayBase< T0 > > operator*(Eigen::ArrayBase< T0 > const &x) const
Multiplication application form.
void operator=(WrapFunction &&c)
AppliedFunction< t_Function const &, Eigen::MatrixBase< T0 > > operator*(Eigen::MatrixBase< T0 > const &x) const
Multiplication application form.
WrapFunction(WrapFunction const &c)
AppliedFunction< t_Function const &, Eigen::ArrayBase< T0 > > operator()(Eigen::ArrayBase< T0 > const &x) const
Function application form.
WrapFunction< VECTOR > wrap(OperatorFunction< VECTOR > const &func, std::array< t_int, 3 > sizes={{1, 1, 0}})
Helper function to wrap functor into expression-able object.
int t_int
Root of the type hierarchy for signed integers.
size_t t_uint
Root of the type hierarchy for unsigned integers.
std::function< void(VECTOR &, VECTOR const &)> OperatorFunction
Typical function out = A*x.
typename VECTOR::PlainObject ReturnType