/*******************************************************************************
*
* 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 .
*
******************************************************************************/
#include "./python_stuff.hpp"
#include "./src/array.hpp"
#include
using namespace triqs::arrays;
using namespace indexmaps;
using namespace storages;
#include "./src/array.hpp"
#include "./src/matrix.hpp"
//#include "./src/vector.hpp"
#include
namespace ExpressionTools {
/**
* Map any callable object to an array expression, elementwise
*/
namespace details {
template
struct map_impl : TRIQS_MODEL_CONCEPT(ImmutableArray) {
typedef typename Expr::value_type value_type;
typedef typename Expr::domain_type domain_type;
Expr const & a;Obj const & obj;std::string name;
map_impl( Obj const & obj_, Expr const & a_,std::string const & name_):a(a_),obj(obj_),name(name_){}
domain_type domain() const { return a.domain();}
template
value_type operator()(Args const & ... args) const { return obj(a (args...)); }
//value_type operator[] (typename Expr::domain_type::index_value_type const & key) const { return obj(a [key]); }
};
template
std::ostream & operator<<(std::ostream & out, map_impl const & x){ return out<
details::map_impl map_expr (Obj const & obj, Expr const & x,std::string const & name="Unknown") {
return details::map_impl(obj,x,name);
}
/**
* Transpose any array expression
*/
namespace details {
template
struct transpose_impl : TRIQS_MODEL_CONCEPT(ImmutableCuboidArray) {
typedef typename Expr::value_type value_type;
typedef typename Expr::domain_type domain_type;
Expr const & a;
transpose_impl( Expr const & a_):a(a_){}
domain_type domain() const { return domain_type(mini_vector(a.domain().lengths()[1], a.domain().lengths()[0])); }
typedef typename Expr::domain_type::index_value_type K;
template value_type operator()(Args const & ... args) const { return a [ K(args...) ]; }
// value_type operator[] (K const & key) const { return a [ K( key[1], key[0]) ]; }
};
template
std::ostream & operator<<(std::ostream & out, transpose_impl const & x){ return out<<"Transpose("< class Transfo>
struct transfo_impl : TRIQS_MODEL_CONCEPT(ImmutableCuboidArray) ,Transfo { //, Tag::expression, Tag::array_algebra_expression_terminal {
Expr const & a; transfo_impl( Expr const & a_):a(a_){}
typedef Transfo T;
typename T::domain_type domain() const { return T::domain(a);}
typename T::value_type operator[] (typename T::domain_type::index_value_type const & key) const { return T::eval(a,key); }
};
template class Transfo>
std::ostream & operator<<(std::ostream & out, transfo_impl const & x){ return out<::name()<<"("< details::transpose_impl Transpose (Expr const & x) { return details::transpose_impl(x);}
template
struct transpose_ {
static_assert( ImmutableArray::value, "transpose_ : the type of the template argument is incorrect, it does not model ImmutableArray");
// static checks here on Expr
static std::string name() { return "Transpose";}
typedef typename Expr::value_type value_type;
typedef typename Expr::domain_type domain_type;
static domain_type domain(Expr const & a) { return domain_type(mini_vector(a.domain().lengths()[1], a.domain().lengths()[0])); }
static value_type eval (Expr const & a, typename domain_type::index_value_type const & key) {
return a [ typename domain_type::index_value_type ( key[1], key[0]) ];
}
};
#define TRIQS_ARRAYS_NAME_APPLY_ARRAY_FUNCTION(Name, ArrayFunction)\
namespace result_of { template struct Name { typedef details::transfo_impl type; }; }\
template typename result_of::Name::type Name (Expr const & x) { return typename result_of::Name::type (x);}\
TRIQS_ARRAYS_NAME_APPLY_ARRAY_FUNCTION (Transpose, transpose_)
}
using namespace ExpressionTools;
int sqr(int x) { return x*x;}
//DEFINE_ARRAY_FUNCTION1( Transpose, transpose_impl);
int main(int argc, char **argv) {
init_python_stuff(argc,argv);
{
array A(3),B(3),C(3);
array F(3);
for (int i =0; i<3; ++i) {
A(i) = i;
B(i) = 1;
C(i) = 10 *i;
F(i) = 2.5 + i;
}
std::cout<<" A = "< Af (2,2), Bf(2,2),Cf(2,2);
Af = A; Bf = B; Bf(0,0) = 1;
std::cout<<" Af = "< F( 0.5 * A);
std::cout << " 0.5 * A = "< R(2,3),Rt(3,2);
for (int i =0; i<2; ++i)
for (int j=0; j<3; ++j)
{ R(i,j) = 10*i+ j;}
//std::cout<<" R = "<< 1 + R<