SOPT
Sparse OPTimisation
Public Types | Public Member Functions | List of all members
sopt::details::WrapFunction< VECTOR > Class Template Reference

Wraps an std::function to return an expression. More...

#include <wrapper.h>

+ Inheritance diagram for sopt::details::WrapFunction< VECTOR >:

Public Types

using t_Function = OperatorFunction< VECTOR >
 Type of function wrapped here. More...
 

Public Member Functions

 WrapFunction (t_Function const &func, std::array< t_int, 3 > sizes={{1, 1, 0}})
 
 WrapFunction (WrapFunction const &c)
 
 WrapFunction (WrapFunction const &&c)
 
void operator= (WrapFunction const &c)
 
void operator= (WrapFunction &&c)
 
template<typename T0 >
AppliedFunction< t_Function const &, Eigen::ArrayBase< T0 > > operator() (Eigen::ArrayBase< T0 > const &x) const
 Function application form. More...
 
template<typename T0 >
AppliedFunction< t_Function const &, Eigen::ArrayBase< T0 > > operator* (Eigen::ArrayBase< T0 > const &x) const
 Multiplication application form. More...
 
template<typename T0 >
AppliedFunction< t_Function const &, Eigen::MatrixBase< T0 > > operator() (Eigen::MatrixBase< T0 > const &x) const
 Function application form. More...
 
template<typename T0 >
AppliedFunction< t_Function const &, Eigen::MatrixBase< T0 > > operator* (Eigen::MatrixBase< T0 > const &x) const
 Multiplication application form. More...
 
std::array< t_int, 3 > const & sizes () const
 Defines relation-ship between input and output sizes. More...
 
template<typename T >
std::enable_if< std::is_integral< T >::value, T >::type rows (T xsize) const
 Output vector size for a input with xsize elements. More...
 

Detailed Description

template<typename VECTOR>
class sopt::details::WrapFunction< VECTOR >

Wraps an std::function to return an expression.

This makes writing the application of a function more beautiful on the eye. A function call func(output, input) can be made to look like output = func(input) or output = func * input.

Definition at line 46 of file wrapper.h.

Member Typedef Documentation

◆ t_Function

template<typename VECTOR >
using sopt::details::WrapFunction< VECTOR >::t_Function = OperatorFunction<VECTOR>

Type of function wrapped here.

Definition at line 49 of file wrapper.h.

Constructor & Destructor Documentation

◆ WrapFunction() [1/3]

template<typename VECTOR >
sopt::details::WrapFunction< VECTOR >::WrapFunction ( t_Function const &  func,
std::array< t_int, 3 >  sizes = {{1, 1, 0}} 
)
inline

Initializes the wrapper

Parameters
[in]funcfunction to wrap
[in]sizesthree integer vector (a, b, c) if N is the size of the input, then (N * a) / b + c is the output b cannot be zero.

Definition at line 56 of file wrapper.h.

56  {{1, 1, 0}})
57  : func(func), sizes_(sizes) {
58  // cannot devide by zero
59  assert(sizes_[1] != 0);
60  }
std::array< t_int, 3 > const & sizes() const
Defines relation-ship between input and output sizes.
Definition: wrapper.h:106

◆ WrapFunction() [2/3]

template<typename VECTOR >
sopt::details::WrapFunction< VECTOR >::WrapFunction ( WrapFunction< VECTOR > const &  c)
inline

Definition at line 61 of file wrapper.h.

61 : func(c.func), sizes_(c.sizes_) {}

◆ WrapFunction() [3/3]

template<typename VECTOR >
sopt::details::WrapFunction< VECTOR >::WrapFunction ( WrapFunction< VECTOR > const &&  c)
inline

Definition at line 62 of file wrapper.h.

62 : func(std::move(c.func)), sizes_(std::move(c.sizes_)) {}

Member Function Documentation

◆ operator()() [1/2]

template<typename VECTOR >
template<typename T0 >
AppliedFunction<t_Function const &, Eigen::ArrayBase<T0> > sopt::details::WrapFunction< VECTOR >::operator() ( Eigen::ArrayBase< T0 > const &  x) const
inline

Function application form.

Definition at line 74 of file wrapper.h.

75  {
76  return AppliedFunction<t_Function const &, Eigen::ArrayBase<T0>>(func, x, rows(x));
77  }
std::enable_if< std::is_integral< T >::value, T >::type rows(T xsize) const
Output vector size for a input with xsize elements.
Definition: wrapper.h:110

References sopt::details::WrapFunction< VECTOR >::rows().

◆ operator()() [2/2]

template<typename VECTOR >
template<typename T0 >
AppliedFunction<t_Function const &, Eigen::MatrixBase<T0> > sopt::details::WrapFunction< VECTOR >::operator() ( Eigen::MatrixBase< T0 > const &  x) const
inline

Function application form.

Definition at line 88 of file wrapper.h.

89  {
90  return AppliedFunction<t_Function const &, Eigen::MatrixBase<T0>>(func, x, rows(x));
91  }

References sopt::details::WrapFunction< VECTOR >::rows().

◆ operator*() [1/2]

template<typename VECTOR >
template<typename T0 >
AppliedFunction<t_Function const &, Eigen::ArrayBase<T0> > sopt::details::WrapFunction< VECTOR >::operator* ( Eigen::ArrayBase< T0 > const &  x) const
inline

Multiplication application form.

Definition at line 81 of file wrapper.h.

82  {
83  return AppliedFunction<t_Function const &, Eigen::ArrayBase<T0>>(func, x, rows(x));
84  }

References sopt::details::WrapFunction< VECTOR >::rows().

◆ operator*() [2/2]

template<typename VECTOR >
template<typename T0 >
AppliedFunction<t_Function const &, Eigen::MatrixBase<T0> > sopt::details::WrapFunction< VECTOR >::operator* ( Eigen::MatrixBase< T0 > const &  x) const
inline

Multiplication application form.

Definition at line 95 of file wrapper.h.

96  {
97  return AppliedFunction<t_Function const &, Eigen::MatrixBase<T0>>(func, x, rows(x));
98  }

References sopt::details::WrapFunction< VECTOR >::rows().

◆ operator=() [1/2]

template<typename VECTOR >
void sopt::details::WrapFunction< VECTOR >::operator= ( WrapFunction< VECTOR > &&  c)
inline

Definition at line 67 of file wrapper.h.

67  {
68  func = std::move(c.func);
69  sizes_ = std::move(c.sizes_);
70  }

◆ operator=() [2/2]

template<typename VECTOR >
void sopt::details::WrapFunction< VECTOR >::operator= ( WrapFunction< VECTOR > const &  c)
inline

Definition at line 63 of file wrapper.h.

63  {
64  func = c.func;
65  sizes_ = c.sizes_;
66  }

Referenced by sopt::LinearTransform< VECTOR >::operator=().

◆ rows()

template<typename VECTOR >
template<typename T >
std::enable_if<std::is_integral<T>::value, T>::type sopt::details::WrapFunction< VECTOR >::rows ( xsize) const
inline

Output vector size for a input with xsize elements.

Definition at line 110 of file wrapper.h.

110  {
111  auto const result = (static_cast<t_int>(xsize) * sizes_[0]) / sizes_[1] + sizes_[2];
112  assert(result >= 0);
113  return static_cast<T>(result);
114  }
int t_int
Root of the type hierarchy for signed integers.
Definition: types.h:13

Referenced by sopt::details::WrapFunction< VECTOR >::operator()(), and sopt::details::WrapFunction< VECTOR >::operator*().

◆ sizes()

template<typename VECTOR >
std::array<t_int, 3> const& sopt::details::WrapFunction< VECTOR >::sizes ( ) const
inline

Defines relation-ship between input and output sizes.

An integer tuple (a, b, c) where, if N is the size of the input, then \((N * a) / b + c\) is the output. \(b\) cannot be zero. In the simplest case where this objects wraps a square matrix, then the sizes are (1, 1, 0). If this objects wraps a rectangular matrix which halves the number of elements, then the sizes would be (1, 2, 0).

Definition at line 106 of file wrapper.h.

106 { return sizes_; }

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