[shark] 58/79: fixed a small bug in proxy assignment and added a template function eval_block which checks at compile time whether the expression is a block expression. If yes, it is evaluated and a temporary is returned, otherwise the expression is returned untouched

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Nov 26 15:41:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository shark.

commit 54cf77f5c5c6ae65c1e40efb997a2e2478b7d52d
Author: Oswin <oswin.krause at di.ku.dk>
Date:   Mon Oct 26 08:16:31 2015 +0100

    fixed a small bug in proxy assignment and added a template function eval_block which checks at compile time whether the expression is a block expression. If yes, it is evaluated and a temporary is returned, otherwise the expression is returned untouched
---
 include/shark/LinAlg/BLAS/assignment.hpp | 76 +++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 2 deletions(-)

diff --git a/include/shark/LinAlg/BLAS/assignment.hpp b/include/shark/LinAlg/BLAS/assignment.hpp
index d64f5f0..30ccf97 100644
--- a/include/shark/LinAlg/BLAS/assignment.hpp
+++ b/include/shark/LinAlg/BLAS/assignment.hpp
@@ -59,7 +59,7 @@ namespace detail{
 	}
 	template<class VecX, class VecV>
 	void plus_assign(vector_expression<VecX>& x, vector_expression<VecV> const& v,blockwise_tag){
-		x().plus_assign_to(v);
+		v().plus_assign_to(x);
 	}
 	template<class VecX, class VecV>
 	void minus_assign(vector_expression<VecX>& x, vector_expression<VecV> const& v,elementwise_tag){
@@ -67,7 +67,7 @@ namespace detail{
 	}
 	template<class VecX, class VecV>
 	void minus_assign(vector_expression<VecX>& x, vector_expression<VecV> const& v,blockwise_tag){
-		x().minus_assign_to(v);
+		v().minus_assign_to(x);
 	}
 	template<class VecX, class VecV>
 	void multiply_assign(vector_expression<VecX>& x, vector_expression<VecV> const& v,elementwise_tag){
@@ -560,5 +560,77 @@ noalias_proxy<C> noalias(temporary_proxy<C> lvalue) {
 	return noalias_proxy<C> (static_cast<C&>(lvalue));
 }
 
+
+
+
+//////////////////////////////////////////////////////////////////////
+/////Evaluate blockwise expressions
+//////////////////////////////////////////////////////////////////////
+namespace detail{
+	template<class E>
+	blas::vector_expression<E> const& evaluate_block(
+		blas::vector_expression<E> const& e,
+		elementwise_tag
+	){
+		return e;
+	}
+	template<class E>
+	typename vector_temporary<E>::type evaluate_block(
+		blas::vector_expression<E> const& e,
+		blockwise_tag
+	){
+		return e();
+	}
+	template<class E>
+	blas::matrix_expression<E> const& evaluate_block(
+		blas::matrix_expression<E> const& e,
+		elementwise_tag
+	){
+		return e;
+	}
+	template<class E>
+	typename matrix_temporary<E>::type evaluate_block(
+		blas::matrix_expression<E> const& e,
+		blockwise_tag
+	){
+		return e();
+	}
+}
+
+///\brief conditionally evaluates a vector expression if it is a block expression
+///
+/// If the expression is a block expression, a temporary vector is created to which
+/// the expression is assigned, which is then returned, otherwise the expression itself
+/// is returned
+template<class E>
+typename boost::mpl::if_<
+	boost::is_same<
+		typename E::evaluation_category,
+		blockwise_tag
+	>,
+	typename vector_temporary<E>::type,
+	blas::vector_expression<E> const&
+>::type
+eval_block(blas::vector_expression<E> const& e){
+	return detail::evaluate_block(e,typename E::evaluation_category());
+}
+///\brief conditionally evaluates a matrix expression if it is a block expression
+///
+/// If the expression is a block expression, a temporary matrix is created to which
+/// the expression is assigned, which is then returned, otherwise the expression itself
+/// is returned
+template<class E>
+typename boost::mpl::if_<
+	boost::is_same<
+		typename E::evaluation_category,
+		blockwise_tag
+	>,
+	typename matrix_temporary<E>::type,
+	blas::matrix_expression<E> const&
+>::type
+eval_block(blas::matrix_expression<E> const& e){
+	return detail::evaluate_block(e,typename E::evaluation_category());
+}
+
 }}
 #endif
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/shark.git



More information about the debian-science-commits mailing list