From c0aef3fd4d5b41eaa615064483f84a2f580b143f Mon Sep 17 00:00:00 2001 From: Pietro Incardona <incardon@mpi-cbg.de> Date: Wed, 7 Dec 2016 15:37:00 +0100 Subject: [PATCH] small changes to documentation --- .../Vector/vector_dist_operators.hpp | 121 +++++++++++------- .../vector_dist_operators_apply_kernel.hpp | 97 ++++++++++++++ .../vector_dist_operators_functions.hpp | 17 ++- .../vector_dist_operators_unit_tests.hpp | 52 ++++++++ 4 files changed, 242 insertions(+), 45 deletions(-) diff --git a/src/Operators/Vector/vector_dist_operators.hpp b/src/Operators/Vector/vector_dist_operators.hpp index ab44d4a3..9e0a9a55 100644 --- a/src/Operators/Vector/vector_dist_operators.hpp +++ b/src/Operators/Vector/vector_dist_operators.hpp @@ -84,23 +84,30 @@ template<typename ObjType> struct has_init<ObjType, typename Void<typename ObjType::has_init>::type> : std::true_type {}; -/*! \brief Call the init function if needed +/*! \brief Call the init function if a type T has the function init * - * \param r_exp expression + * \tparam type T * */ template <typename T, bool has_init = has_init<T>::value > struct call_init_if_needed { + //! it call the function init for r_exp if T has the function init static inline void call(T & r_exp) { r_exp.init(); } }; +/*! \brief Call the init function if a type T has the function init + * + * \tparam type T + * + */ template <typename T> struct call_init_if_needed<T,false> { + //! it call the function init for r_exp if T has the function init static inline void call(T & r_exp) { } @@ -129,11 +136,15 @@ class vector_dist_expression_op template <typename exp1, typename exp2> class vector_dist_expression_op<exp1,exp2,VECT_SUM> { + //! expression 1 const exp1 o1; + + //! expression 2 const exp2 o2; public: + //! constructor of the expression to sum two expression inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2) :o1(o1),o2(o2) {} @@ -153,6 +164,8 @@ public: * * \param key where to evaluate the expression * + * \return return the result of the expression + * */ template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) + o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const { @@ -170,11 +183,15 @@ public: template <typename exp1, typename exp2> class vector_dist_expression_op<exp1,exp2,VECT_SUB> { + //! expression 1 const exp1 o1; + + //! expression 2 const exp2 o2; public: + //! Costruct a subtraction expression out of two expressions inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2) :o1(o1),o2(o2) {} @@ -194,6 +211,8 @@ public: * * \param key where to evaluate the expression * + * \return the result of the expression + * */ template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) - o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const { @@ -210,11 +229,15 @@ public: template <typename exp1, typename exp2> class vector_dist_expression_op<exp1,exp2,VECT_MUL> { + //! expression 1 const exp1 o1; + + //! expression 2 const exp2 o2; public: + //! constructor from two expressions vector_dist_expression_op(const exp1 & o1, const exp2 & o2) :o1(o1),o2(o2) {} @@ -234,6 +257,8 @@ public: * * \param key where to evaluate the expression * + * \return the result of the expression + * */ template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) * o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const { @@ -250,11 +275,15 @@ public: template <typename exp1, typename exp2> class vector_dist_expression_op<exp1,exp2,VECT_DIV> { + //! expression 1 const exp1 o1; + + //! expression 2 const exp2 o2; public: + //! constructor from two expressions vector_dist_expression_op(const exp1 & o1, const exp2 & o2) :o1(o1),o2(o2) {} @@ -274,6 +303,8 @@ public: * * \param key where to evaluate the expression * + * \return the result of the expression + * */ template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) / o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const { @@ -283,49 +314,69 @@ public: /*! \brief selector for position or properties * + * \tparam vector type of the original vector + * + * \tparam prp property id * */ template <typename vector, unsigned int prp> struct pos_or_prop { + //! return the value (position or property) of the particle k in the vector v static inline auto value(vector & v, const vect_dist_key_dx & k) -> decltype(v.template getProp<prp>(k)) { return v.template getProp<prp>(k); } }; +/*! \brief selector for position or properties + * + * \tparam vector type of the original vector + * + * \tparam prp property id + * + */ template <typename vector> struct pos_or_prop<vector,PROP_POS> { + //! return the value (position or property) of the particle k in the vector v static inline auto value(vector & v, const vect_dist_key_dx & k) -> decltype(getExpr(v.getPos(k))) { return getExpr(v.getPos(k)); } }; +/*! \brief it take an expression and create the negatove of this expression + * + * + */ template <typename exp1> class vector_dist_expression_op<exp1,void,VECT_SUB_UNI> { + //! expression 1 const exp1 o1; public: + //! constructor from an expresssion vector_dist_expression_op(const exp1 & o1) :o1(o1) {} + //! initialize the expression tree inline void init() const { o1.init(); } + //! return the result of the expression template<typename r_type=typename std::remove_reference<decltype(-(o1.value(vect_dist_key_dx(0))))>::type > inline r_type value(const vect_dist_key_dx & key) const { return -(o1.value(key)); } }; -/*! \brief Main class that encapsulate a vector properties +/*! \brief Main class that encapsulate a vector properties operand to be used for expressions construction * * \tparam prp property involved * \tparam vector involved @@ -334,15 +385,18 @@ public: template<unsigned int prp, typename vector> class vector_dist_expression { + //! The vector vector & v; public: + //! The type of the internal vector typedef vector vtype; //! Property id of the point static const unsigned int prop = prp; + //! constructor for an external vector vector_dist_expression(vector & v) :v(v) {} @@ -351,6 +405,8 @@ public: * * It return the vector used in getVExpr, to get this object * + * \return the vector + * */ vector & getVector() { @@ -367,7 +423,9 @@ public: /*! \brief Evaluate the expression * - * \param key where to evaluate the expression + * \param k where to evaluate the expression + * + * \return the result of the expression * */ inline auto value(const vect_dist_key_dx & k) const -> decltype(pos_or_prop<vector,prp>::value(v,k)) @@ -379,6 +437,8 @@ public: * * \param v_exp expression to evaluate * + * \return itself + * */ template<unsigned int prp2> vector & operator=(const vector_dist_expression<prp2,vector> & v_exp) { @@ -402,6 +462,8 @@ public: * * \param v_exp expression to evaluate * + * \return itself + * */ template<typename exp1, typename exp2, unsigned int op> vector & operator=(const vector_dist_expression_op<exp1,exp2,op> & v_exp) { @@ -425,6 +487,8 @@ public: * * \param d value to fill * + * \return the internal vector + * */ vector & operator=(double d) { @@ -464,10 +528,12 @@ template <unsigned int prp,typename vector> inline vector_dist_expression<prp,ve template<unsigned int prp> class vector_dist_expression<prp,double> { + //! constant parameter double d; public: + //! constructor from a constant expression inline vector_dist_expression(const double & d) :d(d) {} @@ -482,7 +548,11 @@ public: /*! \brief Evaluate the expression * - * It just return the velue set in the constructor + * \param k ignored position in the vector + * + * It just return the value set in the constructor + * + * \return the constant value * */ inline double value(const vect_dist_key_dx & k) const @@ -507,7 +577,7 @@ public: //! type of object the structure return then evaluated typedef float vtype; - //! constrictir from constant value + //! constrictor from constant value inline vector_dist_expression(const float & d) :d(d) {} @@ -521,6 +591,8 @@ public: {} /*! \brief Evaluate the expression + * + * \param k ignored position in the vector * * It just return the value set in the constructor * @@ -533,43 +605,6 @@ public: } }; - - -/*! \brief Main class that encapsulate a float constant - * - * \param prp no meaning - * - */ -template<typename T> -class vector_dist_expression<PROP_CUSTOM,T> -{ - -public: - - typedef float vtype; - - inline vector_dist_expression() - {} - - /*! \brief This function must be called before value - * - * it initialize the expression if needed - * - */ - inline void init() const - {} - - /*! \brief Evaluate the expression - * - * It just return the velue set in the constructor - * - */ - inline T value(const vect_dist_key_dx & k) const - { - return T(0.0); - } -}; - /* \brief sum two distributed vector expression * * \param va vector expression one diff --git a/src/Operators/Vector/vector_dist_operators_apply_kernel.hpp b/src/Operators/Vector/vector_dist_operators_apply_kernel.hpp index 59bbc478..59a51645 100644 --- a/src/Operators/Vector/vector_dist_operators_apply_kernel.hpp +++ b/src/Operators/Vector/vector_dist_operators_apply_kernel.hpp @@ -22,15 +22,19 @@ template<typename ObjType> struct is_expression<ObjType, typename Void<typename ObjType::is_expression>::type> : std::true_type {}; +//! It give the return type of the expression if applicable template<typename exp, bool is_exp = is_expression<exp>::value> struct apply_kernel_rtype { + //! indicate the return type of the expression exp typedef typename exp::return_type rtype; }; +//! It give the return type of the expression if applicable template<typename exp> struct apply_kernel_rtype<exp,false> { + //! indicate the return type of the expression exp typedef exp rtype; }; @@ -42,6 +46,7 @@ struct apply_kernel_rtype<exp,false> template<typename rtype> struct set_zero { + //! return 0 static rtype create() { return 0.0; @@ -51,6 +56,7 @@ struct set_zero template<unsigned int dim, typename T> struct set_zero<Point<dim,T>> { + //! return a point with all the coordinates set to zero static Point<dim,T> create() { Point<dim,T> ret; @@ -67,6 +73,17 @@ struct set_zero<Point<dim,T>> template<typename T, typename vector, typename exp,typename NN_type, typename Kernel, typename rtype, bool is_exp=is_expression<T>::value> struct apply_kernel_is_number_or_expression { + /*! \brief Apply the kernel expression to a particle + * + * \param vd vector with the particles positions + * \param cl Cell-list + * \param v_exp expression to execute for each particle + * \param key to which particle to apply the expression + * \param lker kernel function + * + * \return the result of apply the kernel on the particle key + * + */ inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const exp & v_exp, const vect_dist_key_dx & key, Kernel & lker) { // accumulator @@ -113,6 +130,16 @@ struct apply_kernel_is_number_or_expression template<typename vector, typename exp,typename NN_type, typename Kernel, typename rtype> struct apply_kernel_is_number_or_expression_sim { + /*! \brief Apply the kernel expression to a particle + * + * \param vd vector with the particles positions + * \param cl Cell-list (symmetric version) + * \param key to which particle to apply the expression + * \param lker kernel function + * + * \return the result of apply the kernel on the particle key + * + */ inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const vect_dist_key_dx & key, Kernel & lker) { // accumulator @@ -154,6 +181,17 @@ struct apply_kernel_is_number_or_expression_sim template<typename T, typename vector, typename exp,typename NN_type, typename Kernel, typename rtype, bool is_exp=is_expression<T>::value> struct apply_kernel_is_number_or_expression_gen { + /*! \brief Apply the kernel expression to a particle + * + * \param vd vector with the particles positions + * \param cl Cell-list + * \param v_exp expression to execute for each particle + * \param key to which particle to apply the expression + * \param lker kernel function + * + * \return the result of apply the kernel on the particle key + * + */ inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const exp & v_exp, const vect_dist_key_dx & key, Kernel & lker) { // accumulator @@ -199,15 +237,26 @@ struct apply_kernel_is_number_or_expression_gen template <typename exp1,typename vector_type> class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN> { + //! Get the type of the Cell-list typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN; + //! Get the type of the kernel typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel; + //! Get the type that contain the particle positions typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig; + //! expression const exp1 o1; + + //! Cell-list NN & cl; + + //! kernel Kernel & ker; + + //! The vector that contain the particles const vector_orig & vd; + //! Get the return type of apply the kernel to a particle typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx(0)))>::rtype rtype; public: @@ -222,6 +271,14 @@ public: o1.init(); } + /*! \brief Constructor + * + * \param o1 expression + * \param cl Cell-list + * \param ker kernel function + * \param vector_orig vector containing the particle positions + * + */ vector_dist_expression_op(const exp1 & o1, NN & cl, Kernel & ker, const vector_orig & vd) :o1(o1),cl(cl),ker(ker),vd(vd) {} @@ -230,6 +287,8 @@ public: * * \param key where to evaluate the expression * + * \return the result of the expression + * */ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const { @@ -246,14 +305,21 @@ public: template <typename exp1,typename vector_type> class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_SIM> { + //! Return the type of the Cell-list typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN; + //! Return the type of the kernel typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel; + //! Return the vector containing the position of the particles typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig; + //! Cell-list NN & cl; + //! kernel Kernel & ker; + //! vector with the particle positions const vector_orig & vd; + //! Get the return type of the expression typedef typename apply_kernel_rtype<decltype(std::declval<Kernel>().value(Point<vector_orig::dims,typename vector_orig::stype>(0.0), Point<vector_orig::dims,typename vector_orig::stype>(0.0) ) )>::rtype rtype; @@ -268,6 +334,13 @@ public: { } + /*! \brief Constructor + * + * \param cl cell-list + * \param ker kernel + * \param vd Vector containing the particle positions + * + */ vector_dist_expression_op(NN & cl, Kernel & ker, const vector_orig & vd) :cl(cl),ker(ker),vd(vd) {} @@ -276,6 +349,8 @@ public: * * \param key where to evaluate the expression * + * \return the result produced by the expression + * */ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const { @@ -293,15 +368,27 @@ public: template <typename exp1,typename vector_type> class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_GEN> { + //! Get the type of the Cell-list typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN; + //! Get the type of the kernel typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel; + + //! Get the type of the vector containing the set of particles typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig; + //! Expression const exp1 o1; + + //! Cell list NN & cl; + + //! Kernel Kernel & ker; + + //! Vector containing the particles const vector_orig & vd; + //! Return type of the expression typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx(0)))>::rtype rtype; public: @@ -316,6 +403,14 @@ public: o1.init(); } + /*! \brief Constructor + * + * \param o1 expression + * \param cl Cell-list + * \param ker Kernel + * \param vd vector containing the set of particles + * + */ vector_dist_expression_op(const exp1 & o1, NN & cl, Kernel & ker, const vector_orig & vd) :o1(o1),cl(cl),ker(ker),vd(vd) {} @@ -324,6 +419,8 @@ public: * * \param key where to evaluate the expression * + * \return the result of the expression + * */ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const { diff --git a/src/Operators/Vector/vector_dist_operators_functions.hpp b/src/Operators/Vector/vector_dist_operators_functions.hpp index ff7308e1..800ab69f 100644 --- a/src/Operators/Vector/vector_dist_operators_functions.hpp +++ b/src/Operators/Vector/vector_dist_operators_functions.hpp @@ -207,25 +207,36 @@ CREATE_VDIST_ARG2_FUNC(pmul,pmul,VECT_PMUL) ////////// Special function reduce ///////////////////////// - +/*! \brief Expression that create a reduction + * + * \tparam exp1 expression + * \tparam vector_type type of the vector + * + */ template <typename exp1, typename vector_type> class vector_dist_expression_op<exp1,vector_type,VECT_SUM_REDUCE> { + //! expression on which apply the reduction const exp1 o1; + //! return type of this expression typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx(0)))>::rtype rtype; - // calculated value + //! return type of the calculated value (without reference) mutable typename std::remove_reference<rtype>::type val; + //! vector on which we apply the reduction expression const vector_type & vd; public: + //! Constructor from expression and the vector of particles vector_dist_expression_op(const exp1 & o1, const vector_type & vd) :o1(o1), vd(vd) {} + //! sum reduction require initialization where we calculate the reduction + //! this produce a cache for the calculated value inline void init() const { o1.init(); @@ -244,12 +255,14 @@ public: } } + //! it return the result of the expression inline typename std::remove_reference<rtype>::type get() { init(); return value(vect_dist_key_dx(0)); } + //! it return the result of the expression (precalculated before) template<typename r_type= typename std::remove_reference<rtype>::type > inline r_type value(const vect_dist_key_dx & key) const { return val; diff --git a/src/Operators/Vector/vector_dist_operators_unit_tests.hpp b/src/Operators/Vector/vector_dist_operators_unit_tests.hpp index 372bde70..2bd0d4aa 100644 --- a/src/Operators/Vector/vector_dist_operators_unit_tests.hpp +++ b/src/Operators/Vector/vector_dist_operators_unit_tests.hpp @@ -652,12 +652,24 @@ typedef vector_dist<3,float,aggregate<float,float,float,VectorS<3,float>,VectorS //! Exponential kernel struct exp_kernel { + //! variance float var; + //! Set the variance of the exponential kernel exp_kernel(float var) :var(var) {} + /*! \brief Result of the exponential kernel + * + * \param p position of the particle p + * \param q position of the particle q + * \param pA property value at p + * \param pB property value at q + * + * \return the result + * + */ inline float value(const Point<3,float> & p, const Point<3,float> & q,float pA,float pB) { float dist = norm(p-q); @@ -665,6 +677,16 @@ struct exp_kernel return (pA + pB) * exp(dist * dist / var); } + /*! \brief Result of the exponential kernel + * + * \param p position of the particle p + * \param q position of the particle q + * \param pA property value at p + * \param pB property value at q + * + * \return the result + * + */ inline Point<3,float> value(const Point<3,float> & p, const Point<3,float> & q,const Point<3,float> & pA, const Point<3,float> & pB) { float dist = norm(p-q); @@ -672,6 +694,17 @@ struct exp_kernel return (pA + pB) * exp(dist * dist / var); } + /*! \brief Result of the exponential kernel + * + * \param p position of the particle p + * \param q position of the particle q + * \param pA property value at p + * \param pB property value at q + * \param vd1 original vector + * + * \return the result + * + */ inline float value(size_t p, size_t q, float pA, float pB, const vector_type & vd1) { Point<3,float> pp = vd1.getPos(p); @@ -682,6 +715,17 @@ struct exp_kernel return (pA + pB) * exp(dist * dist / var); } + /*! \brief Result of the exponential kernel + * + * \param p position of the particle p + * \param q position of the particle q + * \param pA property value at p + * \param pB property value at q + * \param vd1 original vector + * + * \return the result + * + */ inline Point<3,float> value(size_t p, size_t q, const Point<3,float> & pA, const Point<3,float> & pB , const vector_type & vd1) { Point<3,float> pp = vd1.getPos(p); @@ -692,6 +736,14 @@ struct exp_kernel return (pA + pB) * exp(dist * dist / var); } + /*! \brief Result of the exponential kernel + * + * \param p position of the particle p + * \param q position of the particle q + * + * \return the result + * + */ inline Point<2,float> value(const Point<3,float> & p, const Point<3,float> & q) { float dist = norm(p-q); -- GitLab