![]() |
Efficient implementation of an arbitrary sized sparse vector.The CompressedVector class is the representation of an arbitrarily sized sparse vector, which stores only non-zero elements of arbitrary type. The type of the elements and the transpose flag of the vector can be specified via the two template parameters: More...
#include <CompressedVector.h>
Inherits blaze::SparseVector< CompressedVector< Type, TF >, TF >.
Public Types | |
typedef CompressedVector< Type, TF > | This |
Type of this CompressedVector instance. | |
typedef This | ResultType |
Result type for expression template evaluations. | |
typedef CompressedVector< Type,!TF > | TransposeType |
Transpose type for expression template evaluations. | |
typedef Type | ElementType |
Type of the compressed vector elements. | |
typedef const Type & | ReturnType |
Return type for expression template evaluations. | |
typedef const CompressedVector & | CompositeType |
Data type for composite expression templates. | |
typedef VectorAccessProxy< This > | Reference |
Reference to a non-constant vector value. | |
typedef const Type & | ConstReference |
Reference to a constant vector value. | |
typedef Element * | Iterator |
Iterator over non-constant elements. | |
typedef const Element * | ConstIterator |
Iterator over constant elements. | |
typedef VT | VectorType |
Type of the vector. | |
Public Member Functions | |
template<typename VT > | |
CompressedVector< Type, TF > & | operator= (const DenseVector< VT, TF > &rhs) |
Assignment operator for dense vectors. More... | |
template<typename VT > | |
CompressedVector< Type, TF > & | operator= (const SparseVector< VT, TF > &rhs) |
Assignment operator for different sparse vectors. More... | |
template<typename VT > | |
CompressedVector< Type, TF > & | operator+= (const Vector< VT, TF > &rhs) |
Addition assignment operator for the addition of a vector ( ![]() | |
template<typename VT > | |
CompressedVector< Type, TF > & | operator-= (const Vector< VT, TF > &rhs) |
Subtraction assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT > | |
CompressedVector< Type, TF > & | operator*= (const Vector< VT, TF > &rhs) |
Multiplication assignment operator for the multiplication of a vector ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , CompressedVector< Type, TF > >::Type & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a compressed vector and a scalar value ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , CompressedVector< Type, TF > >::Type & | operator/= (Other rhs) |
Division assignment operator for the division of a compressed vector by a scalar value ( ![]() | |
template<typename Other > | |
CompressedVector< Type, TF > & | scale (Other scalar) |
Scaling of the compressed vector by the scalar value scalar ( ![]() | |
VectorType & | operator~ () |
Conversion operator for non-constant vectors. More... | |
const VectorType & | operator~ () const |
Conversion operator for constant vectors. More... | |
Constructors | |
CompressedVector () | |
The default constructor for CompressedVector. | |
CompressedVector (size_t size) | |
Constructor for a compressed vector of size n. More... | |
CompressedVector (size_t size, size_t nonzeros) | |
Constructor for a compressed vector of size n. More... | |
CompressedVector (const CompressedVector &sv) | |
The copy constructor for CompressedVector. More... | |
template<typename VT > | |
CompressedVector (const DenseVector< VT, TF > &dv) | |
Conversion constructor from dense vectors. More... | |
template<typename VT > | |
CompressedVector (const SparseVector< VT, TF > &sv) | |
Conversion constructor from different sparse vectors. More... | |
Destructor | |
~CompressedVector () | |
The destructor for CompressedVector. | |
Data access functions | |
Reference | operator[] (size_t index) |
Subscript operator for the direct access to the compressed vector elements. More... | |
ConstReference | operator[] (size_t index) const |
Subscript operator for the direct access to the compressed vector elements. More... | |
Iterator | begin () |
Returns an iterator to the first non-zero element of the compressed vector. More... | |
ConstIterator | begin () const |
Returns an iterator to the first non-zero element of the compressed vector. More... | |
ConstIterator | cbegin () const |
Returns an iterator to the first non-zero element of the compressed vector. More... | |
Iterator | end () |
Returns an iterator just past the last non-zero element of the compressed vector. More... | |
ConstIterator | end () const |
Returns an iterator just past the last non-zero element of the compressed vector. More... | |
ConstIterator | cend () const |
Returns an iterator just past the last non-zero element of the compressed vector. More... | |
Assignment operators | |
CompressedVector & | operator= (const CompressedVector &rhs) |
Copy assignment operator for CompressedVector. More... | |
template<typename VT > | |
CompressedVector & | operator= (const DenseVector< VT, TF > &rhs) |
template<typename VT > | |
CompressedVector & | operator= (const SparseVector< VT, TF > &rhs) |
template<typename VT > | |
CompressedVector & | operator+= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
CompressedVector & | operator-= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
CompressedVector & | operator*= (const Vector< VT, TF > &rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , CompressedVector >::Type & | operator*= (Other rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , CompressedVector >::Type & | operator/= (Other rhs) |
Low-level utility functions | |
void | append (size_t index, const Type &value, bool check=false) |
Appending an element to the compressed vector. More... | |
Expression template evaluation functions | |
template<typename Other > | |
bool | canAlias (const Other *alias) const |
Returns whether the vector can alias with the given address alias. More... | |
template<typename Other > | |
bool | isAliased (const Other *alias) const |
Returns whether the vector is aliased with the given address alias. More... | |
template<typename VT > | |
void | assign (const DenseVector< VT, TF > &rhs) |
Default implementation of the assignment of a dense vector. More... | |
template<typename VT > | |
void | assign (const SparseVector< VT, TF > &rhs) |
Default implementation of the assignment of a sparse vector. More... | |
template<typename VT > | |
void | addAssign (const DenseVector< VT, TF > &rhs) |
Default implementation of the addition assignment of a dense vector. More... | |
template<typename VT > | |
void | addAssign (const SparseVector< VT, TF > &rhs) |
Default implementation of the addition assignment of a sparse vector. More... | |
template<typename VT > | |
void | subAssign (const DenseVector< VT, TF > &rhs) |
Default implementation of the subtraction assignment of a dense vector. More... | |
template<typename VT > | |
void | subAssign (const SparseVector< VT, TF > &rhs) |
Default implementation of the subtraction assignment of a sparse vector. More... | |
Private Types | |
typedef SparseElement< Type > | ElementBase |
Base class for the compressed vector element. | |
Utility functions | |
size_t | size () const |
Returns the current size/dimension of the compressed vector. More... | |
size_t | capacity () const |
Returns the maximum capacity of the compressed vector. More... | |
size_t | nonZeros () const |
Returns the number of non-zero elements in the compressed vector. More... | |
void | reset () |
Reset to the default initial values. More... | |
void | clear () |
Clearing the compressed vector. More... | |
Iterator | insert (size_t index, const Type &value) |
Inserting an element into the compressed vector. More... | |
void | erase (size_t index) |
Erasing an element from the compressed vector. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the compressed vector. More... | |
Iterator | find (size_t index) |
Searches for a specific vector element. More... | |
ConstIterator | find (size_t index) const |
Searches for a specific vector element. More... | |
void | resize (size_t n, bool preserve=true) |
Changing the size of the compressed vector. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the compressed vector. More... | |
template<typename Other > | |
CompressedVector & | scale (Other scalar) |
void | swap (CompressedVector &sv) |
Swapping the contents of two compressed vectors. More... | |
size_t | extendCapacity () const |
Calculating a new vector capacity. More... | |
Member variables | |
size_t | size_ |
The current size/dimension of the compressed vector. | |
size_t | capacity_ |
The maximum capacity of the compressed vector. | |
Iterator | begin_ |
Pointer to the first non-zero element of the compressed vector. | |
Iterator | end_ |
Pointer one past the last non-zero element of the compressed vector. | |
static const Type | zero_ = Type() |
Neutral element for accesses to zero elements. | |
Efficient implementation of an arbitrary sized sparse vector.
The CompressedVector class is the representation of an arbitrarily sized sparse vector, which stores only non-zero elements of arbitrary type. The type of the elements and the transpose flag of the vector can be specified via the two template parameters:
Inserting/accessing elements in a compressed vector can be done by several alternative functions. The following example demonstrates all options:
The use of CompressedVector is very natural and intuitive. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of dense and sparse vectors with fitting element types. The following example gives an impression of the use of CompressedVector:
|
inlineexplicit |
Constructor for a compressed vector of size n.
n | The size of the vector. |
|
inlineexplicit |
Constructor for a compressed vector of size n.
n | The size of the vector. |
nonzeros | The number of expected non-zero elements. |
|
inline |
The copy constructor for CompressedVector.
sv | Compressed vector to be copied. |
The copy constructor is explicitly defined due to the required dynamic memory management and in order to enable/facilitate NRV optimization.
|
inline |
Conversion constructor from dense vectors.
dv | Dense vector to be copied. |
|
inline |
Conversion constructor from different sparse vectors.
sv | Sparse vector to be copied. |
|
inline |
Default implementation of the addition assignment of a dense vector.
rhs | The right-hand side dense vector to be added. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Default implementation of the addition assignment of a sparse vector.
rhs | The right-hand side sparse vector to be added. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Appending an element to the compressed vector.
index | The index of the new element. The index has to be in the range ![]() |
value | The value of the element to be appended. |
check | true if the new value should be checked for default values, false if not. |
This function provides a very efficient way to fill a compressed vector with elements. It appends a new element to the end of the compressed vector without any memory allocation. Therefore it is strictly necessary to keep the following preconditions in mind:
Ignoring these preconditions might result in undefined behavior! The optional check parameter specifies whether the new value should be tested for a default value. If the new value is a default value (for instance 0 in case of an integral element type) the value is not appended. Per default the values are not tested.
Note: Although append() does not allocate new memory, it still invalidates all iterators returned by the end() functions!
|
inline |
Default implementation of the assignment of a dense vector.
rhs | The right-hand side dense vector to be assigned. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Default implementation of the assignment of a sparse vector.
rhs | The right-hand side sparse vector to be assigned. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Returns an iterator to the first non-zero element of the compressed vector.
|
inline |
Returns an iterator to the first non-zero element of the compressed vector.
|
inline |
Returns whether the vector can alias with the given address alias.
alias | The alias to be checked. |
This function returns whether the given address can alias with the vector. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.
|
inline |
Returns the maximum capacity of the compressed vector.
|
inline |
Returns an iterator to the first non-zero element of the compressed vector.
|
inline |
Returns an iterator just past the last non-zero element of the compressed vector.
|
inline |
Clearing the compressed vector.
After the clear() function, the size of the compressed vector is 0.
|
inline |
Returns an iterator just past the last non-zero element of the compressed vector.
|
inline |
Returns an iterator just past the last non-zero element of the compressed vector.
|
inline |
Erasing an element from the compressed vector.
index | The index of the element to be erased. The index has to be in the range ![]() |
This function erases an element from the compressed vector.
|
inline |
Erasing an element from the compressed vector.
pos | Iterator to the element to be erased. |
This function erases an element from the compressed vector.
|
inlineprivate |
Calculating a new vector capacity.
This function calculates a new vector capacity based on the current capacity of the sparse vector. Note that the new capacity is restricted to the interval .
|
inline |
Searches for a specific vector element.
index | The index of the search element. The index has to be in the range ![]() |
This function can be used to check whether a specific element is contained in the sparse vector. It specifically searches for the element with index index. In case the element is found, the function returns an iterator to the element. Otherwise an iterator just past the last non-zero element of the compressed vector (the end() iterator) is returned. Note that the returned compressed vector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Searches for a specific vector element.
index | The index of the search element. The index has to be in the range ![]() |
This function can be used to check whether a specific element is contained in the sparse vector. It specifically searches for the element with index index. In case the element is found, the function returns an iterator to the element. Otherwise an iterator just past the last non-zero element of the compressed vector (the end() iterator) is returned. Note that the returned compressed vector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
CompressedVector< Type, TF >::Iterator blaze::CompressedVector< Type, TF >::insert | ( | size_t | index, |
const Type & | value | ||
) |
Inserting an element into the compressed vector.
index | The index of the new element. The index has to be in the range ![]() |
value | The value of the element to be inserted. |
std::invalid_argument | Invalid compressed vector access index. |
This function inserts a new element into the compressed vector. However, duplicate elements are not allowed. In case the sparse vector already contains an element with index index, a std::invalid_argument exception is thrown.
|
inline |
Returns whether the vector is aliased with the given address alias.
alias | The alias to be checked. |
This function returns whether the given address is aliased with the vector. In contrast to the conAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.
|
inline |
Returns the number of non-zero elements in the compressed vector.
Note that the number of non-zero elements is always smaller than the current size of the compressed vector.
|
inline |
Multiplication assignment operator for the multiplication of a vector ( ).
rhs | The right-hand side vector to be multiplied with the compressed vector. |
std::invalid_argument | Vector sizes do not match. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Multiplication assignment operator for the multiplication between a compressed vector and a scalar value ( ).
rhs | The right-hand side scalar value for the multiplication. |
This operator can only be used for built-in data types. Additionally, the elements of the compressed vector must support the multiplication assignment operator for the given scalar built-in data type.
|
inline |
Addition assignment operator for the addition of a vector ( ).
rhs | The right-hand side vector to be added to the compressed vector. |
std::invalid_argument | Vector sizes do not match. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Subtraction assignment operator for the subtraction of a vector ( ).
rhs | The right-hand side vector to be subtracted from the compressed vector. |
std::invalid_argument | Vector sizes do not match. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Division assignment operator for the division of a compressed vector by a scalar value ( ).
rhs | The right-hand side scalar value for the division. |
This operator can only be used for built-in data types. Additionally, the elements of the compressed vector must either support the multiplication assignment operator for the given floating point data type or the division assignment operator for the given integral data type.
|
inline |
Copy assignment operator for CompressedVector.
rhs | Compressed vector to be copied. |
The compressed vector is resized according to the given compressed vector and initialized as a copy of this vector.
|
inline |
Assignment operator for dense vectors.
rhs | Dense vector to be copied. |
The vector is resized according to the given dense vector and initialized as a copy of this vector.
|
inline |
Assignment operator for different sparse vectors.
rhs | Sparse vector to be copied. |
The vector is resized according to the given sparse vector and initialized as a copy of this vector.
|
inline |
Subscript operator for the direct access to the compressed vector elements.
index | Access index. The index has to be in the range ![]() |
This function returns a reference to the accessed value at position index. In case the compressed vector does not yet store an element for index index, a new element is inserted into the compressed vector. An alternative for traversing the non-zero elements of the sparse vector are the begin() and end() functions.
|
inline |
Subscript operator for the direct access to the compressed vector elements.
index | Access index. The index has to be in the range ![]() |
|
inlineinherited |
Conversion operator for non-constant vectors.
|
inlineinherited |
Conversion operator for constant vectors.
void blaze::CompressedVector< Type, TF >::reserve | ( | size_t | n | ) |
Setting the minimum capacity of the compressed vector.
n | The new minimum capacity of the compressed vector. |
This function increases the capacity of the compressed vector to at least n elements. The current values of the vector elements are preserved.
|
inline |
Reset to the default initial values.
|
inline |
Changing the size of the compressed vector.
n | The new size of the compressed vector. |
preserve | true if the old values of the vector should be preserved, false if not. |
This function resizes the compressed vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the compressed vector is too small. Therefore this function potentially changes all vector elements. In order to preserve the old vector values, the preserve flag can be set to true.
|
inline |
Scaling of the compressed vector by the scalar value scalar ( ).
scalar | The scalar value for the vector scaling. |
|
inline |
Returns the current size/dimension of the compressed vector.
|
inline |
Default implementation of the subtraction assignment of a dense vector.
rhs | The right-hand side dense vector to be subtracted. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Default implementation of the subtraction assignment of a sparse vector.
rhs | The right-hand side sparse vector to be subtracted. |
This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.
|
inline |
Swapping the contents of two compressed vectors.
sv | The compressed vector to be swapped. |
no-throw | guarantee. |