diff --git a/test/triqs/arrays/mapped_functions.cpp b/test/triqs/arrays/mapped_functions.cpp index faf8ab72..a506b563 100644 --- a/test/triqs/arrays/mapped_functions.cpp +++ b/test/triqs/arrays/mapped_functions.cpp @@ -53,6 +53,8 @@ template void test( T val=1 ) { auto aa = array{ { 1,2}, {3,4}}; TEST(make_matrix(exp(aa))); + TEST(make_matrix(conj(A))); + // does not compile, since exp is only element wise at the moment // to do : implement it for matrix... //TEST(make_matrix(exp( matrix{{ 1,2}, {3,4}} ))); @@ -60,7 +62,7 @@ template void test( T val=1 ) { int main(int argc, char **argv) { - + conj (8); test(); test(); test(); diff --git a/test/triqs/arrays/mapped_functions.output b/test/triqs/arrays/mapped_functions.output index b6584857..5843c2db 100644 --- a/test/triqs/arrays/mapped_functions.output +++ b/test/triqs/arrays/mapped_functions.output @@ -42,6 +42,10 @@ (make_matrix(exp(aa))) ---> [[2.71828,7.38906] [20.0855,54.5982]] +(make_matrix(conj(A))) ---> +[[1,3,5] + [2,4,6] + [3,5,7]] (A) ---> [[1,3,5] [2,4,6] @@ -86,6 +90,10 @@ (make_matrix(exp(aa))) ---> [[2.71828,7.38906] [20.0855,54.5982]] +(make_matrix(conj(A))) ---> +[[1,3,5] + [2,4,6] + [3,5,7]] (A) ---> [[1,3,5] [2,4,6] @@ -130,6 +138,10 @@ (make_matrix(exp(aa))) ---> [[2.71828,7.38906] [20.0855,54.5982]] +(make_matrix(conj(A))) ---> +[[(1,0),(3,0),(5,0)] + [(2,0),(4,0),(6,0)] + [(3,0),(5,0),(7,0)]] (A) ---> [[(1,0),(3,0),(5,0)] [(2,0),(4,0),(6,0)] @@ -174,6 +186,10 @@ (make_matrix(exp(aa))) ---> [[(2.71828,0),(7.38906,0)] [(20.0855,0),(54.5982,0)]] +(make_matrix(conj(A))) ---> +[[(1,0),(3,0),(5,0)] + [(2,0),(4,0),(6,0)] + [(3,0),(5,0),(7,0)]] (A) ---> [[(-2,3),(-6,9),(-10,15)] [(-4,6),(-8,12),(-12,18)] @@ -218,3 +234,7 @@ (make_matrix(exp(aa))) ---> [[(2.71828,0),(7.38906,0)] [(20.0855,0),(54.5982,0)]] +(make_matrix(conj(A))) ---> +[[(-2,-3),(-6,-9),(-10,-15)] + [(-4,-6),(-8,-12),(-12,-18)] + [(-6,-9),(-10,-15),(-14,-21)]] diff --git a/triqs/arrays/mapped_functions.hpp b/triqs/arrays/mapped_functions.hpp index 2b68ba47..32b3af73 100644 --- a/triqs/arrays/mapped_functions.hpp +++ b/triqs/arrays/mapped_functions.hpp @@ -24,6 +24,11 @@ #include namespace triqs { namespace arrays { + // complex conjugation for integers + inline int conj(int const& x) { return x; } + inline long conj(long const& x) { return x; } + inline long long conj(long long const& 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));} @@ -45,7 +50,7 @@ namespace triqs { namespace arrays { 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) +#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);