Blaze 3.9
Public Types | Static Public Attributes | List of all members
blaze::SparseVectorProxy< PT, VT > Class Template Reference

Proxy backend for sparse vector types. More...

#include <SparseVectorProxy.h>

Inherits blaze::SparseVector< PT, IsRowVector_v< VT > >.

Public Types

using ResultType = ResultType_t< VT >
 Result type for expression template evaluations.
 
using TransposeType = TransposeType_t< VT >
 Transpose type for expression template evaluations.
 
using ElementType = ElementType_t< VT >
 Type of the sparse vector elements.
 
using ReturnType = ReturnType_t< VT >
 Return type for expression template evaluations.
 
using CompositeType = CompositeType_t< VT >
 Data type for composite expression templates.
 
using Reference = Reference_t< VT >
 Reference to a non-constant vector value.
 
using ConstReference = ConstReference_t< VT >
 Reference to a constant vector value.
 
using Iterator = Iterator_t< VT >
 Iterator over non-constant elements.
 
using ConstIterator = ConstIterator_t< VT >
 Iterator over constant elements.
 
using VectorType = PT
 Type of the vector.
 

Public Member Functions

Data access functions
Reference operator[] (size_t index) const
 Subscript operator for the direct access to vector elements. More...
 
Reference at (size_t index) const
 Checked access to the vector elements. More...
 
Iterator begin () const
 Returns an iterator to the first element of the represented vector. More...
 
ConstIterator cbegin () const
 Returns an iterator to the first element of the represented vector. More...
 
Iterator end () const
 Returns an iterator just past the last element of the represented vector. More...
 
ConstIterator cend () const
 Returns an iterator just past the last element of the represented vector. More...
 
Utility functions
size_t size () const
 Returns the current size/dimension of the represented vector. More...
 
size_t capacity () const
 Returns the maximum capacity of the represented vector. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the represented vector. More...
 
void reset () const
 Reset to the default initial value. More...
 
void clear () const
 Clearing the represented vector. More...
 
void resize (size_t n, bool preserve=true) const
 Changing the size of the represented vector. More...
 
void reserve (size_t n) const
 Setting the minimum capacity of the represented vector. More...
 
Insertion functions
Iterator set (size_t index, const ElementType &value) const
 Setting an element of the represented sparse vector. More...
 
Iterator insert (size_t index, const ElementType &value) const
 Inserting an element into the represented sparse vector. More...
 
void append (size_t index, const ElementType &value, bool check=false) const
 Appending an element to the represented sparse vector. More...
 
Erase functions
void erase (size_t index) const
 Erasing an element from the sparse vector. More...
 
Iterator erase (Iterator pos) const
 Erasing an element from the sparse vector. More...
 
Iterator erase (Iterator first, Iterator last) const
 Erasing a range of elements from the sparse vector. More...
 
template<typename Pred , typename = DisableIf_t< IsIntegral_v<Pred> >>
void erase (Pred predicate)
 Erasing specific elements from the sparse vector. More...
 
template<typename Pred >
void erase (Iterator first, Iterator last, Pred predicate)
 Erasing specific elements from a range of the sparse vector. More...
 
Lookup functions
Iterator find (size_t index) const
 Searches for a specific vector element. More...
 
Iterator lowerBound (size_t index) const
 Returns an iterator to the first index not less then the given index. More...
 
Iterator upperBound (size_t index) const
 Returns an iterator to the first index greater then the given index. More...
 
Numeric functions
template<typename Other >
void scale (const Other &scalar) const
 Scaling of the sparse vector by the scalar value scalar ( $ \vec{a}=\vec{b}*s $). More...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr PT & operator~ () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
BLAZE_ALWAYS_INLINE constexpr const PT & operator~ () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 
constexpr PT & operator* () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
constexpr const PT & operator* () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 

Static Public Attributes

static constexpr bool smpAssignable = VT::smpAssignable
 Compilation flag for SMP assignments.
 
static constexpr bool transposeFlag
 Transpose flag of the vector.
 

Protected Member Functions

Special member functions
 SparseVectorProxy ()=default
 
 SparseVectorProxy (const SparseVectorProxy &)=default
 
 SparseVectorProxy (SparseVectorProxy &&)=default
 
 ~SparseVectorProxy ()=default
 
SparseVectorProxyoperator= (const SparseVectorProxy &)=default
 
SparseVectorProxyoperator= (SparseVectorProxy &&)=default
 

Detailed Description

template<typename PT, typename VT>
class blaze::SparseVectorProxy< PT, VT >

Proxy backend for sparse vector types.

The SparseVectorProxy class serves as a backend for the Proxy class. It is used in case the data type represented by the proxy is a sparse vector and augments the Proxy interface by the complete interface required of sparse vectors.

Member Function Documentation

◆ append()

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::append ( size_t  index,
const ElementType value,
bool  check = false 
) const
inline

Appending an element to the represented sparse vector.

Parameters
indexThe index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be appended.
checktrue if the new value should be checked for default values, false if not.
Returns
void
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function provides a very efficient way to fill a sparse vector with elements. It appends a new element to the end of the sparse vector without any memory allocation. Therefore it is strictly necessary to keep the following preconditions in mind:

  • the index of the new element must be strictly larger than the largest index of non-zero elements in the sparse vector
  • the current number of non-zero elements must be smaller than the capacity of the vector

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!

◆ at()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Reference blaze::SparseVectorProxy< PT, VT >::at ( size_t  index) const
inline

Checked access to the vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::invalid_argumentInvalid access to restricted element.
std::out_of_rangeInvalid vector access index.

This function returns a reference to the accessed value at position index. In case the sparse vector does not yet store an element for index index, a new element is inserted into the sparse vector. In contrast to the subscript operator this function always performs a check of the given access index.

◆ begin()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::begin
inline

Returns an iterator to the first element of the represented vector.

Returns
Iterator to the first element of the vector.

◆ capacity()

template<typename PT , typename VT >
size_t blaze::SparseVectorProxy< PT, VT >::capacity
inline

Returns the maximum capacity of the represented vector.

Returns
The capacity of the vector.

◆ cbegin()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::ConstIterator blaze::SparseVectorProxy< PT, VT >::cbegin
inline

Returns an iterator to the first element of the represented vector.

Returns
Iterator to the first element of the vector.

◆ cend()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::ConstIterator blaze::SparseVectorProxy< PT, VT >::cend
inline

Returns an iterator just past the last element of the represented vector.

Returns
Iterator just past the last element of the vector.

◆ clear()

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::clear
inline

Clearing the represented vector.

Returns
void

This function clears the vector to its default initial state.

◆ end()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::end
inline

Returns an iterator just past the last element of the represented vector.

Returns
Iterator just past the last element of the vector.

◆ erase() [1/5]

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::erase ( Iterator  first,
Iterator  last 
) const
inline

Erasing a range of elements from the sparse vector.

Parameters
firstIterator to first element to be erased.
lastIterator just past the last element to be erased.
Returns
Iterator to the element after the erased element.
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function erases a range of elements from the sparse vector.

◆ erase() [2/5]

template<typename PT , typename VT >
template<typename Pred >
void blaze::SparseVectorProxy< PT, VT >::erase ( Iterator  first,
Iterator  last,
Pred  predicate 
)
inline

Erasing specific elements from a range of the sparse vector.

Parameters
firstIterator to first element of the range.
lastIterator just past the last element of the range.
predicateThe unary predicate for the element selection.
Returns
void.

This function erases specific elements from a range of elements of the sparse vector. The elements are selected by the given unary predicate predicate, which is expected to accept a single argument of the type of the elements and to be pure.

Note
The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!

◆ erase() [3/5]

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::erase ( Iterator  pos) const
inline

Erasing an element from the sparse vector.

Parameters
posIterator to the element to be erased.
Returns
Iterator to the element after the erased element.
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function erases an element from the sparse vector.

◆ erase() [4/5]

template<typename PT , typename VT >
template<typename Pred , typename >
void blaze::SparseVectorProxy< PT, VT >::erase ( Pred  predicate)
inline

Erasing specific elements from the sparse vector.

Parameters
predicateThe unary predicate for the element selection.
Returns
void.

This function erases specific elements from the sparse vector. The elements are selected by the given unary predicate predicate, which is expected to accept a single argument of the type of the elements and to be pure.

Note
The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!

◆ erase() [5/5]

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::erase ( size_t  index) const
inline

Erasing an element from the sparse vector.

Parameters
indexThe index of the element to be erased. The index has to be in the range $[0..N-1]$.
Returns
void
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function erases an element from the sparse vector.

◆ find()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::find ( size_t  index) const
inline

Searches for a specific vector element.

Parameters
indexThe index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

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 sparse vector (the end() iterator) is returned. Note that the returned sparse vector iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!

◆ insert()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::insert ( size_t  index,
const ElementType value 
) const
inline

Inserting an element into the represented sparse vector.

Parameters
indexThe index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be inserted.
Returns
Reference to the inserted value.
Exceptions
std::invalid_argumentInvalid access to restricted element.
std::invalid_argumentInvalid sparse vector access index.

This function inserts a new element into the sparse 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.

◆ lowerBound()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::lowerBound ( size_t  index) const
inline

Returns an iterator to the first index not less then the given index.

Parameters
indexThe index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index not less then the given index, end() iterator otherwise.

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 vector iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!

◆ nonZeros()

template<typename PT , typename VT >
size_t blaze::SparseVectorProxy< PT, VT >::nonZeros
inline

Returns the number of non-zero elements in the represented vector.

Returns
The number of non-zero elements in the vector.

Note that the number of non-zero elements is always smaller than the current size of the sparse vector.

◆ operator*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const PT & blaze::Vector< PT , TF >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for constant vectors.

Returns
Const reference of the actual type of the vector.

This operator performs the CRTP-based type-safe downcast to the actual type VT of the vector. It will return a constant reference to the actual type VT.

◆ operator*() [2/2]

BLAZE_ALWAYS_INLINE constexpr PT & blaze::Vector< PT , TF >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for non-constant vectors.

Returns
Mutable reference of the actual type of the vector.

This operator performs the CRTP-based type-safe downcast to the actual type VT of the vector. It will return a mutable reference to the actual type VT.

◆ operator[]()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Reference blaze::SparseVectorProxy< PT, VT >::operator[] ( size_t  index) const
inline

Subscript operator for the direct access to vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function returns a reference to the accessed value at position index. In case the sparse vector does not yet store an element for index index, a new element is inserted into the sparse vector. A more efficient alternative for traversing the non-zero elements of the sparse vector are the begin() and end() functions.

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE constexpr const PT & blaze::Vector< PT , TF >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for constant vectors.

Returns
Constant reference of the actual type of the vector.

This operator performs the CRTP-based type-safe downcast to the actual type VT of the vector. It will return a constant reference to the actual type VT.

◆ operator~() [2/2]

BLAZE_ALWAYS_INLINE constexpr PT & blaze::Vector< PT , TF >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for non-constant vectors.

Returns
Mutable reference of the actual type of the vector.

This operator performs the CRTP-based type-safe downcast to the actual type VT of the vector. It will return a mutable reference to the actual type VT.

◆ reserve()

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::reserve ( size_t  n) const
inline

Setting the minimum capacity of the represented vector.

Parameters
nThe new minimum capacity of the vector.
Returns
void
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function increases the capacity of the sparse vector to at least n elements. The current values of the vector elements are preserved.

◆ reset()

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::reset
inline

Reset to the default initial value.

Returns
void

This function resets all elements of the vector to the default initial values.

◆ resize()

template<typename PT , typename VT >
void blaze::SparseVectorProxy< PT, VT >::resize ( size_t  n,
bool  preserve = true 
) const
inline

Changing the size of the represented vector.

Parameters
nThe new size of the vector.
preservetrue if the old values of the vector should be preserved, false if not.
Returns
void
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function changes the size of the vector. Depending on the type of the vector, during this operation new dynamic memory may be allocated in case the capacity of the vector is too small. Note that this function may invalidate all existing views (subvectors, ...) on the vector if it is used to shrink the vector. Additionally, the resize() operation potentially changes all vector elements. In order to preserve the old vector values, the preserve flag can be set to true.

◆ scale()

template<typename PT , typename VT >
template<typename Other >
void blaze::SparseVectorProxy< PT, VT >::scale ( const Other &  scalar) const
inline

Scaling of the sparse vector by the scalar value scalar ( $ \vec{a}=\vec{b}*s $).

Parameters
scalarThe scalar value for the vector scaling.
Returns
void
Exceptions
std::invalid_argumentInvalid access to restricted element.

This function scales the vector by applying the given scalar value scalar to each element of the vector. For built-in and complex data types it has the same effect as using the multiplication assignment operator.

◆ set()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::set ( size_t  index,
const ElementType value 
) const
inline

Setting an element of the represented sparse vector.

Parameters
indexThe index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be set.
Returns
Reference to the set value.
Exceptions
std::invalid_argumentInvalid access to restricted element.
std::invalid_argumentInvalid sparse vector access index.

This function sets the value of an element of the sparse vector. In case the sparse vector already contains an element with index index its value is modified, else a new element with the given value is inserted.

◆ size()

template<typename PT , typename VT >
size_t blaze::SparseVectorProxy< PT, VT >::size
inline

Returns the current size/dimension of the represented vector.

Returns
The size of the vector.

◆ upperBound()

template<typename PT , typename VT >
SparseVectorProxy< PT, VT >::Iterator blaze::SparseVectorProxy< PT, VT >::upperBound ( size_t  index) const
inline

Returns an iterator to the first index greater then the given index.

Parameters
indexThe index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index greater then the given index, end() iterator otherwise.

This function returns an iterator to the first element with an index greater then the given index. In combination with the lowerBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned sparse vector iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!


The documentation for this class was generated from the following files: