00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_SUBMATRIX_INCLUDE
00013 #define MTL_SUBMATRIX_INCLUDE
00014
00015 #include <cmath>
00016 #include <boost/numeric/mtl/utility/exception.hpp>
00017
00018 namespace mtl { namespace matrix {
00019
00020
00021 template <typename Matrix>
00022 struct sub_matrix_t
00023 {
00024
00025
00026
00027
00028
00029 };
00030
00031 namespace impl {
00032
00033 template <typename Matrix>
00034 inline void correct_sub_matrix_indices(Matrix const& matrix,
00035 typename sub_matrix_t<Matrix>::size_type& begin_row,
00036 typename sub_matrix_t<Matrix>::size_type& end_row,
00037 typename sub_matrix_t<Matrix>::size_type& begin_col,
00038 typename sub_matrix_t<Matrix>::size_type& end_col)
00039 {
00040 using std::min;
00041 MTL_DEBUG_THROW_IF( begin_row < 0 || end_row < 0, index_out_of_range());
00042 end_row= min(end_row, num_rows(matrix));
00043 begin_row= min(begin_row, end_row);
00044
00045 MTL_DEBUG_THROW_IF( begin_col < 0 || end_col < 0, index_out_of_range());
00046 end_col= min(end_col, num_cols(matrix));
00047 begin_col= min(begin_col, end_col);
00048 }
00049
00050 }
00051
00053 template <typename Matrix>
00054 inline typename sub_matrix_t<Matrix>::sub_matrix_type
00055 sub_matrix(Matrix& matrix,
00056 typename sub_matrix_t<Matrix>::size_type begin_row,
00057 typename sub_matrix_t<Matrix>::size_type end_row,
00058 typename sub_matrix_t<Matrix>::size_type begin_col,
00059 typename sub_matrix_t<Matrix>::size_type end_col)
00060 {
00061 impl::correct_sub_matrix_indices(matrix, begin_row, end_row, begin_col, end_col);
00062 return sub_matrix_t<Matrix>()(matrix, begin_row, end_row, begin_col, end_col);
00063 }
00064
00065 template <typename Matrix>
00066 inline typename sub_matrix_t<Matrix>::const_sub_matrix_type
00067 sub_matrix(Matrix const& matrix,
00068 typename sub_matrix_t<Matrix>::size_type begin_row,
00069 typename sub_matrix_t<Matrix>::size_type end_row,
00070 typename sub_matrix_t<Matrix>::size_type begin_col,
00071 typename sub_matrix_t<Matrix>::size_type end_col)
00072 {
00073 impl::correct_sub_matrix_indices(matrix, begin_row, end_row, begin_col, end_col);
00074 return sub_matrix_t<Matrix>()(matrix, begin_row, end_row, begin_col, end_col);
00075 }
00076
00077 }}
00078
00079 #endif // MTL_SUBMATRIX_INCLUDE