Statistics
| Revision:

## root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / accumulators / numeric / functional / vector.hpp @ 2486

 1 ///////////////////////////////////////////////////////////////////////////////  /// \file vector.hpp  ///  // Copyright 2005 Eric Niebler. Distributed under the Boost  // Software License, Version 1.0. (See accompanying file  // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  #ifndef BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005  #define BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005  #ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED  # error Include this file before boost/accumulators/numeric/functional.hpp  #endif  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  namespace boost { namespace numeric  {   namespace operators   {   namespace acc_detail   {   template   struct make_vector   {   typedef std::vector type;   };   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector / Right where Right is a scalar.   template   typename lazy_enable_if<   is_scalar   , acc_detail::make_vector >   >::type   operator /(std::vector const &left, Right const &right)   {   typedef typename functional::divides::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::divides(left[i], right);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector / vector.   template   std::vector::result_type>   operator /(std::vector const &left, std::vector const &right)   {   typedef typename functional::divides::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::divides(left[i], right[i]);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector * Right where Right is a scalar.   template   typename lazy_enable_if<   is_scalar   , acc_detail::make_vector >   >::type   operator *(std::vector const &left, Right const &right)   {   typedef typename functional::multiplies::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::multiplies(left[i], right);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle Left * vector where Left is a scalar.   template   typename lazy_enable_if<   is_scalar   , acc_detail::make_vector >   >::type   operator *(Left const &left, std::vector const &right)   {   typedef typename functional::multiplies::result_type value_type;   std::vector result(right.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::multiplies(left, right[i]);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector * vector   template   std::vector::result_type>   operator *(std::vector const &left, std::vector const &right)   {   typedef typename functional::multiplies::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::multiplies(left[i], right[i]);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector + vector   template   std::vector::result_type>   operator +(std::vector const &left, std::vector const &right)   {   typedef typename functional::plus::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::plus(left[i], right[i]);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector - vector   template   std::vector::result_type>   operator -(std::vector const &left, std::vector const &right)   {   typedef typename functional::minus::result_type value_type;   std::vector result(left.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::minus(left[i], right[i]);   }   return result;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle vector += vector   template   std::vector &   operator +=(std::vector &left, std::vector const &right)   {   BOOST_ASSERT(left.size() == right.size());   for(std::size_t i = 0, size = left.size(); i != size; ++i)   {   numeric::plus_assign(left[i], right[i]);   }   return left;   }   ///////////////////////////////////////////////////////////////////////////////   // Handle -vector   template   std::vector::result_type>   operator -(std::vector const &arg)   {   typedef typename functional::unary_minus::result_type value_type;   std::vector result(arg.size());   for(std::size_t i = 0, size = result.size(); i != size; ++i)   {   result[i] = numeric::unary_minus(arg[i]);   }   return result;   }   }   namespace functional   {   struct std_vector_tag;   template   struct tag >   {   typedef std_vector_tag type;   };   ///////////////////////////////////////////////////////////////////////////////   // element-wise min of std::vector   template   struct min_assign   : std::binary_function   {   void operator ()(Left &left, Right &right) const   {   BOOST_ASSERT(left.size() == right.size());   for(std::size_t i = 0, size = left.size(); i != size; ++i)   {   if(numeric::less(right[i], left[i]))   {   left[i] = right[i];   }   }   }   };   ///////////////////////////////////////////////////////////////////////////////   // element-wise max of std::vector   template   struct max_assign   : std::binary_function   {   void operator ()(Left &left, Right &right) const   {   BOOST_ASSERT(left.size() == right.size());   for(std::size_t i = 0, size = left.size(); i != size; ++i)   {   if(numeric::greater(right[i], left[i]))   {   left[i] = right[i];   }   }   }   };   // partial specialization for std::vector.   template   struct fdiv   : mpl::if_<   are_integral   , divides   , divides   >::type   {};   // promote   template   struct promote   : std::unary_function   {   To operator ()(From &arr) const   {   typename remove_const::type res(arr.size());   for(std::size_t i = 0, size = arr.size(); i != size; ++i)   {   res[i] = numeric::promote(arr[i]);   }   return res;   }   };   template   struct promote   : std::unary_function   {   ToFrom &operator ()(ToFrom &tofrom) const   {   return tofrom;   }   };   ///////////////////////////////////////////////////////////////////////////////   // functional::as_min   template   struct as_min   : std::unary_function::type>   {   typename remove_const::type operator ()(T &arr) const   {   return 0 == arr.size()   ? T()   : T(arr.size(), numeric::as_min(arr[0]));   }   };   ///////////////////////////////////////////////////////////////////////////////   // functional::as_max   template   struct as_max   : std::unary_function::type>   {   typename remove_const::type operator ()(T &arr) const   {   return 0 == arr.size()   ? T()   : T(arr.size(), numeric::as_max(arr[0]));   }   };   ///////////////////////////////////////////////////////////////////////////////   // functional::as_zero   template   struct as_zero   : std::unary_function::type>   {   typename remove_const::type operator ()(T &arr) const   {   return 0 == arr.size()   ? T()   : T(arr.size(), numeric::as_zero(arr[0]));   }   };   ///////////////////////////////////////////////////////////////////////////////   // functional::as_one   template   struct as_one   : std::unary_function::type>   {   typename remove_const::type operator ()(T &arr) const   {   return 0 == arr.size()   ? T()   : T(arr.size(), numeric::as_one(arr[0]));   }   };   } // namespace functional  }} // namespace boost::numeric  #endif