00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_RIGHT_SCALE_INPLACE_INCLUDE
00013 #define MTL_RIGHT_SCALE_INPLACE_INCLUDE
00014
00015 #include <boost/numeric/mtl/mtl_fwd.hpp>
00016 #include <boost/numeric/mtl/utility/tag.hpp>
00017 #include <boost/numeric/mtl/operation/assign_each_nonzero.hpp>
00018 #include <boost/numeric/mtl/operation/mult.hpp>
00019
00020 #include <boost/lambda/lambda.hpp>
00021
00022
00023 namespace mtl {
00024
00025
00027 template <typename Factor, typename Collection>
00028 void right_scale_inplace(Collection& c, const Factor& alpha, tag::scalar)
00029 {
00030 assign_each_nonzero(c, boost::lambda::_1 * alpha);
00031 }
00032
00033 template <typename Factor, typename Matrix>
00034 void right_scale_inplace(Matrix& m, tag::matrix, const Factor& alpha, tag::matrix)
00035 {
00036 using mtl::swap;
00037
00038 Matrix tmp(num_rows(m), num_cols(m));
00039 mult(m, alpha, tmp);
00040 swap(m, tmp);
00041 }
00042
00043 #if 0 // Row vector times Matrix is not yet implemented
00044 template <typename Factor, typename Vector>
00045 void right_scale_inplace(Vector& v, tag::vector, const Factor& alpha, tag::matrix)
00046 {
00047 using mtl::swap;
00048
00049 Vector tmp(size(v));
00050 mult(v, alpha, tmp);
00051 swap(v, tmp);
00052 }
00053 #endif
00054
00056 template <typename Factor, typename Collection>
00057 void right_scale_inplace(Collection& c, const Factor& alpha, tag::matrix)
00058 {
00059
00060 right_scale_inplace(c, typename traits::category<Collection>::type(), alpha, tag::matrix());
00061 }
00062
00064 template <typename Factor, typename Collection>
00065 void right_scale_inplace(Collection& c, const Factor& alpha)
00066 {
00067
00068 right_scale_inplace(c, alpha, typename traits::category<Factor>::type());
00069 }
00070
00071
00072
00073
00074 }
00075
00076 #endif // MTL_RIGHT_SCALE_INPLACE_INCLUDE