All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | List of all members
blaze::DynamicVector< Type, TF > Class Template Reference

Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the representation of an arbitrary sized vector with dynamically allocated 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 <DynamicVector.h>

Inherits blaze::DenseVector< DynamicVector< Type, TF >, TF >.

Public Types

enum  { vectorizable = IsVectorizable<Type>::value }
 Compilation flag for intrinsic optimization. More...
 
typedef DynamicVector< Type, TF > This
 Type of this DynamicVector instance.
 
typedef This ResultType
 Result type for expression template evaluations.
 
typedef DynamicVector< Type,!TF > TransposeType
 Transpose type for expression template evaluations.
 
typedef Type ElementType
 Type of the vector elements.
 
typedef IT::Type IntrinsicType
 Intrinsic type of the vector elements.
 
typedef const Type & ReturnType
 Return type for expression template evaluations.
 
typedef const DynamicVectorCompositeType
 Data type for composite expression templates.
 
typedef Type & Reference
 Reference to a non-constant vector value.
 
typedef const Type & ConstReference
 Reference to a constant vector value.
 
typedef Type * Iterator
 Iterator over non-constant elements.
 
typedef const Type * ConstIterator
 Iterator over constant elements.
 
typedef CMathTrait< Type >::Type LengthType
 Vector length return type. More...
 
typedef VT VectorType
 Type of the vector.
 

Public Member Functions

template<typename Other , size_t N>
DynamicVector< Type, TF > & operator= (const Other(&rhs)[N])
 Array assignment to all vector elements. More...
 
template<typename VT >
DynamicVector< Type, TF > & operator= (const Vector< VT, TF > &rhs)
 Assignment operator for different vectors. More...
 
template<typename VT >
DynamicVector< Type, TF > & operator+= (const Vector< VT, TF > &rhs)
 Addition assignment operator for the addition of a vector ( $ \vec{a}+=\vec{b} $). More...
 
template<typename VT >
DynamicVector< Type, TF > & operator-= (const Vector< VT, TF > &rhs)
 Subtraction assignment operator for the subtraction of a vector ( $ \vec{a}-=\vec{b} $). More...
 
template<typename VT >
DynamicVector< Type, TF > & operator*= (const Vector< VT, TF > &rhs)
 Multiplication assignment operator for the multiplication of a vector ( $ \vec{a}*=\vec{b} $). More...
 
template<typename Other >
EnableIf< IsNumeric< Other >
, DynamicVector< Type, TF >
>::Type & 
operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a vector and a scalar value ( $ \vec{a}*=s $). More...
 
template<typename Other >
EnableIf< IsNumeric< Other >
, DynamicVector< Type, TF >
>::Type & 
operator/= (Other rhs)
 Division assignment operator for the division of a vector by a scalar value ( $ \vec{a}/=s $). More...
 
template<typename Other >
DynamicVector< Type, TF > & scale (Other scalar)
 Scaling of the vector by the scalar value scalar ( $ \vec{a}=\vec{b}*s $). More...
 
template<typename VT >
DisableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedAssign< VT > >::Type 
assign (const DenseVector< VT, TF > &rhs)
 Default implementation of the assignment of a dense vector. More...
 
template<typename VT >
EnableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedAssign< VT > >::Type 
assign (const DenseVector< VT, TF > &rhs)
 Intrinsic optimized implementation of the assignment of a dense vector. More...
 
template<typename VT >
DisableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedAddAssign< VT >
>::Type 
addAssign (const DenseVector< VT, TF > &rhs)
 Default implementation of the addition assignment of a dense vector. More...
 
template<typename VT >
EnableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedAddAssign< VT >
>::Type 
addAssign (const DenseVector< VT, TF > &rhs)
 Intrinsic optimized implementation of the addition assignment of a dense vector. More...
 
template<typename VT >
DisableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedSubAssign< VT >
>::Type 
subAssign (const DenseVector< VT, TF > &rhs)
 Default implementation of the subtraction assignment of a dense vector. More...
 
template<typename VT >
EnableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedSubAssign< VT >
>::Type 
subAssign (const DenseVector< VT, TF > &rhs)
 Intrinsic optimized implementation of the subtraction assignment of a dense vector. More...
 
template<typename VT >
DisableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedMultAssign< VT >
>::Type 
multAssign (const DenseVector< VT, TF > &rhs)
 Default implementation of the multiplication assignment of a dense vector. More...
 
template<typename VT >
EnableIf< typename
DynamicVector< Type, TF >
::BLAZE_TEMPLATE
VectorizedMultAssign< VT >
>::Type 
multAssign (const DenseVector< VT, TF > &rhs)
 Intrinsic optimized implementation of the multiplication assignment of a dense vector. More...
 
VectorTypeoperator~ ()
 Conversion operator for non-constant vectors. More...
 
const VectorTypeoperator~ () const
 Conversion operator for constant vectors. More...
 
Constructors
 DynamicVector ()
 The default constructor for DynamicVector.
 
 DynamicVector (size_t n)
 Constructor for a vector of size n. No element initialization is performed! More...
 
 DynamicVector (size_t n, Type init)
 Constructor for a homogeneous initialization of all n vector elements. More...
 
 DynamicVector (const DynamicVector &v)
 The copy constructor for DynamicVector. More...
 
template<typename VT >
 DynamicVector (const Vector< VT, TF > &v)
 Conversion constructor from different vectors. More...
 
template<typename Other , size_t N>
 DynamicVector (const Other(&rhs)[N])
 Array initialization of all vector elements. More...
 
Destructor
 ~DynamicVector ()
 The destructor for DynamicVector.
 
Data access functions
Reference operator[] (size_t index)
 Subscript operator for the direct access to the vector elements. More...
 
ConstReference operator[] (size_t index) const
 Subscript operator for the direct access to the vector elements. More...
 
Type * data ()
 Low-level data access to the vector elements. More...
 
const Type * data () const
 Low-level data access to the vector elements. More...
 
Iterator begin ()
 Returns an iterator to the first element of the dynamic vector. More...
 
ConstIterator begin () const
 Returns an iterator to the first element of the dynamic vector. More...
 
ConstIterator cbegin () const
 Returns an iterator to the first element of the dynamic vector. More...
 
Iterator end ()
 Returns an iterator just past the last element of the dynamic vector. More...
 
ConstIterator end () const
 Returns an iterator just past the last element of the dynamic vector. More...
 
ConstIterator cend () const
 Returns an iterator just past the last element of the dynamic vector. More...
 
Assignment operators
template<typename Other , size_t N>
DynamicVectoroperator= (const Other(&rhs)[N])
 
DynamicVectoroperator= (Type rhs)
 Homogenous assignment to all vector elements. More...
 
DynamicVectoroperator= (const DynamicVector &rhs)
 Copy assignment operator for DynamicVector. More...
 
template<typename VT >
DynamicVectoroperator= (const Vector< VT, TF > &rhs)
 
template<typename VT >
DynamicVectoroperator+= (const Vector< VT, TF > &rhs)
 
template<typename VT >
DynamicVectoroperator-= (const Vector< VT, TF > &rhs)
 
template<typename VT >
DynamicVectoroperator*= (const Vector< VT, TF > &rhs)
 
template<typename Other >
EnableIf< IsNumeric< Other >
, DynamicVector >::Type & 
operator*= (Other rhs)
 
template<typename Other >
EnableIf< IsNumeric< Other >
, DynamicVector >::Type & 
operator/= (Other rhs)
 
Read/Write functions
void read (const char *file)
 Reading the vector from a file. More...
 
void write (const char *file, std::streamsize prec=6) const
 Writing the vector to a file. More...
 
Expression template evaluation functions
template<typename Other >
bool canAlias (const Other *alias) const
 Returns whether the vector can alias with the given address alias. More...
 
template<typename Other >
bool isAliased (const Other *alias) const
 Returns whether the vector is aliased with the given address alias. More...
 
IntrinsicType get (size_t index) const
 Access to the intrinsic elements of the vector. More...
 
template<typename VT >
DisableIf< VectorizedAssign
< VT > >::Type 
assign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
EnableIf< VectorizedAssign< VT >
>::Type 
assign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
void assign (const SparseVector< VT, TF > &rhs)
 Default implementation of the assignment of a sparse vector. More...
 
template<typename VT >
DisableIf< VectorizedAddAssign
< VT > >::Type 
addAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
EnableIf< VectorizedAddAssign
< VT > >::Type 
addAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
void addAssign (const SparseVector< VT, TF > &rhs)
 Default implementation of the addition assignment of a sparse vector. More...
 
template<typename VT >
DisableIf< VectorizedSubAssign
< VT > >::Type 
subAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
EnableIf< VectorizedSubAssign
< VT > >::Type 
subAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
void subAssign (const SparseVector< VT, TF > &rhs)
 Default implementation of the subtraction assignment of a sparse vector. More...
 
template<typename VT >
DisableIf
< VectorizedMultAssign< VT >
>::Type 
multAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
EnableIf< VectorizedMultAssign
< VT > >::Type 
multAssign (const DenseVector< VT, TF > &rhs)
 
template<typename VT >
void multAssign (const SparseVector< VT, TF > &rhs)
 Default implementation of the multiplication assignment of a sparse vector. More...
 

Private Types

typedef IntrinsicTrait< Type > IT
 Intrinsic trait for the vector element type.
 

Private Attributes

Member variables
size_t size_
 The current size/dimension of the vector.
 
size_t capacity_
 The maximum capacity of the vector.
 
Type *BLAZE_RESTRICT v_
 The dynamically allocated vector elements. More...
 

Utility functions

size_t size () const
 Returns the current size/dimension of the vector. More...
 
size_t capacity () const
 Returns the maximum capacity of the vector. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the vector. More...
 
void reset ()
 Reset to the default initial values. More...
 
void clear ()
 Clearing the vector. More...
 
void resize (size_t n, bool preserve=true)
 Changing the size of the vector. More...
 
void extend (size_t n, bool preserve=true)
 Extending the size of the vector. More...
 
void reserve (size_t n)
 Setting the minimum capacity of the vector. More...
 
LengthType length () const
 Calculation of the vector length $|\vec{a}|$. More...
 
const Type sqrLength () const
 Calculation of the vector square length $|\vec{a}|^2$. More...
 
DynamicVectornormalize ()
 Normalization of the vector ( $|\vec{a}|=1$). More...
 
const DynamicVector getNormalized () const
 Calculation of the normalized vector ( $|\vec{a}|=1$). More...
 
template<typename Other >
DynamicVectorscale (Other scalar)
 
void swap (DynamicVector &v)
 Swapping the contents of two vectors. More...
 
size_t adjustCapacity (size_t minCapacity) const
 Adjusting the new capacity of the vector according to its data type Type. More...
 

Detailed Description

template<typename Type, bool TF = defaultTransposeFlag>
class blaze::DynamicVector< Type, TF >

Efficient implementation of an arbitrary sized vector.

The DynamicVector class template is the representation of an arbitrary sized vector with dynamically allocated elements 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 >

These contiguously stored elements can be directly accessed with the subscript operator. The numbering of the vector elements is

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

The use of DynamicVector 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 DynamicVector:

DynamicVector<double> a( 2 ); // Non-initialized 2D vector of size 2
a[0] = 1.0; // Initialization of the first element
a[1] = 2.0; // Initialization of the second element
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
a *= 2.0; // In-place scaling of vector
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

Member Typedef Documentation

template<typename Type, bool TF = defaultTransposeFlag>
typedef CMathTrait<Type>::Type blaze::DynamicVector< Type, TF >::LengthType

Vector length return type.

Return type of the DynamicVector<Type,TF>::length function.

Member Enumeration Documentation

template<typename Type, bool TF = defaultTransposeFlag>
anonymous enum

Compilation flag for intrinsic optimization.

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

Constructor & Destructor Documentation

template<typename Type , bool TF>
blaze::DynamicVector< Type, TF >::DynamicVector ( size_t  n)
inlineexplicit

Constructor for a vector of size n. No element initialization is performed!

Parameters
nThe size of the vector.

Note: This constructor is only responsible to allocate the required dynamic memory. No element initialization is performed!

template<typename Type, bool TF>
blaze::DynamicVector< Type, TF >::DynamicVector ( size_t  n,
Type  init 
)
inlineexplicit

Constructor for a homogeneous initialization of all n vector elements.

Parameters
nThe size of the vector.
initThe initial value of the vector elements.

All vector elements are initialized with the specified value.

template<typename Type, bool TF>
blaze::DynamicVector< Type, TF >::DynamicVector ( const DynamicVector< Type, TF > &  v)
inline

The copy constructor for DynamicVector.

Parameters
vVector to be copied.

The copy constructor is explicitly defined due to the required dynamic memory management and in order to enable/facilitate NRV optimization.

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

Conversion constructor from different vectors.

Parameters
vVector to be copied.
template<typename Type , bool TF>
template<typename Other , size_t N>
blaze::DynamicVector< Type, TF >::DynamicVector ( const Other(&)  rhs[N])
inlineexplicit

Array initialization of all vector elements.

Parameters
rhsN-dimensional array for the initialization.

This assignment operator offers the option to directly initialize the elements of the vector:

const real init[4] = { 1, 2, 3 };

The vector is sized accoring to the size of the array and initialized with the given values. Missing values are initialized with zero (as e.g. the fourth element in the example).

Member Function Documentation

template<typename Type , bool TF>
template<typename VT >
void blaze::DynamicVector< Type, TF >::addAssign ( const SparseVector< VT, TF > &  rhs)
inline

Default implementation of the addition assignment of a sparse vector.

Parameters
rhsThe right-hand side sparse vector to be added.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type blaze::DynamicVector< Type, TF >::addAssign ( const DenseVector< VT, TF > &  rhs)
inline

Default implementation of the addition assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be added.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type blaze::DynamicVector< Type, TF >::addAssign ( const DenseVector< VT, TF > &  rhs)
inline

Intrinsic optimized implementation of the addition assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be added.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type , bool TF>
size_t blaze::DynamicVector< Type, TF >::adjustCapacity ( size_t  minCapacity) const
inlineprivate

Adjusting the new capacity of the vector according to its data type Type.

Parameters
minCapacityThe minimum necessary capacity.
Returns
The new capacity.
template<typename Type , bool TF>
template<typename VT >
void blaze::DynamicVector< Type, TF >::assign ( const SparseVector< VT, TF > &  rhs)
inline

Default implementation of the assignment of a sparse vector.

Parameters
rhsThe right-hand side sparse vector to be assigned.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type blaze::DynamicVector< Type, TF >::assign ( const DenseVector< VT, TF > &  rhs)
inline

Default implementation of the assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be assigned.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type blaze::DynamicVector< Type, TF >::assign ( const DenseVector< VT, TF > &  rhs)
inline

Intrinsic optimized implementation of the assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be assigned.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type , bool TF>
DynamicVector< Type, TF >::Iterator blaze::DynamicVector< Type, TF >::begin ( )
inline

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

Returns
Iterator to the first element of the dynamic vector.
template<typename Type , bool TF>
DynamicVector< Type, TF >::ConstIterator blaze::DynamicVector< Type, TF >::begin ( ) const
inline

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

Returns
Iterator to the first element of the dynamic vector.
template<typename Type , bool TF>
template<typename Other >
bool blaze::DynamicVector< Type, TF >::canAlias ( const Other *  alias) const
inline

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.

template<typename Type , bool TF>
size_t blaze::DynamicVector< Type, TF >::capacity ( ) const
inline

Returns the maximum capacity of the vector.

Returns
The capacity of the vector.
template<typename Type , bool TF>
DynamicVector< Type, TF >::ConstIterator blaze::DynamicVector< Type, TF >::cbegin ( ) const
inline

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

Returns
Iterator to the first element of the dynamic vector.
template<typename Type , bool TF>
DynamicVector< Type, TF >::ConstIterator blaze::DynamicVector< Type, TF >::cend ( ) const
inline

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

Returns
Iterator just past the last element of the dynamic vector.
template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::clear ( )
inline

Clearing the vector.

Returns
void

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

template<typename Type , bool TF>
Type * blaze::DynamicVector< Type, TF >::data ( )
inline

Low-level data access to the vector elements.

Returns
Pointer to the internal element storage.
template<typename Type , bool TF>
const Type * blaze::DynamicVector< Type, TF >::data ( ) const
inline

Low-level data access to the vector elements.

Returns
Pointer to the internal element storage.
template<typename Type , bool TF>
DynamicVector< Type, TF >::Iterator blaze::DynamicVector< Type, TF >::end ( )
inline

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

Returns
Iterator just past the last element of the dynamic vector.
template<typename Type , bool TF>
DynamicVector< Type, TF >::ConstIterator blaze::DynamicVector< Type, TF >::end ( ) const
inline

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

Returns
Iterator just past the last element of the dynamic vector.
template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::extend ( size_t  n,
bool  preserve = true 
)
inline

Extending the size of the vector.

Parameters
nNumber of additional vector elements.
preservetrue if the old values of the vector should be preserved, false if not.
Returns
void

This function increases the vector size by n elements. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. Therefore this function potentially changes all vector elements. In order to preserve the old vector values, the preserve flag can be set to true. However, new vector elements are not initialized!

template<typename Type , bool TF>
DynamicVector< Type, TF >::IntrinsicType blaze::DynamicVector< Type, TF >::get ( size_t  index) const
inline

Access to the intrinsic elements of the vector.

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

This function offers a direct access to the intrinsic elements of the vector. It 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.

template<typename Type , bool TF>
const DynamicVector< Type, TF > blaze::DynamicVector< Type, TF >::getNormalized ( ) const
inline

Calculation of the normalized vector ( $|\vec{a}|=1$).

Returns
The normalized vector.

The function returns the normalized vector. This operation is only defined for floating point vectors. The attempt to use this function for an integral vector results in a compile time error.

template<typename Type , bool TF>
template<typename Other >
bool blaze::DynamicVector< Type, TF >::isAliased ( const Other *  alias) const
inline

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 conAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.

template<typename Type , bool TF>
DynamicVector< Type, TF >::LengthType blaze::DynamicVector< Type, TF >::length ( ) const
inline

Calculation of the vector length $|\vec{a}|$.

Returns
The length of the vector.

This function calculates the actual length of the vector. The return type of the length() function depends on the actual type of the vector instance:

Type LengthType
float float
integral data types and double double
long double long double

Note: This operation is only defined for built-in data types. In case Type is a user defined data type the attempt to use the length() function results in a compile time error!

template<typename Type , bool TF>
template<typename VT >
void blaze::DynamicVector< Type, TF >::multAssign ( const SparseVector< VT, TF > &  rhs)
inline

Default implementation of the multiplication assignment of a sparse vector.

Parameters
rhsThe right-hand side sparse vector to be multiplied.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type blaze::DynamicVector< Type, TF >::multAssign ( const DenseVector< VT, TF > &  rhs)
inline

Default implementation of the multiplication assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be multiplied.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type blaze::DynamicVector< Type, TF >::multAssign ( const DenseVector< VT, TF > &  rhs)
inline

Intrinsic optimized implementation of the multiplication assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be multiplied.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type , bool TF>
size_t blaze::DynamicVector< 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.

template<typename Type , bool TF>
DynamicVector< Type, TF > & blaze::DynamicVector< Type, TF >::normalize ( )
inline

Normalization of the vector ( $|\vec{a}|=1$).

Returns
Reference to the vector.

Normalization of the vector to a length of 1. This operation is only defined for floating point vectors. The attempt to use this function for an integral vector results in a compile time error.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::operator*= ( const Vector< VT, TF > &  rhs)
inline

Multiplication assignment operator for the multiplication of a vector ( $ \vec{a}*=\vec{b} $).

Parameters
rhsThe right-hand side vector to be multiplied with the vector.
Returns
Reference to the vector.
Exceptions
std::invalid_argumentVector sizes do not match.

In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename Other >
EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type& blaze::DynamicVector< Type, TF >::operator*= ( Other  rhs)
inline

Multiplication assignment operator for the multiplication between a vector and a scalar value ( $ \vec{a}*=s $).

Parameters
rhsThe right-hand side scalar value for the multiplication.
Returns
Reference to the vector.
template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::operator+= ( const Vector< VT, TF > &  rhs)
inline

Addition assignment operator for the addition of a vector ( $ \vec{a}+=\vec{b} $).

Parameters
rhsThe right-hand side vector to be added to the vector.
Returns
Reference to the vector.
Exceptions
std::invalid_argumentVector sizes do not match.

In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::operator-= ( const Vector< VT, TF > &  rhs)
inline

Subtraction assignment operator for the subtraction of a vector ( $ \vec{a}-=\vec{b} $).

Parameters
rhsThe right-hand side vector to be subtracted from the vector.
Returns
Reference to the vector.
Exceptions
std::invalid_argumentVector sizes do not match.

In case the current sizes of the two vectors don't match, a std::invalid_argument exception is thrown.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename Other >
EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type& blaze::DynamicVector< Type, TF >::operator/= ( Other  rhs)
inline

Division assignment operator for the division of a vector by a scalar value ( $ \vec{a}/=s $).

Parameters
rhsThe right-hand side scalar value for the division.
Returns
Reference to the vector.

Note: A division by zero is only checked by an user assert.

template<typename Type, bool TF>
DynamicVector< Type, TF > & blaze::DynamicVector< Type, TF >::operator= ( Type  rhs)
inline

Homogenous assignment to all vector elements.

Parameters
rhsScalar value to be assigned to all vector elements.
Returns
Reference to the assigned vector.
template<typename Type, bool TF>
DynamicVector< Type, TF > & blaze::DynamicVector< Type, TF >::operator= ( const DynamicVector< Type, TF > &  rhs)
inline

Copy assignment operator for DynamicVector.

Parameters
rhsVector to be copied.
Returns
Reference to the assigned vector.

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

template<typename Type, bool TF = defaultTransposeFlag>
template<typename Other , size_t N>
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::operator= ( const Other(&)  rhs[N])
inline

Array assignment to all vector elements.

Parameters
rhsN-dimensional array for the assignment.
Returns
Reference to the assigned vector.

This assignment operator offers the option to directly set all elements of the vector:

const real init[4] = { 1, 2, 3 };
v = init;

The vector is resized accoring to the size of the array and initialized with the given values. Missing values are initialized with zero (as e.g. the fourth element in the example).

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::operator= ( const Vector< VT, TF > &  rhs)
inline

Assignment operator for different vectors.

Parameters
rhsVector to be copied.
Returns
Reference to the assigned vector.

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

template<typename Type , bool TF>
DynamicVector< Type, TF >::Reference blaze::DynamicVector< Type, TF >::operator[] ( size_t  index)
inline

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.
template<typename Type , bool TF>
DynamicVector< Type, TF >::ConstReference blaze::DynamicVector< Type, TF >::operator[] ( size_t  index) const
inline

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.
template<typename , bool >
VectorType& blaze::Vector< typename, bool >::operator~ ( )
inlineinherited

Conversion operator for non-constant vectors.

Returns
Reference of the actual type of the vector.
template<typename , bool >
const VectorType& blaze::Vector< typename, bool >::operator~ ( ) const
inlineinherited

Conversion operator for constant vectors.

Returns
Const reference of the actual type of the vector.
template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::read ( const char *  file)

Reading the vector from a file.

Parameters
fileThe name of the input file.
Returns
void
Exceptions
std::runtime_errorInput error.

This function reads a vector from the specified file file. The file has to contain the vector data in the following format:

#size
v[0]
v[1]
v[2]
...

where $ v[i], i \in [0..N-1], $ specifies the vector elements. In case the output file could not be opened or an input error occured, a std::runtime_error is thrown.

template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::reserve ( size_t  n)
inline

Setting the minimum capacity of the vector.

Parameters
nThe new minimum capacity of the vector.
Returns
void

This function increases the capacity of the vector to at least n elements. The current values of the vector elements are preserved.

template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::reset ( )
inline

Reset to the default initial values.

Returns
void
template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::resize ( size_t  n,
bool  preserve = true 
)
inline

Changing the size of the vector.

Parameters
nThe new size of the vector.
preservetrue if the old values of the vector should be preserved, false if not.
Returns
void

This function resizes the vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. Therefore this function potentially changes all vector elements. In order to preserve the old vector values, the preserve flag can be set to true. However, new vector elements are not initialized!
The following example illustrates the resize operation of a vector of size 2 to a vector of size 4. The new, uninitialized elements are marked with x:

\[ \left(\begin{array}{*{2}{c}} 1 & 2 \\ \end{array}\right) \Longrightarrow \left(\begin{array}{*{4}{c}} 1 & 2 & x & x \\ \end{array}\right) \]

template<typename Type, bool TF = defaultTransposeFlag>
template<typename Other >
DynamicVector<Type,TF>& blaze::DynamicVector< Type, TF >::scale ( Other  scalar)
inline

Scaling of the vector by the scalar value scalar ( $ \vec{a}=\vec{b}*s $).

Parameters
scalarThe scalar value for the vector scaling.
Returns
Reference to the vector.
template<typename Type , bool TF>
size_t blaze::DynamicVector< Type, TF >::size ( ) const
inline

Returns the current size/dimension of the vector.

Returns
The size of the vector.
template<typename Type , bool TF>
const Type blaze::DynamicVector< Type, TF >::sqrLength ( ) const
inline

Calculation of the vector square length $|\vec{a}|^2$.

Returns
The square length of the vector.

This function calculates the actual square length of the vector.

Note: This operation is only defined for built-in data types. In case Type is a user defined data type the attempt to use the length() function results in a compile time error!

template<typename Type , bool TF>
template<typename VT >
void blaze::DynamicVector< Type, TF >::subAssign ( const SparseVector< VT, TF > &  rhs)
inline

Default implementation of the subtraction assignment of a sparse vector.

Parameters
rhsThe right-hand side sparse vector to be subtracted.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type blaze::DynamicVector< Type, TF >::subAssign ( const DenseVector< VT, TF > &  rhs)
inline

Default implementation of the subtraction assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be subtracted.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type, bool TF = defaultTransposeFlag>
template<typename VT >
EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type blaze::DynamicVector< Type, TF >::subAssign ( const DenseVector< VT, TF > &  rhs)
inline

Intrinsic optimized implementation of the subtraction assignment of a dense vector.

Parameters
rhsThe right-hand side dense vector to be subtracted.
Returns
void

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. Instead of using this function use the assignment operator.

template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::swap ( DynamicVector< Type, TF > &  v)
inline

Swapping the contents of two vectors.

Parameters
vThe vector to be swapped.
Returns
void
Exceptions
no-throwguarantee.
template<typename Type , bool TF>
void blaze::DynamicVector< Type, TF >::write ( const char *  file,
std::streamsize  prec = 6 
) const

Writing the vector to a file.

Parameters
fileThe name of the output file.
precThe number of non-zero digits displayed in the output file.
Returns
void
Exceptions
std::runtime_errorOutput error.

This function writes the vector to the specified file file using the following format:

#size
v[0]
v[1]
v[2]
...

where $ v[i], i \in [0..N-1], $ specifies the vector elements. In case the output file could not be opened, a std::runtime_error is thrown.

Note: All previous data is replaced by the vector data!

Member Data Documentation

template<typename Type, bool TF = defaultTransposeFlag>
Type* BLAZE_RESTRICT blaze::DynamicVector< Type, TF >::v_
private

The dynamically allocated vector elements.

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)\]


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