TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::AnnotatedArray< DataType, AxesType > Class Template Reference

Array with additional information about its axes. More...

#include <AnnotatedArray.h>

Inheritance diagram for TBTK::AnnotatedArray< DataType, AxesType >:
TBTK::Array< DataType > TBTK::Serializable

Public Member Functions

 AnnotatedArray ()
 
 AnnotatedArray (const Array< DataType > &array, const std::vector< std::vector< AxesType >> &axes)
 
 AnnotatedArray (const std::string &serialization, Serializable::Mode mode)
 
const std::vector< std::vector< AxesType > > & getAxes () const
 
std::string serialize (Serializable::Mode mode) const
 
- Public Member Functions inherited from TBTK::Array< DataType >
 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
 
- Public Member Functions inherited from TBTK::Serializable
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)
 

Additional Inherited Members

- Public Types inherited from TBTK::Serializable
enum  Mode { Debug, Binary, XML, JSON }
 
- Static Public Member Functions inherited from TBTK::Array< DataType >
static Array create (const std::vector< unsigned int > &ranges)
 
static Array create (const std::vector< unsigned int > &ranges, const DataType &fillValue)
 
static Array contract (const Array &array0, const std::vector< Subindex > &pattern0, const Array &array1, const std::vector< Subindex > &pattern1)
 
- Static Public Member Functions inherited from TBTK::Serializable
static bool hasID (const std::string &serialization, Mode mode)
 
static std::string getID (const std::string &serialization, Mode mode)
 
static std::string extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode)
 
- Static Protected Member Functions inherited from TBTK::Serializable
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)
 

Detailed Description

template<typename DataType, typename AxesType>
class TBTK::AnnotatedArray< DataType, AxesType >

Array with additional information about its axes.

The AnnotatedArray extends the Array with axes. The number of axes must be the same as the number of Array dimensions and each axis must have the same number of entries as the corresponding Array range.

Example

#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
#include <vector>
using namespace std;
using namespace TBTK;
int main(){
//Create Arrays and axes.
Array<unsigned int> array({2, 3});
std::vector<std::vector<double>> axes = {
{0, 1},
{1, 1.5, 2}
};
//Fill the Array with values.
for(unsigned int x = 0; x < 2; x++){
for(unsigned int y = 0; y < 3; y++){
array[{x, y}] = x*y;
}
}
//Bundle the array and axes and an AnnotatedArray.
AnnotatedArray<unsigned int, double> annotatedArray(array, axes);
//Print the Array.
Streams::out << annotatedArray << "\n";
//Get and print the axes.
const std::vector<std::vector<double>> &annotatedAxes
= annotatedArray.getAxes();
Streams::out << "Axes:\n";
for(unsigned int n = 0; n < annotatedAxes.size(); n++){
Streams::out << "\t" << Array<double>(annotatedAxes[n])
<< "\n";
}
}

Output

[[0, 0, 0]
[0, 1, 2]]
Axes:
[0, 1]
[1, 1.5, 2]

Constructor & Destructor Documentation

◆ AnnotatedArray() [1/3]

template<typename DataType , typename AxesType >
TBTK::AnnotatedArray< DataType, AxesType >::AnnotatedArray

Constructor.

◆ AnnotatedArray() [2/3]

template<typename DataType , typename AxesType >
TBTK::AnnotatedArray< DataType, AxesType >::AnnotatedArray ( const Array< DataType > &  array,
const std::vector< std::vector< AxesType >> &  axes 
)

Constructor.

Parameters
arrayThe Array data.
axesThe axes of the Array.

◆ AnnotatedArray() [3/3]

template<typename DataType , typename AxesType >
TBTK::AnnotatedArray< DataType, AxesType >::AnnotatedArray ( const std::string &  serialization,
Serializable::Mode  mode 
)

Constructs an AnnotatedArray from a serialization string.

Parameters
serializationSerialization string from which to construct the AnnotatedArray.
modeThe mode with which the string has been serialized.

Member Function Documentation

◆ getAxes()

template<typename DataType , typename AxesType >
const std::vector< std::vector< AxesType > > & TBTK::AnnotatedArray< DataType, AxesType >::getAxes

Return the axes of the AnnotatedArray.

Returns
The axes of the AnnotatedArray.

◆ serialize()

template<typename DataType , typename AxesType >
std::string TBTK::AnnotatedArray< DataType, AxesType >::serialize ( Serializable::Mode  mode) const
virtual

Implements Serilizable::serialize().

Implements TBTK::Serializable.


The documentation for this class was generated from the following file:
TBTK::Array
Multi-dimensional array.
Definition: Array.h:98
TBTK::AnnotatedArray
Array with additional information about its axes.
Definition: AnnotatedArray.h:41
Streams.h
Streams for TBTK output.
AnnotatedArray.h
Array with additional information about its axes.
TBTK::Initialize
void Initialize()
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
TBTK.h
TBTK initialization.