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

Dense vector representation of an initializer list. More...

#include <InitializerVector.h>

Inherits blaze::DenseVector< InitializerVector< Type, TF, Tag >, TF >.

Classes

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

Public Types

using This = InitializerVector< Type, TF, Tag >
 Type of this InitializerVector instance.
 
using BaseType = DenseVector< This, TF >
 Base type of this InitializerVector instance.
 
using ResultType = DynamicVector< Type, TF >
 Result type for expression template evaluations.
 
using TransposeType = DynamicVector< Type,!TF >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the vector elements.
 
using TagType = Tag
 Tag type of this InitializerVector instance.
 
using ReturnType = const Type &
 Return type for expression template evaluations.
 
using CompositeType = const InitializerVector &
 Data type for composite expression templates.
 
using Reference = const Type &
 Reference to a non-constant vector value.
 
using ConstReference = const Type &
 Reference to a constant vector value.
 
using Pointer = const Type *
 Pointer to a non-constant vector value.
 
using ConstPointer = const Type *
 Pointer to a constant vector value.
 
using Iterator = InitializerIterator< Type >
 Iterator over non-constant elements.
 
using ConstIterator = InitializerIterator< Type >
 Iterator over constant elements.
 
using VectorType = InitializerVector< Type, TF, Tag >
 Type of the vector.
 

Public Member Functions

Constructors
 InitializerVector (initializer_list< Type > list) noexcept
 Constructor for InitializerVector. More...
 
 InitializerVector (initializer_list< Type > list, size_t n)
 Constructor for InitializerVector. More...
 
 InitializerVector (const InitializerVector &)=default
 
Destructor
 ~InitializerVector ()=default
 
Data access functions
ConstReference operator[] (size_t index) const noexcept
 Subscript operator for the direct access to the vector elements. More...
 
ConstReference at (size_t index) const
 Checked access to the vector elements. More...
 
ConstPointer data () const noexcept
 Low-level data access to the vector elements. More...
 
ConstIterator begin () const noexcept
 Returns an iterator to the first element of the initializer vector. More...
 
ConstIterator cbegin () const noexcept
 Returns an iterator to the first element of the initializer vector. More...
 
ConstIterator end () const noexcept
 Returns an iterator just past the last element of the initializer vector. More...
 
ConstIterator cend () const noexcept
 Returns an iterator just past the last element of the initializer vector. More...
 
Assignment operators
InitializerVectoroperator= (const InitializerVector &)=delete
 
Utility functions
size_t size () const noexcept
 Returns the current size/dimension of the vector. More...
 
size_t spacing () const noexcept
 Returns the minimum capacity of the vector. More...
 
size_t capacity () const noexcept
 Returns the maximum capacity of the vector. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the vector. More...
 
void swap (InitializerVector &v) noexcept
 Swapping the contents of two vectors. More...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr InitializerVector< Type, TF, Tag > & operator~ () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
BLAZE_ALWAYS_INLINE constexpr const InitializerVector< Type, TF, Tag > & operator~ () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 
constexpr InitializerVector< Type, TF, Tag > & operator* () noexcept
 CRTP-based conversion operation for non-constant vectors. More...
 
constexpr const InitializerVector< Type, TF, Tag > & operator* () const noexcept
 CRTP-based conversion operation for constant vectors. More...
 

Static Public Attributes

static constexpr bool simdEnabled = false
 Compilation flag for SIMD optimization. More...
 
static constexpr bool smpAssignable = false
 Compilation flag for SMP assignments. More...
 
static constexpr bool transposeFlag
 Transpose flag of the vector.
 

Expression template evaluation functions

using ListType = initializer_list< Type >
 Type of the represented initializer list.
 
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...
 

Member variables

size_t size_
 The current size/dimension of the vector.
 
ListType list_
 The initializer list represented by the vector. More...
 
static const Type zero_ {}
 Neutral element for accesses to zero elements.
 

Detailed Description

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

Dense vector representation of an initializer list.

The InitializerVector class template is a dense vector representation of an (extended) initializer list 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 >
} // namespace blaze
InitializerVector(initializer_list< Type > list) noexcept
Constructor for InitializerVector.
Definition: InitializerVector.h:359

On construction, an InitializerVector is immediately bound to an initializer list:

const auto list = { 2, 6, -1, 3, 5 };
blaze::InitializerVector<int> a( list ); // Representation of the initializer list as dense column vector
Dense vector representation of an initializer list.
Definition: InitializerVector.h:182

It is possible to only represent an extended initializer list by providing an additional size argument:

const auto list = { 2, 6, -1, 3, 5 };
blaze::InitializerVector<int> b( list, 5UL ); // Representation of the original initializer list
blaze::InitializerVector<int> c( list, 8UL ); // Representing the initializer list { 2, 6, -1, 3, 5, 0, 0, 0 }

Since an InitializerVector represents a specific initializer list, its lifetime is bound to the lifetime of the according initializer list. When the initializer list goes out of scope access to the initializer list via an InitializerVector results in undefined behavior:

blaze::InitializerVector<int> d{ 1, 2, 3, 4, 5 }; // Undefined behavior!
blaze::InitializerVector<int> e( { 0, 3, 2 }, 3UL ); // Undefined behavior!

Also, an InitializerVector can only be used on the right of an assignment as its elements are considered to be immutable. The following example gives an impression on the usage of an InitializerVector:

const auto list = { 2, 6, -1, 3, 5 };
blaze::InitializerVector<int> f( list ); // Representation of the initializer list as dense vector
g = f; // Initialize vector g via vector f
f = g; // Compilation error! Cannot assign to an initializer vector
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223

An initializer vector can be used as operand in arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) 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 InitializerVector:

const auto list = { 1.0, 2.0 };
InitializerVector<double> a( list );
DynamicVector<double> b( 2, 2.0 ); // Directly, homogeneously initialized 2D vector
CompressedVector<float> c( 2 ); // Empty sparse single precision vector
DynamicVector<double> d; // Default constructed dynamic vector
DynamicMatrix<double> A; // Default constructed row-major matrix
d = a + b; // Vector addition between vectors of equal element type
d = a - c; // Vector subtraction between a dense and sparse vector with different element types
d = a * b; // Component-wise vector multiplication
d = a * 2.0; // Scaling of vector a
d = 2.0 * a; // Scaling of vector a
d += a - b; // Addition assignment
d -= a + c; // Subtraction assignment
d *= a * b; // Multiplication assignment
double scalar = trans( a ) * b; // Scalar/dot/inner product between two vectors
A = a * trans( b ); // Outer product between two vectors
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766

Constructor & Destructor Documentation

◆ InitializerVector() [1/2]

template<typename Type , bool TF, typename Tag >
blaze::InitializerVector< Type, TF, Tag >::InitializerVector ( initializer_list< Type >  list)
inlinenoexcept

Constructor for InitializerVector.

Parameters
listThe initializer list represented by the vector.

◆ InitializerVector() [2/2]

template<typename Type , bool TF, typename Tag >
blaze::InitializerVector< Type, TF, Tag >::InitializerVector ( initializer_list< Type >  list,
size_t  n 
)
inline

Constructor for InitializerVector.

Parameters
listThe initializer list represented by the vector.
nThe size of the vector.
Exceptions
std::invalid_argumentInvalid initializer list dimension.

Member Function Documentation

◆ at()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstReference blaze::InitializerVector< Type, TF, Tag >::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::out_of_rangeInvalid vector access index.

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

◆ begin()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstIterator blaze::InitializerVector< Type, TF, Tag >::begin
inlinenoexcept

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

Returns
Iterator to the first element of the initializer vector.

◆ canAlias()

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

◆ capacity()

template<typename Type , bool TF, typename Tag >
size_t blaze::InitializerVector< Type, TF, Tag >::capacity
inlinenoexcept

Returns the maximum capacity of the vector.

Returns
The maximum capacity of the vector.

◆ cbegin()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstIterator blaze::InitializerVector< Type, TF, Tag >::cbegin
inlinenoexcept

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

Returns
Iterator to the first element of the initializer vector.

◆ cend()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstIterator blaze::InitializerVector< Type, TF, Tag >::cend
inlinenoexcept

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

Returns
Iterator just past the last element of the initializer vector.

◆ data()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstPointer blaze::InitializerVector< Type, TF, Tag >::data
inlinenoexcept

Low-level data access to the vector elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the initializer vector.

◆ end()

template<typename Type , bool TF, typename Tag >
InitializerVector< Type, TF, Tag >::ConstIterator blaze::InitializerVector< Type, TF, Tag >::end
inlinenoexcept

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

Returns
Iterator just past the last element of the initializer vector.

◆ isAliased()

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

◆ nonZeros()

template<typename Type , bool TF, typename Tag >
size_t blaze::InitializerVector< Type, TF, Tag >::nonZeros
inline

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

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

This function returns the number of non-zero elements in the vector (i.e. the elements that compare unequal to their default value). Note that the number of non-zero elements is always less than or equal to the current size of the vector.

◆ operator*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const InitializerVector< Type, TF, Tag > & blaze::Vector< InitializerVector< 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 InitializerVector< Type, TF, Tag > & blaze::Vector< InitializerVector< 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 >
InitializerVector< Type, TF, Tag >::ConstReference blaze::InitializerVector< Type, TF, Tag >::operator[] ( size_t  index) const
inlinenoexcept

Subscript operator for the direct 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.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.

◆ operator~() [1/2]

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

◆ size()

template<typename Type , bool TF, typename Tag >
size_t blaze::InitializerVector< Type, TF, Tag >::size
inlinenoexcept

Returns the current size/dimension of the vector.

Returns
The size of the vector.

◆ spacing()

template<typename Type , bool TF, typename Tag >
size_t blaze::InitializerVector< Type, TF, Tag >::spacing
inlinenoexcept

Returns the minimum capacity of the vector.

Returns
The minimum capacity of the vector.

This function returns the minimum capacity of the vector, which corresponds to the current size plus padding.

◆ swap()

template<typename Type , bool TF, typename Tag >
void blaze::InitializerVector< Type, TF, Tag >::swap ( InitializerVector< Type, TF, Tag > &  v)
inlinenoexcept

Swapping the contents of two vectors.

Parameters
vThe vector to be swapped.
Returns
void

Member Data Documentation

◆ list_

template<typename Type , bool TF, typename Tag >
ListType blaze::InitializerVector< Type, TF, Tag >::list_
private

The initializer list represented by the vector.

Access to the vector elements is gained via the subscript operator. The order of the elements is

\[\left(\begin{array}{*{5}{c}} 0 & 1 & 2 & \cdots & N-1 \\ \end{array}\right)\]

◆ simdEnabled

template<typename Type , bool TF, typename Tag >
constexpr bool blaze::InitializerVector< Type, TF, Tag >::simdEnabled = false
staticconstexpr

Compilation flag for SIMD optimization.

The simdEnabled compilation flag indicates whether expressions the vector is involved in can be optimized via SIMD operationss. In case the element type of the vector is a vectorizable data type, the simdEnabled compilation flag is set to true, otherwise it is set to false.

◆ smpAssignable

template<typename Type , bool TF, typename Tag >
constexpr bool blaze::InitializerVector< Type, TF, Tag >::smpAssignable = false
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: