00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_DIAGONAL_SETUP_INCLUDE
00013 #define MTL_DIAGONAL_SETUP_INCLUDE
00014
00015 #include <boost/numeric/mtl/matrix/inserter.hpp>
00016 #include <boost/numeric/mtl/concept/collection.hpp>
00017 #include <boost/numeric/mtl/utility/exception.hpp>
00018 #include <boost/numeric/mtl/operation/set_to_zero.hpp>
00019 #include <boost/numeric/linear_algebra/identity.hpp>
00020
00021 namespace mtl { namespace matrix {
00022
00024
00032 template <typename Matrix, typename Value>
00033 inline void diagonal_setup(Matrix& matrix, const Value& value)
00034 {
00035 using std::min;
00036 if (num_rows(matrix) == 0 || num_cols(matrix) == 0)
00037 return;
00038
00039 set_to_zero(matrix);
00040 inserter<Matrix> ins(matrix, 1);
00041 for (typename Collection<Matrix>::size_type i= 0, n= min(num_rows(matrix), num_cols(matrix)); i < n; ++i)
00042 ins[i][i] << value;
00043 }
00044
00045 }}
00046
00047 #endif // MTL_DIAGONAL_SETUP_INCLUDE