Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
Seldon::Vector2< T, Allocator0, Allocator1 > Class Template Reference

Vector of vectors. More...

#include <Vector2.hxx>

Public Types

typedef T value_type
 
typedef T * pointer
 
typedef T & reference
 

Public Member Functions

 Vector2 ()
 Default constructor. More...
 
 Vector2 (long length)
 Constructor. More...
 
 Vector2 (const Vector< long > &length)
 Constructor. More...
 
 ~Vector2 ()
 Destructor. The vector of vectors and the inner vectors are deallocated.
 
bool IsEmpty () const
 Checks whether no elements are contained in the inner vectors. More...
 
long GetLength () const
 Returns the size along dimension 1. More...
 
long GetSize () const
 Returns the size along dimension 1. More...
 
long GetLength (long i) const
 Returns the size of the inner vector #i. More...
 
long GetSize (long i) const
 Returns the size of the inner vector #i. More...
 
size_t GetMemorySize () const
 Returns the memory used by the object in bytes. More...
 
long GetNelement () const
 Returns the total number of elements in the inner vectors. More...
 
long GetNelement (long beg, long end) const
 Returns the total number of elements in a range of inner vectors. More...
 
Vector< long > GetShape () const
 Returns the shape. More...
 
void GetShape (Vector< long > &shape) const
 Returns the shape. More...
 
void Reallocate (long M)
 Reallocates the vector of vector. More...
 
void Reallocate (long i, long N)
 Reallocates the inner vector #i. More...
 
void Reallocate (const Vector< long > &length)
 Reallocates the whole structure. More...
 
void Select (long beg, long end)
 Selects a range of inner vectors. More...
 
Vector< T, VectFull, Allocator0 > Flatten () const
 Returns all values in a vector. More...
 
template<class Td , class Allocatord >
void Flatten (Vector< Td, VectFull, Allocatord > &data) const
 Returns all values in a vector. More...
 
template<class Td , class Allocatord >
void Flatten (long beg, long end, Vector< Td, VectFull, Allocatord > &data) const
 Returns in a vector all values from a range of inner vectors. More...
 
void PushBack (long i, const T &x)
 Appends an element at the end of the inner vector #i. More...
 
void PushBack (const Vector< T, VectFull, Allocator0 > &X)
 Appends an inner vector at the end of the vector. More...
 
void PushBack (const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > &V)
 Appends a vector of vectors. More...
 
void PushBack (const Vector2< T, Allocator0, Allocator1 > &V)
 Appends a vector of vectors. More...
 
void Clear ()
 Clears the vector.
 
void Clear (long i)
 Clears a given vector. More...
 
void Fill (const T &x)
 Fills the vector with a given value. More...
 
Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > & GetVector ()
 Returns the vector of vectors. More...
 
const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > GetVector () const
 
Vector< T, VectFull, Allocator0 > & GetVector (long i)
 Returns a given inner vector. More...
 
const Vector< T, VectFull, Allocator0 > & GetVector (long i) const
 Returns a given inner vector. More...
 
void Copy (const Vector2< T, Allocator0, Allocator1 > &V)
 Copies a Vector2 instance. More...
 
Vector2< T, Allocator0, Allocator1 > Copy () const
 Copies a Vector2 instance. More...
 
const Vector< T, VectFull, Allocator0 > & operator() (long i) const
 Returns a given inner vector. More...
 
Vector< T, VectFull, Allocator0 > & operator() (long i)
 Returns a given inner vector. More...
 
const_reference operator() (long i, long j) const
 Returns an element of a given inner vector. More...
 
reference operator() (long i, long j)
 Returns an element of a given inner vector. More...
 
template<class V2 >
bool HasSameShape (const V2 &V) const
 Checks whether another Vector2 instance has the same shape. More...
 
void Print () const
 Displays the vector.
 
void Write (string file_name, bool with_size=true) const
 Writes the instance in a binary file. More...
 
void Write (ostream &file_stream, bool with_size=true) const
 Writes the instance in a stream in a binary format. More...
 
void Read (string file_name, bool with_size=true)
 Reads the Vector2 from a file. More...
 
void Read (istream &file_stream, bool with_size=true)
 Reads the Vector2 from a file. More...
 

Public Attributes

const typedef T * const_pointer
 
const typedef T & const_reference
 

Protected Attributes

Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > data_
 

Detailed Description

template<class T, class Allocator0 = typename SeldonDefaultAllocator<VectFull, T>::allocator, class Allocator1 = SELDON_VECTOR2_DEFAULT_ALLOCATOR_1< Vector<T, VectFull, Allocator0> >>
class Seldon::Vector2< T, Allocator0, Allocator1 >

Vector of vectors.

Vector2 is a structure that acts like a vector of vectors. The inner vectors can be of any dimension, so that this structure is more flexible than a matrix.

Template Parameters
Tnumerical type of the inner vectors.
Allocator0allocator for the inner vectors. The default allocator is SELDON_DEFAULT_ALLOCATOR.
Allocator1allocator for the vector of vectors. It is recommended to choose NewAlloc or, for more efficient in reallocations, MallocObject (default allocator here): these allocators can manage an array of inner vectors.

Definition at line 53 of file Vector2.hxx.

Constructor & Destructor Documentation

◆ Vector2() [1/3]

template<class T , class Allocator0 , class Allocator1 >
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2

Default constructor.

Nothing is allocated.

Definition at line 47 of file Vector2.cxx.

◆ Vector2() [2/3]

template<class T , class Allocator0 , class Allocator1 >
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2 ( long  length)

Constructor.

The vector of vectors is allocated with length empty vectors.

Parameters
[in]lengththe length of the vector of vectors.

Definition at line 57 of file Vector2.cxx.

◆ Vector2() [3/3]

template<class T , class Allocator0 , class Allocator1 >
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2 ( const Vector< long > &  length)

Constructor.

The vector of vectors and the inner vectors are allocated.

Parameters
[in]lengththe lengths of the inner vectors. The vector of vectors will obviously have as many elements as length has.

Definition at line 69 of file Vector2.cxx.

Member Function Documentation

◆ Clear()

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Clear ( long  i)

Clears a given vector.

Parameters
[in]iindex of the vector to be cleared.

Definition at line 443 of file Vector2.cxx.

◆ Copy() [1/2]

template<class T , class Allocator0 , class Allocator1 >
Vector2< T, Allocator0, Allocator1 > Seldon::Vector2< T, Allocator0, Allocator1 >::Copy

Copies a Vector2 instance.

Returns
A copy of the current Vector2 instance.
Note
The current instance and the copy do not share memory on exit.

Definition at line 535 of file Vector2.cxx.

◆ Copy() [2/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Copy ( const Vector2< T, Allocator0, Allocator1 > &  V)

Copies a Vector2 instance.

Parameters
[in]VVector2 instance to be copied.
Note
The current instance and V do not share memory on exit: V is duplicated in memory.

Definition at line 519 of file Vector2.cxx.

◆ Fill()

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Fill ( const T &  x)

Fills the vector with a given value.

Parameters
[in]xvalue to fill the vector with.

Definition at line 454 of file Vector2.cxx.

◆ Flatten() [1/3]

template<class T , class Allocator0 , class Allocator1 >
Vector< T, VectFull, Allocator0 > Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten

Returns all values in a vector.

The output vector contains all inner vectors concatenated in the same order as they appear in the current Vector2 instance.

Returns
All values from the current Vector2 instance.

Definition at line 316 of file Vector2.cxx.

◆ Flatten() [2/3]

template<class T , class Allocator0 , class Allocator1 >
template<class Td , class Allocatord >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten ( long  beg,
long  end,
Vector< Td, VectFull, Allocatord > &  data 
) const

Returns in a vector all values from a range of inner vectors.

The output vector data contains all inner vectors, in the index range [beg, end[, concatenated in the same order as they appear in the current Vector2 instance.

Parameters
[in]beginclusive lower-bound for the indexes.
[in]endexclusive upper-bound for the indexes.
[out]datathe values contained in the inner vectors [beg, end[.

Definition at line 357 of file Vector2.cxx.

◆ Flatten() [3/3]

template<class T , class Allocator0 , class Allocator1 >
template<class Td , class Allocatord >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten ( Vector< Td, VectFull, Allocatord > &  data) const

Returns all values in a vector.

The output vector data contains all inner vectors concatenated in the same order as they appear in the current Vector2 instance.

Parameters
[out]dataall values from the current Vector2 instance.

Definition at line 335 of file Vector2.cxx.

◆ GetLength() [1/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetLength

Returns the size along dimension 1.

Returns
The size along dimension 1.

Definition at line 126 of file Vector2.cxx.

◆ GetLength() [2/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetLength ( long  i) const

Returns the size of the inner vector #i.

Parameters
[in]iindex.
Returns
The size of the inner vector #i.

Definition at line 166 of file Vector2.cxx.

◆ GetMemorySize()

template<class T , class Allocator0 , class Allocator1 >
size_t Seldon::Vector2< T, Allocator0, Allocator1 >::GetMemorySize

Returns the memory used by the object in bytes.

In this method, the type T is assumed to be "static" such that sizeof(T) provides the correct size

Definition at line 150 of file Vector2.cxx.

◆ GetNelement() [1/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetNelement

Returns the total number of elements in the inner vectors.

Returns
The sum of the lengths of the inner vectors.

Definition at line 177 of file Vector2.cxx.

◆ GetNelement() [2/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetNelement ( long  beg,
long  end 
) const

Returns the total number of elements in a range of inner vectors.

Returns the total number of elements in the range [beg, end[ of inner vectors.

Parameters
[in]beginclusive lower-bound for the indexes.
[in]endexclusive upper-bound for the indexes.
Returns
The sum of the lengths of the inner vectors with index beg to end-1.

Definition at line 195 of file Vector2.cxx.

◆ GetShape() [1/2]

template<class T , class Allocator0 , class Allocator1 >
Vector< long > Seldon::Vector2< T, Allocator0, Allocator1 >::GetShape

Returns the shape.

Returns
A vector with the lengths of the inner vectors.

Definition at line 220 of file Vector2.cxx.

◆ GetShape() [2/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::GetShape ( Vector< long > &  shape) const

Returns the shape.

Parameters
[out]shapethe lengths of the inner vectors.

Definition at line 234 of file Vector2.cxx.

◆ GetSize() [1/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetSize

Returns the size along dimension 1.

Returns
The size along dimension 1.

Definition at line 115 of file Vector2.cxx.

◆ GetSize() [2/2]

template<class T , class Allocator0 , class Allocator1 >
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetSize ( long  i) const

Returns the size of the inner vector #i.

Parameters
[in]iindex.
Returns
The size of the inner vector #i.

Definition at line 138 of file Vector2.cxx.

◆ GetVector() [1/3]

template<class T , class Allocator0 , class Allocator1 >
const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector

Returns the vector of vectors.

Returns
The vector of vectors.

Definition at line 467 of file Vector2.cxx.

◆ GetVector() [2/3]

template<class T , class Allocator0 , class Allocator1 >
Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector ( long  i)

Returns a given inner vector.

Parameters
[in]iindex of the inner vector.
Returns
The inner vector #i.

Definition at line 492 of file Vector2.cxx.

◆ GetVector() [3/3]

template<class T , class Allocator0 , class Allocator1 >
const Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector ( long  i) const

Returns a given inner vector.

Parameters
[in]iindex of the inner vector.
Returns
The inner vector #i.

Definition at line 505 of file Vector2.cxx.

◆ HasSameShape()

template<class T , class Allocator0 , class Allocator1 >
template<class V2 >
bool Seldon::Vector2< T, Allocator0, Allocator1 >::HasSameShape ( const V2 &  V) const

Checks whether another Vector2 instance has the same shape.

Checks whether another Vector2 instance has the same shape as the current instance. The shapes are the same if both instances have the same number of inner vectors, and if the inner vectors have the same lengths.

Parameters
[in]VVector2 instance whose shape is compared to that of the current instance.
Returns
True if the current instance as the same shape as V, false otherwise.

Definition at line 618 of file Vector2.cxx.

◆ IsEmpty()

template<class T , class Allocator0 , class Allocator1 >
bool Seldon::Vector2< T, Allocator0, Allocator1 >::IsEmpty

Checks whether no elements are contained in the inner vectors.

Returns
True is no inner vector contains an element, false otherwise.

Definition at line 101 of file Vector2.cxx.

◆ operator()() [1/4]

template<class T , class Allocator0 , class Allocator1 >
Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::operator() ( long  i)

Returns a given inner vector.

Parameters
[in]iindex of the inner vector.
Returns
The inner vector #i.

Definition at line 568 of file Vector2.cxx.

◆ operator()() [2/4]

template<class T , class Allocator0 , class Allocator1 >
const Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::operator() ( long  i) const

Returns a given inner vector.

Parameters
[in]iindex of the inner vector.
Returns
The inner vector #i.

Definition at line 555 of file Vector2.cxx.

◆ operator()() [3/4]

template<class T , class Allocator0 , class Allocator1 >
Vector2< T, Allocator0, Allocator1 >::reference Seldon::Vector2< T, Allocator0, Allocator1 >::operator() ( long  i,
long  j 
)

Returns an element of a given inner vector.

Parameters
[in]iindex of the inner vector.
[in]jindex of the element in the inner vector #i.
Returns
The element #j of the inner vector #i.

Definition at line 596 of file Vector2.cxx.

◆ operator()() [4/4]

template<class T , class Allocator0 , class Allocator1 >
Vector2< T, Allocator0, Allocator1 >::const_reference Seldon::Vector2< T, Allocator0, Allocator1 >::operator() ( long  i,
long  j 
) const

Returns an element of a given inner vector.

Parameters
[in]iindex of the inner vector.
[in]jindex of the element in the inner vector #i.
Returns
The element #j of the inner vector #i.

Definition at line 582 of file Vector2.cxx.

◆ PushBack() [1/4]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack ( const Vector2< T, Allocator0, Allocator1 > &  V)

Appends a vector of vectors.

The inner vectors of V are appended to the current instance, in the same order as they appear in V.

Parameters
[in]Vvector of vectors to be appended.

Definition at line 424 of file Vector2.cxx.

◆ PushBack() [2/4]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack ( const Vector< T, VectFull, Allocator0 > &  X)

Appends an inner vector at the end of the vector.

Parameters
[in]Xvector to be appended.

Definition at line 396 of file Vector2.cxx.

◆ PushBack() [3/4]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack ( const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > &  V)

Appends a vector of vectors.

The inner vectors of V are appended to the current instance, in the same order as they appear in V.

Parameters
[in]Vvector of vectors to be appended.

Definition at line 409 of file Vector2.cxx.

◆ PushBack() [4/4]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack ( long  i,
const T &  x 
)

Appends an element at the end of the inner vector #i.

Parameters
[in]iindex of the inner vector to which x should be appended.
[in]xelement to be appended.

Definition at line 384 of file Vector2.cxx.

◆ Read() [1/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Read ( istream &  stream,
bool  with_size = true 
)

Reads the Vector2 from a file.

Sets the current Vector2 instance according to a binary stream that stores the total number of inner vectors, and, for each inner vector, the length of the vector (integer) and its elements.

Parameters
[in,out]streaminput stream.
[in]with_sizeif set to 'false', the total number of inner vectors and the lengths of the vectors are not available in the stream. In this case, the shape of the current instance is unchanged and the values of the elements are directly read in the file.

Definition at line 760 of file Vector2.cxx.

◆ Read() [2/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Read ( string  file_name,
bool  with_size = true 
)

Reads the Vector2 from a file.

Sets the current Vector2 instance according to a binary file that stores the total number of inner vectors, and, for each inner vector, the length of the vector (integer) and its elements.

Parameters
[in]file_namefile name.
[in]with_sizeif set to 'false', the total number of inner vectors and the lengths of the vectors are not available in the file. In this case, the shape of the current instance is unchanged and the values of the elements are directly read in the file.

Definition at line 729 of file Vector2.cxx.

◆ Reallocate() [1/3]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate ( const Vector< long > &  length)

Reallocates the whole structure.

Parameters
[in]lengththe new lengths of the inner vectors. The vector of vectors will obviously have as many elements as length has.

Definition at line 272 of file Vector2.cxx.

◆ Reallocate() [2/3]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate ( long  i,
long  N 
)

Reallocates the inner vector #i.

Parameters
[in]iindex of the inner vector to be reallocated.
[in]Nthe new size of the inner vector #i.

Definition at line 259 of file Vector2.cxx.

◆ Reallocate() [3/3]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate ( long  M)

Reallocates the vector of vector.

Parameters
[in]Mthe new size of the vector of vectors.

Definition at line 247 of file Vector2.cxx.

◆ Select()

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Select ( long  beg,
long  end 
)

Selects a range of inner vectors.

Only the inner vectors with index in [beg, end[ are kept. The other vectors are destroyed.

Parameters
[in]beginclusive lower-bound for the indexes.
[in]endexclusive upper-bound for the indexes.

Definition at line 288 of file Vector2.cxx.

◆ Write() [1/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Write ( ostream &  stream,
bool  with_size = true 
) const

Writes the instance in a stream in a binary format.

The number of inner vectors (longeger) is written first. Then for each vector, the length of the vector (longeger) and all elements of the vector are written.

Parameters
[in,out]streamoutput stream.
[in]with_sizeif set to 'false', the number of vectors and the lengths of the inner vectors are not saved.

Definition at line 686 of file Vector2.cxx.

◆ Write() [2/2]

template<class T , class Allocator0 , class Allocator1 >
void Seldon::Vector2< T, Allocator0, Allocator1 >::Write ( string  file_name,
bool  with_size = true 
) const

Writes the instance in a binary file.

The number of inner vectors (longeger) is written first. Then for each vector, the length of the vector (longeger) and all elements of the vector are written.

Parameters
[in]file_namefile name.
[in]with_sizeif set to 'false', the number of vectors and the lengths of the inner vectors are not saved.

Definition at line 657 of file Vector2.cxx.


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