00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_SIMPLIFY_BASE_CASE_MATRIX_INCLUDE
00013 #define MTL_SIMPLIFY_BASE_CASE_MATRIX_INCLUDE
00014
00015 #include <boost/numeric/mtl/matrix/dimension.hpp>
00016 #include <boost/numeric/mtl/utility/exception.hpp>
00017 #include <boost/numeric/mtl/operation/sub_matrix.hpp>
00018 #include <boost/numeric/mtl/recursion/base_case_matrix.hpp>
00019
00020
00021 namespace mtl { namespace recursion {
00022
00023
00024 namespace impl {
00025
00026
00027 template <typename Matrix, typename BaseCaseMatrix, typename BaseCaseTest>
00028 struct simplify_base_case_matrix
00029 {
00030 BaseCaseMatrix operator()(Matrix const& matrix, BaseCaseTest const test)
00031 {
00032 typename Matrix::size_type begin_row= matrix.begin_row(), begin_col= matrix.begin_col();
00033
00034 if (matrix.num_rows() == BaseCaseTest::base_case_size
00035 && matrix.num_cols() == BaseCaseTest::base_case_size)
00036 return BaseCaseMatrix(non_fixed::dimensions(matrix.num_rows(), matrix.num_cols()),
00037 &const_cast<Matrix&>(matrix)[begin_row][begin_col]);
00038
00039 BaseCaseMatrix square(non_fixed::dimensions(BaseCaseTest::base_case_size, BaseCaseTest::base_case_size),
00040 &const_cast<Matrix&>(matrix)[begin_row][begin_col]);
00041 return sub_matrix(square, begin_row, matrix.num_rows(), begin_col, matrix.num_cols());
00042 }
00043 };
00044
00045 template <typename Matrix, typename BaseCaseTest>
00046 struct simplify_base_case_matrix<Matrix, Matrix, BaseCaseTest>
00047 {
00048 Matrix operator()(Matrix const& matrix, BaseCaseTest const test)
00049 {
00050 return matrix;
00051 }
00052 };
00053
00054
00055 #if 0
00056 inline BaseCaseMatrix
00057 simplify_base_case_matrix(Matrix const& matrix, BaseCaseMatrix const&, BaseCaseTest const&)
00058 {
00059 typename Matrix::size_type begin_row= matrix.begin_row(), begin_col= matrix.begin_col();
00060
00061 if (matrix.num_rows() == BaseCaseTest::base_case_size
00062 && matrix.num_cols() == BaseCaseTest::base_case_size)
00063 return BaseCaseMatrix(non_fixed::dimensions(matrix.num_rows(), matrix.num_cols()),
00064 &const_cast<Matrix&>(matrix)[begin_row][begin_col]);
00065
00066 BaseCaseMatrix square(non_fixed::dimensions(BaseCaseTest::base_case_size, BaseCaseTest::base_case_size),
00067 &const_cast<Matrix&>(matrix)[begin_row][begin_col]);
00068 return sub_matrix(square, begin_row, matrix.num_rows(), begin_col, matrix.num_cols());
00069 }
00070
00071
00072 template <typename Matrix, typename BaseCaseTest>
00073 inline Matrix
00074 simplify_base_case_matrix(Matrix const& matrix, Matrix const&, BaseCaseTest const&)
00075 {
00076 return matrix;
00077 }
00078 #endif
00079
00080 }
00081
00082 template <typename Matrix, typename BaseCaseTest>
00083 typename base_case_matrix<Matrix, BaseCaseTest>::type inline
00084 simplify_base_case_matrix(Matrix const& matrix, BaseCaseTest test)
00085 {
00086
00087 MTL_DEBUG_THROW_IF(num_rows(matrix) > BaseCaseTest::base_case_size || num_cols(matrix) > BaseCaseTest::base_case_size,
00088 logic_error("Matrix dimension is larger than base case"));
00089
00090 return impl::simplify_base_case_matrix<Matrix, typename base_case_matrix<Matrix, BaseCaseTest>::type, BaseCaseTest>()(matrix, test);
00091
00092 }
00093
00094 }}
00095
00096
00097 #endif // MTL_SIMPLIFY_BASE_CASE_MATRIX_INCLUDE