TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
doc_overview.cpp
1#include <nda/nda.hpp>
2#include <nda/h5.hpp>
3#include <h5/h5.hpp>
4
5int main() {
6 // create an array of shape (4,4,4)
7 nda::array<long, 3> A(4, 4, 4);
8
9 // create an array given its data
10 nda::array<long, 2> B{{1, 2}, {3, 4}, {5, 6}};
11
12 // assign a scalar to the full array or a single element
13 A() = 0;
14 A(0, 1, 2) = 40;
15
16 // access single elements
17 [[maybe_unused]] long a = A(0, 1, 2) + B(0, 1);
18
19 // access a slice of the array of shape (3, 2)
20 auto V = A(nda::range(0, 3), nda::range(0, 2), 0);
21
22 // lazy arithmetic operations
23 auto C = V + 2 * B; // C is an expression
24 [[maybe_unused]] auto D = nda::make_regular(C); // D is an array
25
26 // various algorithms
29 nda::sum(V);
30
31 // write to HDF5 file
32 {
33 h5::file file("dat.h5", 'w');
34 h5::write(file, "A", A);
35 }
36
37 // read from HDF5 file
39 {
40 h5::file file("dat.h5", 'r');
41 h5::read(file, "A", E);
42 }
43}
auto max_element(A const &a)
Find the maximum element of an array.
auto sum(A const &a)
Sum all the elements of an nda::Array object.
auto min_element(A const &a)
Find the minimum element of an array.
decltype(auto) make_regular(A &&a)
Make a given object regular.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Provides HDF5 support for the nda library.
Includes all relevant headers for the core nda library.