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/>.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#include "./common.hpp"
|
|
|
|
#define ARRAY_DEBUG_SLICE
|
|
|
|
|
2014-06-15 14:28:16 +02:00
|
|
|
#include <triqs/arrays/array.hpp>
|
2013-07-17 19:24:07 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
using namespace triqs::arrays;
|
|
|
|
|
|
|
|
///
|
2014-09-07 14:34:10 +02:00
|
|
|
template <typename IM, typename A> void print_in_indexmap_order(std::ostream &out, IM const &im, A const &a) {
|
|
|
|
out << "[";
|
2013-06-30 21:41:56 +02:00
|
|
|
for (typename IM::iterator it(im); it; ++it) {
|
|
|
|
auto i = it.indices();
|
2014-09-07 14:34:10 +02:00
|
|
|
out << a(i[0], i[1], i[2]) << " ";
|
2013-06-30 21:41:56 +02:00
|
|
|
}
|
2014-09-07 14:34:10 +02:00
|
|
|
out << "]";
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
template <class AA> void f(AA &A) {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
for (int j = 0; j < 3; ++j)
|
|
|
|
for (int k = 0; k < 4; ++k) A(i, j, k) = 100 * (i + 1) + 10 * (j + 1) + (k + 1);
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
print_in_indexmap_order(std::cout, A.indexmap(), A);
|
|
|
|
std::cout << std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
std::cout << A(0, range(), range()) << std::endl;
|
|
|
|
std::cout << A(1, range(), range()) << std::endl;
|
|
|
|
std::cout << A(range(), 0, range()) << std::endl;
|
|
|
|
std::cout << A(range(), range(), 1) << std::endl;
|
|
|
|
std::cout << A(range(), 0, 1) << std::endl;
|
|
|
|
std::cout << "-------------------------------------------------- " << std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
try {
|
2014-09-07 14:34:10 +02:00
|
|
|
|
|
|
|
// permutation in triqs::arrays
|
|
|
|
array<long, 3> A0(2, 3, 4);
|
|
|
|
array<long, 3, _traversal_dynamical> A1(2, 3, 4, make_memory_layout(2, 1, 0));
|
|
|
|
array<long, 3, _traversal_dynamical> A2(2, 3, 4, make_memory_layout(2, 0, 1));
|
|
|
|
array<long, 3> A3(2, 3, 4, make_memory_layout(0, 1, 2));
|
|
|
|
array<long, 3, _traversal_fortran> A4(2, 3, 4, FORTRAN_LAYOUT);
|
|
|
|
|
|
|
|
f(A0);
|
|
|
|
f(A1);
|
|
|
|
f(A2);
|
|
|
|
f(A3);
|
|
|
|
f(A4);
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
catch (const char *ERR) {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
std::cout << "Error is " << ERR << std::endl;
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 14:34:10 +02:00
|
|
|
return 0;
|
2013-07-17 19:24:07 +02:00
|
|
|
}
|
|
|
|
|