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

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 and the transpose flag of the vector can be specified via the two template parameters: More...

#include <InitializerVector.h>

Inherits blaze::DenseVector< InitializerVector< Type, TF >, 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 >
 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 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 = VT
 Type of the vector.
 

Public Member Functions

BLAZE_ALWAYS_INLINE constexpr VectorTypeoperator~ () noexcept
 Conversion operator for non-constant vectors. More...
 
BLAZE_ALWAYS_INLINE constexpr const VectorTypeoperator~ () const noexcept
 Conversion operator for constant vectors. More...
 
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...
 
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...
 

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 = TF
 Transpose flag of the vector.
 

Private Types

using ListType = initializer_list< Type >
 Type of the represented initializer list.
 

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 = defaultTransposeFlag>
class blaze::InitializerVector< Type, TF >

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 and the transpose flag of the vector can be specified via the two template parameters:

template< typename Type, bool TF >

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

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

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

Constructor & Destructor Documentation

◆ InitializerVector() [1/2]

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

Constructor for InitializerVector.

Parameters
listThe initializer list represented by the vector.

◆ InitializerVector() [2/2]

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

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>
InitializerVector< Type, TF >::ConstReference blaze::InitializerVector< Type, TF >::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>
InitializerVector< Type, TF >::ConstIterator blaze::InitializerVector< Type, TF >::begin ( ) const
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>
template<typename Other >
bool blaze::InitializerVector< Type, TF >::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>
size_t blaze::InitializerVector< Type, TF >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the vector.

Returns
The maximum capacity of the vector.

◆ cbegin()

template<typename Type , bool TF>
InitializerVector< Type, TF >::ConstIterator blaze::InitializerVector< Type, TF >::cbegin ( ) const
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>
InitializerVector< Type, TF >::ConstIterator blaze::InitializerVector< Type, TF >::cend ( ) const
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>
InitializerVector< Type, TF >::ConstPointer blaze::InitializerVector< Type, TF >::data ( ) const
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>
InitializerVector< Type, TF >::ConstIterator blaze::InitializerVector< Type, TF >::end ( ) const
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>
template<typename Other >
bool blaze::InitializerVector< Type, TF >::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>
size_t blaze::InitializerVector< Type, TF >::nonZeros ( ) const
inline

Returns the number of non-zero elements in the 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 Type , bool TF>
InitializerVector< Type, TF >::ConstReference blaze::InitializerVector< Type, TF >::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]

template<typename VT, bool TF>
BLAZE_ALWAYS_INLINE constexpr VectorType& blaze::Vector< VT, TF >::operator~ ( )
inlinenoexceptinherited

Conversion operator for non-constant vectors.

Returns
Reference of the actual type of the vector.

◆ operator~() [2/2]

template<typename VT, bool TF>
BLAZE_ALWAYS_INLINE constexpr const VectorType& blaze::Vector< VT, TF >::operator~ ( ) const
inlinenoexceptinherited

Conversion operator for constant vectors.

Returns
Const reference of the actual type of the vector.

◆ size()

template<typename Type , bool TF>
size_t blaze::InitializerVector< Type, TF >::size ( ) const
inlinenoexcept

Returns the current size/dimension of the vector.

Returns
The size of the vector.

◆ spacing()

template<typename Type , bool TF>
size_t blaze::InitializerVector< Type, TF >::spacing ( ) const
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>
void blaze::InitializerVector< Type, TF >::swap ( InitializerVector< Type, TF > &  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 = defaultTransposeFlag>
ListType blaze::InitializerVector< Type, TF >::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 = defaultTransposeFlag>
constexpr bool blaze::InitializerVector< Type, TF >::simdEnabled = false
static

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 = defaultTransposeFlag>
constexpr bool blaze::InitializerVector< Type, TF >::smpAssignable = false
static

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 file: