roboptim::CachedFunction< T > Class Template Reference

Store previous function computation. More...

#include <roboptim/core/decorator/cached-function.hh>

List of all members.

Public Types

typedef T::traits_t traits_t
 Import traits type.
typedef
GenericDifferentiableFunction
< traits_t >::interval_t 
interval_t
 Import interval type.
typedef argument_t cacheKey_t
 Key type for the cache.
typedef LRUCache< cacheKey_t,
vector_t, Hasher
functionCache_t
typedef LRUCache< cacheKey_t,
gradient_t, Hasher
gradientCache_t
typedef LRUCache< cacheKey_t,
jacobian_t, Hasher
jacobianCache_t
typedef LRUCache< cacheKey_t,
hessian_t, Hasher
hessianCache_t

Public Member Functions

 ROBOPTIM_TWICE_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ (GenericTwiceDifferentiableFunction< traits_t >)
 CachedFunction (boost::shared_ptr< T > fct, size_t size=10)
 Cache a RobOptim function.
 ~CachedFunction ()
void reset ()
 Reset the caches.

Protected Member Functions

template<typename U >
void cachedFunctionGradient (gradient_ref gradient, const_argument_ref argument, size_type functionId, typename detail::CachedFunctionTypes< U >::isDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionGradient (gradient_ref gradient, const_argument_ref argument, size_type functionId, typename detail::CachedFunctionTypes< U >::isNotDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionJacobian (jacobian_ref jacobian, const_argument_ref argument, typename detail::CachedFunctionTypes< U >::isDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionJacobian (jacobian_ref jacobian, const_argument_ref argument, typename detail::CachedFunctionTypes< U >::isNotDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionHessian (hessian_ref hessian, const_argument_ref argument, size_type functionId, typename detail::CachedFunctionTypes< U >::isTwiceDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionHessian (hessian_ref hessian, const_argument_ref argument, size_type functionId, typename detail::CachedFunctionTypes< U >::isNotTwiceDifferentiable_t::type *=0) const
template<typename U >
void cachedFunctionDerivative (gradient_ref derivative, value_type argument, size_type order, typename detail::CachedFunctionTypes< U >::isNTimesDerivable_t::type *=0) const
template<typename U >
void cachedFunctionDerivative (gradient_ref derivative, value_type argument, size_type order, typename detail::CachedFunctionTypes< U >::isNotNTimesDerivable_t::type *=0) const
virtual void impl_compute (result_ref result, const_argument_ref argument) const
virtual void impl_gradient (gradient_ref gradient, const_argument_ref argument, size_type functionId=0) const
virtual void impl_jacobian (jacobian_ref jacobian, const_argument_ref arg) const
virtual void impl_hessian (hessian_ref hessian, const_argument_ref argument, size_type functionId=0) const
virtual void impl_derivative (gradient_ref derivative, value_type argument, size_type order=1) const

Protected Attributes

boost::shared_ptr< T > function_
std::vector< functionCache_tcache_
std::vector< gradientCache_tgradientCache_
jacobianCache_t jacobianCache_
std::vector< hessianCache_thessianCache_

Detailed Description

template<typename T>
class roboptim::CachedFunction< T >

Store previous function computation.

When an expensive function is called several times at the same point (exactly!), the cached function prevents useless computation by caching the function result.

This decorator is experimental in this release.

Template Parameters:
Tinput function type.

Member Typedef Documentation

template<typename T>
typedef argument_t roboptim::CachedFunction< T >::cacheKey_t

Key type for the cache.

template<typename T>
typedef LRUCache<cacheKey_t, vector_t, Hasher> roboptim::CachedFunction< T >::functionCache_t
template<typename T>
typedef LRUCache<cacheKey_t, gradient_t, Hasher> roboptim::CachedFunction< T >::gradientCache_t
template<typename T>
typedef LRUCache<cacheKey_t, hessian_t, Hasher> roboptim::CachedFunction< T >::hessianCache_t

Import interval type.

template<typename T>
typedef LRUCache<cacheKey_t, jacobian_t, Hasher> roboptim::CachedFunction< T >::jacobianCache_t
template<typename T>
typedef T::traits_t roboptim::CachedFunction< T >::traits_t

Import traits type.


Constructor & Destructor Documentation

template<typename T >
roboptim::CachedFunction< T >::CachedFunction ( boost::shared_ptr< T >  fct,
size_t  size = 10 
) [explicit]

Cache a RobOptim function.

Parameters:
fctfunction to cache.
sizesize of the LRU cache.
template<typename T >
roboptim::CachedFunction< T >::~CachedFunction ( )

Member Function Documentation

template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionDerivative ( gradient_ref  derivative,
value_type  argument,
size_type  order,
typename detail::CachedFunctionTypes< U >::isNTimesDerivable_t::type *  = 0 
) const [protected]
template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionDerivative ( gradient_ref  derivative,
value_type  argument,
size_type  order,
typename detail::CachedFunctionTypes< U >::isNotNTimesDerivable_t::type *  = 0 
) const [protected]
template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionGradient ( gradient_ref  gradient,
const_argument_ref  argument,
size_type  functionId,
typename detail::CachedFunctionTypes< U >::isDifferentiable_t::type *  = 0 
) const [protected]

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().

template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionGradient ( gradient_ref  gradient,
const_argument_ref  argument,
size_type  functionId,
typename detail::CachedFunctionTypes< U >::isNotDifferentiable_t::type *  = 0 
) const [protected]
template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionHessian ( hessian_ref  hessian,
const_argument_ref  argument,
size_type  functionId,
typename detail::CachedFunctionTypes< U >::isTwiceDifferentiable_t::type *  = 0 
) const [protected]

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().

template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionHessian ( hessian_ref  hessian,
const_argument_ref  argument,
size_type  functionId,
typename detail::CachedFunctionTypes< U >::isNotTwiceDifferentiable_t::type *  = 0 
) const [protected]
template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionJacobian ( jacobian_ref  jacobian,
const_argument_ref  argument,
typename detail::CachedFunctionTypes< U >::isDifferentiable_t::type *  = 0 
) const [protected]

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::LRUCache< K, V, H >::find(), roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().

template<typename T >
template<typename U >
void roboptim::CachedFunction< T >::cachedFunctionJacobian ( jacobian_ref  jacobian,
const_argument_ref  argument,
typename detail::CachedFunctionTypes< U >::isNotDifferentiable_t::type *  = 0 
) const [protected]
template<typename T >
void roboptim::CachedFunction< T >::impl_compute ( result_ref  result,
const_argument_ref  argument 
) const [protected, virtual]

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::LRUCache< K, V, H >::find(), roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().

template<typename T >
void roboptim::CachedFunction< T >::impl_derivative ( gradient_ref  derivative,
value_type  argument,
size_type  order = 1 
) const [protected, virtual]
template<typename T >
void roboptim::CachedFunction< T >::impl_gradient ( gradient_ref  gradient,
const_argument_ref  argument,
size_type  functionId = 0 
) const [protected, virtual]
template<typename T >
void roboptim::CachedFunction< T >::impl_hessian ( hessian_ref  hessian,
const_argument_ref  argument,
size_type  functionId = 0 
) const [protected, virtual]
template<typename T >
void roboptim::CachedFunction< T >::impl_jacobian ( jacobian_ref  jacobian,
const_argument_ref  arg 
) const [protected, virtual]
template<typename T >
void roboptim::CachedFunction< T >::reset ( )

Reset the caches.


Member Data Documentation

template<typename T>
std::vector<functionCache_t> roboptim::CachedFunction< T >::cache_ [mutable, protected]
template<typename T>
boost::shared_ptr<T> roboptim::CachedFunction< T >::function_ [protected]
template<typename T>
std::vector<gradientCache_t> roboptim::CachedFunction< T >::gradientCache_ [mutable, protected]
template<typename T>
std::vector<hessianCache_t> roboptim::CachedFunction< T >::hessianCache_ [mutable, protected]
template<typename T>
jacobianCache_t roboptim::CachedFunction< T >::jacobianCache_ [mutable, protected]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines