vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
Public Types | Public Member Functions | Public Attributes | List of all members
vspline::grok_type< IN, OUT, _vsize > Struct Template Reference

class grok_type is a helper class wrapping a vspline::unary_functor so that it's type becomes opaque - a technique called 'type erasure', here applied to vspline::unary_functors with their specific capability of providing both vectorized and unvectorized operation in one common object. More...

#include <unary_functor.h>

Inheritance diagram for vspline::grok_type< IN, OUT, _vsize >:
vspline::unary_functor< IN, IN, vspline::vector_traits< IN > ::size > vspline::callable< grok_type< IN, IN, vspline::vector_traits< IN > ::size >, IN, IN, vspline::vector_traits< IN > ::size > vspline::unary_functor_tag< _vsize >

Public Types

typedef vspline::unary_functor< IN, OUT, _vsize > base_type
 
typedef std::function< void(const in_type &, out_type &) > eval_type
 
typedef std::function< out_type(const in_type &) > call_type
 
typedef std::function< void(const in_v &, out_v &) > v_eval_type
 
typedef std::function< out_v(const in_v &) > v_call_type
 
typedef IN in_type
 
typedef OUT out_type
 
typedef vector_traits< IN, vsize >::type in_v
 vectorized in_type and out_type. vspline::vector_traits supplies these types so that multidimensional/multichannel data come as vigra::TinyVectors, while 'singular' data won't be made into TinyVectors of one element. More...
 
typedef vector_traits< OUT, vsize >::type out_v
 
- Public Types inherited from vspline::unary_functor< IN, IN, vspline::vector_traits< IN > ::size >
enum  
 
enum  
 
enum  
 
typedef IN in_type
 
typedef IN out_type
 
typedef vspline::vector_traits< IN >::ele_type in_ele_type
 
typedef vspline::vector_traits< IN >::ele_type out_ele_type
 
typedef vigra::TinyVector< in_ele_type, dim_inin_nd_ele_type
 
typedef vigra::TinyVector< out_ele_type, dim_outout_nd_ele_type
 
typedef vector_traits< IN, vsize >::ele_v in_ele_v
 a simdized type of the elementary type of result_type, which is used for coefficients and results. this is fixed via the traits class vector_traits (in vector.h). Note how we derive this type using vsize from the template argument, not what vspline::vector_traits deems appropriate for ele_type - though both numbers will be the same in most cases. More...
 
typedef vector_traits< IN, vsize >::ele_v out_ele_v
 
typedef vector_traits< IN, vsize >::nd_ele_v in_nd_ele_v
 
typedef vector_traits< IN, vsize >::nd_ele_v out_nd_ele_v
 
typedef vector_traits< IN, vsize >::type in_v
 vectorized in_type and out_type. vspline::vector_traits supplies these types so that multidimensional/multichannel data come as vigra::TinyVectors, while 'singular' data won't be made into TinyVectors of one element. More...
 
typedef vector_traits< IN, vsize >::type out_v
 
typedef vector_traits< int, vsize >::ele_v ic_v
 vsize wide vector of ints, used for gather/scatter indexes More...
 
- Public Types inherited from vspline::callable< grok_type< IN, IN, vspline::vector_traits< IN > ::size >, IN, IN, vspline::vector_traits< IN > ::size >
typedef vector_traits< IN, vsize >::type cl_in_v
 
typedef vector_traits< IN, vsize >::type cl_out_v
 

Public Member Functions

 operator bool ()
 
 grok_type ()
 we provide a default constructor so we can create an empty grok_type and assign to it later. Calling the empty grok_type's eval will result in an exception. More...
 
 grok_type (const eval_type &fev, const v_eval_type &vfev)
 direct initialization of the internal evaluation functions this overload, with two arguments, specifies the unvectorized and the vectorized evaluation function explicitly. More...
 
 grok_type (call_type f, v_call_type vf)
 constructor taking a call_type and a v_call_type, initializing the two std::functions _ev and _v_ev with wrappers around these arguments which provide the 'standard' vspline evaluation functor signature More...
 
template<class grokkee_type , typename std::enable_if< std::is_base_of< vspline::unary_functor_tag< vsize >, grokkee_type > ::value, int > ::type = 0>
 grok_type (grokkee_type grokkee)
 constructor from 'grokkee' using lambda expressions to initialize the std::functions _ev and _v_ev. we enable this if grokkee_type is a vspline::unary_functor More...
 
 grok_type (const eval_type &fev)
 constructor taking only an unvectorized evaluation function. this function is broadcast, providing evaluation of SIMD types with non-vector code, which is less efficient. More...
 
 grok_type (const call_type &f)
 constructor taking only one call_type, which is also broadcast, since the call_type std::function is wrapped to provide a std::function with vspline's standard evaluation functor signature and the result is fed to the single-argument functor above. More...
 
void eval (const IN &i, OUT &o) const
 unvectorized evaluation. This is delegated to _ev. More...
 
template<typename = std::enable_if < ( vsize > 1 ) >>
void eval (const in_v &i, out_v &o) const
 vectorized evaluation function template the eval overload above will catch calls with (in_type, out_type) while this overload will catch vectorized evaluations. More...
 
- Public Member Functions inherited from vspline::callable< grok_type< IN, IN, vspline::vector_traits< IN > ::size >, IN, IN, vspline::vector_traits< IN > ::size >
IN operator() (const IN &in) const
 
IN operator() (const IN &in)
 
cl_out_v operator() (const cl_in_v &in) const
 
cl_out_v operator() (const cl_in_v &in)
 

Public Attributes

eval_type _ev
 
v_eval_type _v_ev
 

Additional Inherited Members

- Static Public Attributes inherited from vspline::unary_functor< IN, IN, vspline::vector_traits< IN > ::size >
static const bool has_capped_eval
 

Detailed Description

template<typename IN, typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
struct vspline::grok_type< IN, OUT, _vsize >

class grok_type is a helper class wrapping a vspline::unary_functor so that it's type becomes opaque - a technique called 'type erasure', here applied to vspline::unary_functors with their specific capability of providing both vectorized and unvectorized operation in one common object.

While 'grokking' a unary_functor may degrade performance slightly, the resulting type is less complex, and when working on complex constructs involving several unary_functors, it can be helpful to wrap the whole bunch into a grok_type for some time to make compiler messages more palatable. I even suspect that the resulting functor, which simply delegates to two std::functions, may optimize better at times than a more complex functor in the 'grokkee'.

Performance aside, 'grokking' a vspline::unary_functor produces a simple, consistent type that can hold any unary_functor with the given input and output type(s), so it allows to hold and use a variety of (intrinsically differently typed) functors at runtime via a common handle which is a vspline::unary_functor itself and can be passed to the transform-type routines. With unary_functors being first-class, copyable objects, this also makes it possible to pass around unary_functors between different TUs where user code can provide new functors at will which can simply be used without having to recompile to make their type known, at the cost of a call through a std::function.

grok_type also provides a convenient way to introduce functors into vspline. Since the functionality is implemented with std::functions, we allow direct initialization of these std::functions on top of 'grokking' the capabilities of another unary_functor via lambda expressions.

Another aspect to grokking is keeping the binary compact. Suppose you have an operation which is polymorphic with several template args. When you instantiate all possible combinations, you end up with a large number of types, each with it's own binary representation. Type erasure can significantly reduce this effect by bundling a whole set of types into a single type. This is especially welcome when working with functor composition: You can build up a variety of functors addressing a specific aspect of your functionality and 'grok' the result, so you only have one type left, which is much easier to handle: you can pass it around and introduce it's type into other parts of your code without having to deal with the complexity of the originla grokked type family.

For grok_type objects where _vsize is greater 1, there are constructor overloads taking only a single function. These constructors broadcast the unvectorized function to process vectorized data, providing a quick way to produce code which runs with vector data, albeit less efficiently than true vector code.

finally, for convenience, grok_type also provides operator(), to use the grok_type object with function call syntax, and it also provides the common 'eval' routine(s), just like any other unary_functor.

Definition at line 679 of file unary_functor.h.

Member Typedef Documentation

◆ base_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef vspline::unary_functor< IN , OUT , _vsize > vspline::grok_type< IN, OUT, _vsize >::base_type

Definition at line 684 of file unary_functor.h.

◆ call_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef std::function< out_type ( const in_type & ) > vspline::grok_type< IN, OUT, _vsize >::call_type

Definition at line 696 of file unary_functor.h.

◆ eval_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef std::function< void ( const in_type & , out_type & ) > vspline::grok_type< IN, OUT, _vsize >::eval_type

Definition at line 695 of file unary_functor.h.

◆ in_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef IN vspline::unary_functor< IN, OUT, _vsize >::in_type

Definition at line 208 of file unary_functor.h.

◆ in_v

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef vector_traits<IN,vsize>::type vspline::unary_functor< IN, OUT, _vsize >::in_v

vectorized in_type and out_type. vspline::vector_traits supplies these types so that multidimensional/multichannel data come as vigra::TinyVectors, while 'singular' data won't be made into TinyVectors of one element.

Definition at line 254 of file unary_functor.h.

◆ out_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef OUT vspline::unary_functor< IN, OUT, _vsize >::out_type

Definition at line 209 of file unary_functor.h.

◆ out_v

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef vector_traits<OUT,vsize>::type vspline::unary_functor< IN, OUT, _vsize >::out_v

Definition at line 255 of file unary_functor.h.

◆ v_call_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef std::function< out_v ( const in_v & ) > vspline::grok_type< IN, OUT, _vsize >::v_call_type

Definition at line 716 of file unary_functor.h.

◆ v_eval_type

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
typedef std::function< void ( const in_v & , out_v & ) > vspline::grok_type< IN, OUT, _vsize >::v_eval_type

Definition at line 708 of file unary_functor.h.

Constructor & Destructor Documentation

◆ grok_type() [1/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( )
inline

we provide a default constructor so we can create an empty grok_type and assign to it later. Calling the empty grok_type's eval will result in an exception.

Definition at line 722 of file unary_functor.h.

◆ grok_type() [2/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( const eval_type fev,
const v_eval_type vfev 
)
inline

direct initialization of the internal evaluation functions this overload, with two arguments, specifies the unvectorized and the vectorized evaluation function explicitly.

Definition at line 728 of file unary_functor.h.

◆ grok_type() [3/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( call_type  f,
v_call_type  vf 
)
inline

constructor taking a call_type and a v_call_type, initializing the two std::functions _ev and _v_ev with wrappers around these arguments which provide the 'standard' vspline evaluation functor signature

Definition at line 739 of file unary_functor.h.

◆ grok_type() [4/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
template<class grokkee_type , typename std::enable_if< std::is_base_of< vspline::unary_functor_tag< vsize >, grokkee_type > ::value, int > ::type = 0>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( grokkee_type  grokkee)
inline

constructor from 'grokkee' using lambda expressions to initialize the std::functions _ev and _v_ev. we enable this if grokkee_type is a vspline::unary_functor

Definition at line 757 of file unary_functor.h.

◆ grok_type() [5/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( const eval_type fev)
inline

constructor taking only an unvectorized evaluation function. this function is broadcast, providing evaluation of SIMD types with non-vector code, which is less efficient.

Definition at line 768 of file unary_functor.h.

◆ grok_type() [6/6]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::grok_type ( const call_type f)
inline

constructor taking only one call_type, which is also broadcast, since the call_type std::function is wrapped to provide a std::function with vspline's standard evaluation functor signature and the result is fed to the single-argument functor above.

Definition at line 785 of file unary_functor.h.

Member Function Documentation

◆ eval() [1/2]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
void vspline::grok_type< IN, OUT, _vsize >::eval ( const IN &  i,
OUT &  o 
) const
inline

unvectorized evaluation. This is delegated to _ev.

Definition at line 791 of file unary_functor.h.

◆ eval() [2/2]

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
template<typename = std::enable_if < ( vsize > 1 ) >>
void vspline::grok_type< IN, OUT, _vsize >::eval ( const in_v i,
out_v o 
) const
inline

vectorized evaluation function template the eval overload above will catch calls with (in_type, out_type) while this overload will catch vectorized evaluations.

Definition at line 801 of file unary_functor.h.

◆ operator bool()

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
vspline::grok_type< IN, OUT, _vsize >::operator bool ( )
inline

Definition at line 700 of file unary_functor.h.

Member Data Documentation

◆ _ev

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
eval_type vspline::grok_type< IN, OUT, _vsize >::_ev

Definition at line 698 of file unary_functor.h.

◆ _v_ev

template<typename IN , typename OUT = IN, size_t _vsize = vspline::vector_traits < IN > :: size>
v_eval_type vspline::grok_type< IN, OUT, _vsize >::_v_ev

Definition at line 712 of file unary_functor.h.


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