Blaze 3.9
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | List of all members
blaze::ZeroVector< Type, TF, Tag > Class Template Reference

Efficient implementation of an arbitrary sized zero vector. More...

#include <ZeroVector.h>

Inherits blaze::Expression< SparseVector< ZeroVector< Type, TF, Tag >, TF > >.

Classes

struct  Rebind
 Rebind mechanism to obtain a ZeroVector with different data/element type. More...
 
struct  Resize
 Resize mechanism to obtain a ZeroVector with a different fixed number of elements. More...
 

Public Types

using This = ZeroVector< Type, TF, Tag >
 Type of this ZeroVector instance.
 
using BaseType = Expression< SparseVector< This, TF > >
 Base type of this ZeroVector instance.
 
using ResultType = This
 Result type for expression template evaluations.
 
using TransposeType = ZeroVector< Type,!TF, Tag >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the zero vector elements.
 
using TagType = Tag
 Tag type of this ZeroVector instance.
 
using ReturnType = const Type &
 Return type for expression template evaluations.
 
using CompositeType = const This &
 Data type for composite expression templates.
 
using Reference = const Type &
 Reference to a zero vector element.
 
using ConstReference = const Type &
 Reference to a constant zero vector element.
 
using Iterator = Element *
 Iterator over non-constant elements.
 
using ConstIterator = const Element *
 Iterator over constant elements.
 
using VectorType = ZeroVector< Type, TF, Tag >
 Type of the vector.
 

Public Member Functions

template<typename VT >
ZeroVector< Type, TF, Tag > & operator= (const Vector< VT, TF > &rhs) &
 Assignment operator for different zero vectors. More...
 
Constructors
constexpr ZeroVector () noexcept
 The default constructor for ZeroVector.
 
constexpr ZeroVector (size_t size) noexcept
 Constructor for a zero vector of size n. More...
 
template<typename VT >
 ZeroVector (const Vector< VT, TF > &v)
 Conversion constructor for different zero vectors. More...
 
 ZeroVector (const ZeroVector &)=default
 
 ZeroVector (ZeroVector &&)=default
 
Destructor
 ~ZeroVector ()=default
 
Data access functions
constexpr ConstReference operator[] (size_t index) const noexcept
 Subscript operator for the direct access to the zero vector elements. More...
 
ConstReference at (size_t index) const
 Checked access to the zero vector elements. More...
 
constexpr ConstIterator begin () const noexcept
 Returns an iterator to the first non-zero element of the zero vector. More...
 
constexpr ConstIterator cbegin () const noexcept
 Returns an iterator to the first non-zero element of the zero vector. More...
 
constexpr ConstIterator end () const noexcept
 Returns an iterator just past the last non-zero element of the zero vector. More...
 
constexpr ConstIterator cend () const noexcept
 Returns an iterator just past the last non-zero element of the zero vector. More...
 
Assignment operators
template<typename VT >
ZeroVectoroperator= (const Vector< VT, TF > &rhs) &
 
ZeroVectoroperator= (const ZeroVector &) &=default
 
ZeroVectoroperator= (ZeroVector &&) &=default
 
Utility functions
constexpr size_t size () const noexcept
 Returns the current size/dimension of the zero vector. More...
 
constexpr size_t capacity () const noexcept
 Returns the maximum capacity of the zero vector. More...
 
constexpr size_t nonZeros () const noexcept
 Returns the number of non-zero elements in the zero vector. More...
 
constexpr void clear () noexcept
 Clearing the zero vector. More...
 
constexpr void resize (size_t n) noexcept
 Changing the size of the zero vector. More...
 
constexpr void swap (ZeroVector &v) noexcept
 Swapping the contents of two zero vectors. More...
 
Lookup functions
ConstIterator find (size_t index) const
 Searches for a specific vector element. More...
 
ConstIterator lowerBound (size_t index) const
 Returns an iterator to the first index not less then the given index. More...
 
ConstIterator upperBound (size_t index) const
 Returns an iterator to the first index greater then the given index. More...
 
Expression template evaluation functions
template<typename Other >
bool canAlias (const Other *alias) const noexcept
 Returns whether the vector can alias with the given address alias. More...
 
template<typename Other >
bool isAliased (const Other *alias) const noexcept
 Returns whether the vector is aliased with the given address alias. More...
 
bool canSMPAssign () const noexcept
 Returns whether the vector can be used in SMP assignments. More...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr ZeroVector< Type, TF, Tag > & operator~ () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
BLAZE_ALWAYS_INLINE constexpr const ZeroVector< Type, TF, Tag > & operator~ () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 
constexpr ZeroVector< Type, TF, Tag > & operator* () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
constexpr const ZeroVector< Type, TF, Tag > & operator* () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 

Static Public Attributes

static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>
 Compilation flag for SMP assignments. More...
 
static constexpr bool transposeFlag
 Transpose flag of the vector.
 

Private Types

using Element = ValueIndexPair< Type >
 Value-index-pair for the ZeroVector class.
 

Member variables

size_t size_
 The current size/dimension of the zero vector.
 
static const Type zero_ {}
 The zero element.
 

Detailed Description

template<typename Type, bool TF, typename Tag>
class blaze::ZeroVector< Type, TF, Tag >

Efficient implementation of an arbitrary sized zero vector.

The ZeroVector class template is the representation of an immutable, arbitrary sized zero vector with N elements of arbitrary type. The type of the elements, the transpose flag, and the group tag of the vector can be specified via the three template parameters:

namespace blaze {
template< typename Type, bool TF, typename Tag >
class ZeroVector;
} // namespace blaze
constexpr ZeroVector() noexcept
The default constructor for ZeroVector.
Definition: ZeroVector.h:361

It is not possible to insert, erase or modify the elements of a zero vector. It is only possible to read from the elements:

// Creating a 4D zero column vector
ZeroVector<double,columnVector> a( 4 );
// The subscript operator provides access to all possible elements of the zero vector,
// including the zero elements.
a[1] = 2.0; // Compilation error: It is not possible to write to a zero vector
double d = a[2]; // Access to the element at index 2
// In order to traverse all non-zero elements currently stored in the vector, the begin()
// and end() functions can be used.
for( ZeroVector<double,columnVector>::Iterator i=a.begin(); i!=a.end(); ++i ) {
... = i->value(); // Access to the value of the non-zero element
... = i->index(); // Access to the index of the non-zero element
}
Efficient implementation of an arbitrary sized zero vector.
Definition: ZeroVector.h:183
Element * Iterator
Iterator over non-constant elements.
Definition: ZeroVector.h:207
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58

The use of ZeroVector is very natural and intuitive. All operations (addition, subtraction, multiplication, ...) can be performed on all possible combinations of dense and sparse vectors with fitting element types. The following example gives an impression of the use of ZeroVector:

ZeroVector<double> z( 3 ); // 3-dimensional zero vector
DynamicVector<double,columnMajor> a( 3 ); // 3-dimensional dynamic dense vector
CompressedVector<double,rowMajor> b( 3 ); // 3-dimensional double precision sparse vector
CompressedVector<float,rowMajor> c( 3 ); // 3-dimensional single precision sparse vector
// ... Initialization of a, b, and c
DynamicVector<double> d( z ); // Creation of a new dense vector as a copy of z
CompressedVector<double> e; // Creation of a default sparse vector
d = z + a; // Addition of a zero vector and a dense vector
d = b - z; // Subtraction of a sparse vector and a zero vector
e = z * c; // Vector multiplication between two vectors of different element types
d = 2.0 * z; // Scaling of a zero vector
e = z * 2.0; // Scaling of a zero vector
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223

Constructor & Destructor Documentation

◆ ZeroVector() [1/2]

template<typename Type , bool TF, typename Tag >
constexpr blaze::ZeroVector< Type, TF, Tag >::ZeroVector ( size_t  n)
explicitconstexprnoexcept

Constructor for a zero vector of size n.

Parameters
nThe size of the vector.

◆ ZeroVector() [2/2]

template<typename Type , bool TF, typename Tag >
template<typename VT >
blaze::ZeroVector< Type, TF, Tag >::ZeroVector ( const Vector< VT, TF > &  v)
inline

Conversion constructor for different zero vectors.

Parameters
vZero vector to be copied.
Exceptions
std::invalid_argumentInvalid setup of zero vector.

The vector is sized according to the given N-dimensional zero vector and initialized as a copy of this vector.

Member Function Documentation

◆ at()

template<typename Type , bool TF, typename Tag >
ZeroVector< Type, TF, Tag >::ConstReference blaze::ZeroVector< Type, TF, Tag >::at ( size_t  index) const
inline

Checked access to the zero vector elements.

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

In contrast to the subscript operator this function always performs a check of the given access indices.

◆ begin()

template<typename Type , bool TF, typename Tag >
constexpr ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::begin
constexprnoexcept

Returns an iterator to the first non-zero element of the zero vector.

Returns
Iterator to the first non-zero element of the zero vector.

◆ canAlias()

template<typename Type , bool TF, typename Tag >
template<typename Other >
bool blaze::ZeroVector< Type, TF, Tag >::canAlias ( const Other *  alias) const
inlinenoexcept

Returns whether the vector can alias with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this vector, false if not.

This function returns whether the given address can alias with the vector. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.

◆ canSMPAssign()

template<typename Type , bool TF, typename Tag >
bool blaze::ZeroVector< Type, TF, Tag >::canSMPAssign
inlinenoexcept

Returns whether the vector can be used in SMP assignments.

Returns
true in case the vector can be used in SMP assignments, false if not.

This function returns whether the vector 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).

◆ capacity()

template<typename Type , bool TF, typename Tag >
constexpr size_t blaze::ZeroVector< Type, TF, Tag >::capacity
constexprnoexcept

Returns the maximum capacity of the zero vector.

Returns
The capacity of the zero vector.

◆ cbegin()

template<typename Type , bool TF, typename Tag >
constexpr ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::cbegin
constexprnoexcept

Returns an iterator to the first non-zero element of the zero vector.

Returns
Iterator to the first non-zero element of the zero vector.

◆ cend()

template<typename Type , bool TF, typename Tag >
constexpr ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::cend
constexprnoexcept

Returns an iterator just past the last non-zero element of the zero vector.

Returns
Iterator just past the last non-zero element of the zero vector.

◆ clear()

template<typename Type , bool TF, typename Tag >
constexpr void blaze::ZeroVector< Type, TF, Tag >::clear
constexprnoexcept

Clearing the zero vector.

Returns
void

After the clear() function, the size of the zero vector is 0.

◆ end()

template<typename Type , bool TF, typename Tag >
constexpr ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::end
constexprnoexcept

Returns an iterator just past the last non-zero element of the zero vector.

Returns
Iterator just past the last non-zero element of the zero vector.

◆ find()

template<typename Type , bool TF, typename Tag >
ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::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 zero vector (the end() iterator) is returned.

◆ isAliased()

template<typename Type , bool TF, typename Tag >
template<typename Other >
bool blaze::ZeroVector< Type, TF, Tag >::isAliased ( const Other *  alias) const
inlinenoexcept

Returns whether the vector is aliased with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this vector, false if not.

This function returns whether the given address is aliased with the vector. In contrast to the canAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.

◆ lowerBound()

template<typename Type , bool TF, typename Tag >
ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::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.

◆ nonZeros()

template<typename Type , bool TF, typename Tag >
constexpr size_t blaze::ZeroVector< Type, TF, Tag >::nonZeros
constexprnoexcept

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

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

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

◆ operator*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const ZeroVector< Type, TF, Tag > & blaze::Vector< ZeroVector< Type, TF, Tag > , 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 ZeroVector< Type, TF, Tag > & blaze::Vector< ZeroVector< Type, TF, Tag > , 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 Type , bool TF, typename Tag >
template<typename VT >
ZeroVector< Type, TF, Tag > & blaze::ZeroVector< Type, TF, Tag >::operator= ( const Vector< VT, TF > &  rhs) &
inline

Assignment operator for different zero vectors.

Parameters
rhsZero vector to be copied.
Returns
Reference to the assigned vector.
Exceptions
std::invalid_argumentInvalid assignment to zero vector.

The vector is resized according to the given zero vector and initialized as a copy of this vector.

◆ operator[]()

template<typename Type , bool TF, typename Tag >
constexpr ZeroVector< Type, TF, Tag >::ConstReference blaze::ZeroVector< Type, TF, Tag >::operator[] ( size_t  index) const
constexprnoexcept

Subscript operator for the direct access to the zero vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE constexpr const ZeroVector< Type, TF, Tag > & blaze::Vector< ZeroVector< Type, TF, Tag > , 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 ZeroVector< Type, TF, Tag > & blaze::Vector< ZeroVector< Type, TF, Tag > , 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.

◆ resize()

template<typename Type , bool TF, typename Tag >
constexpr void blaze::ZeroVector< Type, TF, Tag >::resize ( size_t  n)
constexprnoexcept

Changing the size of the zero vector.

Parameters
nThe new size of the zero vector.
Returns
void

This function resizes the zero vector using the given size to n. Note that this function may invalidate all existing views (subvectors, ...) on the vector if it is used to shrink the vector.

◆ size()

template<typename Type , bool TF, typename Tag >
constexpr size_t blaze::ZeroVector< Type, TF, Tag >::size
constexprnoexcept

Returns the current size/dimension of the zero vector.

Returns
The size of the zero vector.

◆ swap()

template<typename Type , bool TF, typename Tag >
constexpr void blaze::ZeroVector< Type, TF, Tag >::swap ( ZeroVector< Type, TF, Tag > &  v)
constexprnoexcept

Swapping the contents of two zero vectors.

Parameters
vThe zero vector to be swapped.
Returns
void

◆ upperBound()

template<typename Type , bool TF, typename Tag >
ZeroVector< Type, TF, Tag >::ConstIterator blaze::ZeroVector< Type, TF, Tag >::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.

Member Data Documentation

◆ smpAssignable

template<typename Type , bool TF, typename Tag >
constexpr bool blaze::ZeroVector< Type, TF, Tag >::smpAssignable = !IsSMPAssignable_v<Type>
staticconstexpr

Compilation flag for SMP assignments.

The smpAssignable compilation flag indicates whether the vector can be used in SMP (shared memory parallel) assignments (both on the left-hand and right-hand side of the assignment).


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