Modules | Classes | Functions

Modules

 Dense Vectors
 
 Sparse Vectors
 

Classes

struct  blaze::Vector< VT, TF >
 Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-dimensional) dense and sparse vector classes within the Blaze library. It provides an abstraction from the actual type of the vector, but enables a conversion back to this type via the 'Curiously Recurring Template Pattern' (CRTP). More...
 

Functions

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::Iterator blaze::begin (Vector< VT, TF > &vector)
 Returns an iterator to the first element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::begin (const Vector< VT, TF > &vector)
 Returns an iterator to the first element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::cbegin (const Vector< VT, TF > &vector)
 Returns an iterator to the first element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::Iterator blaze::end (Vector< VT, TF > &vector)
 Returns an iterator just past the last element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::end (const Vector< VT, TF > &vector)
 Returns an iterator just past the last element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::cend (const Vector< VT, TF > &vector)
 Returns an iterator just past the last element of the given vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE constexpr size_t blaze::size (const Vector< VT, TF > &vector) noexcept
 Returns the current size/dimension of the vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE size_t blaze::capacity (const Vector< VT, TF > &vector) noexcept
 Returns the maximum capacity of the vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros (const Vector< VT, TF > &vector)
 Returns the number of non-zero elements in the vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE void blaze::resize (Vector< VT, TF > &vector, size_t n, bool preserve)
 Changing the size of the vector. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE void blaze::shrinkToFit (Vector< VT, TF > &vector)
 Requesting the removal of unused capacity. More...
 
template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE constexpr bool blaze::isEmpty (const Vector< VT, TF > &vector) noexcept
 Checks if the given vector is empty. More...
 
template<typename VT1 , bool TF1, typename VT2 , bool TF2>
BLAZE_ALWAYS_INLINE bool blaze::isSame (const Vector< VT1, TF1 > &a, const Vector< VT2, TF2 > &b) noexcept
 Returns whether the two given vectors represent the same observable state. More...
 

Vector global functions

template<typename VT , bool TF>
const VT::ResultType blaze::evaluate (const Vector< VT, TF > &vector)
 Evaluates the given vector expression. More...
 

Vector functions

template<typename VT , bool TF>
bool blaze::isUniform (const Vector< VT, TF > &v)
 Checks if the given vector is a uniform vector. More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::inner (const Vector< T1, false > &lhs, const Vector< T2, false > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::inner (const Vector< T1, false > &lhs, const Vector< T2, true > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::inner (const Vector< T1, true > &lhs, const Vector< T2, false > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::inner (const Vector< T1, true > &lhs, const Vector< T2, true > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , bool TF1, typename T2 , bool TF2>
decltype(auto) blaze::dot (const Vector< T1, TF1 > &lhs, const Vector< T2, TF2 > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , bool TF1, typename T2 , bool TF2>
decltype(auto) blaze::operator, (const Vector< T1, TF1 > &lhs, const Vector< T2, TF2 > &rhs)
 Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::outer (const Vector< T1, false > &lhs, const Vector< T2, false > &rhs)
 Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::outer (const Vector< T1, false > &lhs, const Vector< T2, true > &rhs)
 Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::outer (const Vector< T1, true > &lhs, const Vector< T2, false > &rhs)
 Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename T1 , typename T2 >
decltype(auto) blaze::outer (const Vector< T1, true > &lhs, const Vector< T2, true > &rhs)
 Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $). More...
 
template<typename VT , bool TF>
decltype(auto) blaze::reverse (const Vector< VT, TF > &v)
 Reverse the elements of a vector. More...
 

Vector operators

template<typename VT , bool TF>
std::ostream & blaze::operator<< (std::ostream &os, const Vector< VT, TF > &v)
 Global output operator for dense and sparse vectors. More...
 

Detailed Description

Function Documentation

◆ begin() [1/2]

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::Iterator blaze::begin ( Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator to the first element of the given vector.

◆ begin() [2/2]

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::begin ( const Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator to the first element of the given vector.

◆ capacity()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE size_t blaze::capacity ( const Vector< VT, TF > &  vector)
noexcept

Returns the maximum capacity of the vector.

Parameters
vectorThe given vector.
Returns
The capacity of the vector.

◆ cbegin()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::cbegin ( const Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator to the first element of the given vector.

◆ cend()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::cend ( const Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator just past the last element of the given vector.

◆ dot()

template<typename T1 , bool TF1, typename T2 , bool TF2>
decltype(auto) blaze::dot ( const Vector< T1, TF1 > &  lhs,
const Vector< T2, TF2 > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ end() [1/2]

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::Iterator blaze::end ( Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator just past the last element of the given vector.

◆ end() [2/2]

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE VT::ConstIterator blaze::end ( const Vector< VT, TF > &  vector)

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

Parameters
vectorThe given dense or sparse vector.
Returns
Iterator just past the last element of the given vector.

◆ evaluate()

template<typename VT , bool TF>
const VT::ResultType blaze::evaluate ( const Vector< VT, TF > &  vector)
inline

Evaluates the given vector expression.

Parameters
vectorThe vector to be evaluated.
Returns
The result of the evaluated vector expression.

This function forces an evaluation of the given vector expression and enables an automatic deduction of the correct result type of an operation. The following code example demonstrates its intended use for the multiplication of a dense and a sparse vector:

In this scenario, the evaluate() function assists in deducing the exact result type of the operation via the 'auto' keyword. Please note that if evaluate() is used in this way, no temporary vector is created and no copy operation is performed. Instead, the result is directly written to the target vector due to the return value optimization (RVO). However, if evaluate() is used in combination with an explicit target type, a temporary will be created and a copy operation will be performed if the used type differs from the type returned from the function:

CompressedVector<double> d( a * b ); // No temporary & no copy operation
DynamicVector<double> e( a * b ); // Temporary & copy operation
d = evaluate( a * b ); // Temporary & copy operation

Sometimes it might be desirable to explicitly evaluate a sub-expression within a larger expression. However, please note that evaluate() is not intended to be used for this purpose. This task is more elegantly and efficiently handled by the eval() function:

d = a + evaluate( b * c ); // Unnecessary creation of a temporary vector
d = a + eval( b * c ); // No creation of a temporary vector

In contrast to the evaluate() function, eval() can take the complete expression into account and therefore can guarantee the most efficient way to evaluate it.

◆ inner() [1/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::inner ( const Vector< T1, false > &  lhs,
const Vector< T2, false > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ inner() [2/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::inner ( const Vector< T1, false > &  lhs,
const Vector< T2, true > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ inner() [3/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::inner ( const Vector< T1, true > &  lhs,
const Vector< T2, false > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ inner() [4/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::inner ( const Vector< T1, true > &  lhs,
const Vector< T2, true > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ isEmpty()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE constexpr bool blaze::isEmpty ( const Vector< VT, TF > &  vector)
noexcept

Checks if the given vector is empty.

Parameters
vectorThe vector to be checked.
Returns
true if the vector is empty, false if not.

This function checks if the total number of elements of the given vector is zero. If the total number of elements is zero the function returns true, otherwise it returns false.

◆ isSame()

template<typename VT1 , bool TF1, typename VT2 , bool TF2>
BLAZE_ALWAYS_INLINE bool blaze::isSame ( const Vector< VT1, TF1 > &  a,
const Vector< VT2, TF2 > &  b 
)
noexcept

Returns whether the two given vectors represent the same observable state.

Parameters
aThe first vector to be tested for its state.
bThe second vector to be tested for its state.
Returns
true in case the two vectors share a state, false otherwise.

The isSame function provides an abstract interface for testing if the two given vectors represent the same observable state. This happens for instance in case a and b refer to the same vector or in case a and b are aliases for the same vector. In case both vectors represent the same observable state, the function returns true, other it returns false.

blaze::DynamicVector<int> vec1( 4UL ); // Setup of a 4-dimensional dynamic vector
blaze::DynamicVector<int> vec2( 4UL ); // Setup of a second 4-dimensional dynamic vector
auto sub1 = subvector( vec1, 0UL, 4UL ); // Subvector of vec1 for the entire range
auto sub2 = subvector( vec1, 1UL, 2UL ); // Subvector of vec1 for the range [1..3]
auto sub3 = subvector( vec1, 1UL, 2UL ); // Second subvector of vec1 for the range [1..3]
isSame( vec1, vec1 ); // returns true since both objects refer to the same vector
isSame( vec1, vec2 ); // returns false since vec1 and vec2 are two different vectors
isSame( vec1, sub1 ); // returns true since sub1 represents the same observable state as vec1
isSame( vec1, sub3 ); // returns false since sub3 only covers part of the range of vec1
isSame( sub2, sub3 ); // returns true since sub1 and sub2 refer to exactly the same range of vec1
isSame( sub1, sub3 ); // returns false since sub1 and sub3 refer to different ranges of vec1

◆ isUniform()

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

Checks if the given vector is a uniform vector.

Parameters
vThe vector to be checked.
Returns
true if the vector is a uniform vector, false if not.

This function checks if the given dense or sparse vector is a uniform vector. The vector is considered to be uniform if all its elements are identical. The following code example demonstrates the use of the function:

// ... Initialization
if( isUniform( a ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isUniform<relaxed>( a ) ) { ... }

It is also possible to check if a vector expression results in a uniform vector:

if( isUniform( a + b ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary vector.

◆ nonZeros()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros ( const Vector< VT, TF > &  vector)

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

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

Note that the number of non-zero elements is always less than or equal to the current size of the vector.

◆ operator,()

template<typename T1 , bool TF1, typename T2 , bool TF2>
decltype(auto) blaze::operator, ( const Vector< T1, TF1 > &  lhs,
const Vector< T2, TF2 > &  rhs 
)

Multiplication operator for the scalar product (dot/inner product) of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the scalar product.
rhsThe right-hand side vector for the scalar product.
Returns
The scalar product.

◆ operator<<()

template<typename VT , bool TF>
std::ostream & blaze::operator<< ( std::ostream &  os,
const Vector< VT, TF > &  v 
)
inline

Global output operator for dense and sparse vectors.

Parameters
osReference to the output stream.
vReference to a constant vector object.
Returns
Reference to the output stream.

◆ outer() [1/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::outer ( const Vector< T1, false > &  lhs,
const Vector< T2, false > &  rhs 
)

Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the outer product.
rhsThe right-hand side vector for the outer product.
Returns
The outer product.

◆ outer() [2/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::outer ( const Vector< T1, false > &  lhs,
const Vector< T2, true > &  rhs 
)

Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the outer product.
rhsThe right-hand side vector for the outer product.
Returns
The outer product.

◆ outer() [3/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::outer ( const Vector< T1, true > &  lhs,
const Vector< T2, false > &  rhs 
)

Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the outer product.
rhsThe right-hand side vector for the outer product.
Returns
The outer product.

◆ outer() [4/4]

template<typename T1 , typename T2 >
decltype(auto) blaze::outer ( const Vector< T1, true > &  lhs,
const Vector< T2, true > &  rhs 
)

Multiplication operator for the outer product of two vectors ( $ s=(\vec{a},\vec{b}) $).

Parameters
lhsThe left-hand side vector for the outer product.
rhsThe right-hand side vector for the outer product.
Returns
The outer product.

◆ resize()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE void blaze::resize ( Vector< VT, TF > &  vector,
size_t  n,
bool  preserve 
)

Changing the size of the vector.

Parameters
vectorThe given vector to be resized.
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_argumentVector cannot be resized.

This function provides a unified interface to resize dense and sparse vectors. In contrast to the resize() member function, which is only available on resizable vector types, this function can be used on both resizable and non-resizable vectors. In case the given vector type VT is resizable (i.e. provides a resize() function), the type-specific resize() member function is called. Depending on the type VT, this may result in the allocation of new dynamic memory and the invalidation of existing views (subvectors, ...). In case VT is non-resizable (i.e. does not provide a resize() function) and if the specified size is not identical to the current size of the vector, a std::invalid_argument exception is thrown.

resize( a, 5UL ); // OK: regular resize operation
resize( b, 3UL ); // OK: No resize necessary
resize( b, 5UL ); // Error: Vector cannot be resized!

◆ reverse()

template<typename VT , bool TF>
decltype(auto) blaze::reverse ( const Vector< VT, TF > &  v)

Reverse the elements of a vector.

Parameters
vThe vector to be reversed.
Returns
The reversed vector.

This function reverses the elements of a dense or sparse vector. The following examples demonstrates this by means of a dense vector:

blaze::DynamicVector<int> a{ 1, 2, 3, 4, 5 };
b = reverse( a ); // Results in ( 5 4 3 2 1 )

◆ shrinkToFit()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE void blaze::shrinkToFit ( Vector< VT, TF > &  vector)

Requesting the removal of unused capacity.

Parameters
vectorThe given vector to be shrunk.
Returns
void

This function tries to minimize the capacity of the vector by removing unused capacity. Please note that in case of a shrinkable vector, due to padding the capacity might not be reduced exactly to the size of the vector. Please also note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of this vector are invalidated. In case of an unshrinkable vector the function has no effect.

◆ size()

template<typename VT , bool TF>
BLAZE_ALWAYS_INLINE constexpr size_t blaze::size ( const Vector< VT, TF > &  vector)
noexcept

Returns the current size/dimension of the vector.

Parameters
vectorThe given vector.
Returns
The size of the vector.