![]() |
Reference to a specific column of a sparse matrix.The SparseColumn template represents a reference to a specific column of a sparse matrix primitive. The type of the sparse matrix is specified via the first template parameter: More...
#include <SparseColumn.h>
Inherits blaze::SparseVector< SparseColumn< MT, SO >, false >, and blaze::View.
Public Types | |
typedef SparseColumn< MT, SO > | This |
Type of this SparseColumn instance. | |
typedef ColumnTrait< MT >::Type | ResultType |
Result type for expression template evaluations. | |
typedef ResultType::TransposeType | TransposeType |
Transpose type for expression template evaluations. | |
typedef MT::ElementType | ElementType |
Type of the column elements. | |
typedef MT::ReturnType | ReturnType |
Return type for expression template evaluations. | |
typedef const SparseColumn & | CompositeType |
Data type for composite expression templates. | |
typedef MT::ConstReference | ConstReference |
Reference to a constant column value. | |
typedef SelectType< useConst, ConstReference, typename MT::Reference >::Type | Reference |
Reference to a non-constant column value. | |
typedef MT::ConstIterator | ConstIterator |
Iterator over constant elements. | |
typedef SelectType< useConst, ConstIterator, typename MT::Iterator >::Type | Iterator |
Iterator over non-constant elements. | |
typedef VT | VectorType |
Type of the vector. | |
Public Member Functions | |
template<typename VT > | |
SparseColumn< MT, SO > & | operator= (const DenseVector< VT, false > &rhs) |
Assignment operator for different dense vectors. More... | |
template<typename VT > | |
SparseColumn< MT, SO > & | operator= (const SparseVector< VT, false > &rhs) |
Assignment operator for different sparse vectors. More... | |
template<typename VT > | |
SparseColumn< MT, SO > & | operator+= (const Vector< VT, false > &rhs) |
Addition assignment operator for the addition of a vector ( ![]() | |
template<typename VT > | |
SparseColumn< MT, SO > & | operator-= (const Vector< VT, false > &rhs) |
Subtraction assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT > | |
SparseColumn< MT, SO > & | operator*= (const Vector< VT, false > &rhs) |
Multiplication assignment operator for the multiplication of a vector ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseColumn< MT, SO > >::Type & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a sparse column and a scalar value ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseColumn< MT, SO > >::Type & | operator/= (Other rhs) |
Division assignment operator for the division of a sparse column by a scalar value ( ![]() | |
template<typename Other > | |
SparseColumn< MT, SO > & | scale (Other scalar) |
Scaling of the sparse column 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 | |
SparseColumn (MT &matrix, size_t index) | |
The constructor for SparseColumn. More... | |
Data access functions | |
Reference | operator[] (size_t index) |
Subscript operator for the direct access to the column elements. More... | |
ConstReference | operator[] (size_t index) const |
Subscript operator for the direct access to the column elements. More... | |
Iterator | begin () |
Returns an iterator to the first element of the column. More... | |
ConstIterator | begin () const |
Returns an iterator to the first element of the column. More... | |
ConstIterator | cbegin () const |
Returns an iterator to the first element of the column. More... | |
Iterator | end () |
Returns an iterator just past the last element of the column. More... | |
ConstIterator | end () const |
Returns an iterator just past the last element of the column. More... | |
ConstIterator | cend () const |
Returns an iterator just past the last element of the column. More... | |
Assignment operators | |
SparseColumn & | operator= (const SparseColumn &rhs) |
Copy assignment operator for SparseColumn. More... | |
template<typename VT > | |
SparseColumn & | operator= (const DenseVector< VT, false > &rhs) |
template<typename VT > | |
SparseColumn & | operator= (const SparseVector< VT, false > &rhs) |
template<typename VT > | |
SparseColumn & | operator+= (const Vector< VT, false > &rhs) |
template<typename VT > | |
SparseColumn & | operator-= (const Vector< VT, false > &rhs) |
template<typename VT > | |
SparseColumn & | operator*= (const Vector< VT, false > &rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseColumn >::Type & | operator*= (Other rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseColumn >::Type & | operator/= (Other rhs) |
Lookup functions | |
Iterator | find (size_t index) |
Searches for a specific column element. More... | |
ConstIterator | find (size_t index) const |
Searches for a specific column 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 column. More... | |
Expression template evaluation functions | |
template<typename Other > | |
bool | canAlias (const Other *alias) const |
Returns whether the sparse column can alias with the given address alias. More... | |
template<typename Other > | |
bool | isAliased (const Other *alias) const |
Returns whether the sparse column is aliased with the given address alias. More... | |
template<typename VT > | |
void | assign (const DenseVector< VT, false > &rhs) |
Default implementation of the assignment of a dense vector. More... | |
template<typename VT > | |
void | assign (const SparseVector< VT, false > &rhs) |
Default implementation of the assignment of a sparse vector. More... | |
template<typename VT > | |
void | addAssign (const DenseVector< VT, false > &rhs) |
Default implementation of the addition assignment of a dense vector. More... | |
template<typename VT > | |
void | addAssign (const SparseVector< VT, false > &rhs) |
Default implementation of the addition assignment of a sparse vector. More... | |
template<typename VT > | |
void | subAssign (const DenseVector< VT, false > &rhs) |
Default implementation of the subtraction assignment of a dense vector. More... | |
template<typename VT > | |
void | subAssign (const SparseVector< VT, false > &rhs) |
Default implementation of the subtraction assignment of a sparse vector. More... | |
Private Types | |
enum | { useConst = IsConst<MT>::value } |
Compilation switch for the non-const reference and iterator types. More... | |
typedef SelectType < IsExpression< MT >::value, MT, MT & >::Type | Operand |
Composite data type of the dense matrix expression. | |
Private Attributes | |
Member variables | |
Operand | matrix_ |
The sparse matrix containing the column. | |
const size_t | col_ |
The index of the column in the matrix. | |
Utility functions | |
size_t | size () const |
Returns the current size/dimension of the sparse column. More... | |
size_t | capacity () const |
Returns the maximum capacity of the sparse column. More... | |
size_t | nonZeros () const |
Returns the number of non-zero elements in the column. More... | |
void | reset () |
Reset to the default initial values. More... | |
Iterator | insert (size_t index, const ElementType &value) |
Inserting an element into the sparse column. More... | |
void | erase (size_t index) |
Erasing an element from the sparse column. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the sparse column. More... | |
Iterator | erase (Iterator first, Iterator last) |
Erasing a range of elements from the sparse column. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the sparse column. More... | |
template<typename Other > | |
SparseColumn & | scale (Other scalar) |
size_t | extendCapacity () const |
Calculating a new sparse column capacity. More... | |
Reference to a specific column of a sparse matrix.
The SparseColumn template represents a reference to a specific column of a sparse matrix primitive. The type of the sparse matrix is specified via the first template parameter:
A reference to a sparse column can be created very conveniently via the column()
function. This reference can be treated as any other column vector, i.e. it can be assigned to, it can be copied from, and it can be used in arithmetic operations. The reference can also be used on both sides of an assignment: The column can either be used as an alias to grant write access to a specific column of a matrix primitive on the left-hand side of an assignment or to grant read-access to a specific column of a matrix primitive or expression on the right-hand side of an assignment. The following example demonstrates this in detail:
A sparse column can be used like any other column vector. For instance, the elements of the sparse column can be directly accessed with the subscript operator.
The numbering of the column elements is
where N is the number of rows of the referenced matrix. Alternatively, the elements of a column can be traversed via iterators. Just as with vectors, in case of non-const columns, begin()
and end()
return an Iterator, which allows a manipulation of the non-zero values, in case of constant columns a ConstIterator is returned:
Inserting/accessing elements in a sparse column can be done by several alternative functions. The following example demonstrates all options:
The current number of column 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 columns are references to specific columns of a matrix, several operations are not possible on views, such as resizing and swapping:
The following example gives an impression of the use of SparseColumn 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:
It is especially noteworthy that column views can be created for both row-major and column-major matrices. Whereas the interface of a row-major matrix only allows to traverse a row directly and the interface of a column-major matrix only allows to traverse a column, via views it is also possible to traverse a column of a row-major matrix. For instance:
However, please note that creating a column view on a matrix stored in a row-major fashion can result in a considerable performance decrease in comparison to a column view on a matrix with column-major storage format. This is due to the non-contiguous storage of the matrix elements. Therefore care has to be taken in the choice of the most suitable storage order:
Although Blaze performs the resulting matrix/vector multiplication as efficiently as possible using a column-major storage order for matrix B would result in a more efficient evaluation.
|
private |
Compilation switch for the non-const reference and iterator types.
The useConst compile time constant expression represents a compilation switch for the non-const reference and iterator types. In case the given sparse matrix of type MT is const qualified, useConst will be set to 1 and the sparse column will return references and iterators to const. Otherwise useConst will be set to 0 and the sparse column will offer write access to the sparse matrix elements both via the subscript operator and iterators.
|
inlineexplicit |
The constructor for SparseColumn.
matrix | The matrix containing the column. |
index | The index of the column. |
std::invalid_argument | Invalid column access index. |
|
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 column.
index | The index of the new element. The index must be smaller than the number of matrix rows. |
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 column with elements. It appends a new element to the end of the sparse column 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 element of the column.
This function returns an iterator to the first element of the column.
|
inline |
Returns an iterator to the first element of the column.
This function returns an iterator to the first element of the column.
|
inline |
Returns whether the sparse column 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 column. 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 sparse column.
|
inline |
Returns an iterator to the first element of the column.
This function returns an iterator to the first element of the column.
|
inline |
Returns an iterator just past the last element of the column.
This function returns an iterator just past the last element of the column.
|
inline |
Returns an iterator just past the last element of the column.
This function returns an iterator just past the last element of the column.
|
inline |
Returns an iterator just past the last element of the column.
This function returns an iterator just past the last element of the column.
|
inline |
Erasing an element from the sparse column.
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 column.
|
inline |
Erasing an element from the sparse column.
pos | Iterator to the element to be erased. |
This function erases an element from the sparse column.
|
inline |
Erasing a range of elements from the sparse column.
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 column.
|
inlineprivate |
Calculating a new sparse column capacity.
This function calculates a new column capacity based on the current capacity of the sparse column. Note that the new capacity is restricted to the interval .
|
inline |
Searches for a specific column 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 column. 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 column (the end() iterator) is returned. Note that the returned sparse column iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Searches for a specific column 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 column. 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 column (the end() iterator) is returned. Note that the returned sparse column iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Inserting an element into the sparse column.
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 column access index. |
This function inserts a new element into the sparse column. However, duplicate elements are not allowed. In case the sparse column already contains an element at index index, a std::invalid_argument exception is thrown.
|
inline |
Returns whether the sparse column 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 column. 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 column 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 column 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 column.
Note that the number of non-zero elements is always less than or equal to the current number of rows of the matrix containing the column.
|
inline |
Multiplication assignment operator for the multiplication of a vector ( ).
rhs | The right-hand side vector to be multiplied with the sparse column. |
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 sparse column 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 column 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 column. |
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 sparse column. |
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 sparse column 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 column 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 SparseColumn.
rhs | Sparse column to be copied. |
std::invalid_argument | Column sizes do not match. |
In case the current sizes of the two columns don't match, a std::invalid_argument exception is thrown.
|
inline |
Assignment operator for different dense vectors.
rhs | Dense vector to be assigned. |
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 |
Assignment operator for different sparse vectors.
rhs | Sparse vector to be assigned. |
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 |
Subscript operator for the direct access to the column elements.
index | Access index. The index must be smaller than the number of matrix rows. |
|
inline |
Subscript operator for the direct access to the column elements.
index | Access index. The index must be smaller than the number of matrix rows. |
|
inlineinherited |
Conversion operator for non-constant vectors.
|
inlineinherited |
Conversion operator for constant vectors.
|
inline |
Setting the minimum capacity of the sparse column.
n | The new minimum capacity of the sparse column. |
This function increases the capacity of the sparse column to at least n elements. The current values of the column elements are preserved.
|
inline |
Reset to the default initial values.
|
inline |
Scaling of the sparse column by the scalar value scalar ( ).
scalar | The scalar value for the column scaling. |
|
inline |
Returns the current size/dimension of the sparse column.
|
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 column 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 column iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!