TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
doc_overview.cpp
1
#include <
nda/nda.hpp
>
2
#include <
nda/h5.hpp
>
3
#include <h5/h5.hpp>
4
5
int
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
27
nda::min_element
(V);
28
nda::max_element
(V);
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
38
nda::array<long, 3>
E;
39
{
40
h5::file file(
"dat.h5"
,
'r'
);
41
h5::read(file,
"A"
, E);
42
}
43
}
nda::max_element
auto max_element(A const &a)
Find the maximum element of an array.
Definition
algorithms.hpp:125
nda::sum
auto sum(A const &a)
Sum all the elements of an nda::Array object.
Definition
algorithms.hpp:179
nda::min_element
auto min_element(A const &a)
Find the minimum element of an array.
Definition
algorithms.hpp:144
nda::make_regular
decltype(auto) make_regular(A &&a)
Make a given object regular.
Definition
basic_functions.hpp:225
nda::array
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Definition
declarations.hpp:64
h5.hpp
Provides HDF5 support for the nda library.
nda.hpp
Includes all relevant headers for the core nda library.
doc
examples
doc_overview.cpp
Generated by
1.17.0