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::CompressedVector< Type, TF > Class Template Reference

Efficient implementation of an arbitrary sized sparse vector.The CompressedVector class is the representation of an arbitrarily sized sparse vector, which stores only non-zero 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 <CompressedVector.h>

Inherits blaze::SparseVector< CompressedVector< Type, TF >, TF >.

Public Types

enum  { canAlias = 0 }
 Compilation flag for the detection of aliasing effects. More...
 
typedef CompressedVector< Type,
TF > 
This
 Type of this CompressedVector instance.
 
typedef This ResultType
 Result type for expression template evaluations.
 
typedef CompressedVector< Type,!TF > TransposeType
 Transpose type for expression template evaluations.
 
typedef Type ElementType
 Type of the compressed vector elements.
 
typedef const Type & ReturnType
 Return type for expression template evaluations.
 
typedef const CompressedVectorCompositeType
 Data type for composite expression templates.
 
typedef VectorAccessProxy< ThisReference
 Reference to a non-constant vector value.
 
typedef const Type & ConstReference
 Reference to a constant vector value.
 
typedef Element * Iterator
 Iterator over non-constant elements.
 
typedef const Element * ConstIterator
 Iterator over constant elements.
 
typedef CMathTrait< Type >::Type LengthType
 Compressed vector length return type.
 
typedef VT VectorType
 Type of the vector.
 

Public Member Functions

VectorTypeoperator~ ()
 Conversion operator for non-constant vectors.
 
const VectorTypeoperator~ () const
 Conversion operator for constant vectors.
 
Constructors
 CompressedVector ()
 The default constructor for CompressedVector.
 
 CompressedVector (size_t size)
 Constructor for a compressed vector of size n.
 
 CompressedVector (size_t size, size_t nonzeros)
 Constructor for a compressed vector of size n.
 
 CompressedVector (const CompressedVector &sv)
 The copy constructor for CompressedVector.
 
template<typename VT >
 CompressedVector (const DenseVector< VT, TF > &dv)
 Conversion constructor from dense vectors.
 
template<typename VT >
 CompressedVector (const SparseVector< VT, TF > &sv)
 Conversion constructor from different sparse vectors.
 
Destructor
 ~CompressedVector ()
 The destructor for CompressedVector.
 
Data access functions
Reference operator[] (size_t index)
 Subscript operator for the direct access to the compressed vector elements.
 
ConstReference operator[] (size_t index) const
 Subscript operator for the direct access to the compressed vector elements.
 
Iterator begin ()
 Returns an iterator to the first non-zero element of the compressed vector.
 
ConstIterator begin () const
 Returns an iterator to the first non-zero element of the compressed vector.
 
ConstIterator cbegin () const
 Returns an iterator to the first non-zero element of the compressed vector.
 
Iterator end ()
 Returns an iterator just past the last non-zero element of the compressed vector.
 
ConstIterator end () const
 Returns an iterator just past the last non-zero element of the compressed vector.
 
ConstIterator cend () const
 Returns an iterator just past the last non-zero element of the compressed vector.
 
Assignment operators
CompressedVectoroperator= (const CompressedVector &rhs)
 Copy assignment operator for CompressedVector.
 
template<typename VT >
CompressedVectoroperator= (const DenseVector< VT, TF > &rhs)
 Assignment operator for dense vectors.
 
template<typename VT >
CompressedVectoroperator= (const SparseVector< VT, TF > &rhs)
 Assignment operator for different sparse vectors.
 
template<typename VT >
CompressedVectoroperator+= (const Vector< VT, TF > &rhs)
 Addition assignment operator for the addition of a vector ( $ \vec{a}+=\vec{b} $).
 
template<typename VT >
CompressedVectoroperator-= (const Vector< VT, TF > &rhs)
 Subtraction assignment operator for the subtraction of a vector ( $ \vec{a}-=\vec{b} $).
 
template<typename VT >
CompressedVectoroperator*= (const Vector< VT, TF > &rhs)
 Multiplication assignment operator for the multiplication of a vector ( $ \vec{a}*=\vec{b} $).
 
template<typename Other >
EnableIf< IsNumeric< Other >
, CompressedVector >::Type & 
operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a compressed vector and a scalar value ( $ \vec{a}*=s $).
 
template<typename Other >
EnableIf< IsNumeric< Other >
, CompressedVector >::Type & 
operator/= (Other rhs)
 Division assignment operator for the division of a compressed vector by a scalar value ( $ \vec{a}/=s $).
 
Expression template evaluation functions
template<typename Other >
bool isAliased (const Other *alias) const
 Returns whether the vector is aliased with the given address alias.
 
template<typename VT >
void assign (const DenseVector< VT, TF > &rhs)
 Default implementation of the assignment of a dense vector.
 
template<typename VT >
void assign (const SparseVector< VT, TF > &rhs)
 Default implementation of the assignment of a sparse vector.
 
template<typename VT >
void addAssign (const DenseVector< VT, TF > &rhs)
 Default implementation of the addition assignment of a dense vector.
 
template<typename VT >
void addAssign (const SparseVector< VT, TF > &rhs)
 Default implementation of the addition assignment of a sparse vector.
 
template<typename VT >
void subAssign (const DenseVector< VT, TF > &rhs)
 Default implementation of the subtraction assignment of a dense vector.
 
template<typename VT >
void subAssign (const SparseVector< VT, TF > &rhs)
 Default implementation of the subtraction assignment of a sparse vector.
 

Private Types

typedef SparseElement< Type > ElementBase
 Base class for the compressed vector element.
 

Utility functions

size_t size () const
 Returns the current size/dimension of the compressed vector.
 
size_t capacity () const
 Returns the maximum capacity of the compressed vector.
 
size_t nonZeros () const
 Returns the number of non-zero elements in the compressed vector.
 
void reset ()
 Reset to the default initial values.
 
void clear ()
 Clearing the compressed vector.
 
void append (size_t index, const Type &value)
 Appending an element to the compressed vector.
 
Type & insert (size_t index, const Type &value)
 Inserting an element into the compressed vector.
 
Iterator find (size_t index)
 Searches for a specific vector element.
 
ConstIterator find (size_t index) const
 Searches for a specific vector element.
 
void resize (size_t n, bool preserve=true)
 Changing the size of the compressed vector.
 
void reserve (size_t n)
 Setting the minimum capacity of the compressed vector.
 
LengthType length () const
 Calculation of the compressed vector length $|\vec{a}|$.
 
const Type sqrLength () const
 Calculation of the vector square length $|\vec{a}|^2$.
 
CompressedVectornormalize ()
 Normalization of the compressed vector ( $|\vec{a}|=1$).
 
const CompressedVector getNormalized () const
 Calculation of the normalized compressed vector ( $|\vec{a}|=1$).
 
template<typename Other >
CompressedVectorscale (Other scalar)
 Scaling of the compressed vector by the scalar value scalar ( $ \vec{a}=\vec{b}*s $).
 
void swap (CompressedVector &sv)
 Swapping the contents of two compressed vectors.
 
size_t extendCapacity () const
 Calculating a new vector capacity.
 

Member variables

size_t size_
 The current size/dimension of the compressed vector.
 
size_t capacity_
 The maximum capacity of the compressed vector.
 
Iterator begin_
 Pointer to the first non-zero element of the compressed vector.
 
Iterator end_
 Pointer one past the last non-zero element of the compressed vector.
 
static const Type zero_ = Type()
 Neutral element for accesses to zero elements.
 

Detailed Description

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

Efficient implementation of an arbitrary sized sparse vector.

The CompressedVector class is the representation of an arbitrarily sized sparse vector, which stores only non-zero 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 >

Inserting/accessing elements in a compressed vector can be done by several alternative functions. The following example demonstrates all options:

// Creating a non-transpose compressed vector of size 100
CompressedVector<double,false> a( 100 );
// The subscript operator provides access to all possible elements of the compressed vector,
// including the zero elements. In case the subscript operator is used to access an element
// that is currently not stored in the sparse vector, the element is inserted into the vector.
a[42] = 2.0;
// An alternative for inserting elements into the vector is the insert() function. However,
// it inserts the element only in case the element is not already contained in the vector.
A.insert( 50, 3.7 );
// A very efficient way to add new elements to a sparse vector is the append() function.
// Note that append() requires that the appended element's index is strictly larger than
// the currently largest non-zero index of the vector and that the vector's capacity
// is large enough to hold the new element.
a.reserve( 10 );
A.append( 51, -2.1 );
// In order to traverse all non-zero elements currently stored in the vector, the begin()
// and end() functions can be used. In the example, all non-zero elements of vector are
// traversed.
for( CompressedVector<double,false>::Iterator i=a.begin(); i!=a.end(); ++i ) {
... = i->value(); // Access to the value of the non-zero element
... = i->index(); // Access to the index of the non-zero element
}

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

CompressedVector<double> a( 2 ); // Default constructed, non-initialized 2D vectors
a[0] = 1.0; // Initialization of the first element
a[1] = 2.0; // Initialization of the second element
CompressedVector<double> b( 2 ); // Empty sparse vector
DynamicVector<float> c( 2, 2.0F ); // Directly, homogeneously initialized dense vector
CompressedVector<double> d; // Default constructed dynamic vector
CompressedMatrix<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 sparse and dense 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::CompressedVector< Type, TF >::LengthType

Compressed vector length return type.

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

Member Enumeration Documentation

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

Compilation flag for the detection of aliasing effects.

This compilation switch indicates whether this type potentially causes compuation errors due to aliasing effects. In case the type can cause aliasing effects, the canAlias switch is set to true, otherwise it is set to false.

Constructor & Destructor Documentation

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

Constructor for a compressed vector of size n.

Parameters
nThe size of the vector.
template<typename Type , bool TF>
blaze::CompressedVector< Type, TF >::CompressedVector ( size_t  n,
size_t  nonzeros 
)
inlineexplicit

Constructor for a compressed vector of size n.

Parameters
nThe size of the vector.
nonzerosThe number of expected non-zero elements.
template<typename Type , bool TF>
blaze::CompressedVector< Type, TF >::CompressedVector ( const CompressedVector< Type, TF > &  sv)
inline

The copy constructor for CompressedVector.

Parameters
svCompressed vector 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::CompressedVector< Type, TF >::CompressedVector ( const DenseVector< VT, TF > &  dv)
inline

Conversion constructor from dense vectors.

Parameters
dvDense vector to be copied.
template<typename Type , bool TF>
template<typename VT >
blaze::CompressedVector< Type, TF >::CompressedVector ( const SparseVector< VT, TF > &  sv)
inline

Conversion constructor from different sparse vectors.

Parameters
svSparse vector to be copied.

Member Function Documentation

template<typename Type , bool TF>
template<typename VT >
void blaze::CompressedVector< 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>
template<typename VT >
void blaze::CompressedVector< 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>
void blaze::CompressedVector< Type, TF >::append ( size_t  index,
const Type &  value 
)

Appending an element to the compressed vector.

Parameters
indexThe index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be appended.
Returns
void

This function provides a very efficient way to fill a compressed vector with elements. It appends a new element to the end of the compressed vector without any additional check or memory allocation. Therefore it is strictly necessary to keep the following preconditions in mind:

  • the index of the new element must be strictly larger than the largest index of non-zero elements in the compressed vector
  • the current number of non-zero elements must be smaller than the capacity of the vector

Ignoring these preconditions might result in undefined behavior!

Note: Although append() does not allocate new memory, it still invalidates all iterators returned by the end() functions!

template<typename Type , bool TF>
template<typename VT >
void blaze::CompressedVector< 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>
template<typename VT >
void blaze::CompressedVector< 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>
CompressedVector< Type, TF >::Iterator blaze::CompressedVector< Type, TF >::begin ( )
inline

Returns an iterator to the first non-zero element of the compressed vector.

Returns
Iterator to the first non-zero element of the compressed vector.
template<typename Type , bool TF>
CompressedVector< Type, TF >::ConstIterator blaze::CompressedVector< Type, TF >::begin ( ) const
inline

Returns an iterator to the first non-zero element of the compressed vector.

Returns
Iterator to the first non-zero element of the compressed vector.
template<typename Type , bool TF>
size_t blaze::CompressedVector< Type, TF >::capacity ( ) const
inline

Returns the maximum capacity of the compressed vector.

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

Returns an iterator to the first non-zero element of the compressed vector.

Returns
Iterator to the first non-zero element of the compressed vector.
template<typename Type , bool TF>
CompressedVector< Type, TF >::ConstIterator blaze::CompressedVector< Type, TF >::cend ( ) const
inline

Returns an iterator just past the last non-zero element of the compressed vector.

Returns
Iterator just past the last non-zero element of the compressed vector.
template<typename Type , bool TF>
void blaze::CompressedVector< Type, TF >::clear ( )
inline

Clearing the compressed vector.

Returns
void

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

template<typename Type , bool TF>
CompressedVector< Type, TF >::Iterator blaze::CompressedVector< Type, TF >::end ( )
inline

Returns an iterator just past the last non-zero element of the compressed vector.

Returns
Iterator just past the last non-zero element of the compressed vector.
template<typename Type , bool TF>
CompressedVector< Type, TF >::ConstIterator blaze::CompressedVector< Type, TF >::end ( ) const
inline

Returns an iterator just past the last non-zero element of the compressed vector.

Returns
Iterator just past the last non-zero element of the compressed vector.
template<typename Type , bool TF>
size_t blaze::CompressedVector< Type, TF >::extendCapacity ( ) const
inlineprivate

Calculating a new vector capacity.

Returns
The new compressed vector capacity.

This function calculates a new vector capacity based on the current capacity of the sparse vector. Note that the new capacity is restricted to the interval $[7..size]$.

template<typename Type , bool TF>
CompressedVector< Type, TF >::Iterator blaze::CompressedVector< Type, TF >::find ( size_t  index)
inline

Searches for a specific vector element.

Parameters
indexThe index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

This function can be used to check whether a specific element is contained in the sparse vector. It specifically searches for the element with index index. In case the element is found, the function returns an iterator to the element. Otherwise an iterator just past the last non-zero element of the compressed vector (the end() iterator) is returned. Note that the returned compressed vector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!

template<typename Type , bool TF>
CompressedVector< Type, TF >::ConstIterator blaze::CompressedVector< Type, TF >::find ( size_t  index) const
inline

Searches for a specific vector element.

Parameters
indexThe index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

This function can be used to check whether a specific element is contained in the sparse vector. It specifically searches for the element with index index. In case the element is found, the function returns an iterator to the element. Otherwise an iterator just past the last non-zero element of the compressed vector (the end() iterator) is returned. Note that the returned compressed vector iterator is subject to invalidation due to inserting operations via the subscript operator or the insert() function!

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

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

Returns
The normalized compressed vector.

The function returns the normalized compressed 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>
Type & blaze::CompressedVector< Type, TF >::insert ( size_t  index,
const Type &  value 
)

Inserting an element into the compressed vector.

Parameters
indexThe index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be inserted.
Returns
Reference to the inserted value.
Exceptions
std::invalid_argumentInvalid compressed vector access index.

This function inserts a new element into the compressed vector. However, duplicate elements are not allowed. In case the sparse vector already contains an element with index index, a std::invalid_argument exception is thrown.

template<typename Type , bool TF>
template<typename Other >
bool blaze::CompressedVector< 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.
template<typename Type , bool TF>
CompressedVector< Type, TF >::LengthType blaze::CompressedVector< Type, TF >::length ( ) const
inline

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

Returns
The length of the compressed 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>
size_t blaze::CompressedVector< Type, TF >::nonZeros ( ) const
inline

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

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

Note that the number of non-zero elements is always smaller than the current size of the compressed vector.

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

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

Returns
Reference to the compressed vector.

Normalization of the compressed 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>
template<typename VT >
CompressedVector< Type, TF > & blaze::CompressedVector< 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 compressed vector.
Returns
Reference to the compressed 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>
template<typename Other >
EnableIf< IsNumeric< Other >, CompressedVector< Type, TF > >::Type & blaze::CompressedVector< Type, TF >::operator*= ( Other  rhs)
inline

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

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

This operator can only be used for built-in data types. Additionally, the elements of the compressed vector must support the multiplication assignment operator for the given scalar built-in data type.

template<typename Type , bool TF>
template<typename VT >
CompressedVector< Type, TF > & blaze::CompressedVector< 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 compressed vector.
Returns
Reference to the compressed 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>
template<typename VT >
CompressedVector< Type, TF > & blaze::CompressedVector< 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 compressed vector.
Returns
Reference to the compressed 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>
template<typename Other >
EnableIf< IsNumeric< Other >, CompressedVector< Type, TF > >::Type & blaze::CompressedVector< Type, TF >::operator/= ( Other  rhs)
inline

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

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

This operator can only be used for built-in data types. Additionally, the elements of the compressed vector must either support the multiplication assignment operator for the given floating point data type or the division assignment operator for the given integral data type.

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

Copy assignment operator for CompressedVector.

Parameters
rhsCompressed vector to be copied.
Returns
Reference to the assigned compressed vector.

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

template<typename Type , bool TF>
template<typename VT >
CompressedVector< Type, TF > & blaze::CompressedVector< Type, TF >::operator= ( const DenseVector< VT, TF > &  rhs)
inline

Assignment operator for dense vectors.

Parameters
rhsDense vector to be copied.
Returns
Reference to the assigned compressed vector.

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

template<typename Type , bool TF>
template<typename VT >
CompressedVector< Type, TF > & blaze::CompressedVector< Type, TF >::operator= ( const SparseVector< VT, TF > &  rhs)
inline

Assignment operator for different sparse vectors.

Parameters
rhsSparse vector to be copied.
Returns
Reference to the assigned compressed vector.

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

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

Subscript operator for the direct access to the compressed vector elements.

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

This function returns a reference to the accessed value at position index. In case the compressed vector does not yet store an element for index index, a new element is inserted into the compressed vector. An alternative for traversing the non-zero elements of the sparse vector are the begin() and end() functions.

template<typename Type , bool TF>
CompressedVector< Type, TF >::ConstReference blaze::CompressedVector< Type, TF >::operator[] ( size_t  index) const
inline

Subscript operator for the direct access to the compressed vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
template<typename VT, bool TF>
VectorType& blaze::Vector< VT, TF >::operator~ ( )
inlineinherited

Conversion operator for non-constant vectors.

Returns
Reference of the actual type of the vector.
template<typename VT, bool TF>
const VectorType& blaze::Vector< VT, TF >::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::CompressedVector< Type, TF >::reserve ( size_t  n)
inline

Setting the minimum capacity of the compressed vector.

Parameters
nThe new minimum capacity of the compressed vector.
Returns
void

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

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

Reset to the default initial values.

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

Changing the size of the compressed vector.

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

This function resizes the compressed vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the compressed 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.

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

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

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

Returns the current size/dimension of the compressed vector.

Returns
The size of the compressed vector.
template<typename Type , bool TF>
const Type blaze::CompressedVector< 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::CompressedVector< 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>
template<typename VT >
void blaze::CompressedVector< 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>
void blaze::CompressedVector< Type, TF >::swap ( CompressedVector< Type, TF > &  sv)
inline

Swapping the contents of two compressed vectors.

Parameters
svThe compressed vector to be swapped.
Returns
void
Exceptions
no-throwguarantee.

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