1#ifndef _RHEOLEF_VEC_EXPR_v2_H
2#define _RHEOLEF_VEC_EXPR_v2_H
45#include "rheolef/vec.h"
46#include "rheolef/dis_inner_product.h"
47#include "rheolef/dis_accumulate.h"
48#include "rheolef/expr_utilities.h"
61template<
class T>
struct is_vec : std::false_type {};
62template<
class T,
class M>
struct is_vec<
vec<
T,
M> > : std::true_type {};
74template <
class Op,
class Expr>
90 template <
class BinaryOp,
class Constant>
94 template <
class BinaryOp,
class Constant>
129#define _RHEOLEF_vec_expr_v2_unary_operator(OP, FUNCTOR) \
130template <class Expr> \
134 details::is_vec_expr_v2_arg<Expr>::value, \
135 details::vec_expr_v2_unary< \
140operator OP (const Expr& expr) \
142 typedef details::vec_expr_v2_unary <FUNCTOR, Expr> expr_t; \
143 return expr_t (FUNCTOR(), expr); \
148#undef _RHEOLEF_vec_expr_v2_unary_operator
155template <
class Op,
class Expr1,
class Expr2>
160 typename Expr1::value_type,
175 check_macro (expr1.size() == expr2.size(),
"linear binary vec expression: incompatible sizes "
176 << expr1.size() <<
" and " << expr2.size());
189 typename Expr1::value_type,
212template <
class Op,
class Expr1,
class Expr2,
class Sfinae =
void>
216template <
class Op,
class Expr1,
class Expr2>
218 typename
std::enable_if<
219 details::is_vec_expr_v2_arg<Expr1>::value &&
220 details::is_vec_expr_v2_arg<Expr2>::value>::type>
222 typedef vec_expr_v2_binary <Op,Expr1,Expr2>
type;
225template <
class Op,
class Expr1,
class Expr2>
227 typename
std::enable_if<
228 details::is_rheolef_arithmetic<Expr1>::value &&
229 details::is_vec_expr_v2_arg<Expr2>::value>::type>
231 typedef generic_binder1st <Op, Expr1>
fun_t;
232 typedef vec_expr_v2_unary <fun_t,Expr2>
type;
235template <
class Op,
class Expr1,
class Expr2>
237 typename
std::enable_if<
238 details::is_vec_expr_v2_arg<Expr1>::value &&
239 details::is_rheolef_arithmetic<Expr2>::value>::type>
241 typedef generic_binder2nd <Op, Expr2>
fun_t;
242 typedef vec_expr_v2_unary <fun_t,Expr1>
type;
248#define _RHEOLEF_vec_expr_v2_binary_operator(OP, FUNCTOR) \
249template <class Expr1, class Expr2> \
253 (details::is_vec_expr_v2_arg<Expr1>::value && \
254 details::is_vec_expr_v2_arg<Expr2>::value) || \
255 (details::is_rheolef_arithmetic<Expr1>::value && \
256 details::is_vec_expr_v2_arg<Expr2>::value) || \
257 (details::is_vec_expr_v2_arg<Expr1>::value && \
258 details::is_rheolef_arithmetic<Expr2>::value), \
260 details::vec_expr_v2_binary_traits< \
265operator OP (const Expr1& expr1, const Expr2& expr2) \
267 typedef typename details::vec_expr_v2_binary_traits <FUNCTOR, Expr1, Expr2>::type expr_t; \
268 return expr_t (FUNCTOR(), expr1, expr2); \
272#undef _RHEOLEF_vec_expr_v2_binary_operator
275template <
class Expr1,
class Expr2>
279 (details::is_rheolef_arithmetic<Expr1>::value &&
282 details::is_rheolef_arithmetic<Expr2>::value),
285 details::generic_multiplies<>,
291 typedef details::generic_multiplies<> fun_t;
292 typedef typename details::vec_expr_v2_binary_traits <fun_t, Expr1, Expr2>::type expr_t;
293 return expr_t (fun_t(), expr1, expr2);
297template <
class Expr1,
class Expr2>
301 (details::is_vec_expr_v2_arg<Expr1>::value &&
302 details::is_rheolef_arithmetic<Expr2>::value),
304 details::vec_expr_v2_binary_traits<
305 details::generic_divides<>,
309operator/ (
const Expr1& expr1,
const Expr2& expr2)
311 typedef details::generic_divides<> fun_t;
312 typedef typename details::vec_expr_v2_binary_traits <fun_t, Expr1, Expr2>::type expr_t;
313 return expr_t (fun_t(), expr1, expr2);
322template<
class T,
class M>
323template<
class Expr,
class Sfinae>
331template<
class T,
class M>
332template <
class Expr,
class Sfinae>
338 resize (expr.ownership());
342 "vec = vec_expression : incompatible size "
343 << n <<
" and " << expr.size());
352#define _RHEOLEF_vec_expr_v2_op_assign(OP, FUNCTOR) \
353template<class T, class M, class Expr> \
355typename std::enable_if< \
356 details::is_vec_expr_v2_arg<Expr>::value, \
358operator OP (vec<T,M>& x, const Expr& expr) \
360 check_macro (x.size() == expr.size(), "vec " << #OP << " vec_expression : incompatible spaces " \
361 << x.size() << " and " << expr.size()); \
362 details::assign_with_operator (x.begin(), x.end(), expr.begin(), FUNCTOR()); \
367#undef _RHEOLEF_vec_expr_v2_op_assign
370#define _RHEOLEF_vec_expr_v2_op_assign_constant(OP, FUNCTOR) \
371template<class T, class M, class Expr> \
373typename std::enable_if< \
374 details::is_rheolef_arithmetic<Expr>::value, \
376operator OP (vec<T,M>& x, const Expr& expr) \
378 details::assign_with_operator (x.begin(), x.end(), details::iterator_on_constant<Expr>(expr), FUNCTOR()); \
385#undef _RHEOLEF_vec_expr_v2_op_assign_constant
391template <
class Expr1,
class Expr2>
398 typename Expr1::float_type,
399 typename Expr2::float_type>::type
401dot (
const Expr1& expr1,
const Expr2& expr2)
403 typedef typename Expr1::memory_type
M;
404 return dis_inner_product (expr1.begin(), expr2.begin(), expr1.size(), expr1.ownership().comm(),
M());
407template <
class Expr1,
class Expr2>
411 details::is_rheolef_arithmetic<Expr1>::value &&
413 typename Expr2::float_type
415dot (
const Expr1& expr1,
const Expr2& expr2)
417 typedef typename Expr2::memory_type
M;
418 return expr1*
dis_accumulate (expr2.begin(), expr2.size(), expr2.ownership().comm(),
M());
421template <
class Expr1,
class Expr2>
425 details::is_vec_expr_v2_arg<Expr1>::value &&
426 details::is_rheolef_arithmetic<Expr2>::value,
427 typename Expr1::float_type
429dot (
const Expr1& expr1,
const Expr2& expr2)
431 typedef typename Expr1::memory_type
M;
432 return dis_accumulate (expr1.begin(), expr1.size(), expr1.ownership().comm(),
M())*expr2;
see the disarray page for the full documentation
see the distributor page for the full documentation
size_type size(size_type iproc) const
see the vec page for the full documentation
vec< T, M > & operator=(const vec< T, M > &x)
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
void assign_with_operator(ForwardIterator first, ForwardIterator last, InputIterator iter_rhs, OpAssign op_assign)
This file is part of Rheolef.
std::iterator_traits< InputIterator >::value_type dis_accumulate(InputIterator first, Size n, const distributor::communicator_type &comm, sequential)
promote< typenamestd::iterator_traits< InputIterator1 >::value_type, typenamestd::iterator_traits< InputIterator2 >::value_type >::type dis_inner_product(InputIterator1 first1, InputIterator2 first2, Size n, const distributor::communicator_type &comm, sequential)
rheolef::std enable_if ::type dot const Expr1 expr1, const Expr2 expr2 dot(const Expr1 &expr1, const Expr2 &expr2)
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
std::forward_iterator_tag iterator_category
const_iterator(Op op, expr1_const_iterator iter1, expr2_const_iterator iter2)
expr2_const_iterator _iter2
promote< typenameExpr1::value_type, typenameExpr2::value_type >::type value_type
const_iterator & operator++()
value_type operator*() const
std::ptrdiff_t difference_type
expr1_const_iterator _iter1
generic_binder2nd< Op, Expr2 > fun_t
vec_expr_v2_unary< fun_t, Expr1 > type
vec_expr_v2_binary< Op, Expr1, Expr2 > type
generic_binder1st< Op, Expr1 > fun_t
vec_expr_v2_unary< fun_t, Expr2 > type
const_iterator begin() const
Expr2::const_iterator expr2_const_iterator
Expr1::const_iterator expr1_const_iterator
expr2_const_iterator _iter2
vec_expr_v2_binary(const Op &op, const Expr1 &expr1, const Expr2 &expr2)
promote< typenameExpr1::value_type, typenameExpr2::value_type >::type value_type
Expr1::size_type size_type
const distributor _ownership
Expr1::memory_type memory_type
const distributor & ownership() const
float_traits< value_type >::type float_type
expr1_const_iterator _iter1
std::forward_iterator_tag iterator_category
expr_const_iterator _expr_iter
const_iterator(Op op, expr_const_iterator expr_iter)
const_iterator & operator++()
Expr::value_type value_type
value_type operator*() const
std::ptrdiff_t difference_type
const_iterator begin() const
Expr::const_iterator expr_const_iterator
const expr_const_iterator _expr_iter
vec_expr_v2_unary(const Op &op, const Expr &expr)
vec_expr_v2_unary(const BinaryOp &binop, const Constant &c, const Expr &expr)
Expr::size_type size_type
const distributor _ownership
vec_expr_v2_unary(const BinaryOp &binop, const Expr &expr, const Constant &c)
Expr::value_type value_type
Expr::memory_type memory_type
const distributor & ownership() const
float_traits< value_type >::type float_type
#define _RHEOLEF_vec_expr_v2_op_assign(OP, FUNCTOR)
#define _RHEOLEF_vec_expr_v2_op_assign_constant(OP, FUNCTOR)
#define _RHEOLEF_vec_expr_v2_unary_operator(OP, FUNCTOR)
#define _RHEOLEF_vec_expr_v2_binary_operator(OP, FUNCTOR)