00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_PRINT_MATRIX_INCLUDE
00013 #define MTL_PRINT_MATRIX_INCLUDE
00014
00015 #include <iostream>
00016 #include <boost/numeric/mtl/mtl_fwd.hpp>
00017 #include <boost/numeric/mtl/utility/tag.hpp>
00018 #include <boost/numeric/mtl/utility/category.hpp>
00019 #include <boost/numeric/mtl/utility/range_generator.hpp>
00020
00021 namespace mtl { namespace matrix {
00022
00023 template <typename Matrix>
00024 std::ostream& print_matrix(Matrix const& matrix, std::ostream& out= std::cout, int width= 3, int precision= 2)
00025 {
00026
00027 for (size_t r = 0; r < num_rows(matrix); ++r) {
00028 out << '[';
00029 for (size_t c = 0; c < num_cols(matrix); ++c) {
00030 out.fill (' '); out.width (width); out.precision (precision);
00031 if (precision)
00032 out.precision(precision);
00033 out << matrix(r, c) << (c < num_cols(matrix) - 1 ? " " : "]\n");
00034 }
00035 }
00036 return out;
00037 }
00038
00039
00040 template <typename Matrix>
00041 void print_matrix_row_cursor(Matrix const& matrix, std::ostream& out= std::cout)
00042 {
00043 typedef glas::tag::row Tag;
00044 typename traits::const_value<Matrix>::type value(matrix);
00045 typedef typename traits::range_generator<Tag, Matrix>::type cursor_type;
00046
00047 for (cursor_type cursor = begin<Tag>(matrix), cend = end<Tag>(matrix); cursor != cend; ++cursor) {
00048 out << '[';
00049 typedef glas::tag::all inner_tag;
00050 typedef typename traits::range_generator<inner_tag, cursor_type>::type icursor_type;
00051 for (icursor_type icursor = begin<inner_tag>(cursor), icend = end<inner_tag>(cursor); icursor != icend; ) {
00052 out << value(*icursor);
00053 ++icursor;
00054 out << ( icursor != icend ? ", " : "]\n");
00055 }
00056 }
00057 }
00058
00059 }}
00060
00061 #endif // MTL_PRINT_MATRIX_INCLUDE