![]() |
View on a specific subvector of a sparse vector.The SparseSubvector template represents a view on a specific subvector of a sparse vector primitive. The type of the sparse vector is specified via the first template parameter: More...
#include <SparseSubvector.h>
Inherits blaze::SparseVector< SparseSubvector< VT, AF, TF >, TF >, and blaze::Subvector.
Classes | |
class | SubvectorElement |
Access proxy for a specific element of the sparse subvector. More... | |
class | SubvectorIterator |
Iterator over the elements of the sparse subvector. More... | |
Public Types | |
enum | { smpAssignable = VT::smpAssignable } |
Compilation switch for the expression template assignment strategy. | |
typedef SparseSubvector< VT, AF, TF > | This |
Type of this SparseSubvector instance. | |
typedef SubvectorTrait< VT >::Type | ResultType |
Result type for expression template evaluations. | |
typedef ResultType::TransposeType | TransposeType |
Transpose type for expression template evaluations. | |
typedef VT::ElementType | ElementType |
Type of the subvector elements. | |
typedef VT::ReturnType | ReturnType |
Return type for expression template evaluations. | |
typedef const SparseSubvector & | CompositeType |
Data type for composite expression templates. | |
typedef VT::ConstReference | ConstReference |
Reference to a constant subvector value. | |
typedef If< IsConst< VT >, ConstReference, typename VT::Reference >::Type | Reference |
Reference to a non-constant subvector value. | |
typedef SubvectorIterator< const VT, typename VT::ConstIterator > | ConstIterator |
Iterator over constant elements. | |
typedef If< IsConst< VT >, ConstIterator, SubvectorIterator< VT, typename VT::Iterator > >::Type | Iterator |
Iterator over non-constant elements. | |
typedef SparseSubvector< VT, AF, TF > | VectorType |
Type of the vector. | |
Public Member Functions | |
template<typename VT2 > | |
SparseSubvector< VT, AF, TF > & | operator= (const Vector< VT2, TF > &rhs) |
Assignment operator for different vectors. More... | |
template<typename VT2 > | |
SparseSubvector< VT, AF, TF > & | operator+= (const Vector< VT2, TF > &rhs) |
Addition assignment operator for the addition of a vector ( ![]() | |
template<typename VT2 > | |
SparseSubvector< VT, AF, TF > & | operator-= (const Vector< VT2, TF > &rhs) |
Subtraction assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT2 > | |
SparseSubvector< VT, AF, TF > & | operator*= (const Vector< VT2, TF > &rhs) |
Multiplication assignment operator for the multiplication of a vector ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other >, SparseSubvector< VT, AF, TF > >::Type & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a sparse subvector and a scalar value ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other >, SparseSubvector< VT, AF, TF > >::Type & | operator/= (Other rhs) |
Division assignment operator for the division of a sparse subvector by a scalar value ( ![]() | |
template<typename Other > | |
SparseSubvector< VT, AF, TF > & | scale (const Other &scalar) |
Scaling of the sparse subvector by the scalar value scalar ( ![]() | |
BLAZE_ALWAYS_INLINE VectorType & | operator~ () |
Conversion operator for non-constant vectors. More... | |
BLAZE_ALWAYS_INLINE const VectorType & | operator~ () const |
Conversion operator for constant vectors. More... | |
Constructors | |
SparseSubvector (Operand vector, size_t index, size_t n) | |
The constructor for SparseSubvector. More... | |
Data access functions | |
Reference | operator[] (size_t index) |
Subscript operator for the direct access to the subvector elements. More... | |
ConstReference | operator[] (size_t index) const |
Subscript operator for the direct access to the subvector elements. More... | |
Reference | at (size_t index) |
Checked access to the subvector elements. More... | |
ConstReference | at (size_t index) const |
Checked access to the subvector elements. More... | |
Iterator | begin () |
Returns an iterator to the first element of the subvector. More... | |
ConstIterator | begin () const |
Returns an iterator to the first element of the subvector. More... | |
ConstIterator | cbegin () const |
Returns an iterator to the first element of the subvector. More... | |
Iterator | end () |
Returns an iterator just past the last element of the subvector. More... | |
ConstIterator | end () const |
Returns an iterator just past the last element of the subvector. More... | |
ConstIterator | cend () const |
Returns an iterator just past the last element of the subvector. More... | |
Assignment operators | |
SparseSubvector & | operator= (const SparseSubvector &rhs) |
Copy assignment operator for SparseSubvector. More... | |
template<typename VT2 > | |
SparseSubvector & | operator= (const Vector< VT2, TF > &rhs) |
template<typename VT2 > | |
SparseSubvector & | operator+= (const Vector< VT2, TF > &rhs) |
template<typename VT2 > | |
SparseSubvector & | operator-= (const Vector< VT2, TF > &rhs) |
template<typename VT2 > | |
SparseSubvector & | operator*= (const Vector< VT2, TF > &rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other >, SparseSubvector >::Type & | operator*= (Other rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other >, SparseSubvector >::Type & | operator/= (Other rhs) |
Utility functions | |
size_t | size () const |
Returns the size/dimension of the sparse subvector. More... | |
size_t | capacity () const |
Returns the maximum capacity of the sparse subvector. More... | |
size_t | nonZeros () const |
Returns the number of non-zero elements in the subvector. More... | |
void | reset () |
Reset to the default initial values. More... | |
Iterator | set (size_t index, const ElementType &value) |
Setting an element of the sparse subvector. More... | |
Iterator | insert (size_t index, const ElementType &value) |
Inserting an element into the sparse subvector. More... | |
void | erase (size_t index) |
Erasing an element from the sparse subvector. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the sparse subvector. More... | |
Iterator | erase (Iterator first, Iterator last) |
Erasing a range of elements from the sparse subvector. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the sparse subvector. More... | |
template<typename Other > | |
SparseSubvector & | scale (const Other &scalar) |
Lookup functions | |
Iterator | find (size_t index) |
Searches for a specific subvector element. More... | |
ConstIterator | find (size_t index) const |
Searches for a specific subvector element. More... | |
Iterator | lowerBound (size_t index) |
Returns an iterator to the first index not less then the given index. More... | |
ConstIterator | lowerBound (size_t index) const |
Returns an iterator to the first index not less then the given index. More... | |
Iterator | upperBound (size_t index) |
Returns an iterator to the first index greater then the given index. More... | |
ConstIterator | upperBound (size_t index) const |
Returns an iterator to the first index greater then the given index. More... | |
Low-level utility functions | |
void | append (size_t index, const ElementType &value, bool check=false) |
Appending an element to the sparse subvector. More... | |
Expression template evaluation functions | |
template<typename Other > | |
bool | canAlias (const Other *alias) const |
Returns whether the sparse subvector can alias with the given address alias. More... | |
template<typename Other > | |
bool | isAliased (const Other *alias) const |
Returns whether the sparse subvector is aliased with the given address alias. More... | |
bool | canSMPAssign () const |
Returns whether the subvector can be used in SMP assignments. More... | |
template<typename VT2 > | |
void | assign (const DenseVector< VT2, TF > &rhs) |
Default implementation of the assignment of a dense vector. More... | |
template<typename VT2 > | |
void | assign (const SparseVector< VT2, TF > &rhs) |
Default implementation of the assignment of a sparse vector. More... | |
template<typename VT2 > | |
void | addAssign (const DenseVector< VT2, TF > &rhs) |
Default implementation of the addition assignment of a dense vector. More... | |
template<typename VT2 > | |
void | addAssign (const SparseVector< VT2, TF > &rhs) |
Default implementation of the addition assignment of a sparse vector. More... | |
template<typename VT2 > | |
void | subAssign (const DenseVector< VT2, TF > &rhs) |
Default implementation of the subtraction assignment of a dense vector. More... | |
template<typename VT2 > | |
void | subAssign (const SparseVector< VT2, TF > &rhs) |
Default implementation of the subtraction assignment of a sparse vector. More... | |
Private Types | |
typedef If< IsExpression< VT >, VT, VT & >::Type | Operand |
Composite data type of the sparse vector expression. | |
Private Attributes | |
Member variables | |
Operand | vector_ |
The sparse vector containing the subvector. | |
const size_t | offset_ |
The offset of the subvector within the sparse vector. | |
const size_t | size_ |
The size of the subvector. | |
View on a specific subvector of a sparse vector.
The SparseSubvector template represents a view on a specific subvector of a sparse vector primitive. The type of the sparse vector is specified via the first template parameter:
A view on a sparse subvector can be created very conveniently via the subvector()
function:
This view can be treated as any other sparse vector, i.e. it can be assigned to, it can be copied from, and it can be used in arithmetic operations. The view can also be used on both sides of an assignment: The subvector can either be used as an alias to grant write access to a specific subvector of a sparse vector primitive on the left-hand side of an assignment or to grant read-access to a specific subvector of a sparse vector primitive or expression on the right-hand side of an assignment. The following example demonstrates this in detail:
A sparse subvector can be used like any other sparse vector. For instance, the elements of the sparse subvector can be directly accessed with the subscript operator.
The numbering of the subvector elements is
where N is the specified size of the subvector. Alternatively, the elements of a subvector can be traversed via iterators. Just as with vectors, in case of non-const subvectors, begin()
and end()
return an Iterator, which allows a manipulation of the non-zero values, in case of constant subvectors a ConstIterator is returned:
Inserting/accessing elements in a sparse subvector can be done by several alternative functions. The following example demonstrates all options:
The current number of subvector elements can be obtained via the size()
function, the current capacity via the capacity()
function, and the number of non-zero elements via the nonZeros()
function. However, since subvector are views on a specific subvector of a vector, several operations are not possible on views, such as resizing and swapping:
The following example gives an impression of the use of SparseSubvector within arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of dense and sparse vectors with fitting element types:
Usually subvectors can be defined anywhere within a vector. They may start at any position and may have an arbitrary size (only restricted by the size of the underlying vector). However, in contrast to vectors themselves, which are always properly aligned in memory and therefore can provide maximum performance, this means that subvectors in general have to be considered to be unaligned. This can be made explicit by the blaze::unaligned flag:
All of these calls to the subvector()
function are identical. Whether the alignment flag is explicitly specified or not, it always returns an unaligned subvector. Whereas this may provide full flexibility in the creation of subvectors, this might result in performance restrictions (even in case the specified subvector could be aligned). However, it is also possible to create aligned subvectors. Aligned subvectors are identical to unaligned subvectors in all aspects, except that they may pose additional alignment restrictions and therefore have less flexibility during creation. These restrictions may limit their application, but due to that they don't suffer from performance penalties and provide the same performance as the underlying vector. Aligned subvectors are created by explicitly specifying the blaze::aligned flag:
In contrast to dense subvectors, which pose several additional alignment restrictions based on the used element type, sparse subvectors at this time don't pose any additional restrictions. Therefore aligned and unaligned sparse subvectors are truly fully identical. Note however that this is not true for dense subvectors (see the DenseSubvector class description)!
It is also possible to create a subvector view on another subvector. In this context it is important to remember that the type returned by the subvector()
function is the same type as the type of the given subvector, since the view on a subvector is just another view on the underlying sparse vector:
|
inlineexplicit |
The constructor for SparseSubvector.
vector | The sparse vector containing the subvector. |
index | The index of the first element of the subvector. |
n | The size of the subvector. |
std::invalid_argument | Invalid subvector specification. |
In case the subvector is not properly specified (i.e. if the specified first index is larger than the size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown.
|
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 sparse subvector.
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 sparse subvector with elements. It appends a new element to the end of the sparse subvector 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.
|
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 |
Checked access to the subvector elements.
index | Access index. The index must be smaller than the number of subvector columns. |
std::out_of_range | Invalid subvector access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inline |
Checked access to the subvector elements.
index | Access index. The index must be smaller than the number of subvector columns. |
std::out_of_range | Invalid subvector access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inline |
Returns an iterator to the first element of the subvector.
This function returns an iterator to the first element of the subvector.
|
inline |
Returns an iterator to the first element of the subvector.
This function returns an iterator to the first element of the subvector.
|
inline |
Returns whether the sparse subvector can alias with the given address alias.
alias | The alias to be checked. |
This function returns whether the given address can alias with the sparse subvector. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.
|
inline |
Returns whether the subvector can be used in SMP assignments.
This function returns whether the subvector can be used in SMP assignments. In contrast to the smpAssignable member enumeration, which is based solely on compile time information, this function additionally provides runtime information (as for instance the current size of the vector).
|
inline |
Returns the maximum capacity of the sparse subvector.
|
inline |
Returns an iterator to the first element of the subvector.
This function returns an iterator to the first element of the subvector.
|
inline |
Returns an iterator just past the last element of the subvector.
This function returns an iterator just past the last element of the subvector.
|
inline |
Returns an iterator just past the last element of the subvector.
This function returns an iterator just past the last element of the subvector.
|
inline |
Returns an iterator just past the last element of the subvector.
This function returns an iterator just past the last element of the subvector.
|
inline |
Erasing an element from the sparse subvector.
index | The index of the element to be erased. The index has to be in the range ![]() |
This function erases an element from the sparse subvector.
|
inline |
Erasing an element from the sparse subvector.
pos | Iterator to the element to be erased. |
This function erases an element from the sparse subvector.
|
inline |
Erasing a range of elements from the sparse subvector.
first | Iterator to first element to be erased. |
last | Iterator just past the last element to be erased. |
This function erases a range of elements from the sparse subvector.
|
inline |
Searches for a specific subvector 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 subvector. 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 sparse subvector (the end() iterator) is returned. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Searches for a specific subvector 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 subvector. 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 sparse subvector (the end() iterator) is returned. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Inserting an element into the sparse subvector.
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 sparse subvector access index. |
This function inserts a new element into the sparse subvector. However, duplicate elements are not allowed. In case the sparse subvector already contains an element at index index, a std::invalid_argument exception is thrown.
|
inline |
Returns whether the sparse subvector is aliased with the given address alias.
alias | The alias to be checked. |
This function returns whether the given address is aliased with the sparse subvector. In contrast to the canAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.
|
inline |
Returns an iterator to the first index not less then the given index.
index | The index of the search element. The index has to be in the range ![]() |
This function returns an iterator to the first element with an index not less then the given index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Returns an iterator to the first index not less then the given index.
index | The index of the search element. The index has to be in the range ![]() |
This function returns an iterator to the first element with an index not less then the given index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Returns the number of non-zero elements in the subvector.
Note that the number of non-zero elements is always smaller than the size of the subvector.
|
inline |
Multiplication assignment operator for the multiplication of a vector ( ).
rhs | The right-hand side vector to be multiplied with the sparse subvector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid assignment to restricted vector. |
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 sparse subvector 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 sparse subvector 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 sparse subvector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid assignment to restricted vector. |
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 sparse subvector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid assignment to restricted vector. |
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 sparse subvector 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 sparse subvector 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 SparseSubvector.
rhs | Sparse subvector to be copied. |
std::invalid_argument | Subvector sizes do not match. |
std::invalid_argument | Invalid assignment to restricted vector. |
In case the current sizes of the two subvectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Assignment operator for different vectors.
rhs | Dense vector to be assigned. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid assignment to restricted vector. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Subscript operator for the direct access to the subvector elements.
index | Access index. The index must be smaller than the number of subvector elements. |
This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.
|
inline |
Subscript operator for the direct access to the subvector elements.
index | Access index. The index must be smaller than the number of subvector elements. |
This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.
|
inlineinherited |
Conversion operator for non-constant vectors.
|
inlineinherited |
Conversion operator for constant vectors.
|
inline |
Setting the minimum capacity of the sparse subvector.
n | The new minimum capacity of the sparse subvector. |
This function increases the capacity of the sparse subvector to at least n elements. The current values of the subvector elements are preserved.
|
inline |
Reset to the default initial values.
|
inline |
Scaling of the sparse subvector by the scalar value scalar ( ).
scalar | The scalar value for the subvector scaling. |
|
inline |
Setting an element of the sparse subvector.
index | The index of the new element. The index has to be in the range ![]() |
value | The value of the element to be set. |
This function sets the value of an element of the sparse subvector. In case the sparse subvector already contains an element with index index its value is modified, else a new element with the given value is inserted.
|
inline |
Returns the size/dimension of the sparse subvector.
|
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 |
Returns an iterator to the first index greater then the given index.
index | The index of the search element. The index has to be in the range ![]() |
This function returns an iterator to the first element with an index greater then the given index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Returns an iterator to the first index greater then the given index.
index | The index of the search element. The index has to be in the range ![]() |
This function returns an iterator to the first element with an index greater then the given index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned sparse subvector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!