/******************************************************************************* * * 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_TOOLS_H #define TRIQS_ARRAYS_EXPRESSION_TOOLS_H #include #include namespace triqs { namespace arrays { using utility::is_in_ZRC; /* namespace tags { struct plus{}; struct minus{}; struct multiplies{}; struct divides{}; } // The basic operations put in a template.... template struct operation; template<> struct operation { template auto operator()(L const & l, R const & r) const -> decltype(l+r) { return l+r;} static const char name = '+'; }; template<> struct operation { template auto operator()(L const & l, R const & r) const -> decltype(l-r) { return l-r;} static const char name = '-'; }; template<> struct operation { template auto operator()(L const & l, R const & r) const -> decltype(l*r) { return l*r;} static const char name = '*'; }; template<> struct operation { template auto operator()(L const & l, R const & r) const -> decltype(l/r) { return l/r;} static const char name = '/'; }; // The scalar ... template struct is_in_ZRC : boost::is_arithmetic {}; template<> struct is_in_ZRC : mpl::true_ {}; template struct is_in_ZRC > : mpl::true_ {}; */ // Wrapping the scalar in a little struct to recognize it // In a matrix expression, the evaluation differ (it is a scalar matrix ....) template struct _scalar_wrap; // First the scalar for an array expression ... template struct _scalar_wrap { typedef typename std::remove_reference::type value_type; S s; template _scalar_wrap(T && x):s(std::forward(x)){} template S operator[](KeyType&& key) const {return s;} template inline S operator()(Args && ... args) const { return s;} friend std::ostream &operator <<(std::ostream &sout, _scalar_wrap const &expr){return sout << expr.s; } }; // Second the scalar for a matrix expression ... template struct _scalar_wrap { static_assert(!std::is_same::value, "lll"); typedef typename std::remove_reference::type value_type; S s; value_type zero; template _scalar_wrap(T && x):s(std::forward(x)), zero{} {} template S operator[](KeyType&& key) const {return (key[0]==key[1] ? s : S());} template inline S operator()(A1 const & a1, A2 const & a2) const { return (a1==a2 ? s : zero);} friend std::ostream &operator <<(std::ostream &sout, _scalar_wrap const &expr){return sout << expr.s; } }; // type of the node template struct node_t : std::conditional::value, _scalar_wrap::type,IsMatrix>, typename utility::remove_rvalue_ref::type> {}; //std::conditional::value, _scalar_wrap::type,IsMatrix>, typename utility::remove_rvalue_ref::type> {}; // get the rank of something .... template struct get_rank { static constexpr int value = std::remove_reference::type::domain_type::rank;}; template struct get_rank<_scalar_wrap> { static constexpr int value =0;}; // //template struct keeper_type : boost::mpl::if_, _scalar_wrap, typename view_type_if_exists_else_type::type> {}; // Combine the two domains of LHS and RHS : need to specialize where there is a scalar struct combine_domain { template inline auto operator() (L const & l, R const & r) const -> decltype(l.domain()) { if (l.domain().lengths() != r.domain().lengths()) TRIQS_RUNTIME_ERROR << "Domain size mismatch : "<< l.domain().lengths()<<" vs" < auto operator() (_scalar_wrap const & w, R const & r) const -> decltype(r.domain()) { return r.domain();} template auto operator() (L const & l, _scalar_wrap const & w) const -> decltype(l.domain()) { return l.domain();} }; }}//namespace triqs::arrays #endif