/*******************************************************************************
*
* 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
namespace triqs { namespace arrays {
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 S value_type;
S s; scalar_wrap(S const &s_):s(s_){}
template value_type operator[](KeyType&& key) const {return s;}
template inline value_type 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 {
typedef S value_type;
S s; scalar_wrap(S const &s_):s(s_){}
template value_type operator[](KeyType&& key) const {return (key[0]==key[1] ? s : S());}
template inline value_type operator()(A1 && a1, A2 && a2) const { return (a1==a2 ? s : S());}
friend std::ostream &operator <<(std::ostream &sout, scalar_wrap const &expr){return sout << expr.s; }
};
// get the rank of something ....
template struct get_rank { static constexpr int value = std::remove_reference::type::domain_type::rank;};
template struct get_rank> { 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();}
};
template
struct type_of_mult{
//typedef typename boost::remove_reference::type T1; typedef typename boost::remove_reference::type T2;
//typedef BOOST_TYPEOF_TPL( (*(pseudo_default_construct())) * (*(pseudo_default_construct()))) type;
typedef decltype ( std::declval::type>() * std::declval::type>() ) type;
};
}}//namespace triqs::arrays
#endif