3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-26 06:14:14 +01:00

arrays: add conj function for arrays/matrix and tests

- map conj (and extend it for integers).
This commit is contained in:
Olivier Parcollet 2013-11-18 20:45:42 +01:00
parent fa6f991473
commit 9cdc139214
3 changed files with 29 additions and 2 deletions

View File

@ -53,6 +53,8 @@ template<typename T> void test( T val=1 ) {
auto aa = array<T,2>{ { 1,2}, {3,4}}; auto aa = array<T,2>{ { 1,2}, {3,4}};
TEST(make_matrix(exp(aa))); TEST(make_matrix(exp(aa)));
TEST(make_matrix(conj(A)));
// does not compile, since exp is only element wise at the moment // does not compile, since exp is only element wise at the moment
// to do : implement it for matrix... // to do : implement it for matrix...
//TEST(make_matrix(exp( matrix<double>{{ 1,2}, {3,4}} ))); //TEST(make_matrix(exp( matrix<double>{{ 1,2}, {3,4}} )));
@ -60,7 +62,7 @@ template<typename T> void test( T val=1 ) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
conj (8);
test<int>(); test<int>();
test<long>(); test<long>();
test<double>(); test<double>();

View File

@ -42,6 +42,10 @@
(make_matrix(exp(aa))) ---> (make_matrix(exp(aa))) --->
[[2.71828,7.38906] [[2.71828,7.38906]
[20.0855,54.5982]] [20.0855,54.5982]]
(make_matrix(conj(A))) --->
[[1,3,5]
[2,4,6]
[3,5,7]]
(A) ---> (A) --->
[[1,3,5] [[1,3,5]
[2,4,6] [2,4,6]
@ -86,6 +90,10 @@
(make_matrix(exp(aa))) ---> (make_matrix(exp(aa))) --->
[[2.71828,7.38906] [[2.71828,7.38906]
[20.0855,54.5982]] [20.0855,54.5982]]
(make_matrix(conj(A))) --->
[[1,3,5]
[2,4,6]
[3,5,7]]
(A) ---> (A) --->
[[1,3,5] [[1,3,5]
[2,4,6] [2,4,6]
@ -130,6 +138,10 @@
(make_matrix(exp(aa))) ---> (make_matrix(exp(aa))) --->
[[2.71828,7.38906] [[2.71828,7.38906]
[20.0855,54.5982]] [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) ---> (A) --->
[[(1,0),(3,0),(5,0)] [[(1,0),(3,0),(5,0)]
[(2,0),(4,0),(6,0)] [(2,0),(4,0),(6,0)]
@ -174,6 +186,10 @@
(make_matrix(exp(aa))) ---> (make_matrix(exp(aa))) --->
[[(2.71828,0),(7.38906,0)] [[(2.71828,0),(7.38906,0)]
[(20.0855,0),(54.5982,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) ---> (A) --->
[[(-2,3),(-6,9),(-10,15)] [[(-2,3),(-6,9),(-10,15)]
[(-4,6),(-8,12),(-12,18)] [(-4,6),(-8,12),(-12,18)]
@ -218,3 +234,7 @@
(make_matrix(exp(aa))) ---> (make_matrix(exp(aa))) --->
[[(2.71828,0),(7.38906,0)] [[(2.71828,0),(7.38906,0)]
[(20.0855,0),(54.5982,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)]]

View File

@ -24,6 +24,11 @@
#include <boost/preprocessor/seq/for_each.hpp> #include <boost/preprocessor/seq/for_each.hpp>
namespace triqs { namespace arrays { 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 ... //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));} //template <typename A> decltype(auto) abs(A && a) { return map( [](auto const &x) { using std::abs; return abs(a);}, std::forward<A>(a));}
@ -45,7 +50,7 @@ namespace triqs { namespace arrays {
typename boost::lazy_enable_if_c<ImmutableCuboidArray<A>::value,std::result_of<map_impl<__triqs_##FNT##_wrap,1>(A)>>::type\ 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)); } FNT(A && a) { return map(__triqs_##FNT##_wrap{})(std::forward<A>(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) #define AUX(r, data, elem) MAP_IT(elem)
BOOST_PP_SEQ_FOR_EACH(AUX , nil , TRIQS_ARRAYS_MATH_FNT); BOOST_PP_SEQ_FOR_EACH(AUX , nil , TRIQS_ARRAYS_MATH_FNT);