|
| Array () |
|
| Array (const std::initializer_list< unsigned int > &ranges) |
|
| Array (const std::initializer_list< unsigned int > &ranges, const DataType &fillValue) |
|
| Array (const std::vector< DataType > &vector) |
|
| Array (const std::vector< std::vector< DataType >> &vector) |
|
| Array (const Range &range) |
|
| Array (const std::string &serialization, Mode mode) |
|
template<typename CastType > |
| operator Array< CastType > () const |
|
DataType & | operator[] (const std::vector< unsigned int > &index) |
|
const DataType & | operator[] (const std::vector< unsigned int > &index) const |
|
DataType & | operator[] (unsigned int n) |
|
const DataType & | operator[] (unsigned int n) const |
|
Array | operator+ (const Array &rhs) const |
|
Array | operator- (const Array &rhs) const |
|
Array | operator* (const DataType &rhs) const |
|
Array | operator* (const Array &rhs) const |
|
Array | operator/ (const DataType &rhs) const |
|
bool | operator== (const Array &rhs) const |
|
Array< DataType > | getSlice (const std::vector< Subindex > &index) const |
|
Array< DataType > | getArrayWithPermutedIndices (const std::vector< unsigned int > &permutation) const |
|
Array< DataType > | getArrayWithReversedIndices () const |
|
const std::vector< unsigned int > & | getRanges () const |
|
CArray< DataType > & | getData () |
|
const CArray< DataType > & | getData () const |
|
unsigned int | getSize () const |
|
std::string | serialize (Mode mode) const |
|
template<> |
std::string | serialize (const bool &data, Mode mode) |
|
template<> |
std::string | serialize (const double &data, Mode mode) |
|
template<> |
std::string | serialize (const std::complex< double > &data, Mode mode) |
|
template<> |
std::string | serialize (const int &data, Mode mode) |
|
template<> |
std::string | serialize (const unsigned int &data, Mode mode) |
|
template<> |
std::string | serialize (const SpinMatrix &data, Mode mode) |
|
template<> |
std::string | serialize (const Statistics &data, Mode mode) |
|
template<> |
std::string | serialize (const std::vector< std::complex< double >> &data, Mode mode) |
|
template<> |
int | deserialize (const std::string &serialization, Mode mode) |
|
|
enum | Mode { Debug,
Binary,
XML,
JSON
} |
|
static bool | validate (const std::string &serialization, const std::string &id, Mode mode) |
|
static std::string | getContent (const std::string &serialization, Mode mode) |
|
static std::vector< std::string > | split (const std::string &content, Mode mode) |
|
template<typename DataType > |
static std::enable_if<!std::is_pointer< DataType >::value, std::string >::type | serialize (const DataType &data, Mode mode) |
|
template<typename DataType > |
static std::enable_if< std::is_pointer< DataType >::value, std::string >::type | serialize (const DataType &data, Mode mode) |
|
template<typename DataType > |
static DataType | deserialize (const std::string &serialization, Mode mode) |
|
static std::string | extract (const std::string &serialization, Mode mode, std::string component) |
|
template<typename DataType>
class TBTK::Array< DataType >
Multi-dimensional array.
The Array provides a convenient interface for handling multi-dimensional array.
Indexing
An Array is created using
Array<DataType> array({SIZE_X, SIZE_Y, SIZE_Z});
or alternatively
Array<DataType> array({SIZE_X, SIZE_Y, SIZE_Z}, value);
to initialize each element to 'value'.
The curly braces determines the Array ranges. Any number of dimensions is possible. Similarly, elements can be accessed using
array[{x, y, z}] = 10;
DataType value = array[{x, y, z}];
Arithmetics
It is possible to add and subtract Arrays with the same ranges.
Array<DataType> sum = array0 + array1;
Array<DataType> difference = array0 - array1;
It is also possible to multiply and divide an Array by a value with the same DataType as the Array elements.
DataType value = 10;
Array<DataType> product = value*array;
Array<DataType> quotient = array/value;
Slicing
Consider the code
Array<DataType> array({SIZE_X, SIZE_Y, SIZE_Z});
Array<DataType> slice = array.getSlice({_a_, 2, _a_});
Here slice will be an Array with ranges {SIZE_X, SIZE_Z} and satsify *slice[{x, z}] = array[{x, 2, z}].
Note: If you write library code for TBTK, use IDX_ALL instead of _a_.
Example
#include <vector>
using namespace std;
using namespace TBTK;
int main(){
for(unsigned int x = 0; x < 2; x++){
for(unsigned int y = 0; y < 3; y++){
for(unsigned int z = 0; z < 4; z++){
array0[{x, y, z}] = x;
array1[{x, y, z}] = 2*y;
array2[{x, y, z}] = 3*z;
}
}
}
const vector<unsigned int> &ranges = result.
getRanges();
Streams::out <<
"Result dimension: " << ranges.size() <<
"\n";
for(unsigned int n = 0; n < ranges.size(); n++)
const vector<unsigned int> &sliceRanges = slice.
getRanges();
Streams::out <<
"Slice dimension: " << sliceRanges.size() <<
"\n";
for(unsigned int n = 0; n < sliceRanges.size(); n++)
for(unsigned int x = 0; x < 2; x++){
for(unsigned int z = 0; z < 4; z++)
}
}
Output
Result dimension: 3
Result ranges: 2 3 4
Slice dimension: 2
Slice ranges: 2 4
Slice values:
0 9 18 27
1 10 19 28