![]() |
Reference to a specific row of a sparse matrix.The SparseRow template represents a reference to a specific row of a sparse matrix primitive. The type of the sparse matrix is specified via the first template parameter: More...
#include <SparseRow.h>
Inherits blaze::SparseVector< SparseRow< MT, SO >, true >, and blaze::Expression.
Public Types | |
typedef SparseRow< MT, SO > | This |
Type of this SparseRow instance. | |
typedef RowTrait< 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 row elements. | |
typedef MT::ReturnType | ReturnType |
Return type for expression template evaluations. | |
typedef const SparseRow & | CompositeType |
Data type for composite expression templates. | |
typedef MT::ConstReference | ConstReference |
Reference to a constant row value. | |
typedef SelectType< useConst, ConstReference, typename MT::Reference >::Type | Reference |
Reference to a non-constant row 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 > | |
SparseRow< MT, SO > & | operator= (const DenseVector< VT, true > &rhs) |
Assignment operator for different dense vectors. More... | |
template<typename VT > | |
SparseRow< MT, SO > & | operator= (const SparseVector< VT, true > &rhs) |
Assignment operator for different sparse vectors. More... | |
template<typename VT > | |
SparseRow< MT, SO > & | operator+= (const Vector< VT, true > &rhs) |
Addition assignment operator for the addition of a vector ( ![]() | |
template<typename VT > | |
SparseRow< MT, SO > & | operator-= (const Vector< VT, true > &rhs) |
Subtraction assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT > | |
SparseRow< MT, SO > & | operator*= (const Vector< VT, true > &rhs) |
Multiplication assignment operator for the multiplication of a vector ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseRow< MT, SO > >::Type & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a sparse row and a scalar value ( ![]() | |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseRow< MT, SO > >::Type & | operator/= (Other rhs) |
Division assignment operator for the division of a sparse row by a scalar value ( ![]() | |
template<typename Other > | |
SparseRow< MT, SO > & | scale (Other scalar) |
Scaling of the sparse row 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 | |
SparseRow (MT &matrix, size_t index) | |
The constructor for SparseRow. More... | |
Data access functions | |
Reference | operator[] (size_t index) |
Subscript operator for the direct access to the row elements. More... | |
ConstReference | operator[] (size_t index) const |
Subscript operator for the direct access to the row elements. More... | |
Iterator | begin () |
Returns an iterator to the first element of the row. More... | |
ConstIterator | begin () const |
Returns an iterator to the first element of the row. More... | |
ConstIterator | cbegin () const |
Returns an iterator to the first element of the row. More... | |
Iterator | end () |
Returns an iterator just past the last element of the row. More... | |
ConstIterator | end () const |
Returns an iterator just past the last element of the row. More... | |
ConstIterator | cend () const |
Returns an iterator just past the last element of the row. More... | |
Assignment operators | |
SparseRow & | operator= (const SparseRow &rhs) |
Copy assignment operator for SparseRow. More... | |
template<typename VT > | |
SparseRow & | operator= (const DenseVector< VT, true > &rhs) |
template<typename VT > | |
SparseRow & | operator= (const SparseVector< VT, true > &rhs) |
template<typename VT > | |
SparseRow & | operator+= (const Vector< VT, true > &rhs) |
template<typename VT > | |
SparseRow & | operator-= (const Vector< VT, true > &rhs) |
template<typename VT > | |
SparseRow & | operator*= (const Vector< VT, true > &rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseRow >::Type & | operator*= (Other rhs) |
template<typename Other > | |
EnableIf< IsNumeric< Other > , SparseRow >::Type & | operator/= (Other rhs) |
Low-level utility functions | |
void | append (size_t index, const ElementType &value, bool check=false) |
Appending an element to the sparse row. More... | |
Expression template evaluation functions | |
template<typename Other > | |
bool | canAlias (const Other *alias) const |
Returns whether the sparse row can alias with the given address alias. More... | |
template<typename Other > | |
bool | isAliased (const Other *alias) const |
Returns whether the sparse row is aliased with the given address alias. More... | |
template<typename VT > | |
void | assign (const DenseVector< VT, true > &rhs) |
Default implementation of the assignment of a dense vector. More... | |
template<typename VT > | |
void | assign (const SparseVector< VT, true > &rhs) |
Default implementation of the assignment of a sparse vector. More... | |
template<typename VT > | |
void | addAssign (const DenseVector< VT, true > &rhs) |
Default implementation of the addition assignment of a dense vector. More... | |
template<typename VT > | |
void | addAssign (const SparseVector< VT, true > &rhs) |
Default implementation of the addition assignment of a sparse vector. More... | |
template<typename VT > | |
void | subAssign (const DenseVector< VT, true > &rhs) |
Default implementation of the subtraction assignment of a dense vector. More... | |
template<typename VT > | |
void | subAssign (const SparseVector< VT, true > &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... | |
Private Attributes | |
Member variables | |
MT & | matrix_ |
The sparse matrix containing the row. | |
const size_t | row_ |
The index of the row in the matrix. | |
Utility functions | |
size_t | size () const |
Returns the current size/dimension of the sparse row. More... | |
size_t | capacity () const |
Returns the maximum capacity of the sparse row. More... | |
size_t | nonZeros () const |
Returns the number of non-zero elements in the row. More... | |
void | reset () |
Reset to the default initial values. More... | |
ElementType & | insert (size_t index, const ElementType &value) |
Inserting an element into the sparse row. More... | |
void | erase (size_t index) |
Erasing an element from the sparse row. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the sparse row. More... | |
Iterator | find (size_t index) |
Searches for a specific row element. More... | |
ConstIterator | find (size_t index) const |
Searches for a specific row element. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the sparse row. More... | |
template<typename Other > | |
SparseRow & | scale (Other scalar) |
size_t | extendCapacity () const |
Calculating a new sparse row capacity. More... | |
Reference to a specific row of a sparse matrix.
The SparseRow template represents a reference to a specific row of a sparse matrix primitive. The type of the sparse matrix is specified via the first template parameter:
A reference to a sparse row can very conveniently be created via the row()
function. This reference can be treated as any other row 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 row can be either used as an alias to grant write access to a specific row of a matrix primitive on the left-hand side of an assignment or to grant read-access to a specific row of a matrix primitive or expression on the right-hand side of an assignment. The following two examples demonstrate this in detail:
A sparse row can be used like any other row vector. For instance, the elements of the sparse row can be directly accessed with the subscript operator. The numbering of the row elements is
where N is the number of columns of the referenced matrix. Alternatively, the elements of a row can be traversed via iterators. Just as with vectors, in case of non-const rows, begin()
and end()
return an Iterator, which allows a manipulation of the non-zero value, in case of a constant rows a ConstIterator is returned:
Inserting/accessing elements in a sparse row can be done by several alternative functions. The following example demonstrates all options:
The current number of row 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 rows are references to specific rows 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 SparseRow 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 row 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 row of a column-major matrix. For instance:
However, please note that creating a row view on a matrix stored in a column-major fashion can result in a considerable performance decrease in comparison to a row view on a matrix with row-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 vector/matrix multiplication as efficiently as possible using a row-major storage order for matrix A 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 row will return references and iterators to const. Otherwise useConst will be set to 0 and the sparse row will offer write access to the sparse matrix elements both via the subscript operator and iterators.
|
inlineexplicit |
The constructor for SparseRow.
matrix | The matrix containing the row. |
index | The index of the row. |
std::invalid_argument | Invalid row 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 row.
index | The index of the new element. The index must be smaller than the number of matrix columns. |
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 row with elements. It appends a new element to the end of the sparse row 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 row.
This function returns an iterator to the first element of the row.
|
inline |
Returns an iterator to the first element of the row.
This function returns an iterator to the first element of the row.
|
inline |
Returns whether the sparse row 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 row. 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 row.
|
inline |
Returns an iterator to the first element of the row.
This function returns an iterator to the first element of the row.
|
inline |
Returns an iterator just past the last element of the row.
This function returns an iterator just past the last element of the row.
|
inline |
Returns an iterator just past the last element of the row.
This function returns an iterator just past the last element of the row.
|
inline |
Returns an iterator just past the last element of the row.
This function returns an iterator just past the last element of the row.
|
inline |
Erasing an element from the sparse row.
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 row.
|
inline |
Erasing an element from the sparse row.
pos | Iterator to the element to be erased. |
This function erases an element from the sparse row.
|
inlineprivate |
Calculating a new sparse row capacity.
This function calculates a new row capacity based on the current capacity of the sparse row. Note that the new capacity is restricted to the interval .
|
inline |
Searches for a specific row 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 row. 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 row (the end() iterator) is returned. Note that the returned sparse row iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Searches for a specific row 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 row. 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 row (the end() iterator) is returned. Note that the returned sparse row iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!
|
inline |
Inserting an element into the sparse row.
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 row access index. |
This function inserts a new element into the sparse row. However, duplicate elements are not allowed. In case the sparse row already contains an element at index index, a std::invalid_argument exception is thrown.
|
inline |
Returns whether the sparse row 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 row. In contrast to the canAlias() 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 row.
Note that the number of non-zero elements is always less than or equal to the current number of columns of the matrix containing the row.
|
inline |
Multiplication assignment operator for the multiplication of a vector ( ).
rhs | The right-hand side vector to be multiplied with the sparse row. |
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 row 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 row 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 row. |
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 row. |
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 row 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 row 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 SparseRow.
rhs | Sparse row to be copied. |
std::invalid_argument | Row sizes do not match. |
In case the current sizes of the two rows 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 row elements.
index | Access index. The index must be smaller than the number of matrix columns. |
|
inline |
Subscript operator for the direct access to the row elements.
index | Access index. The index must be smaller than the number of matrix columns. |
|
inlineinherited |
Conversion operator for non-constant vectors.
|
inlineinherited |
Conversion operator for constant vectors.
|
inline |
Setting the minimum capacity of the sparse row.
n | The new minimum capacity of the sparse row. |
This function increases the capacity of the sparse row to at least n elements. The current values of the row elements are preserved.
|
inline |
Reset to the default initial values.
|
inline |
Scaling of the sparse row by the scalar value scalar ( ).
scalar | The scalar value for the row scaling. |
|
inline |
Returns the current size/dimension of the sparse row.
|
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.