Hex  1.0
Hydrogen-electron collision solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Data Fields | Protected Attributes
NumberArray< T, Alloc > Class Template Reference

A comfortable number array class. More...

#include <arrays.h>

Inheritance diagram for NumberArray< T, Alloc >:
Inheritance graph
[legend]
Collaboration diagram for NumberArray< T, Alloc >:
Collaboration graph
[legend]

Public Types

typedef T DataType
 
typedef T * iterator
 
typedef T const * const_iterator
 
- Public Types inherited from Array< T, Alloc >
typedef T DataType
 
typedef T * iterator
 
typedef T const * const_iterator
 
- Public Types inherited from ArrayView< T >
typedef T DataType
 
typedef T * iterator
 
typedef T const * const_iterator
 

Public Member Functions

 NumberArray ()
 
 Alloc (n, x)
 
 Nres_ (size())
 
 name_ ()
 
 NumberArray (size_t n, T const *x)
 
 NumberArray (ArrayView< T > const &a)
 
 NumberArray (NumberArray< T > const &a)
 
 NumberArray (std::vector< T > const &a)
 
 NumberArray (std::initializer_list< T > a)
 
template<typename ForwardIterator >
 NumberArray (ForwardIterator i, ForwardIterator j)
 
 NumberArray (NumberArray< T > &&a)
 
 ~NumberArray ()
 
size_t size () const
 Item count. More...
 
virtual size_t resize (size_t n)
 Resize array. More...
 
size_t reserve (size_t n)
 Reserve memory. More...
 
T & operator[] (size_t i)
 Element-wise access (non-const). More...
 
T const & operator[] (size_t i) const
 Element-wise access (const). More...
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
T & front (int i=0)
 
T const & front (int i=0) const
 
T & back (int i=0)
 
T const & back (int i=0) const
 
virtual void push_front (T const &a)
 Add element to beginning. More...
 
virtual void push_back (T const &a)
 Add element to end. More...
 
pop_back ()
 Remove the last element. More...
 
template<class InputIterator >
void append (InputIterator first, InputIterator last)
 Append a range of values at end. More...
 
bool empty () const
 Check that size equals to zero. More...
 
void clear ()
 Fill array with zeros. More...
 
void drop ()
 Reset array: deallocate everything, resize to zero. More...
 
NumberArray< T > & operator= (NumberArray< T > const &b)
 
NumberArray< T > & operator= (NumberArray< T > &&b)
 
NumberArray< T > conj () const
 Return complex conjugated array. More...
 
double norm () const
 Compute usual 2-norm. More...
 
template<class Functor >
auto transform (Functor f) const -> NumberArray< decltype(f(T(0)))>
 Apply a user transformation. More...
 
ArrayView< T > slice (size_t left, size_t right) const
 Return a subarray using ArrayView. More...
 
std::string toBlob () const
 Convert to SQL BLOB. More...
 
void fromBlob (std::string const &s)
 Convert from SQL BLOB. More...
 
void link (std::string name)
 Link to HDF file. More...
 
std::tuple< NumberArray< int >
, NumberArray< T > > 
compress (int consec) const
 Get compressed array. More...
 
NumberArray< T > decompress (NumberArray< int > const &zero_blocks) const
 Decompress array. More...
 
virtual T * data ()
 Data pointer. More...
 
virtual T const * data () const
 
bool hdfsave (std::string name, bool docompress=false, int consec=10) const
 Save array to HDF file. More...
 
bool hdfsave () const
 
bool hdfload (std::string name)
 Load array from HDF file. More...
 
bool hdfload ()
 
- Public Member Functions inherited from Array< T, Alloc >
 Array ()
 
 Alloc::alloc (n))
 
 Array (size_t n, T const *const x)
 
 Array (Array< T > const &a)
 
 Array (const ArrayView< T > a)
 
 Array (Array< T > &&a)
 
 Array (std::vector< T > const &a)
 
 Array (std::initializer_list< T > a)
 
template<typename ForwardIterator >
 Array (ForwardIterator i, ForwardIterator j)
 
 ~Array ()
 
size_t size () const
 Return number of elements. More...
 
T & operator[] (size_t i)
 Element-wise access (non-const). More...
 
T const & operator[] (size_t i) const
 Element-wise access (const). More...
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
T & front (int i=0)
 
T const & front (int i=0) const
 
T & back (int i=0)
 
T const & back (int i=0) const
 
template<class InputIterator >
void append (InputIterator first, InputIterator last)
 Append more items. More...
 
void insert (iterator it, T x)
 Insert item. More...
 
bool empty () const
 Check that size equals to zero. More...
 
Array< T > & operator= (Array< T > const &b)
 
Array< T > & operator= (Array< T > &&b)
 
- Public Member Functions inherited from ArrayView< T >
 ArrayView ()
 
 ArrayView (size_t n, T *ptr)
 
 ArrayView (ArrayView< T > const &a, size_t i=0, size_t n=0)
 
 ArrayView (Array< T > const &a, size_t i=0, size_t n=0)
 
 ArrayView (NumberArray< T > const &a, size_t i=0, size_t n=0)
 
 ArrayView (const_iterator i, const_iterator j)
 
 ArrayView (ArrayView< T > &&r)
 
virtual ~ArrayView ()
 
ArrayView< T > & operator= (const ArrayView< T > v)
 Assignment operator. More...
 
T & operator[] (size_t i)
 Element-wise access (non-const). More...
 
T const & operator[] (size_t i) const
 Element-wise access (const). More...
 
size_t size () const
 Length of the array (number of elements). More...
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
T & front (int i=0)
 
T const & front (int i=0) const
 
T & back (int i=0)
 
T const & back (int i=0) const
 
void fill (T x)
 Fill the array with a value. More...
 
bool empty () const
 Check whether the size is equal to zero. More...
 
template<class = typename std::enable_if<is_scalar<T>::value>>
double norm () const
 Two-norm (defined only for scalar data type). More...
 

Data Fields

 __pad0__: Array<T
 
- Data Fields inherited from Array< T, Alloc >
 __pad0__: ArrayView<T>(n
 

Protected Attributes

size_t Nres_
 Allocated memory. More...
 
std::string name_
 HDF file to store to / load from. More...
 
- Protected Attributes inherited from ArrayView< T >
size_t N_
 Number of elements in the array. More...
 
T * array_
 Pointer to the array. More...
 

Detailed Description

template<class T, class Alloc = PlainAllocator<T>>
class NumberArray< T, Alloc >

Class NumberArray is intended as a Hex's replacement for std::vector<T> for number type T. Properties:

Member Typedef Documentation

template<class T, class Alloc = PlainAllocator<T>>
typedef T const* NumberArray< T, Alloc >::const_iterator
template<class T, class Alloc = PlainAllocator<T>>
typedef T NumberArray< T, Alloc >::DataType
template<class T, class Alloc = PlainAllocator<T>>
typedef T* NumberArray< T, Alloc >::iterator

Constructor & Destructor Documentation

template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( size_t  n,
T const *  x 
)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( ArrayView< T > const &  a)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( NumberArray< T > const &  a)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( std::vector< T > const &  a)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( std::initializer_list< T >  a)
inline
template<class T, class Alloc = PlainAllocator<T>>
template<typename ForwardIterator >
NumberArray< T, Alloc >::NumberArray ( ForwardIterator  i,
ForwardIterator  j 
)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::NumberArray ( NumberArray< T > &&  a)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::~NumberArray ( )
inline

Member Function Documentation

template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::Alloc ( ,
 
)
template<class T, class Alloc = PlainAllocator<T>>
template<class InputIterator >
void NumberArray< T, Alloc >::append ( InputIterator  first,
InputIterator  last 
)
inline

Takes the values specified by two iterators and appends them to the end of the array. If the reserved storage is large enough, no reallocation will take place.

template<class T, class Alloc = PlainAllocator<T>>
T& NumberArray< T, Alloc >::back ( int  i = 0)
inline
template<class T, class Alloc = PlainAllocator<T>>
T const& NumberArray< T, Alloc >::back ( int  i = 0) const
inline
template<class T, class Alloc = PlainAllocator<T>>
iterator NumberArray< T, Alloc >::begin ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
const_iterator NumberArray< T, Alloc >::begin ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
const_iterator NumberArray< T, Alloc >::cbegin ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
const_iterator NumberArray< T, Alloc >::cend ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
void NumberArray< T, Alloc >::clear ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
std::tuple<NumberArray<int>,NumberArray<T> > NumberArray< T, Alloc >::compress ( int  consec) const
inline

Omit all consecutive occurences of zero (threshold number of consecutive occurences is specified in "consec") and save the start and (one after) end position of the zero blocks in the array to a new array conventionally called "zero_blocks".

Returns
Pair "zero_blocks", "compressed_array".
template<class T, class Alloc = PlainAllocator<T>>
NumberArray<T> NumberArray< T, Alloc >::conj ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
virtual T* NumberArray< T, Alloc >::data ( )
inlinevirtual

Get pointer to the aligned memory. In the present implementation the pointer is filtered through the builtin function

__builtin_assume_aligned(pointer, alignment)

to make the compiler (GCC) assume that the memory pointed to by the data pointer is specifically aligned.

Note
It is not clear, however, if the state "assumed aligned" is preserved when passing the pointer as a return value. It may be necessary to filter the pointer through the builtin function just before the pointer is accessed. See e.g. SymDiaMatrix::dot function.

Reimplemented from Array< T, Alloc >.

template<class T, class Alloc = PlainAllocator<T>>
virtual T const* NumberArray< T, Alloc >::data ( ) const
inlinevirtual

Reimplemented from Array< T, Alloc >.

template<class T, class Alloc = PlainAllocator<T>>
NumberArray<T> NumberArray< T, Alloc >::decompress ( NumberArray< int > const &  zero_blocks) const
inline

This function will create a new array using self and the supplied compression info "zero_blocks". The parameter "zero_blocks" is expected to have an even count of items; every pair of items then specifies start and (one after) end position of a block of zeros in the decompressed array. The decompressed array is returned and the original array left intact.

template<class T, class Alloc = PlainAllocator<T>>
void NumberArray< T, Alloc >::drop ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
bool NumberArray< T, Alloc >::empty ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
iterator NumberArray< T, Alloc >::end ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
const_iterator NumberArray< T, Alloc >::end ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
void NumberArray< T, Alloc >::fromBlob ( std::string const &  s)
inline

Decode string from SQL-readable BLOB (hexadecimal format) to correct binary array.

Warning
The data are assumed to possess the endianness of the current machine.
template<class T, class Alloc = PlainAllocator<T>>
T& NumberArray< T, Alloc >::front ( int  i = 0)
inline
template<class T, class Alloc = PlainAllocator<T>>
T const& NumberArray< T, Alloc >::front ( int  i = 0) const
inline
template<class T, class Alloc = PlainAllocator<T>>
bool NumberArray< T, Alloc >::hdfload ( std::string  name)
inline

See hdfsave for the expected structure of the HDF file.

Parameters
nameFilename.
template<class T, class Alloc = PlainAllocator<T>>
bool NumberArray< T, Alloc >::hdfload ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
bool NumberArray< T, Alloc >::hdfsave ( std::string  name,
bool  docompress = false,
int  consec = 10 
) const
inline

This function will save the array data into a HDF5 file. The file will then contain two datasets:

  • "array" - the data itself, with large block of zeros omitted (if requested by the docompress flag
  • "zero_blocks" - the compression information containing starting and ending positions of the zero blocks (hence the length of this dataset os always even)
Parameters
nameFilename.
docompressWhether to apply a trivial compression (contract the repeated zeros).
consecMinimal consecutive occurences for compression.
template<class T, class Alloc = PlainAllocator<T>>
bool NumberArray< T, Alloc >::hdfsave ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
void NumberArray< T, Alloc >::link ( std::string  name)
inline

In order to avoid repetitious specifying of the HDF filename, it is possible to link the array to a single file and then use hdfload and hdfsave functions without arguments.

template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::name_ ( )
inline
template<class T, class Alloc = PlainAllocator<T>>
double NumberArray< T, Alloc >::norm ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::Nres_ ( size()  )
template<class T, class Alloc = PlainAllocator<T>>
NumberArray<T>& NumberArray< T, Alloc >::operator= ( NumberArray< T > const &  b)
inline
template<class T, class Alloc = PlainAllocator<T>>
NumberArray<T>& NumberArray< T, Alloc >::operator= ( NumberArray< T > &&  b)
inline
template<class T, class Alloc = PlainAllocator<T>>
T& NumberArray< T, Alloc >::operator[] ( size_t  i)
inline
template<class T, class Alloc = PlainAllocator<T>>
T const& NumberArray< T, Alloc >::operator[] ( size_t  i) const
inline
template<class T, class Alloc = PlainAllocator<T>>
T NumberArray< T, Alloc >::pop_back ( )
inlinevirtual

Calls Array::pop_back without any modification.

Returns
Value of the removed element.

Reimplemented from Array< T, Alloc >.

template<class T, class Alloc = PlainAllocator<T>>
virtual void NumberArray< T, Alloc >::push_back ( T const &  a)
inlinevirtual

Appends a new element to the end of the array. If the reserved storage has sufficient size, no reallocation takes place.

Reimplemented from Array< T, Alloc >.

template<class T, class Alloc = PlainAllocator<T>>
virtual void NumberArray< T, Alloc >::push_front ( T const &  a)
inlinevirtual

Prepends a new element to the start of the array. If the reserved storage has sufficient size, no reallocation takes place. The whole array has to be shifted by one element in any case.

template<class T, class Alloc = PlainAllocator<T>>
size_t NumberArray< T, Alloc >::reserve ( size_t  n)
inline

If the requested reserve size is greater than than the current reserve size, the memory is reallocated. Reserved memory allows fast push_back-s and similar operations, because no reallocation is necessary then.

Returns
New reserve size.
template<class T, class Alloc = PlainAllocator<T>>
virtual size_t NumberArray< T, Alloc >::resize ( size_t  n)
inlinevirtual

Set size of the array. If the new size is less than the reserved memory, the end of the array is just appropriately shifted. The "new" elements are not initialized. If the size is bigger than the reserve, the reallocation takes place and new elements are initialized to T(0).

Returns
New size of the array.

Reimplemented from Array< T, Alloc >.

template<class T, class Alloc = PlainAllocator<T>>
size_t NumberArray< T, Alloc >::size ( ) const
inline
template<class T, class Alloc = PlainAllocator<T>>
ArrayView<T> NumberArray< T, Alloc >::slice ( size_t  left,
size_t  right 
) const
inline
template<class T, class Alloc = PlainAllocator<T>>
std::string NumberArray< T, Alloc >::toBlob ( ) const
inline

Converts contents to SQL-readable BLOB (hexadecimal text format)

Warning
The data are stored in the endianness of the current machine.
template<class T, class Alloc = PlainAllocator<T>>
template<class Functor >
auto NumberArray< T, Alloc >::transform ( Functor  f) const -> NumberArray<decltype(f(T(0)))>
inline

The functor "f" will be applied on every item and the resulting array is returned. It is expected that the return value of the functor is a number type, so that NumberArray can be used.

Field Documentation

template<class T, class Alloc = PlainAllocator<T>>
NumberArray< T, Alloc >::__pad0__
template<class T, class Alloc = PlainAllocator<T>>
std::string NumberArray< T, Alloc >::name_
protected
template<class T, class Alloc = PlainAllocator<T>>
size_t NumberArray< T, Alloc >::Nres_
protected

The documentation for this class was generated from the following file: