3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 03:33:50 +01:00
dft_tools/test/triqs/arrays/ellipsis.cpp
Olivier Parcollet 47cb8a03f7 [arrays] Important changes in implementation.
- Simplify group_indices
  - Only for C ordered, remove complex compile time.
  - Could be generalized to non C ordered, but no need.
- Fix slice for custom orders.
- Generalize the group_indices for the custom order.
- Add c_ordered_transposed_view (useful ?)
- Improve slice, special for ellipsis (quicker).
- Simplify TraversalOrder
- Assignement. Specialize one case for speed.
- use FORCEINLINE in foreach, according to speed test for clang
- add one speed test
- Modify iterators for better speed.
- along the lines decided for the foreach
- update doc.
2014-10-18 21:20:17 +02:00

77 lines
2.1 KiB
C++

/*******************************************************************************
*
* 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"
#include <triqs/arrays/array.hpp>
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/arrays/matrix.hpp>
#include <iostream>
#include <triqs/arrays/asserts.hpp>
using namespace triqs::arrays;
template<typename ArrayType>
array_view<typename ArrayType::value_type, ArrayType::rank-1> sum0 (ArrayType const & A) {
array<typename ArrayType::value_type, ArrayType::rank-1> res = A(0,ellipsis());
for (size_t u =1; u< A.shape()[0]; ++u) res += A(u,ellipsis());
return res;
}
int main(int argc, char **argv) {
{
array<long,3> A(2,3,4) ;
A() = 7;
std::cerr<< A(0, ellipsis() ) <<std::endl;
array<long,4> B(2,3,4,5) ;
B() = 8;
std::cerr<< B(0, ellipsis(), 3 ) <<std::endl;
std::cerr<< B(0, ellipsis(), 2, 3 ) <<std::endl;
std::cerr<< B( ellipsis(), 2, 3 ) <<std::endl;
assert_all_close (B(0, ellipsis(), 3 ) , B(0, range(),range(), 3 ) , 1.e-15);
assert_all_close (B(0, ellipsis(),2, 3 ) , B(0, range(), 2, 3 ) , 1.e-15);
assert_all_close (B( ellipsis(),2, 3 ) , B( range(),range(), 2, 3 ) , 1.e-15);
std::cerr << B.shape() <<std::endl;
}
///.....
{
array<double,2> A(5,2); A() =2;
array<double,3> B(5,2,3); B() = 3;
std::cerr<< sum0(A) << sum0(B) <<std::endl;
}
return 0;
}