Sparse vector class. More...
#include <SparseVector.hxx>
Public Types | |
typedef Allocator::value_type | value_type |
typedef Allocator::pointer | pointer |
typedef Allocator::const_pointer | const_pointer |
typedef Allocator::reference | reference |
typedef Allocator::const_reference | const_reference |
typedef SeldonDefaultAllocator< VectFull, int >::allocator | AllocatorInt |
typedef VectSparse | storage |
typedef Allocator | allocator |
Public Member Functions | |
Vector () | |
Default constructor. More... | |
Vector (size_t i) | |
Main constructor. More... | |
Vector (const Vector< T, VectSparse, Allocator > &A) | |
Copy constructor. More... | |
~Vector () | |
Destructor. | |
void | Clear () |
Clears the vector. More... | |
void | Reallocate (size_t i) |
Vector reallocation. More... | |
void | ReallocateVector (size_t i) |
Vector reallocation. More... | |
void | Resize (size_t i) |
Changes the number of non-zero entries of the vector. More... | |
void | ResizeVector (size_t i) |
Changes the number of non-zero entries of the vector. More... | |
void | SetData (size_t nz, T *data, int *index) |
Changes the length of the vector and sets its data array (low level method). More... | |
template<class Allocator2 > | |
void | SetData (Vector< T, VectFull, Allocator2 > &data, Vector< int > &index) |
Changes the length of the vector and sets its data array (low level method). More... | |
template<class Allocator2 > | |
void | SetData (const Vector< T, VectSparse, Allocator2 > &V) |
Lets the current vector point to the data of a second vector (low level method). More... | |
void | Nullify () |
Clears the vector without releasing memory. More... | |
reference | Value (int i) |
Access operator. More... | |
const_reference | Value (int i) const |
Access operator. More... | |
int & | Index (int i) |
Access operator. More... | |
int | Index (int i) const |
Access operator. More... | |
value_type | operator() (int i) |
Access method. More... | |
reference | Get (int i) |
Access method. More... | |
reference | Val (int i) |
Access method. More... | |
value_type | operator() (int i) const |
Access operator. More... | |
const_reference | Get (int i) const |
Access method. More... | |
const_reference | Val (int i) const |
Access method. More... | |
Vector< T, VectSparse, Allocator > & | operator= (const Vector< T, VectSparse, Allocator > &X) |
Duplicates a vector (assignment operator). More... | |
template<class T2 , class Alloc2 > | |
void | Copy (const Vector< T2, VectSparse, Alloc2 > &X) |
Duplicates a vector. More... | |
int * | GetIndex () const |
Returns a pointer to the array containing the indices of the non-zero entries. More... | |
size_t | GetMemorySize () const |
Returns the memory used by the object in bytes. More... | |
template<class T0 > | |
Vector< T, VectSparse, Allocator > & | operator= (const T0 &X) |
Fills the vector with a given value. More... | |
void | Print () const |
Displays the vector. | |
void | Assemble () |
Assembles the vector. More... | |
template<class T0 > | |
void | RemoveSmallEntry (const T0 &epsilon) |
Removes small entries. More... | |
void | AddInteraction (int i, const T &val) |
Adds val to the vector component #i. More... | |
void | AddInteractionRow (size_t, int *, T *, bool already_sorted=false) |
Adds given values to several components of the vector. More... | |
template<class Allocator0 > | |
void | AddInteractionRow (size_t nb, const Vector< int > &col, const Vector< T, VectFull, Allocator0 > &val, bool already_sorted=false) |
Adds given values to several components of the vector. More... | |
ClassComplexType< T >::Treal | GetNormInf () const |
Returns the infinite norm. More... | |
int | GetNormInfIndex () const |
Returns the index of the highest absolute value. More... | |
void | Write (string FileName) const |
Writes the vector in a file. More... | |
void | Write (ostream &FileStream) const |
Writes the vector in a stream, in binary format. More... | |
void | WriteText (string FileName) const |
Writes the vector in a text file. More... | |
void | WriteText (ostream &FileStream) const |
Writes the vector in a stream, in text format. More... | |
void | Read (string FileName) |
Sets the vector from a file in binary format. More... | |
void | Read (istream &FileStream) |
Sets the vector from a file stream, in binary format. More... | |
void | ReadText (string FileName) |
Sets the vector from a text file. More... | |
void | ReadText (istream &FileStream) |
Sets the vector from a file stream, in text format. More... | |
void | SetData (size_t i, pointer data) |
template<class Allocator0 > | |
void | SetData (const Vector< T, VectFull, Allocator0 > &V) |
Lets the current vector point to the data of another vector. More... | |
reference | operator() (long i) |
Access operator. More... | |
const_reference | operator() (long i) const |
Access operator. More... | |
reference | Get (long i) |
Access to element i. More... | |
const_reference | Get (long i) const |
Access to element i. More... | |
void | Copy (const Vector< T, VectFull, Allocator > &X) |
Duplicates a vector. More... | |
Vector< T, VectFull, Allocator > | Copy () const |
Duplicates a vector. More... | |
void | Append (const T &x) |
Appends an element to the vector. More... | |
template<class T0 > | |
void | PushBack (const T0 &x) |
Appends an element at the end of the vector. More... | |
template<class Allocator0 > | |
void | PushBack (const Vector< T, VectFull, Allocator0 > &X) |
Appends a vector X at the end of the vector. More... | |
size_t | GetDataSize () |
Returns the number of elements stored. More... | |
void | Zero () |
Sets all elements to zero. More... | |
void | Fill () |
Fills the vector with 0, 1, 2, ... | |
template<class T0 > | |
void | Fill (const T0 &x) |
Fills the vector with a given value. More... | |
template<class T0 > | |
Vector< T, VectFull, Allocator > & | operator*= (const T0 &X) |
Multiplies a vector by a scalar. More... | |
template<class E > | |
Vector< T, VectFull, Allocator > & | operator+= (const VectorExpression< T, E > &) |
Operator +=, *this = *this + X where X is an expression. | |
template<class E > | |
Vector< T, VectFull, Allocator > & | operator-= (const VectorExpression< T, E > &) |
Operator -=, *this = *this - X where X is an expression. | |
void | FillRand () |
Fills the vector randomly. More... | |
void | Write (string FileName, bool with_size=true) const |
Writes the vector in a file. More... | |
void | Write (ostream &FileStream, bool with_size=true) const |
Writes the vector in a file stream. More... | |
void | Read (string FileName, bool with_size=true) |
Sets the vector from a file. More... | |
void | Read (istream &FileStream, bool with_size=true) |
Sets the vector from a file stream. More... | |
long | GetM () const |
Returns the number of elements. More... | |
size_t | GetLength () const |
Returns the number of elements. More... | |
size_t | GetSize () const |
Returns the number of elements stored. More... | |
pointer | GetData () const |
Returns a pointer to data_ (stored data). More... | |
const_pointer | GetDataConst () const |
Returns a const pointer to data_ (stored data). More... | |
void * | GetDataVoid () const |
Returns a pointer of type "void*" to the data array (data_). More... | |
const void * | GetDataConstVoid () const |
Returns a pointer of type "const void*" to the data array (data_). More... | |
Protected Attributes | |
size_t | m_ |
pointer | data_ |
Sparse vector class.
Definition at line 29 of file SparseVector.hxx.
|
inlineexplicit |
Default constructor.
On exit, the vector is empty.
Definition at line 39 of file SparseVectorInline.cxx.
|
explicit |
Main constructor.
Builds a vector of a given size.
i | length of the vector. |
Definition at line 38 of file SparseVector.cxx.
|
inline |
Copy constructor.
Builds a copy of a vector.
V | vector to be copied. |
Definition at line 52 of file SparseVectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::AddInteraction | ( | int | i, |
const T & | val | ||
) |
Adds val to the vector component #i.
If the vector has no entry at i, a new entry with value val is introduced. Otherwise, this method sums the existing value and val.
[in] | i | index of the component. |
[in] | val | value to be added to the vector component i. |
Definition at line 560 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::AddInteractionRow | ( | size_t | n, |
const Vector< int > & | index2, | ||
const Vector< T, VectFull, Allocator0 > & | value2, | ||
bool | already_sorted = false |
||
) |
Adds given values to several components of the vector.
This method sorts the values to be added (according to their indices) and adds them with the vector values. For every component, if the vector has no entry, a new entry is introduced. Otherwise, the method sums the existing value and the corresponsing value in value.
[in] | n | number of values to be added. |
[in] | index | indices of the values to be added. |
[in] | value | values to be added. |
[in] | already_sorted | true if the indices are already sorted. |
Definition at line 629 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::AddInteractionRow | ( | size_t | n, |
int * | index, | ||
T * | value, | ||
bool | already_sorted = false |
||
) |
Adds given values to several components of the vector.
This method sorts the values to be added (according to their indices) and adds them with the vector values. For every component, if the vector has no entry, a new entry is introduced. Otherwise, the method sums the existing value and the corresponsing value in value.
[in] | n | number of values to be added. |
[in] | index | indices of the values to be added. |
[in] | value | values to be added. |
[in] | already_sorted | true if the indices are already sorted. |
Definition at line 604 of file SparseVector.cxx.
|
inlineinherited |
Appends an element to the vector.
x | element to be appended. |
Definition at line 665 of file VectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Assemble |
Assembles the vector.
Definition at line 509 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Clear |
Clears the vector.
Destructs the vector.
Definition at line 80 of file SparseVector.cxx.
|
inlineinherited |
Duplicates a vector.
Definition at line 600 of file VectorInline.cxx.
|
inlineinherited |
Duplicates a vector.
X | vector to be copied. |
Definition at line 584 of file VectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Copy | ( | const Vector< T2, VectSparse, Alloc2 > & | X | ) |
Duplicates a vector.
X | vector to be copied. |
Definition at line 465 of file SparseVector.cxx.
|
inlineinherited |
Fills the vector with a given value.
x | value to fill the vector with. |
Definition at line 749 of file VectorInline.cxx.
|
inlineinherited |
Fills the vector randomly.
Definition at line 777 of file VectorInline.cxx.
Vector< T, VectSparse, Allocator >::reference Seldon::Vector< T, VectSparse, Allocator >::Get | ( | int | i | ) |
Access method.
Returns the value of element i.
[in] | i | index. |
WrongArgument | No reference can be returned because the element is a zero entry (not stored in the vector). |
Definition at line 366 of file SparseVector.cxx.
Vector< T, VectSparse, Allocator >::const_reference Seldon::Vector< T, VectSparse, Allocator >::Get | ( | int | i | ) | const |
Access method.
Returns the value of element i.
[in] | i | index. |
WrongArgument | No reference can be returned because the element is a zero entry (not stored in the vector). |
Definition at line 392 of file SparseVector.cxx.
|
inlineinherited |
Access to element i.
i | index. |
Definition at line 513 of file VectorInline.cxx.
|
inlineinherited |
Access to element i.
i | index. |
Definition at line 549 of file VectorInline.cxx.
|
inlineinherited |
Returns a pointer to data_ (stored data).
Definition at line 177 of file VectorInline.cxx.
|
inlineinherited |
Returns a const pointer to data_ (stored data).
Definition at line 189 of file VectorInline.cxx.
|
inlineinherited |
Returns a pointer of type "const void*" to the data array (data_).
Definition at line 212 of file VectorInline.cxx.
|
inlineinherited |
Returns the number of elements stored.
Definition at line 710 of file VectorInline.cxx.
|
inlineinherited |
Returns a pointer of type "void*" to the data array (data_).
Definition at line 201 of file VectorInline.cxx.
|
inline |
Returns a pointer to the array containing the indices of the non-zero entries.
Definition at line 189 of file SparseVectorInline.cxx.
|
inlineinherited |
Returns the number of elements.
Definition at line 142 of file VectorInline.cxx.
|
inlineinherited |
Returns the number of elements.
Definition at line 131 of file VectorInline.cxx.
|
inline |
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 201 of file SparseVectorInline.cxx.
ClassComplexType< T >::Treal Seldon::Vector< T, VectSparse, Allocator >::GetNormInf |
Returns the infinite norm.
Definition at line 736 of file SparseVector.cxx.
int Seldon::Vector< T, VectSparse, Allocator >::GetNormInfIndex |
Returns the index of the highest absolute value.
Definition at line 751 of file SparseVector.cxx.
|
inlineinherited |
Returns the number of elements stored.
Definition at line 153 of file VectorInline.cxx.
|
inline |
Access operator.
i | index. |
Definition at line 134 of file SparseVectorInline.cxx.
|
inline |
Access operator.
i | index. |
Definition at line 151 of file SparseVectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Nullify |
Clears the vector without releasing memory.
On exit, the vector is empty and the memory has not been released. It is useful for low level manipulations on a Vector instance.
Definition at line 294 of file SparseVector.cxx.
Vector< T, VectSparse, Allocator >::value_type Seldon::Vector< T, VectSparse, Allocator >::operator() | ( | int | i | ) |
Access method.
Returns the value of element i.
[in] | i | index. |
WrongArgument | No reference can be returned because the element is a zero entry (not stored in the vector). |
Definition at line 340 of file SparseVector.cxx.
Vector< T, VectSparse, Allocator >::value_type Seldon::Vector< T, VectSparse, Allocator >::operator() | ( | int | i | ) | const |
Access operator.
i | index. |
Definition at line 314 of file SparseVector.cxx.
|
inlineinherited |
Access operator.
i | index. |
Definition at line 495 of file VectorInline.cxx.
|
inlineinherited |
Access operator.
i | index. |
Definition at line 531 of file VectorInline.cxx.
|
inlineinherited |
Multiplies a vector by a scalar.
alpha | scalar. |
Definition at line 612 of file VectorInline.cxx.
Vector< T, VectSparse, Allocator > & Seldon::Vector< T, VectSparse, Allocator >::operator= | ( | const T0 & | x | ) |
Fills the vector with a given value.
x | value to fill the vector with. |
Definition at line 486 of file SparseVector.cxx.
|
inline |
Duplicates a vector (assignment operator).
X | vector to be copied. |
Definition at line 170 of file SparseVectorInline.cxx.
|
inlineinherited |
Appends an element at the end of the vector.
x | element to be appended. |
Definition at line 678 of file VectorInline.cxx.
|
inlineinherited |
Appends a vector X at the end of the vector.
X | vector to be appended. |
Definition at line 691 of file VectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Read | ( | istream & | stream | ) |
Sets the vector from a file stream, in binary format.
Sets the vector according to a binary stream that stores the data like method Write(ostream&).
stream | stream from which to read the vector values. |
Definition at line 928 of file SparseVector.cxx.
|
inherited |
Sets the vector from a file stream.
Sets the vector according to a binary file stream that stores the length of the vector (integer) and all elements.
FileStream | file stream. |
with_size | if set to 'false', the length of the vector is not available in the stream. In this case, the current size N of the vector is unchanged, and N elements are read in the stream. |
Definition at line 370 of file Vector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Read | ( | string | FileName | ) |
Sets the vector from a file in binary format.
Sets the vector according to a binary file that stores the data like method Write(string).
FileName | file name. |
Definition at line 904 of file SparseVector.cxx.
|
inherited |
Sets the vector from a file.
Sets the vector according to a binary file that stores the length of the vector (integer) and all elements.
FileName | file name. |
with_size | if set to 'false', the length of the vector is not available in the file. In this case, the current size N of the vector is unchanged, and N elements are read in the file. |
Definition at line 341 of file Vector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::ReadText | ( | istream & | stream | ) |
Sets the vector from a file stream, in text format.
Sets the vector according to a stream, in text format, that stores the data like method WriteText(ostream&).
stream | stream from which to read the vector values. |
Definition at line 987 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::ReadText | ( | string | FileName | ) |
Sets the vector from a text file.
Sets the vector according to a text file that stores the data like method WriteText(string).
FileName | file name. |
Definition at line 963 of file SparseVector.cxx.
|
inline |
Vector reallocation.
The vector is resized.
i | new length of the vector. |
Definition at line 68 of file SparseVectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::ReallocateVector | ( | size_t | i | ) |
Vector reallocation.
The vector is resized.
i | new length of the vector. |
Definition at line 123 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::RemoveSmallEntry | ( | const T0 & | epsilon | ) |
Removes small entries.
Any number whose absolute value is below (or equal) to epsilon is removed.
epsilon | the threshold value. |
Definition at line 533 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Resize | ( | size_t | n | ) |
Changes the number of non-zero entries of the vector.
Changes the number of non-zero entries to n. If n non-zero entries are available before resizing, they are all kept. Otherwise, only the first
non-zero entries are kept.
n | new number of non-zero entries of the vector. |
Definition at line 173 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::ResizeVector | ( | size_t | n | ) |
Changes the number of non-zero entries of the vector.
Changes the number of non-zero entries to n. If n non-zero entries are available before resizing, they are all kept. Otherwise, only the first
non-zero entries are kept.
n | new number of non-zero entries of the vector. |
Definition at line 186 of file SparseVector.cxx.
|
inlineinherited |
Lets the current vector point to the data of another vector.
Deallocates memory allocated for the current data array. Then sets the length and the data of the current vector to that of V. On exit, the current vector shares it data array with V.
V | vector whose data should be shared with current instance. |
Definition at line 463 of file VectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::SetData | ( | const Vector< T, VectSparse, Allocator2 > & | V | ) |
Lets the current vector point to the data of a second vector (low level method).
Reallocates the current vector and lets its data point to those of V.
V | the vector to which the current vector points to (on exit). |
Definition at line 281 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::SetData | ( | size_t | i, |
T * | data, | ||
int * | index | ||
) |
Changes the length of the vector and sets its data array (low level method).
Reallocates a vector and sets the new data array. It is useful to create a vector from pre-existing data.
i | new length of the vector. |
data | the new data array. data contains the new elements of the vector and must therefore contain i elements. |
index | the new index array. index contains the new indices of the non-zero entries and it must therefore contain i elements. |
Definition at line 224 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::SetData | ( | Vector< T, VectFull, Allocator2 > & | data, |
Vector< int > & | index | ||
) |
Changes the length of the vector and sets its data array (low level method).
Reallocates a vector and sets the new data array. It is useful to create a vector from pre-existing data.
data | the new data array. data contains the new elements of the vector and must therefore contain i elements. |
index | the new index array. index contains the new indices of the non-zero entries and it must therefore contain i elements. |
Definition at line 249 of file SparseVector.cxx.
Vector< T, VectSparse, Allocator >::reference Seldon::Vector< T, VectSparse, Allocator >::Val | ( | int | i | ) |
Access method.
Returns the value of element i.
[in] | i | index. |
WrongArgument | if i does not belong to the sparsity pattern |
Definition at line 416 of file SparseVector.cxx.
Vector< T, VectSparse, Allocator >::const_reference Seldon::Vector< T, VectSparse, Allocator >::Val | ( | int | i | ) | const |
Access method.
Returns the value of element i.
[in] | i | index. |
WrongArgument | if i does not belong to the sparsity pattern |
Definition at line 441 of file SparseVector.cxx.
|
inline |
Access operator.
i | index. |
Definition at line 99 of file SparseVectorInline.cxx.
|
inline |
Access operator.
i | index. |
Definition at line 117 of file SparseVectorInline.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Write | ( | ostream & | stream | ) | const |
Writes the vector in a stream, in binary format.
It writes in binary format: (1) the number of non-zero entries in the vector (integer), (2) the indices of the non-zero entries (integers), and (3) the non-zero values of the vector.
stream | stream in which the vector is to be written. |
Definition at line 810 of file SparseVector.cxx.
|
inherited |
Writes the vector in a file stream.
The length of the vector (integer) and all elements of the vector are stored in binary format.
FileStream | file stream. |
with_size | if set to 'false', the length of the vector is not saved. |
Definition at line 152 of file Vector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::Write | ( | string | FileName | ) | const |
Writes the vector in a file.
It stores in binary format: (1) the number of non-zero entries in the vector (integer), (2) the indices of the non-zero entries (integers), and (3) the non-zero values of the vector.
FileName | file name. |
Definition at line 785 of file SparseVector.cxx.
|
inherited |
Writes the vector in a file.
The length of the vector (integer) and all elements of the vector are stored in binary format.
FileName | file name. |
with_size | if set to 'false', the length of the vector is not saved. |
Definition at line 124 of file Vector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::WriteText | ( | ostream & | stream | ) | const |
Writes the vector in a stream, in text format.
All non-zero elements of the vector are stored in text format: every line of the text file contains one index and one value. The length is not stored.
stream | stream in which the vector is to be written. |
Definition at line 874 of file SparseVector.cxx.
void Seldon::Vector< T, VectSparse, Allocator >::WriteText | ( | string | FileName | ) | const |
Writes the vector in a text file.
All non-zero elements of the vector are stored in text format: every line of the text file contains one index and one value. The length is not stored.
FileName | file name. |
Definition at line 847 of file SparseVector.cxx.
|
inlineinherited |
Sets all elements to zero.
Definition at line 727 of file VectorInline.cxx.