This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "roboptim-core".
The branch, master has been updated via 11f0b418862fd26d07643b1eaa35ab4e1d34af48 (commit) from e487dc074102f28f3209cacb12b40ef8d5633981 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 11f0b418862fd26d07643b1eaa35ab4e1d34af48 Author: Thomas Moulard <thomas.moul...@gmail.com> Date: Mon Mar 1 16:28:08 2010 +0100 Use shared pointers in caching proxy. * include/roboptim/core/cached-function.hh, * include/roboptim/core/cached-function.hxx: Use shared pointers. * tests/cached-function.cc: Update. Signed-off-by: Thomas Moulard <thomas.moul...@gmail.com> diff --git a/ChangeLog b/ChangeLog index b57ca11..f9b9ded 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2010-03-01 Thomas Moulard <thomas.moul...@gmail.com> + Use shared pointers in caching proxy. + * include/roboptim/core/cached-function.hh, + * include/roboptim/core/cached-function.hxx: Use shared pointers. + * tests/cached-function.cc: Update. + +2010-03-01 Thomas Moulard <thomas.moul...@gmail.com> + Implement function caching. * include/Makefile.am: Distribute new header and source. * include/roboptim/core/cached-function.hh: New. diff --git a/include/roboptim/core/cached-function.hh b/include/roboptim/core/cached-function.hh index e37f17c..5c032e4 100644 --- a/include/roboptim/core/cached-function.hh +++ b/include/roboptim/core/cached-function.hh @@ -22,10 +22,9 @@ # include <map> -# include <roboptim/core/n-times-derivable-function.hh> - +# include <boost/shared_ptr.hpp> -#include <roboptim/core/io.hh> +# include <roboptim/core/n-times-derivable-function.hh> namespace roboptim { @@ -77,7 +76,7 @@ namespace roboptim typedef std::map<Function::vector_t, Function::vector_t, ltvector> functionCache_t; - explicit CachedFunction (const T& fct) throw (); + explicit CachedFunction (boost::shared_ptr<const T> fct) throw (); ~CachedFunction () throw (); void reset () throw (); @@ -101,7 +100,7 @@ namespace roboptim size_type order = 1) const throw (); private: - const T& function_; + boost::shared_ptr<const T> function_; mutable std::vector<functionCache_t> cache_; mutable std::vector<functionCache_t> gradientCache_; mutable std::vector<functionCache_t> hessianCache_; diff --git a/include/roboptim/core/cached-function.hxx b/include/roboptim/core/cached-function.hxx index c5f8c0c..80d117e 100644 --- a/include/roboptim/core/cached-function.hxx +++ b/include/roboptim/core/cached-function.hxx @@ -64,12 +64,12 @@ namespace roboptim } // end of anonymous namespace. template <typename T> - CachedFunction<T>::CachedFunction (const T& fct) throw () - : T (fct.inputSize (), fct.outputSize (), cachedFunctionName (fct)), + CachedFunction<T>::CachedFunction (boost::shared_ptr<const T> fct) throw () + : T (fct->inputSize (), fct->outputSize (), cachedFunctionName (*fct)), function_ (fct), cache_ (derivativeSize<T>::value), - gradientCache_ (fct.outputSize ()), - hessianCache_ (fct.outputSize ()) + gradientCache_ (fct->outputSize ()), + hessianCache_ (fct->outputSize ()) { } @@ -102,7 +102,7 @@ namespace roboptim return; } std::cout << "not cached" << std::endl; - function_ (result, argument); + (*function_) (result, argument); cache_[0][argument] = result; } @@ -129,7 +129,7 @@ namespace roboptim gradient = it->second; return; } - function_.gradient (gradient, argument, functionId); + function_->gradient (gradient, argument, functionId); gradientCache_[functionId][argument] = gradient; } @@ -168,7 +168,7 @@ namespace roboptim hessian = it->second; return; } - function_.hessian (hessian, argument, functionId); + function_->hessian (hessian, argument, functionId); hessianCache_[functionId][argument] = hessian; } @@ -212,7 +212,7 @@ namespace roboptim derivative = it->second; return; } - function_.derivative (derivative, x, order); + function_->derivative (derivative, x, order); cache_[order][x] = derivative; } diff --git a/tests/cached-function.cc b/tests/cached-function.cc index c984487..5c5efcc 100644 --- a/tests/cached-function.cc +++ b/tests/cached-function.cc @@ -47,7 +47,7 @@ struct F : public DerivableFunction int run_test () { - F f; + boost::shared_ptr<F> f (new F ()); CachedFunction<DerivableFunction> cachedF (f); @@ -60,7 +60,7 @@ int run_test () x[0] = i; std::cout << cachedF (x) << std::endl; std::cout << cachedF (x) << std::endl; - assert (f (x)[0] == cachedF (x)[0]); + assert ((*f) (x)[0] == cachedF (x)[0]); std::cout << cachedF.gradient (x) << std::endl; std::cout << cachedF.gradient (x) << std::endl; ----------------------------------------------------------------------- Summary of changes: ChangeLog | 7 +++++++ include/roboptim/core/cached-function.hh | 9 ++++----- include/roboptim/core/cached-function.hxx | 16 ++++++++-------- tests/cached-function.cc | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) hooks/post-receive -- roboptim-core ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ roboptim-commit mailing list roboptim-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/roboptim-commit