00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_INVERT_DIAGONAL_INCLUDE
00013 #define MTL_INVERT_DIAGONAL_INCLUDE
00014
00015 #include <boost/numeric/mtl/utility/tag.hpp>
00016 #include <boost/numeric/mtl/utility/range_generator.hpp>
00017 #include <boost/numeric/mtl/utility/property_map.hpp>
00018 #include <boost/numeric/linear_algebra/inverse.hpp>
00019
00020 namespace mtl { namespace matrix {
00022 template <typename Matrix>
00023 inline void invert_diagonal(Matrix& matrix)
00024 {
00025 using math::reciprocal;
00026 namespace traits = mtl::traits;
00027
00028 typename traits::row<Matrix>::type row(matrix);
00029 typename traits::col<Matrix>::type col(matrix);
00030 typename traits::value<Matrix>::type value(matrix);
00031
00032 typedef typename traits::range_generator<tag::major, Matrix>::type cursor_type;
00033 typedef typename traits::range_generator<tag::nz, cursor_type>::type icursor_type;
00034
00035 for (cursor_type cursor = begin<tag::major>(matrix), cend = end<tag::major>(matrix); cursor != cend; ++cursor)
00036 for (icursor_type icursor = begin<tag::nz>(cursor), icend = end<tag::nz>(cursor); icursor != icend; ++icursor)
00037 if (row(*icursor) == col(*icursor))
00038 value(*icursor, reciprocal(value(*icursor)));
00039 }
00040
00041
00042 }}
00043
00044 #endif // MTL_INVERT_DIAGONAL_INCLUDE