00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_MATRIX_SWAP_ROW
00013 #define MTL_MATRIX_SWAP_ROW
00014
00015 #include <boost/numeric/mtl/utility/exception.hpp>
00016 #include <boost/numeric/mtl/utility/tag.hpp>
00017 #include <boost/numeric/mtl/utility/category.hpp>
00018 #include <boost/numeric/mtl/utility/enable_if.hpp>
00019 #include <boost/numeric/mtl/concept/collection.hpp>
00020
00021
00022 namespace mtl {
00023
00024 namespace matrix {
00025
00026 namespace detail {
00027
00028 template <typename Matrix, typename Orientation>
00029 inline void swap_row(Matrix& A, typename Collection<Matrix>::size_type i,
00030 typename Collection<Matrix>::size_type j, tag::dense, Orientation)
00031 {
00032
00033 using std::swap;
00034 for (typename Collection<Matrix>::size_type k= 0; k < num_cols(A); k++)
00035 swap(A[i][k], A[j][k]);
00036 }
00037
00038 template <typename Matrix>
00039 inline void swap_row(Matrix& A, typename Collection<Matrix>::size_type i,
00040 typename Collection<Matrix>::size_type j, tag::sparse, boost::mpl::true_)
00041 {
00042 MTL_THROW(logic_error("This is not implemented yet."));
00043 }
00044
00045 template <typename Matrix>
00046 inline void swap_row(Matrix& A, typename Collection<Matrix>::size_type i,
00047 typename Collection<Matrix>::size_type j, tag::sparse, boost::mpl::false_)
00048 {
00049 MTL_THROW(logic_error("This is an ugly operation and not implemented yet."));
00050 }
00051
00052 }
00054 template <typename Matrix>
00055 typename mtl::traits::enable_if_matrix<Matrix>::type
00056 inline swap_row(Matrix& A, typename Collection<Matrix>::size_type i,
00057 typename Collection<Matrix>::size_type j)
00058 {
00059 if (i == j) return;
00060 detail::swap_row(A, i, j, typename mtl::traits::category<Matrix>::type(),
00061 mtl::traits::is_row_major<Matrix>());
00062 }
00063
00064 }
00065
00066
00067 namespace vector {
00069 template <typename Vector>
00070 typename mtl::traits::enable_if_vector<Vector>::type
00071 inline swap_row(Vector& v, typename Collection<Vector>::size_type i,
00072 typename Collection<Vector>::size_type j)
00073 {
00074 using std::swap;
00075 if (i == j) return;
00076 swap(v[i], v[j]);
00077 }
00078
00079 }
00080
00081 using matrix::swap_row;
00082 using vector::swap_row;
00083
00084 }
00085
00086 #endif // MTL_MATRIX_SWAP_ROW