/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2011 by O. Parcollet * * TRIQS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * TRIQS. If not, see . * ******************************************************************************/ #ifndef TRIQS_ARRAYS_EXPRESSION_VECTOR_ALGEBRA_H #define TRIQS_ARRAYS_EXPRESSION_VECTOR_ALGEBRA_H #include "./tools.hpp" #include "../matrix.hpp" namespace triqs { namespace arrays { template struct vector_expr : TRIQS_MODEL_CONCEPT(ImmutableVector) { typedef typename keeper_type::type L_t; typedef typename keeper_type::type R_t; L_t l; R_t r; template vector_expr(LL && l_, RR && r_) : l(std::forward(l_)), r(std::forward(r_)) {} static_assert( get_rank::value==0 || get_rank::value==0 || get_rank::value == get_rank::value, "rank mismatch in array operations"); typedef typename std::result_of(typename L_t::value_type,typename R_t::value_type)>::type value_type; typedef typename std::remove_reference::type>::type domain_type; domain_type domain() const { return combine_domain()(l,r); } mini_vector shape() const { return this->domain().lengths();} //size_t dim0() const { return this->domain().lengths()[0];} size_t size() const { return this->domain().lengths()[0];} //template value_type operator[](KeyType && key) const { return operation()(l[std::forward(key)] , r[std::forward(key)]);} template value_type operator()(Args && ... args) const { return operation()(l(std::forward(args)...) , r(std::forward(args)...));} friend std::ostream &operator <<(std::ostream &sout, vector_expr const &expr){return sout << "("<::name << " "< // a special case : the unary operator ! struct vector_unary_m_expr : TRIQS_MODEL_CONCEPT(ImmutableVector) { typedef typename keeper_type::type L_t; L_t l; template vector_unary_m_expr(LL && l_) : l(std::forward(l_)) {} typedef typename L_t::value_type value_type; typedef typename L_t::domain_type domain_type; domain_type domain() const { return l.domain(); } mini_vector shape() const { return this->domain().lengths();} //size_t dim0() const { return this->domain().lengths()[0];} size_t size() const { return this->domain().lengths()[0];} //template value_type operator[](KeyType&& key) const {return -l[key];} template value_type operator()(Args && ... args) const { return -l(std::forward(args)...);} friend std::ostream &operator <<(std::ostream &sout, vector_unary_m_expr const &expr){return sout << '-'<\ typename std::enable_if::value && TRAIT2 ::value, vector_expr>::type\ operator OP (A1 const & a1, A2 const & a2) { return vector_expr(a1,a2);} #define DELETE_OPERATOR(TAG, OP, TRAIT1, TRAIT2) \ template\ typename std::enable_if::value && TRAIT2 ::value, vector_expr>::type\ operator OP (A1 const & a1, A2 const & a2) = delete; DEFINE_OPERATOR(plus, +, ImmutableVector,ImmutableVector); DEFINE_OPERATOR(minus, -, ImmutableVector,ImmutableVector); DELETE_OPERATOR(multiplies, *, ImmutableVector,ImmutableVector); DELETE_OPERATOR(divides, /, ImmutableVector,ImmutableVector); DEFINE_OPERATOR(multiplies, *, is_in_ZRC,ImmutableVector); DEFINE_OPERATOR(multiplies, *, ImmutableVector,is_in_ZRC); DEFINE_OPERATOR(divides, /, ImmutableVector,is_in_ZRC); #undef DEFINE_OPERATOR // the unary is special template typename std::enable_if::value, vector_unary_m_expr>::type operator - (A1 const & a1) { return {a1};} template vector make_vector( Expr const & e) { return vector(e);} }}//namespace triqs::arrays #endif