2013-07-17 19:24:07 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef TRIQS_ARRAYS_MAPPED_FNT_H
|
|
|
|
#define TRIQS_ARRAYS_MAPPED_FNT_H
|
|
|
|
#include "./functional/map.hpp"
|
|
|
|
#include <boost/preprocessor/seq/for_each.hpp>
|
|
|
|
namespace triqs { namespace arrays {
|
|
|
|
|
2013-12-21 20:07:52 +01:00
|
|
|
// not for libc++ (already defined)
|
|
|
|
#if !defined(_LIBCPP_VERSION)
|
2013-11-18 20:45:42 +01:00
|
|
|
// complex conjugation for integers
|
2013-11-20 15:11:29 +01:00
|
|
|
inline int conj(int x) { return x; }
|
|
|
|
inline long conj(long x) { return x; }
|
|
|
|
inline long long conj(long long x) { return x; }
|
2013-12-21 20:07:52 +01:00
|
|
|
inline std::complex<double> conj(double x) { return x; }
|
|
|
|
#endif
|
2013-11-18 20:45:42 +01:00
|
|
|
|
2013-09-10 11:18:04 +02:00
|
|
|
//C++14 will simply be ...
|
|
|
|
//template <typename A> decltype(auto) abs(A && a) { return map( [](auto const &x) { using std::abs; return abs(a);}, std::forward<A>(a));}
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
using std::pow;
|
|
|
|
template<typename T> TYPE_ENABLE_IF(T, std::is_integral<T>) pow(T x, int n) { return (n==0 ? 1 : pow(x,n-1)*x);}
|
|
|
|
struct pow_wrap {
|
2013-09-10 11:18:04 +02:00
|
|
|
int n;
|
|
|
|
template<typename A> A operator()( A const & a) const { return pow(a,n);}
|
2013-07-17 19:24:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A>
|
2013-09-10 11:18:04 +02:00
|
|
|
typename boost::lazy_enable_if_c<!ImmutableMatrix<A>::value,std::result_of<map_impl<pow_wrap,1>(A)>>::type
|
|
|
|
pow(A && a, int n) { return map(pow_wrap{n})(std::forward<A>(a)); }
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
#define MAP_IT(FNT) \
|
|
|
|
using std::FNT;\
|
2013-09-10 11:18:04 +02:00
|
|
|
struct __triqs_##FNT##_wrap { template<typename A> auto operator()(A const & a) const DECL_AND_RETURN(FNT(a)); };\
|
|
|
|
template <typename A> \
|
|
|
|
typename boost::lazy_enable_if_c<ImmutableCuboidArray<A>::value,std::result_of<map_impl<__triqs_##FNT##_wrap,1>(A)>>::type\
|
|
|
|
FNT(A && a) { return map(__triqs_##FNT##_wrap{})(std::forward<A>(a)); }
|
|
|
|
|
2013-11-18 20:45:42 +01:00
|
|
|
#define TRIQS_ARRAYS_MATH_FNT (abs)(real)(imag)(floor)(conj)
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
#define AUX(r, data, elem) MAP_IT(elem)
|
2013-09-10 11:18:04 +02:00
|
|
|
BOOST_PP_SEQ_FOR_EACH(AUX , nil , TRIQS_ARRAYS_MATH_FNT);
|
2013-07-17 19:24:07 +02:00
|
|
|
#undef AUX
|
|
|
|
#undef MAP_IT
|
2013-09-10 11:18:04 +02:00
|
|
|
#undef TRIQS_ARRAYS_MATH_FNT
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-10 11:18:04 +02:00
|
|
|
// 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<typename A> auto operator()(A const & a) const DECL_AND_RETURN(FNT(a)); };\
|
|
|
|
template <typename A> \
|
|
|
|
typename boost::lazy_enable_if_c<ImmutableArray<A>::value||ImmutableVector<A>::value,std::result_of<map_impl<__triqs_##FNT##_wrap,1>(A)>>::type\
|
|
|
|
FNT(A && a) { return map(__triqs_##FNT##_wrap{})(std::forward<A>(a)); }
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-10 11:18:04 +02:00
|
|
|
#define TRIQS_ARRAYS_MATH_FNT (exp)(cos)(sin)(tan)(cosh)(sinh)(tanh)(acos)(asin)(atan)(log)(sqrt)
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-09-10 11:18:04 +02:00
|
|
|
#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
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
}}//namespace triqs::arrays
|
|
|
|
#endif
|
|
|
|
|