![]() |
Blaze
3.6
|
Efficient implementation of a uniform vector.The UniformVector class template is the representation of an arbitrary sized uniform vector with elements 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 <UniformVector.h>
Inherits blaze::Expression< DenseVector< UniformVector< Type, TF >, TF > >.
Classes | |
struct | Rebind |
Rebind mechanism to obtain a UniformVector with different data/element type. More... | |
struct | Resize |
Resize mechanism to obtain a UniformVector with a different fixed number of elements. More... | |
Public Types | |
using | This = UniformVector< Type, TF > |
Type of this UniformVector instance. | |
using | BaseType = DenseVector< This, TF > |
Base type of this UniformVector instance. | |
using | ResultType = This |
Result type for expression template evaluations. | |
using | TransposeType = UniformVector< Type,!TF > |
Transpose type for expression template evaluations. | |
using | ElementType = Type |
Type of the vector elements. | |
using | SIMDType = SIMDTrait_t< ElementType > |
SIMD type of the vector elements. | |
using | ReturnType = const Type & |
Return type for expression template evaluations. | |
using | CompositeType = const UniformVector & |
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 = UniformIterator< const Type, aligned > |
Iterator over non-constant elements. | |
using | ConstIterator = UniformIterator< const Type, aligned > |
Iterator over constant elements. | |
using | VectorType = VT |
Type of the vector. | |
Public Member Functions | |
template<typename VT > | |
UniformVector< Type, TF > & | operator= (const Vector< VT, TF > &rhs) |
Assignment operator for different vectors. More... | |
template<typename VT > | |
UniformVector< Type, TF > & | operator+= (const Vector< VT, TF > &rhs) |
Addition assignment operator for the addition of a vector ( ![]() | |
template<typename VT > | |
UniformVector< Type, TF > & | operator-= (const Vector< VT, TF > &rhs) |
Subtraction assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT > | |
UniformVector< Type, TF > & | operator *= (const Vector< VT, TF > &rhs) |
Multiplication assignment operator for the subtraction of a vector ( ![]() | |
template<typename VT > | |
UniformVector< Type, TF > & | operator/= (const DenseVector< VT, TF > &rhs) |
Division assignment operator for the division of a dense vector ( ![]() | |
template<typename Other > | |
UniformVector< Type, TF > & | scale (const Other &scalar) |
Scaling of the vector by the scalar value scalar ( ![]() | |
BLAZE_ALWAYS_INLINE constexpr VectorType & | operator~ () noexcept |
Conversion operator for non-constant vectors. More... | |
BLAZE_ALWAYS_INLINE constexpr const VectorType & | operator~ () const noexcept |
Conversion operator for constant vectors. More... | |
Constructors | |
constexpr | UniformVector () noexcept |
The default constructor for UniformVector. | |
constexpr | UniformVector (size_t n) |
Constructor for a vector of size n. More... | |
constexpr | UniformVector (size_t n, const Type &init) |
Constructor for a homogeneous initialization of all n vector elements. More... | |
template<typename VT > | |
UniformVector (const Vector< VT, TF > &v) | |
Conversion constructor for different uniform vectors. More... | |
UniformVector (const UniformVector &)=default | |
UniformVector (UniformVector &&)=default | |
Destructor | |
~UniformVector ()=default | |
Data access functions | |
constexpr 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... | |
constexpr ConstPointer | data () const noexcept |
Low-level data access to the vector elements. More... | |
constexpr ConstIterator | begin () const noexcept |
Returns an iterator to the first element of the uniform vector. More... | |
constexpr ConstIterator | cbegin () const noexcept |
Returns an iterator to the first element of the uniform vector. More... | |
constexpr ConstIterator | end () const noexcept |
Returns an iterator just past the last element of the uniform vector. More... | |
constexpr ConstIterator | cend () const noexcept |
Returns an iterator just past the last element of the uniform vector. More... | |
Assignment operators | |
constexpr UniformVector & | operator= (const Type &rhs) |
Homogenous assignment to all vector elements. More... | |
UniformVector & | operator= (const UniformVector &)=default |
UniformVector & | operator= (UniformVector &&)=default |
template<typename VT > | |
UniformVector & | operator= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
UniformVector & | operator+= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
UniformVector & | operator-= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
UniformVector & | operator *= (const Vector< VT, TF > &rhs) |
template<typename VT > | |
UniformVector & | operator/= (const DenseVector< VT, TF > &rhs) |
template<typename ST > | |
auto | operator *= (ST rhs) -> EnableIf_t< IsNumeric_v< ST >, UniformVector & > |
Multiplication assignment operator for the multiplication between a vector and a scalar value ( ![]() | |
template<typename ST > | |
auto | operator/= (ST rhs) -> EnableIf_t< IsNumeric_v< ST >, UniformVector & > |
Division assignment operator for the division between a vector and a scalar value ( ![]() | |
Utility functions | |
constexpr size_t | size () const noexcept |
Returns the current size/dimension of the vector. More... | |
constexpr size_t | spacing () const noexcept |
Returns the minimum capacity of the vector. More... | |
constexpr 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... | |
constexpr void | reset () |
Reset to the default initial values. More... | |
constexpr void | clear () |
Clearing the vector. More... | |
constexpr void | resize (size_t n, bool preserve=true) |
Changing the size of the vector. More... | |
constexpr void | extend (size_t n, bool preserve=true) |
Extending the size of the vector. More... | |
constexpr void | swap (UniformVector &v) noexcept |
Swapping the contents of two vectors. More... | |
Numeric functions | |
template<typename Other > | |
UniformVector & | scale (const Other &scalar) |
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 | isAligned () const noexcept |
Returns whether the vector is properly aligned in memory. More... | |
bool | canSMPAssign () const noexcept |
Returns whether the vector can be used in SMP assignments. More... | |
BLAZE_ALWAYS_INLINE SIMDType | load (size_t index) const noexcept |
Load of a SIMD element of the vector. More... | |
BLAZE_ALWAYS_INLINE SIMDType | loada (size_t index) const noexcept |
Aligned load of a SIMD element of the vector. More... | |
BLAZE_ALWAYS_INLINE SIMDType | loadu (size_t index) const noexcept |
Unaligned load of a SIMD element of the vector. More... | |
Static Public Attributes | |
static constexpr bool | simdEnabled = IsVectorizable_v<Type> |
Compilation flag for SIMD optimization. More... | |
static constexpr bool | smpAssignable = !IsSMPAssignable_v<Type> |
Compilation flag for SMP assignments. More... | |
static constexpr bool | transposeFlag = TF |
Transpose flag of the vector. | |
Private Attributes | |
Member variables | |
size_t | size_ |
The current size/dimension of the uniform vector. | |
Type | value_ |
The value of all elements of the uniform vector. | |
Static Private Attributes | |
static constexpr size_t | SIMDSIZE = SIMDTrait<ElementType>::size |
The number of elements packed within a single SIMD element. | |
Efficient implementation of a uniform vector.
The UniformVector class template is the representation of an arbitrary sized uniform vector with elements of arbitrary type. The type of the elements and the transpose flag of the vector can be specified via the two template parameters:
These uniform elements can be directly accessed with the subscript operator. The numbering of the vector elements is
The use of UniformVector is very natural and intuitive. 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 UniformVector:
|
inlineexplicit |
Constructor for a vector of size n.
n | The size of the vector. |
|
inlineexplicit |
Constructor for a homogeneous initialization of all n vector elements.
n | The size of the vector. |
init | The initial value of the vector elements. |
All vector elements are initialized with the specified value.
|
inline |
Conversion constructor for different uniform vectors.
v | Uniform vector to be copied. |
std::invalid_argument | Invalid setup of uniform vector. |
The vector is sized according to the given -dimensional uniform vector and initialized as a copy of this vector.
|
inline |
Checked access to the vector elements.
index | Access index. The index has to be in the range ![]() |
std::out_of_range | Invalid vector access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inlinenoexcept |
Returns an iterator to the first element of the uniform vector.
|
inlinenoexcept |
Returns whether the vector can alias with the given address alias.
alias | The alias to be checked. |
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.
|
inlinenoexcept |
Returns whether the vector can be used in SMP assignments.
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).
|
inlinenoexcept |
Returns the maximum capacity of the vector.
|
inlinenoexcept |
Returns an iterator to the first element of the uniform vector.
|
inlinenoexcept |
Returns an iterator just past the last element of the uniform vector.
|
inline |
|
inlinenoexcept |
Low-level data access to the vector elements.
This function returns a pointer to the internal storage of the uniform vector. Note that you can NOT assume that elements of the uniform vector lie adjacent to each other!
|
inlinenoexcept |
Returns an iterator just past the last element of the uniform vector.
|
inline |
Extending the size of the vector.
n | Number of additional vector elements. |
preserve | true if the old values of the vector should be preserved, false if not. |
This function increases the vector size by n elements. Note that this function potentially changes all vector elements. In order to preserve the old vector values, the preserve flag can be set to true.
|
inlinenoexcept |
Returns whether the vector is aliased with the given address alias.
alias | The alias to be checked. |
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.
|
inlinenoexcept |
Returns whether the vector is properly aligned in memory.
This function returns whether the vector is guaranteed to be properly aligned in memory, i.e. whether the beginning and the end of the vector are guaranteed to conform to the alignment restrictions of the element type Type.
|
noexcept |
Load of a SIMD element of the vector.
index | Access index. The index must be smaller than the number of vector elements. |
This function performs a load of a specific SIMD element of the dense vector. The index must be smaller than the number of vector elements and it must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
noexcept |
Aligned load of a SIMD element of the vector.
index | Access index. The index must be smaller than the number of vector elements. |
This function performs an aligned load of a specific SIMD element of the dense vector. The index must be smaller than the number of vector elements and it must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
noexcept |
Unaligned load of a SIMD element of the vector.
index | Access index. The index must be smaller than the number of vector elements. |
This function performs an unaligned load of a specific SIMD element of the dense vector. The index must be smaller than the number of vector elements and it must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
inline |
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.
|
inline |
Multiplication assignment operator for the multiplication between a vector and a scalar value ( ).
scalar | The right-hand side scalar value for the multiplication. |
|
inline |
Multiplication assignment operator for the subtraction of a vector ( ).
rhs | The right-hand side vector to be multiplied with the vector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid multiplication assignment to uniform vector. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Addition assignment operator for the addition of a vector ( ).
rhs | The right-hand side vector to be added to the vector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid addition assignment to uniform vector. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Subtraction assignment operator for the subtraction of a vector ( ).
rhs | The right-hand side vector to be subtracted from the vector. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid subtraction assignment to uniform vector. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Division assignment operator for the division between a vector and a scalar value ( ).
scalar | The right-hand side scalar value for the division. |
|
inline |
Division assignment operator for the division of a dense vector ( ).
rhs | The right-hand side dense vector divisor. |
std::invalid_argument | Vector sizes do not match. |
std::invalid_argument | Invalid multiplication assignment to uniform vector. |
In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.
|
inline |
Homogenous assignment to all vector elements.
rhs | Scalar value to be assigned to all vector elements. |
|
inline |
Assignment operator for different vectors.
rhs | Vector to be copied. |
The vector is resized according to the given uniform vector and initialized as a copy of this vector.
|
inlinenoexcept |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range ![]() |
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.
|
inlinenoexceptinherited |
Conversion operator for non-constant vectors.
|
inlinenoexceptinherited |
Conversion operator for constant vectors.
|
inline |
Reset to the default initial values.
|
inline |
Changing the size of the vector.
n | The new size of the vector. |
preserve | true if the old values of the vector should be preserved, false if not. |
This function resizes the 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. 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.
|
inline |
Scaling of the vector by the scalar value scalar ( ).
scalar | The scalar value for the vector scaling. |
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:
|
inlinenoexcept |
Returns the current size/dimension of the vector.
|
inlinenoexcept |
Returns the minimum capacity of the vector.
This function returns the minimum capacity of the vector, which corresponds to the current size plus padding.
|
inlinenoexcept |
Swapping the contents of two vectors.
v | The vector to be swapped. |
|
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.
|
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).