00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_SUM_INCLUDE
00013 #define MTL_SUM_INCLUDE
00014
00015 #include <iostream>
00016 #include <cmath>
00017
00018 #include <boost/numeric/mtl/concept/collection.hpp>
00019 #include <boost/numeric/mtl/utility/tag.hpp>
00020 #include <boost/numeric/mtl/utility/category.hpp>
00021 #include <boost/numeric/mtl/vector/reduction.hpp>
00022 #include <boost/numeric/mtl/vector/reduction_functors.hpp>
00023
00024
00025 namespace mtl {
00026
00027 namespace impl {
00028
00029
00030
00031 template <unsigned long Unroll, typename Vector>
00032 typename Collection<Vector>::value_type
00033 inline sum(const Vector& vector, tag::vector)
00034 {
00035 typedef typename Collection<Vector>::value_type result_type;
00036 return vector::reduction<Unroll, vector::sum_functor, result_type>::apply(vector);
00037 }
00038
00039 }
00040
00042 template <unsigned long Unroll, typename Value>
00043 typename Collection<Value>::value_type
00044 inline sum(const Value& value)
00045 {
00046 return impl::sum<Unroll>(value, typename traits::category<Value>::type());
00047 }
00048
00049 template <typename Value>
00050 typename Collection<Value>::value_type
00051 inline sum(const Value& value)
00052 {
00053 return sum<8>(value);
00054 }
00055
00056 }
00057
00058 #endif // MTL_SUM_INCLUDE