Commit 4e3b2026 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

small workaround for mtl dense_vector 'bug' when using const value_type

parent e8a3e3b6
...@@ -159,7 +159,8 @@ namespace AMDiS { ...@@ -159,7 +159,8 @@ namespace AMDiS {
/// vector *= scalar (elementwise) /// vector *= scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
Vector<T>& operator*=(Vector<T>& v, S scal) typename enable_if< traits::is_multiplicable<S, T>, Vector<T> >::type &
operator*=(Vector<T>& v, S scal)
{ {
T *vIt; T *vIt;
for (vIt = v.begin(); vIt != v.end(); ++vIt) for (vIt = v.begin(); vIt != v.end(); ++vIt)
...@@ -169,17 +170,17 @@ namespace AMDiS { ...@@ -169,17 +170,17 @@ namespace AMDiS {
/// vector := vector * scalar (elementwise) /// vector := vector * scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
Vector<typename traits::mult_type<T, S>::type> typename enable_if< traits::is_multiplicable<S, T>, Vector<T> >::type
operator*(Vector<T> const& v, S scal) operator*(Vector<T> result, S scal)
{ {
Vector<typename traits::mult_type<T, S>::type> result = v;
result *= scal; result *= scal;
return result; return result;
} }
/// vector /= scalar (elementwise) /// vector /= scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
Vector<T>& operator/=(Vector<T>& v, S scal) typename enable_if< traits::is_multiplicable<S, T>, Vector<T> >::type &
operator/=(Vector<T>& v, S scal)
{ {
T *vIt; T *vIt;
for (vIt = v.begin(); vIt != v.end(); ++vIt) for (vIt = v.begin(); vIt != v.end(); ++vIt)
...@@ -189,10 +190,9 @@ namespace AMDiS { ...@@ -189,10 +190,9 @@ namespace AMDiS {
/// vector := vector / scalar (elementwise) /// vector := vector / scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
Vector<typename traits::mult_type<T, S>::type> typename enable_if< traits::is_multiplicable<S, T>, Vector<T> >::type
operator/(Vector<T> const& v, S scal) operator/(Vector<T> result, S scal)
{ {
Vector<typename traits::mult_type<T, S>::type> result = v;
result /= scal; result /= scal;
return result; return result;
} }
...@@ -319,7 +319,7 @@ namespace AMDiS { ...@@ -319,7 +319,7 @@ namespace AMDiS {
/// vector := vector * scalar (elementwise) /// vector := vector * scalar (elementwise)
template<typename T, typename S> template<typename T, typename S>
WorldVector<T> typename enable_if< traits::is_multiplicable<S, T>, WorldVector<T> >::type
operator*(WorldVector<T> const& v, S scal) operator*(WorldVector<T> const& v, S scal)
{ {
WorldVector<T> result = v; WorldVector<T> result = v;
...@@ -329,7 +329,7 @@ namespace AMDiS { ...@@ -329,7 +329,7 @@ namespace AMDiS {
/// vector := scalar * vector (elementwise) /// vector := scalar * vector (elementwise)
template<typename T, typename S> template<typename T, typename S>
WorldVector<T> typename enable_if< traits::is_multiplicable<S, T>, WorldVector<T> >::type
operator*(S scal, WorldVector<T> const& v) operator*(S scal, WorldVector<T> const& v)
{ {
WorldVector<T> result = v; WorldVector<T> result = v;
...@@ -339,7 +339,7 @@ namespace AMDiS { ...@@ -339,7 +339,7 @@ namespace AMDiS {
/// vector := vector / scalar (elementwise) /// vector := vector / scalar (elementwise)
template<typename T, typename S> template<typename T, typename S>
WorldVector<T> typename enable_if< traits::is_multiplicable<S, T>, WorldVector<T> >::type
operator/(WorldVector<T> const& v, S scal) operator/(WorldVector<T> const& v, S scal)
{ {
WorldVector<T> result = v; WorldVector<T> result = v;
...@@ -359,7 +359,7 @@ namespace AMDiS { ...@@ -359,7 +359,7 @@ namespace AMDiS {
/// matrix := matrix * scalar (elementwise) /// matrix := matrix * scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
WorldMatrix<T> typename enable_if< traits::is_multiplicable<S, T>, WorldMatrix<T> >::type
operator*(WorldMatrix<T> const& m, S scal) operator*(WorldMatrix<T> const& m, S scal)
{ {
WorldMatrix<T> result = m; WorldMatrix<T> result = m;
...@@ -369,7 +369,7 @@ namespace AMDiS { ...@@ -369,7 +369,7 @@ namespace AMDiS {
/// matrix := scalar * matrix (elementwise) /// matrix := scalar * matrix (elementwise)
template <typename T, typename S> template <typename T, typename S>
WorldMatrix<T> typename enable_if< traits::is_multiplicable<S, T>, WorldMatrix<T> >::type
operator*(S scal, WorldMatrix<T> const& m) operator*(S scal, WorldMatrix<T> const& m)
{ {
WorldMatrix<T> result = m; WorldMatrix<T> result = m;
...@@ -379,7 +379,7 @@ namespace AMDiS { ...@@ -379,7 +379,7 @@ namespace AMDiS {
/// matrix := matrix / scalar (elementwise) /// matrix := matrix / scalar (elementwise)
template <typename T, typename S> template <typename T, typename S>
WorldMatrix<T> typename enable_if< traits::is_multiplicable<S, T>, WorldMatrix<T> >::type
operator/(WorldMatrix<T> const& m, S scal) operator/(WorldMatrix<T> const& m, S scal)
{ {
WorldMatrix<T> result = m; WorldMatrix<T> result = m;
......
...@@ -59,7 +59,7 @@ namespace AMDiS ...@@ -59,7 +59,7 @@ namespace AMDiS
using namespace mtl::vector; using namespace mtl::vector;
typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type> param; typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type> param;
mtl::dense_vector<const value_type, param> tmp(AMDiS::size(v), v.begin()); mtl::dense_vector<value_type, param> tmp(AMDiS::size(v), const_cast<value_type*>(v.begin()));
return mtl::two_norm(tmp); return mtl::two_norm(tmp);
} }
...@@ -110,7 +110,7 @@ namespace AMDiS ...@@ -110,7 +110,7 @@ namespace AMDiS
using namespace mtl::vector; using namespace mtl::vector;
typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type> param; typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type> param;
mtl::dense_vector<const value_type, param> tmp(AMDiS::size(v), v.begin()); mtl::dense_vector<value_type, param> tmp(AMDiS::size(v), const_cast<value_type*>(v.begin()));
return mtl::vector::one_norm(tmp); return mtl::vector::one_norm(tmp);
} }
......
...@@ -64,8 +64,8 @@ namespace AMDiS ...@@ -64,8 +64,8 @@ namespace AMDiS
using namespace mtl::vector; using namespace mtl::vector;
typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type1> param1; typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type1> param1;
typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type2> param2; typedef parameters<mtl::col_major, non_fixed::dimension, false, size_type2> param2;
mtl::dense_vector<const value_type1, param1> tmp1(AMDiS::size(v1), v1.begin()); mtl::dense_vector<value_type1, param1> tmp1(AMDiS::size(v1), const_cast<value_type1*>(v1.begin()));
mtl::dense_vector<const value_type2, param2> tmp2(AMDiS::size(v2), v2.begin()); mtl::dense_vector<value_type2, param2> tmp2(AMDiS::size(v2), const_cast<value_type2*>(v2.begin()));
return mtl::dot(tmp1, tmp2); return mtl::dot(tmp1, tmp2);
} }
......
...@@ -61,6 +61,15 @@ namespace AMDiS ...@@ -61,6 +61,15 @@ namespace AMDiS
// dummy type // dummy type
typedef boost::numeric::ublas::error_cant_deduce_type no_valid_type; typedef boost::numeric::ublas::error_cant_deduce_type no_valid_type;
template <class A, class B>
struct is_multiplicable : boost::mpl::not_<
boost::is_same< typename mtl::Multiplicable<A,B>::result_type,
no_valid_type > > {};
template <class A, class B>
struct is_addable : boost::mpl::not_<
boost::is_same< typename mtl::Addable<A,B>::result_type,
no_valid_type > > {};
#ifdef HAS_CPP11 #ifdef HAS_CPP11
template <typename T> template <typename T>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment