00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_LEFT_SCALE_INPLACE_INCLUDE
00013 #define MTL_LEFT_SCALE_INPLACE_INCLUDE
00014
00015 #include <boost/numeric/mtl/mtl_fwd.hpp>
00016 #include <boost/numeric/mtl/utility/category.hpp>
00017 #include <boost/numeric/mtl/utility/tag.hpp>
00018 #include <boost/numeric/mtl/utility/enable_if.hpp>
00019 #include <boost/numeric/mtl/operation/assign_each_nonzero.hpp>
00020 #include <boost/numeric/mtl/operation/mult.hpp>
00021 #include <boost/numeric/mtl/operation/left_scale_inplace.hpp>
00022
00023 #include <boost/lambda/lambda.hpp>
00024
00025
00026 namespace mtl {
00027
00028 namespace impl {
00029
00030 template <typename Factor, typename Collection>
00031 inline Collection& left_scale_inplace(const Factor& alpha, tag::scalar, Collection& c)
00032 {
00033 assign_each_nonzero(c, alpha * boost::lambda::_1);
00034 return c;
00035 }
00036
00037 template <typename Factor, typename Collection>
00038 inline Collection& left_scale_inplace(const Factor& alpha, tag::matrix, Collection& c)
00039 {
00040 Collection tmp(alpha * c);
00041 swap(tmp, c);
00042 return c;
00043 }
00044 }
00045
00046 namespace matrix {
00047
00049 template <typename Factor, typename Matrix>
00050 typename mtl::traits::enable_if_matrix<Matrix, Matrix&>::type
00051 inline left_scale_inplace(const Factor& alpha, Matrix& A)
00052 {
00053 return mtl::impl::left_scale_inplace(alpha, typename mtl::traits::category<Factor>::type(), A);
00054 }
00055 }
00056
00057 namespace vector {
00058
00060 template <typename Factor, typename Vector>
00061 typename mtl::traits::enable_if_vector<Vector, Vector&>::type
00062 inline left_scale_inplace(const Factor& alpha, Vector& v)
00063 {
00064 return mtl::impl::left_scale_inplace(alpha, typename mtl::traits::category<Factor>::type(), v);
00065 }
00066 }
00067
00068 using vector::left_scale_inplace;
00069 using matrix::left_scale_inplace;
00070
00071 }
00072
00073 #endif // MTL_LEFT_SCALE_INPLACE_INCLUDE