/*******************************************************************************
*
* 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_MAPPED_FNT_H
#define TRIQS_ARRAYS_MAPPED_FNT_H
#include "./functional/map.hpp"
#include
namespace triqs { namespace arrays {
// complex conjugation for integers
inline int conj(int x) { return x; }
inline long conj(long x) { return x; }
inline long long conj(long long x) { return x; }
inline double conj(double x) { return x; }
//C++14 will simply be ...
//template decltype(auto) abs(A && a) { return map( [](auto const &x) { using std::abs; return abs(a);}, std::forward(a));}
using std::pow;
template TYPE_ENABLE_IF(T, std::is_integral) pow(T x, int n) { return (n==0 ? 1 : pow(x,n-1)*x);}
struct pow_wrap {
int n;
template A operator()( A const & a) const { return pow(a,n);}
};
template
typename boost::lazy_enable_if_c::value,std::result_of(A)>>::type
pow(A && a, int n) { return map(pow_wrap{n})(std::forward(a)); }
#define MAP_IT(FNT) \
using std::FNT;\
struct __triqs_##FNT##_wrap { template auto operator()(A const & a) const DECL_AND_RETURN(FNT(a)); };\
template \
typename boost::lazy_enable_if_c::value,std::result_of(A)>>::type\
FNT(A && a) { return map(__triqs_##FNT##_wrap{})(std::forward(a)); }
#define TRIQS_ARRAYS_MATH_FNT (abs)(real)(imag)(floor)(conj)
#define AUX(r, data, elem) MAP_IT(elem)
BOOST_PP_SEQ_FOR_EACH(AUX , nil , TRIQS_ARRAYS_MATH_FNT);
#undef AUX
#undef MAP_IT
#undef TRIQS_ARRAYS_MATH_FNT
// Functions only defined for vector, array but NOT for matrix. They act element wise.
#define MAP_IT(FNT) \
using std::FNT;\
struct __triqs_##FNT##_wrap { template auto operator()(A const & a) const DECL_AND_RETURN(FNT(a)); };\
template \
typename boost::lazy_enable_if_c::value||ImmutableVector::value,std::result_of(A)>>::type\
FNT(A && a) { return map(__triqs_##FNT##_wrap{})(std::forward(a)); }
#define TRIQS_ARRAYS_MATH_FNT (exp)(cos)(sin)(tan)(cosh)(sinh)(tanh)(acos)(asin)(atan)(log)(sqrt)
#define AUX(r, data, elem) MAP_IT(elem)
BOOST_PP_SEQ_FOR_EACH(AUX , nil , TRIQS_ARRAYS_MATH_FNT);
#undef AUX
#undef MAP_IT
#undef TRIQS_ARRAYS_MATH_FNT
}}//namespace triqs::arrays
#endif