00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_SET_TO_0_INCLUDE
00013 #define MTL_SET_TO_0_INCLUDE
00014
00015 #include <algorithm>
00016 #include <boost/numeric/mtl/utility/enable_if.hpp>
00017 #include <boost/numeric/mtl/utility/tag.hpp>
00018 #include <boost/numeric/mtl/utility/category.hpp>
00019 #include <boost/numeric/mtl/concept/collection.hpp>
00020 #include <boost/numeric/linear_algebra/identity.hpp>
00021
00022 namespace mtl {
00023
00024
00025 namespace matrix {
00026 template <typename Coll>
00027 typename mtl::traits::enable_if_matrix<Coll>::type
00028 set_to_zero(Coll& collection);
00029 }
00030 namespace vector {
00031 template <typename Coll>
00032 typename mtl::traits::enable_if_vector<Coll>::type
00033 set_to_zero(Coll& collection);
00034 }
00035
00036 namespace impl {
00037
00038 template <typename Coll>
00039 void set_to_zero(Coll& collection, tag::contiguous_dense, tag::scalar)
00040 {
00041 using math::zero;
00042 typename Collection<Coll>::value_type ref, my_zero(zero(ref));
00043
00044 std::fill(collection.elements(), collection.elements()+collection.used_memory(), my_zero);
00045 }
00046
00047 template <typename Coll>
00048 void set_to_zero(Coll& collection, tag::std_vector, tag::scalar)
00049 {
00050 using math::zero;
00051 typename Collection<Coll>::value_type ref, my_zero(zero(ref));
00052
00053 std::fill(collection.begin(), collection.end(), my_zero);
00054 }
00055
00056 template <typename Matrix>
00057 void set_to_zero(Matrix& matrix, tag::morton_dense, tag::scalar)
00058 {
00059 using math::zero;
00060 typename Collection<Matrix>::value_type ref, my_zero(zero(ref));
00061
00062
00063
00064 std::fill(matrix.elements(), matrix.elements() + matrix.used_memory(), my_zero);
00065
00066 #if 0
00067 for (int i= 0; i < matrix.num_rows(); i++)
00068 for (int j= 0; i < matrix.num_cols(); i++)
00069 matrix[i][j]= my_zero;
00070 #endif
00071 }
00072
00073
00074
00075 template <typename Coll>
00076 void set_to_zero(Coll& collection, tag::contiguous_dense, tag::collection)
00077 {
00078 for (typename Collection<Coll>::size_type i= 0; i < collection.used_memory(); ++i)
00079 set_to_zero(collection.value_n(i));
00080 }
00081
00082
00083
00084 template <typename Coll>
00085 void set_to_zero(Coll& collection, tag::sparse, tag::universe)
00086 {
00087 collection.make_empty();
00088 }
00089
00090
00091 template <typename Coll>
00092 void set_to_zero(Coll& collection, tag::multi_vector, tag::universe)
00093 {
00094 using mtl::vector::set_to_zero;
00095 for (typename Collection<Coll>::size_type i= 0; i < num_cols(collection); ++i)
00096 set_to_zero(collection.vector(i));
00097 }
00098
00099 }
00100
00101
00102 namespace matrix {
00103
00106 template <typename Coll>
00107 typename mtl::traits::enable_if_matrix<Coll>::type
00108 set_to_zero(Coll& collection)
00109 {
00110 using mtl::traits::category;
00111 typedef typename Collection<Coll>::value_type value_type;
00112 mtl::impl::set_to_zero(collection, typename category<Coll>::type(),typename category<value_type>::type());
00113 }
00114
00115 }
00116
00117 namespace vector {
00118
00121 template <typename Coll>
00122 typename mtl::traits::enable_if_vector<Coll>::type
00123 set_to_zero(Coll& collection)
00124 {
00125 using mtl::traits::category;
00126 typedef typename Collection<Coll>::value_type value_type;
00127 mtl::impl::set_to_zero(collection, typename category<Coll>::type(),typename category<value_type>::type());
00128 }
00129
00130 }
00131
00132 }
00133
00134 #endif // MTL_SET_TO_0_INCLUDE