Store previous function computation. More...
#include <roboptim/core/decorator/cached-function.hh>
Public Types | |
typedef T::traits_t | traits_t |
Import traits type. More... | |
typedef GenericDifferentiableFunction < traits_t >::interval_t | interval_t |
Import interval type. More... | |
typedef argument_t | cacheKey_t |
Key type for the cache. More... | |
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. More... | |
~CachedFunction () | |
void | reset () |
Reset the caches. More... | |
virtual std::ostream & | print (std::ostream &o) const |
Display the cached function on the specified output stream. More... | |
const boost::shared_ptr< const T > | function () const |
Get the inner cached function. More... | |
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, const_argument_ref, size_type, 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, const_argument_ref, 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, const_argument_ref, size_type, 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 *) const |
template<typename U > | |
void | cachedFunctionDerivative (gradient_ref, value_type, size_type, 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_t > | cache_ |
std::vector< gradientCache_t > | gradientCache_ |
jacobianCache_t | jacobianCache_ |
std::vector< hessianCache_t > | hessianCache_ |
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.
T | input function type. |
typedef argument_t roboptim::CachedFunction< T >::cacheKey_t |
Key type for the cache.
typedef LRUCache<cacheKey_t, vector_t, Hasher> roboptim::CachedFunction< T >::functionCache_t |
typedef LRUCache<cacheKey_t, gradient_t, Hasher> roboptim::CachedFunction< T >::gradientCache_t |
typedef LRUCache<cacheKey_t, hessian_t, Hasher> roboptim::CachedFunction< T >::hessianCache_t |
typedef GenericDifferentiableFunction<traits_t>:: interval_t roboptim::CachedFunction< T >::interval_t |
Import interval type.
typedef LRUCache<cacheKey_t, jacobian_t, Hasher> roboptim::CachedFunction< T >::jacobianCache_t |
typedef T::traits_t roboptim::CachedFunction< T >::traits_t |
Import traits type.
|
explicit |
Cache a RobOptim function.
fct | function to cache. |
size | size of the LRU cache. |
roboptim::CachedFunction< T >::~CachedFunction | ( | ) |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
References roboptim::CachedFunction< T >::function_, roboptim::CachedFunction< T >::gradientCache_, roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().
|
inlineprotected |
|
inlineprotected |
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
References roboptim::CachedFunction< T >::function_, roboptim::CachedFunction< T >::hessianCache_, roboptim::is_malloc_allowed(), and roboptim::set_is_malloc_allowed().
|
inlineprotected |
|
inlineprotected |
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
ROBOPTIM_DO_NOT_CHECK_ALLOCATION
References roboptim::LRUCache< K, V, H >::end(), roboptim::LRUCache< K, V, H >::find(), roboptim::CachedFunction< T >::function_, roboptim::is_malloc_allowed(), roboptim::CachedFunction< T >::jacobianCache_, and roboptim::set_is_malloc_allowed().
|
inlineprotected |
const boost::shared_ptr< const T > roboptim::CachedFunction< T >::function | ( | ) | const |
Get the inner cached function.
|
protectedvirtual |
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().
|
protectedvirtual |
References roboptim::derivative().
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
virtual |
Display the cached function on the specified output stream.
o | output stream used for display |
References roboptim::decindent(), roboptim::iendl(), and roboptim::incindent().
void roboptim::CachedFunction< T >::reset | ( | ) |
Reset the caches.
roboptim::CachedFunction< T >::ROBOPTIM_TWICE_DIFFERENTIABLE_FUNCTION_FWD_TYPEDEFS_ | ( | GenericTwiceDifferentiableFunction< traits_t > | ) |
|
mutableprotected |
Referenced by roboptim::CachedFunction< T >::cachedFunctionDerivative().
|
protected |
|
mutableprotected |
Referenced by roboptim::CachedFunction< T >::cachedFunctionGradient().
|
mutableprotected |
Referenced by roboptim::CachedFunction< T >::cachedFunctionHessian().
|
mutableprotected |
Referenced by roboptim::CachedFunction< T >::cachedFunctionJacobian().