Blaze 3.9
Vector Operations

Table of Contents


Constructors


Instantiating and setting up a vector is very easy and intuitive. However, there are a few rules to take care of:

  • In case the last template parameter (the transpose flag) is omitted, the vector is per default a column vector.
  • The elements of a StaticVector or HybridVector are default initialized (i.e. built-in data types are initialized to 0, class types are initialized via the default constructor).
  • Newly allocated elements of a DynamicVector or CompressedVector remain uninitialized if they are of built-in type and are default constructed if they are of class type.


Default Construction

// All vectors can be default constructed. Whereas the size
// of StaticVectors is fixed via the second template parameter,
// the initial size of a default constructed DynamicVector or
// CompressedVector is 0.
StaticVector<int,2UL> v1; // Instantiation of a 2D integer column vector.
// All elements are initialized to 0.
StaticVector<long,3UL,columnVector> v2; // Instantiation of a 3D long integer column vector.
// Again, all elements are initialized to 0L.
DynamicVector<float> v3; // Instantiation of a dynamic single precision column
// vector of size 0.
DynamicVector<double,rowVector> v4; // Instantiation of a dynamic double precision row
// vector of size 0.
CompressedVector<int> v5; // Instantiation of a compressed integer column
// vector of size 0.
CompressedVector<double,rowVector> v6; // Instantiation of a compressed double precision row
// vector of size 0.
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223
Efficient implementation of a fixed-sized vector.
Definition: StaticVector.h:230


Construction with Specific Size

The DynamicVector, HybridVector and CompressedVector classes offer a constructor that allows to immediately give the vector the required size. Whereas both dense vectors (i.e. DynamicVector and HybridVector) use this information to allocate memory for all vector elements, CompressedVector merely acquires the size but remains empty.

DynamicVector<int,columnVector> v7( 9UL ); // Instantiation of an integer dynamic column vector
// of size 9. The elements are NOT initialized!
HybridVector< complex<float>, 5UL > v8( 2UL ); // Instantiation of a column vector with two single
// precision complex values. The elements are
// default constructed.
CompressedVector<int,rowVector> v9( 10UL ); // Instantiation of a compressed row vector with
// size 10. Initially, the vector provides no
// capacity for non-zero elements.


Initialization Constructors

All dense vector classes offer a constructor that allows for a direct, homogeneous initialization of all vector elements. In contrast, for sparse vectors the predicted number of non-zero elements can be specified

StaticVector<int,3UL,rowVector> v10( 2 ); // Instantiation of a 3D integer row vector.
// All elements are initialized to 2.
DynamicVector<float> v11( 3UL, 7.0F ); // Instantiation of a dynamic single precision
// column vector of size 3. All elements are
// set to 7.0F.
CompressedVector<float,rowVector> v12( 15UL, 3UL ); // Instantiation of a single precision column
// vector of size 15, which provides enough
// space for at least 3 non-zero elements.


Array Construction

Alternatively, all dense vector classes offer a constructor for an initialization with a dynamic or static array, or with a std::array. If the vector is initialized from a dynamic array, the constructor expects the actual size of the array as first argument, the array as second argument. In case of a static array or std::array, the fixed size of the array is used:

const unique_ptr<double[]> array1( new double[2] );
// ... Initialization of the dynamic array
blaze::StaticVector<double,2UL> v13( 2UL, array1.get() );
const int array2[4] = { 4, -5, -6, 7 };
const std::array<float,3UL> array3{ 1.1F, 2.2F, 3.3F };


Initializer List Construction

In addition, all dense and sparse vector classes can be directly initialized by means of an initializer list:

blaze::DynamicVector<float> v16{ 1.0F, 2.0F, 3.0F, 4.0F };
blaze::CompressedVector<int> v17{ 0, 2, 0, 0, 5, 0, 7, 0 };

Dynamically sized vectors (such as e.g. HybridVector, DynamicVector or CompressedVector) are sized according to the size of the initializer list and all their elements are (copy) assigned the values of the list. For fixed size vectors (such as e.g. StaticVector) missing values are initialized as default and in case the size of the initializer list exceeds the size of the vector a std::invalid_argument exception is thrown. In case of sparse vectors, only the non-zero elements are used to initialize the vector.


Copy Construction

All dense and sparse vectors can be created as the copy of any other dense or sparse vector with the same transpose flag (i.e. blaze::rowVector or blaze::columnVector).

StaticVector<int,9UL,columnVector> v18( v7 ); // Instantiation of the dense column vector v17
// as copy of the dense column vector v7.
DynamicVector<int,rowVector> v19( v9 ); // Instantiation of the dense row vector v18 as
// copy of the sparse row vector v9.
CompressedVector<int,columnVector> v20( v1 ); // Instantiation of the sparse column vector v19
// as copy of the dense column vector v1.
CompressedVector<float,rowVector> v21( v12 ); // Instantiation of the sparse row vector v20 as
// copy of the row vector v12.

Note that it is not possible to create a StaticVector as a copy of a vector with a different size:

StaticVector<int,5UL,columnVector> v22( v7 ); // Runtime error: Size does not match!
StaticVector<int,4UL,rowVector> v23( v10 ); // Compile time error: Size does not match!


Assignment


There are several types of assignment to dense and sparse vectors: Homogeneous Assignment, Array Assignment, Copy Assignment, and Compound Assignment.


Homogeneous Assignment

Sometimes it may be necessary to assign the same value to all elements of a dense vector. For this purpose, the assignment operator can be used:

// Setting all integer elements of the StaticVector to 2
v1 = 2;
// Setting all double precision elements of the DynamicVector to 5.0
v2 = 5.0;


Array Assignment

Dense vectors can also be assigned a static array or std::array:

const float array1[2] = { 1.0F, 2.0F };
const std::array<double,5UL> array2{ 2.1, 4.0, -1.7, 8.6, -7.2 };
v1 = array1;
v2 = array2;


Initializer List Assignment

Alternatively, it is possible to directly assign an initializer list to a dense or sparse vector:

v1 = { 1.0F, 2.0F };
v2 = { 2.1, 0.0, -1.7, 0.0, -7.2 };

Dynamically sized vectors (such as e.g. HybridVector, DynamicVector or CompressedVector) are resized according to the size of the initializer list and all their elements are (copy) assigned the values of the list. For fixed size vectors (such as e.g. StaticVector) missing values are reset to their default value and in case the size of the initializer list exceeds the size of the vector a std::invalid_argument exception is thrown. In case of sparse vectors, only the non-zero elements are considered.


Copy Assignment

For all vector types it is generally possible to assign another vector with the same transpose flag (i.e. blaze::columnVector or blaze::rowVector). Note that in case of StaticVectors, the assigned vector is required to have the same size as the StaticVector since the size of a StaticVector cannot be adapted!

// ... Initialization of the vectors
v1 = v2; // OK: Assignment of a 3D dense column vector to another 3D dense column vector
v1 = v4; // OK: Assignment of a 3D sparse column vector to a 3D dense column vector
v1 = v3; // Runtime error: Cannot assign a 5D vector to a 3D static vector
v1 = v5; // Compilation error: Cannot assign a row vector to a column vector


Compound Assignment

Next to plain assignment, it is also possible to use addition assignment, subtraction assignment, and multiplication assignment. Note however, that in contrast to plain assignment the size and the transpose flag of the vectors has be to equal in order to able to perform a compound assignment.

// ... Initialization of the vectors
v1 += v2; // OK: Addition assignment between two column vectors of the same size
v1 += v3; // Runtime error: No compound assignment between vectors of different size
v1 -= v4; // Compilation error: No compound assignment between vectors of different transpose flag
v4 *= v5; // OK: Multiplication assignment between two row vectors of the same size


Element Access


Subscript Operator

The easiest and most intuitive way to access a dense or sparse vector is via the subscript operator. The indices to access a vector are zero-based:

v1[0] = 1;
v1[1] = 3;
// ...
v2[2] = 7.3F;
v2[4] = -1.4F;

Whereas using the subscript operator on a dense vector only accesses the already existing element, accessing an element of a sparse vector via the subscript operator potentially inserts the element into the vector and may therefore be more expensive. Consider the following example:

for( size_t i=0UL; i<v1.size(); ++i ) {
... = v1[i];
}
static constexpr size_t size() noexcept
Returns the current size/dimension of the vector.
Definition: StaticVector.h:1683

Although the compressed vector is only used for read access within the for loop, using the subscript operator temporarily inserts 10 non-zero elements into the vector. Therefore the preferred way to traverse the non-zero elements of a sparse vector is to use iterators.


Iterators

An alternate way to traverse the elements contained in a dense or sparse vector is by means of iterators. For that purpose, all vectors provide the begin(), cbegin(), end(), and cend() members functions. In case of non-const vectors, begin() and end() return an Iterator, which allows a manipulation of the (non-zero) value. In case of a constant vector or in case cbegin() or cend() are used a ConstIterator is returned. Iterators on dense vectors traverse all elements of the vector, including the zero elements. Iterators on sparse vectors only traverse the non-zero elements.

The following two examples demonstrate how to traverse the elements of a dense and sparse vector, respectively:

DynamicVector<int> v1( 10UL );
// Traversing all elements contained in the vector by Iterator
for( DynamicVector<int>::Iterator it=v1.begin(); it!=v1.end(); ++it ) {
*it = ...; // OK: Write access to the value of the element.
... = *it; // OK: Read access to the value of the element.
}
// Traversing all elements contained in the vector by ConstIterator
for( DynamicVector<int>::ConstIterator it=v1.cbegin(); it!=v1.cend(); ++it ) {
*it = ...; // Compilation error: Assignment to the value via a ConstIterator is invalid.
... = *it; // OK: Read access to the value of the element.
}
// Traversing the vector elements by means of a range-based for loop
for( int& i : v1 ) {
i = ...; // OK: Write access to the value of the element.
... = i; // OK: Read access to the value of the element.
}
constexpr Iterator begin() noexcept
Returns an iterator to the first element of the static vector.
Definition: StaticVector.h:1080
constexpr Iterator end() noexcept
Returns an iterator just past the last element of the static vector.
Definition: StaticVector.h:1137
constexpr ConstIterator cend() const noexcept
Returns an iterator just past the last element of the static vector.
Definition: StaticVector.h:1175
constexpr ConstIterator cbegin() const noexcept
Returns an iterator to the first element of the static vector.
Definition: StaticVector.h:1118
CompressedVector<int> v2( 10UL );
// ... Initialization of the vector
// Traversing the non-zero elements contained in the vector by Iterator
for( CompressedVector<int>::Iterator it=v2.begin(); it!=v2.end(); ++it ) {
it->value() = ...; // OK: Write access to the value of the non-zero element.
... = it->value(); // OK: Read access to the value of the non-zero element.
it->index() = ...; // Compilation error: The index of a non-zero element cannot be changed.
... = it->index(); // OK: Read access to the index of the non-zero element.
}
// Traversing the non-zero elements contained in the vector by ConstIterator
for( CompressedVector<int>::ConstIterator it=v2.cbegin(); it!=v2.cend(); ++it ) {
it->value() = ...; // Compilation error: Assignment to the value via a ConstIterator is invalid.
... = it->value(); // OK: Read access to the value of the non-zero element.
it->index() = ...; // Compilation error: The index of a non-zero element cannot be changed.
... = it->index(); // OK: Read access to the index of the non-zero element.
}
Iterator begin() noexcept
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:1070
ConstIterator cbegin() const noexcept
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:1104
ConstIterator cend() const noexcept
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:1155
Iterator end() noexcept
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:1121

Note that begin(), cbegin(), end(), and cend() are also available as free functions:

for( CompressedVector<int>::Iterator it=begin( v2 ); it!=end( v2 ); ++it ) {
// ...
}
for( CompressedVector<int>::ConstIterator it=cbegin( v2 ); it!=cend( v2 ); ++it ) {
// ...
}
MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:628
MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:562
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518


.data() / data()

Sometimes it is necessary to acquire a pointer to the first element of the underlying array of a dense vector. For that purpose the data() member function or the free data() function can be used:

// Instantiating a dynamic vector with 10 elements
v.data(); // Returns a pointer to the first element of the dynamic vector
data( v ); // Same effect as the member function
MT::ElementType * data(DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:182


Element Insertion


In contrast to dense vectors, that store all elements independent of their value and that offer direct access to all elements, sparse vectors only store the non-zero elements contained in the vector. Therefore it is necessary to explicitly add elements to the vector.


Subscript Operator

The first option to add elements to a sparse vector is the subscript operator:

CompressedVector<int> v1( 3UL );
v1[1] = 2;

In case the element at the given index is not yet contained in the vector, it is automatically inserted. Otherwise the old value is replaced by the new value 2. The operator returns a reference to the sparse vector element.


.set()

An alternative to the subscript operator is the set() function: In case the element is not yet contained in the vector the element is inserted, else the element's value is modified:

// Insert or modify the value at index 3
v1.set( 3, 1 );


.insert()

The insertion of elements can be better controlled via the insert() function. In contrast to the subscript operator and the set() function it emits an exception in case the element is already contained in the vector. In order to check for this case, the find() function can be used:

// In case the element at index 4 is not yet contained in the matrix it is inserted
// with a value of 6.
if( v1.find( 4 ) == v1.end() )
v1.insert( 4, 6 );


.append()

Although the insert() function is very flexible, due to performance reasons it is not suited for the setup of large sparse vectors. A very efficient, yet also very low-level way to fill a sparse vector is the append() function. It requires the sparse vector to provide enough capacity to insert a new element. Additionally, the index of the new element must be larger than the index of the previous element. Violating these conditions results in undefined behavior!

v1.reserve( 10 ); // Reserving space for 10 non-zero elements
v1.append( 5, -2 ); // Appending the element -2 at index 5
v1.append( 6, 4 ); // Appending the element 4 at index 6
// ...


Element Removal


.erase()

The erase() member functions can be used to remove elements from a sparse vector. The following example gives an impression of the five different flavors of erase():

CompressedVector<int> v( 42 );
// ... Initialization of the vector
// Erasing the element at index 21
v.erase( 21 );
// Erasing a single element via iterator
v.erase( v.find( 4 ) );
// Erasing all non-zero elements in the range [7..24]
v.erase( v.lowerBound( 7 ), v.upperBound( 24 ) );
// Erasing all non-zero elements with a value larger than 9 by passing a unary predicate
v.erase( []( int i ){ return i > 9; } );
// Erasing all non-zero elements in the range [30..40] with a value larger than 5
v.erase( v.lowerBound( 30 ), v.upperBound( 40 ), []( int i ){ return i > 5; } );


Element Lookup


A sparse vector only stores the non-zero elements contained in the vector. Therefore, whenever accessing a vector element at a specific index a lookup operation is required. Whereas the subscript operator is performing this lookup automatically, it is also possible to use the find(), lowerBound(), and upperBound() member functions for a manual lookup.


.find() / find()

The find() function can be used to check whether a specific element is contained in a sparse vector. It specifically searches for the element at the given 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 iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!

CompressedVector<int> a( 42 );
// ... Initialization of the vector
// Searching the element at index 7. In case the element is not
// contained in the vector, the end() iterator is returned.
CompressedVector<int>::Iterator pos( a.find( 7 ) );
if( pos != a.end( 7 ) ) {
// ...
}

Alternatively, the free function find() can be used to find a specific element in a sparse vector:

find( a, 7 ); // Searching the element at index 7; same effect as the member function
MT::Iterator find(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:144


.lowerBound() / lowerBound()

The lowerBound() function returns an iterator to the first element with an index not less then the given index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!

CompressedVector<int> a( 42 );
// ... Initialization of the vector
// Searching the lower bound of index 17.
CompressedVector<int>::Iterator pos1( a.lowerBound( 17 ) );
// Searching the upper bound of index 28
CompressedVector<int>::Iterator pos2( a.upperBound( 28 ) );
// Erasing all elements in the specified range
a.erase( pos1, pos2 );

Alternatively, the free function lowerBound() can be used to:

lowerBound( a, 17 ); // Searching the lower bound of index 17; same effect as the member function
MT::Iterator lowerBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: SparseMatrix.h:194


.upperBound() / upperBound()

The upperBound() function returns an iterator to the first element with an index greater then the given index. In combination with the lowerBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned iterator is subject to invalidation due to inserting operations via the subscript operator, the set() function or the insert() function!

CompressedVector<int> a( 42 );
// ... Initialization of the vector
// Searching the lower bound of index 17.
CompressedVector<int>::Iterator pos1( a.lowerBound( 17 ) );
// Searching the upper bound of index 28
CompressedVector<int>::Iterator pos2( a.upperBound( 28 ) );
// Erasing all elements in the specified range
a.erase( pos1, pos2 );

Alternatively, the free function upperBound() can be used to:

upperBound( a, 28 ); // Searching the upper bound of index 28; same effect as the member function
MT::Iterator upperBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: SparseMatrix.h:244


Non-Modifying Operations


.size() / size()

Via the size() member function, the current size of a dense or sparse vector can be queried:

// Instantiating a dynamic vector with size 10
v1.size(); // Returns 10
// Instantiating a compressed vector with size 12 and capacity for 3 non-zero elements
v2.size(); // Returns 12
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DynamicVector.h:1609

Alternatively, the free function size() can be used to query to current size of a vector. In contrast to the member function, the free function can also be used to query the size of vector expressions:

size( v1 ); // Returns 10, i.e. has the same effect as the member function
size( v2 ); // Returns 12, i.e. has the same effect as the member function
blaze::DynamicMatrix<int> A( 15UL, 12UL );
size( A * v2 ); // Returns 15, i.e. the size of the resulting vector
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676


.capacity() / capacity()

Via the capacity() (member) function the internal capacity of a dense or sparse vector can be queried. Note that the capacity of a vector doesn't have to be equal to the size of a vector. In case of a dense vector the capacity will always be greater or equal than the size of the vector, in case of a sparse vector the capacity may even be less than the size.

v1.capacity(); // Returns at least 10

For symmetry reasons, there is also a free function /c capacity() available that can be used to query the capacity:

capacity( v1 ); // Returns at least 10, i.e. has the same effect as the member function
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692

Note, however, that it is not possible to query the capacity of a vector expression:

capacity( A * v1 ); // Compilation error!


.nonZeros() / nonZeros()

For both dense and sparse vectors the number of non-zero elements can be determined via the nonZeros() member function. Sparse vectors directly return their number of non-zero elements, dense vectors traverse their elements and count the number of non-zero elements.

v1.nonZeros(); // Returns the number of non-zero elements in the dense vector
v2.nonZeros(); // Returns the number of non-zero elements in the sparse vector
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: DynamicVector.h:1664

There is also a free function nonZeros() available to query the current number of non-zero elements:

nonZeros( v1 ); // Returns the number of non-zero elements in the dense vector
nonZeros( v2 ); // Returns the number of non-zero elements in the sparse vector
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730

The free nonZeros() function can also be used to query the number of non-zero elements in a vector expression. However, the result is not the exact number of non-zero elements, but may be a rough estimation:

nonZeros( A * v1 ); // Estimates the number of non-zero elements in the vector expression


isEmpty()

The isEmpty() function returns whether the total number of elements of the vector is zero:

blaze::DynamicVector<int> a; // Create an empty vector
isEmpty( a ); // Returns true
a.resize( 10 ); // Resize to 10 elements
isEmpty( a ); // Returns false
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: DynamicVector.h:1747
constexpr bool isEmpty(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is empty.
Definition: Matrix.h:1364


isnan()

The isnan() function provides the means to check a dense or sparse vector for non-a-number elements:

// ... Resizing and initialization
if( isnan( a ) ) { ... }
bool isnan(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for not-a-number elements.
Definition: DenseMatrix.h:1290
// ... Resizing and initialization
if( isnan( a ) ) { ... }

If at least one element of the vector is not-a-number, the function returns true, otherwise it returns false.


isinf()

The isinf() function checks the given dense or sparse vector for infinite (inf) elements:

// ... Resizing and initialization
if( isinf( a ) ) { ... }
bool isinf(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for infinite elements.
Definition: DenseMatrix.h:1339
// ... Resizing and initialization
if( isinf( a ) ) { ... }

If at least one element of the vector is infinite, the function returns true, otherwise it returns false.


isfinite()

The isfinite() function checks if all elements of the given dense or sparse vector are finite elements (i.e. normal, subnormal or zero elements, but not infinite or NaN):

// ... Resizing and initialization
if( isfinite( a ) ) { ... }
bool isfinite(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for finite elements.
Definition: DenseMatrix.h:1389
// ... Resizing and initialization
if( isfinite( a ) ) { ... }

If all elements of the vector are finite, the function returns true, otherwise it returns false.


isDefault()

The isDefault() function returns whether the given dense or sparse vector is in default state:

// ... Resizing and initialization
if( isDefault( a ) ) { ... }
Efficient implementation of a dynamically sized vector with static memory.
Definition: HybridVector.h:222
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169

A vector is in default state if it appears to just have been default constructed. All resizable vectors (HybridVector, DynamicVector, or CompressedVector) and CustomVector are in default state if its size is equal to zero. A non-resizable vector (StaticVector, all subvectors, element selections, rows, and columns) is in default state if all its elements are in default state. For instance, in case the vector is instantiated for a built-in integral or floating point data type, the function returns true in case all vector elements are 0 and false in case any vector element is not 0.


isUniform()

In order to check if all vector elements are identical, the isUniform() function can be used:

// ... Resizing and initialization
if( isUniform( a ) ) { ... }
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:1766

Note that in case of sparse vectors the zero elements are also taken into account!


isZero()

In order to check if all vector elements are zero, the isZero() function can be used:

// ... Resizing and initialization
if( isZero( a ) ) { ... }
bool isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819


length() / sqrLength()

In order to calculate the length (magnitude) of a dense or sparse vector, both the length() and sqrLength() function can be used:

const float len = length ( v ); // Computes the current length of the vector
const float sqrlen = sqrLength( v ); // Computes the square length of the vector
decltype(auto) length(const DenseVector< VT, TF > &dv)
Calculation of the length (magnitude) of the dense vector .
Definition: DVecNormExpr.h:654
decltype(auto) sqrLength(const DenseVector< VT, TF > &dv)
Calculation of the square length (magnitude) of the dense vector .
Definition: DVecNormExpr.h:635

Note that both functions can only be used for vectors with built-in or complex element type!


trans()

As already mentioned, vectors can either be column vectors (blaze::columnVector) or row vectors (blaze::rowVector). A column vector cannot be assigned to a row vector and vice versa. However, vectors can be transposed via the trans() function:

v1 = v2; // Compilation error: Cannot assign a row vector to a column vector
v1 = trans( v2 ); // OK: Transposing the row vector to a column vector and assigning it
// to the column vector v1
v2 = trans( v1 ); // OK: Transposing the column vector v1 and assigning it to the row vector v2
v1 += trans( v2 ); // OK: Addition assignment of two column vectors
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766


ctrans()

It is also possible to compute the conjugate transpose of a vector. This operation is available via the ctrans() function:

v1 = ctrans( v2 ); // Compute the conjugate transpose vector
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1501
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73

Note that the ctrans() function has the same effect as manually applying the conj() and trans() function in any order:

v1 = trans( conj( v2 ) ); // Computing the conjugate transpose vector
v1 = conj( trans( v2 ) ); // Computing the conjugate transpose vector
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1464


reverse()

Via the reverse() function is is possible to reverse the elements of a dense or sparse vector. The following examples demonstrates this by means of a dense vector:

blaze::DynamicVector<int> a{ 1, 2, 3, 4, 5 };
b = reverse( a ); // Results in ( 5 4 3 2 1 )
decltype(auto) reverse(MT &&m)
Reverse the rows or columns of a matrix.
Definition: Matrix.h:878


eval() / evaluate()

The evaluate() function forces an evaluation of the given vector expression and enables an automatic deduction of the correct result type of an operation. The following code example demonstrates its intended use for the multiplication of a dense and a sparse vector:

// ... Resizing and initialization
auto c = evaluate( a * b );
MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:1282

In this scenario, the evaluate() function assists in deducing the exact result type of the operation via the auto keyword. Please note that if evaluate() is used in this way, no temporary vector is created and no copy operation is performed. Instead, the result is directly written to the target vector due to the return value optimization (RVO). However, if evaluate() is used in combination with an explicit target type, a temporary will be created and a copy operation will be performed if the used type differs from the type returned from the function:

CompressedVector<double> d( a * b ); // No temporary & no copy operation
DynamicVector<double> e( a * b ); // Temporary & copy operation
d = evaluate( a * b ); // Temporary & copy operation

Sometimes it might be desirable to explicitly evaluate a sub-expression within a larger expression. However, please note that evaluate() is not intended to be used for this purpose. This task is more elegantly and efficiently handled by the eval() function:

d = a + evaluate( b * c ); // Unnecessary creation of a temporary vector
d = a + eval( b * c ); // No creation of a temporary vector
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:790

In contrast to the evaluate() function, eval() can take the complete expression into account and therefore can guarantee the most efficient way to evaluate it (see also Intra-Statement Optimization).


noalias()

The Blaze library is able to reliably detect aliasing during the assignment of vectors. In case the aliasing would lead to an incorrect result, Blaze introduces an intermediate temporary of the appropriate type to break the aliasing. For instance, in the following example Blaze performs an alias detection in both assignments, but only, in the second assignment it detects a problematic aliasing and uses an intermediate temporary in order to be able to compute the correct result:

x = x + y; // No problematic aliasing of x, no intermediate temporary is required.
x = A * x; // Problematic aliasing of x; intermediate temporary required!

The detection of aliasing effects, however, takes a small runtime effort. In order to disable the aliasing detection, the noalias() function can be used:

x = noalias( x + y ); // No alias detection performed, no intermediate temporary.
x = noalias( A * x ); // No alias detection performed, no intermediate temporary.
// Note that the final result will be incorrect!
decltype(auto) noalias(const DenseMatrix< MT, SO > &dm)
Forces the non-aliased evaluation of the given dense matrix expression dm.
Definition: DMatNoAliasExpr.h:679
Warning
The noalias() operation has the semantics of a cast: The caller is completely responsible and the system trusts the given information. Using noalias() in a situation where an aliasing effect occurs leads to undefined behavior (which can be violated invariants or wrong computation results)!


nosimd()

By default, Blaze attempts to vectorize all operations by means of SSE, AVX, etc. in order to achieve maximum performance. However, via the nosimd() operation it is possible to disable the SIMD evaluation of any operation:

x = nosimd( x + y ); // Disables SIMD for the vector/vector addition
x = nosimd( A * x ); // Disables SIMD for the matrix/vector multiplication
decltype(auto) nosimd(const DenseMatrix< MT, SO > &dm)
Disables the SIMD evaluation of the given dense matrix expression dm.
Definition: DMatNoSIMDExpr.h:717

Please note that the main purpose of the nosimd() operation is to enable an easy performance comparison between the vectorized and non-vectorized evaluation. Using the nosimd() operation will likely result in significantly reduced performance!


fix()

By default, resizable vectors such as DynamicVector, HybridVector, and CompressedVector can adapt their size during an assignment:

blaze::DynamicVector<int> a{ 1, 2 }; // Setup of a vector with 2 elements
blaze::DynamicVector<int> b{ 1, 2, 3, 4 }; // Setup of a vector with 4 elements
a = b; // Resizes vector 'a' to 4 elements

Via the fix() operation it is possible to fix the size of a resizable vector. If a vector with a different size is assigned, instead of resizing the vector the operation fails by throwing a std::invalid_argument exception:

blaze::DynamicVector<int> a{ 1, 2 }; // Setup of a vector with 2 elements
blaze::DynamicVector<int> b{ 1, 2, 3, 4 }; // Setup of a vector with 4 elements
fix( a ) = b; // Throws an exception: Vector cannot be resized!
decltype(auto) fix(DenseMatrix< MT, SO > &dm) noexcept
Fixing the size of the given dense matrix.
Definition: DMatFixExpr.h:227


Modifying Operations


.resize() / .reserve()

The size of a StaticVector is fixed by the second template parameter and a CustomVector cannot be resized. In contrast, the size of DynamicVectors, HybridVectors as well as CompressedVectors can be changed via the resize() function:

DynamicVector<int,columnVector> v1;
CompressedVector<int,rowVector> v2( 4 );
v2[1] = -2;
v2[3] = 11;
// Adapting the size of the dynamic and compressed vectors. The (optional) second parameter
// specifies whether the existing elements should be preserved. Per default, the existing
// elements are preserved.
v1.resize( 5UL ); // Resizing vector v1 to 5 elements. Elements of built-in type remain
// uninitialized, elements of class type are default constructed.
v1.resize( 3UL, false ); // Resizing vector v1 to 3 elements. The old elements are lost, the
// new elements are NOT initialized!
v2.resize( 8UL, true ); // Resizing vector v2 to 8 elements. The old elements are preserved.
v2.resize( 5UL, false ); // Resizing vector v2 to 5 elements. The old elements are lost.

Note that resizing a vector invalidates all existing views (see e.g. Subvectors) on the vector:

blaze::DynamicVector<int,rowVector> v1( 10UL ); // Creating a dynamic vector of size 10
auto sv = subvector( v1, 2UL, 5UL ); // Creating a view on the range [2..6]
v1.resize( 6UL ); // Resizing the vector invalidates the view
decltype(auto) subvector(Vector< VT, TF > &, RSAs...)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:158

When the internal capacity of a vector is no longer sufficient, the allocation of a larger junk of memory is triggered. In order to avoid frequent reallocations, the reserve() function can be used up front to set the internal capacity:

v1.reserve( 100 );
v1.size(); // Returns 0
v1.capacity(); // Returns at least 100
void reserve(size_t n)
Setting the minimum capacity of the vector.
Definition: DynamicVector.h:1821
size_t capacity() const noexcept
Returns the maximum capacity of the vector.
Definition: DynamicVector.h:1644

Note that the size of the vector remains unchanged, but only the internal capacity is set according to the specified value!


.shrinkToFit()

The internal capacity of vectors with dynamic memory is preserved in order to minimize the number of reallocations. For that reason, the resize() and reserve() functions can lead to memory overhead. The shrinkToFit() member function can be used to minimize the internal capacity:

blaze::DynamicVector<int> v1( 1000UL ); // Create a vector of 1000 integers
v1.resize( 10UL ); // Resize to 10, but the capacity is preserved
v1.shrinkToFit(); // Remove the unused capacity
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: DynamicVector.h:1853

Please note that due to padding the capacity might not be reduced exactly to size(). Please also note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of the vector are invalidated.

reset() / clear()

In order to reset all elements of a vector, the reset() function can be used:

// Setup of a single precision column vector, whose elements are initialized with 2.0F.
// Resetting all elements to 0.0F. Only the elements are reset, the size of the vector is unchanged.
reset( v1 ); // Resetting all elements
v1.size(); // Returns 3: size and capacity remain unchanged
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806

In order to return a vector to its default state (i.e. the state of a default constructed vector), the clear() function can be used:

// Setup of a single precision column vector, whose elements are initialized with -1.0F.
// Resetting the entire vector.
clear( v1 ); // Resetting the entire vector
v1.size(); // Returns 0: size is reset, but capacity remains unchanged
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960

Note that resetting or clearing both dense and sparse vectors does not change the capacity of the vectors.


swap()

Via the swap() function it is possible to completely swap the contents of two vectors of the same type:

swap( v1, v2 ); // Swapping the contents of v1 and v2
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:225


Arithmetic Operations


normalize()

The normalize() function can be used to scale any non-zero vector to a length of 1. In case the vector does not contain a single non-zero element (i.e. is a zero vector), the normalize() function returns a zero vector.

v1 = normalize( v1 ); // Normalizing the dense vector v1
length( v1 ); // Returns 1 (or 0 in case of a zero vector)
v1 = normalize( v2 ); // Assigning v1 the normalized vector v2
length( v1 ); // Returns 1 (or 0 in case of a zero vector)
decltype(auto) normalize(const DenseVector< VT, TF > &vec)
Normalization of the dense vector ( ).
Definition: DVecScalarMultExpr.h:1155

Note that the normalize() function only works for floating point vectors. The attempt to use it for an integral vector results in a compile time error.


min() / max()

The min() and max() functions can be used for a single vector, multiple vectors, and a vector and a scalar.

Single Vector

If passed a single vector, the functions return the smallest and largest element of the given dense vector or the smallest and largest non-zero element of the given sparse vector, respectively:

min( a ); // Returns -5
max( a ); // Returns 7
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
min( b ); // Returns 1
max( b ); // Returns 3

For more information on the unary min() and max() reduction operations see the Reduction Operations section.

Multiple Vectors

If passed two or more dense vectors, the min() and max() functions compute the componentwise minimum or maximum of the given vectors, respectively:

min( a, c ); // Results in the vector ( -5, 1, -7, -4 )
max( a, c, d ); // Results in the vector ( -5, 3, 7, 4 )

Please note that sparse vectors can only be used in the unary min() and max() functions. Also note that all forms of the min() and max() functions can be used to compute the smallest and largest element of a vector expression:

min( a + b + c ); // Returns -9, i.e. the smallest value of the resulting vector
max( a - b - c ); // Returns 11, i.e. the largest value of the resulting vector
min( a + c, c - d ); // Results in ( -10 -2 -7 0 )
max( a - c, c + d ); // Results in ( 0 4 14 6 )

Vector and Scalar

If passed a dense vector and a scalar, the min() and max() functions compute the componentwise minimum or maximum between the given vector and a uniform vector represented by the scalar value:

min( a, 0 ); // Results in ( -5, 0, 0, -4 )
min( 0, a ); // Results in ( -5, 0, 0, -4 )
max( a, 0 ); // Results in ( 0, 2, 7, 0 )
max( 0, a ); // Results in ( 0, 2, 7, 0 )


softmax()

The softmax function, also called the normalized exponential function, of a given dense vector can be computed via softmax(). The resulting dense vector consists of real values in the range (0..1], which add up to 1.

blaze::StaticVector<double,7UL,rowVector> x{ 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0 };
// Evaluating the softmax function
y = softmax( x ); // Results in ( 0.024 0.064 0.175 0.475 0.024 0.064 0.175 )
double s = sum( y ); // Results in 1
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
auto softmax(const DenseMatrix< MT, SO > &dm)
Computes the softmax function for the given dense matrix.
Definition: DMatSoftmaxExpr.h:88


abs()

The abs() function can be used to compute the absolute values of each element of a vector. For instance, the following computation

decltype(auto) abs(const DenseMatrix< MT, SO > &dm)
Applies the abs() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1296

results in the vector

                      \f$ b = \left(\begin{array}{*{1}{c}}
                      1 \\
                      2 \\
                      3 \\
                      \end{array}\right)\f$


sign()

The sign() function can be used to evaluate the sign of each element of a vector a. For each element i the corresponding result is 1 if a[i] is greater than zero, 0 if a[i] is zero, and -1 if a[i] is less than zero. For instance, the following use of the sign() function

decltype(auto) sign(const DenseMatrix< MT, SO > &dm)
Applies the sign() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1324

results in the vector

                      \f$ b = \left(\begin{array}{*{1}{c}}
                      -1 \\
                       1 \\
                       0 \\
                      \end{array}\right)\f$


floor() / ceil() / trunc() / round()

The floor(), ceil(), trunc(), and round() functions can be used to round down/up each element of a vector, respectively:

b = floor( a ); // Rounding down each element of the vector
b = ceil ( a ); // Rounding up each element of the vector
b = trunc( a ); // Truncating each element of the vector
b = round( a ); // Rounding each element of the vector
decltype(auto) trunc(const DenseMatrix< MT, SO > &dm)
Applies the trunc() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1408
decltype(auto) floor(const DenseMatrix< MT, SO > &dm)
Applies the floor() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1352
decltype(auto) ceil(const DenseMatrix< MT, SO > &dm)
Applies the ceil() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1380
decltype(auto) round(const DenseMatrix< MT, SO > &dm)
Applies the round() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1436


conj()

The conj() function can be applied on a dense or sparse vector to compute the complex conjugate of each element of the vector:

using cplx = std::complex<double>;
// Creating the vector
// ( (-2,-1) )
// ( ( 1, 1) )
StaticVector<cplx,2UL> a{ cplx(-2.0,-1.0), cplx(1.0,1.0) };
// Computing the vector of complex conjugates
// ( (-2, 1) )
// ( ( 1,-1) )
StaticVector<cplx,2UL> b;
b = conj( a );

Additionally, vectors can be conjugated in-place via the conjugate() function:

conjugate( c ); // In-place conjugate operation.
c = conj( c ); // Same as above
BLAZE_ALWAYS_INLINE void conjugate(T &a) noexcept(IsNumeric_v< T >)
In-place conjugation of the given value/object.
Definition: Conjugate.h:118


real()

The real() function can be used on a dense or sparse vector to extract the real part of each element of the vector:

using cplx = std::complex<double>;
// Creating the vector
// ( (-2,-1) )
// ( ( 1, 1) )
StaticVector<cplx,2UL> a{ cplx(-2.0,-1.0), cplx(1.0,1.0) };
// Extracting the real part of each vector element
// ( -2 )
// ( 1 )
StaticVector<double,2UL> b;
b = real( a );
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1529


imag()

The imag() function can be used on a dense or sparse vector to extract the imaginary part of each element of the vector:

using cplx = std::complex<double>;
// Creating the vector
// ( (-2,-1) )
// ( ( 1, 1) )
StaticVector<cplx,2UL> a{ cplx(-2.0,-1.0), cplx(1.0,1.0) };
// Extracting the imaginary part of each vector element
// ( -1 )
// ( 1 )
StaticVector<double,2UL> b;
b = imag( a );
decltype(auto) imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatMapExpr.h:1557


arg()

The arg() function can be used on a dense or sparse vector to compute the phase angle for each element of the vector:

using cplx = std::complex<double>;
// Creating the vector
// ( (-2,-1) )
// ( ( 1, 1) )
StaticVector<cplx,2UL> a{ cplx(-2.0,-1.0), cplx(1.0,1.0) };
// Compute the phase angle of each vector element
// ( -2.67795 )
// ( 0.785398 )
StaticVector<double,2UL> b;
b = arg( a );
decltype(auto) arg(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the phase angle of each single element of dm.
Definition: DMatMapExpr.h:1585


sqrt() / invsqrt()

Via the sqrt() and invsqrt() functions the (inverse) square root of each element of a vector can be computed:

b = sqrt( a ); // Computes the square root of each element
c = invsqrt( a ); // Computes the inverse square root of each element
decltype(auto) invsqrt(const DenseMatrix< MT, SO > &dm)
Computes the inverse square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1647
decltype(auto) sqrt(const DenseMatrix< MT, SO > &dm)
Computes the square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1616

Note that in case of sparse vectors only the non-zero elements are taken into account!


cbrt() / invcbrt()

The cbrt() and invcbrt() functions can be used to compute the the (inverse) cubic root of each element of a vector:

b = cbrt( a ); // Computes the cubic root of each element
c = invcbrt( a ); // Computes the inverse cubic root of each element
decltype(auto) cbrt(const DenseMatrix< MT, SO > &dm)
Computes the cubic root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1678
decltype(auto) invcbrt(const DenseMatrix< MT, SO > &dm)
Computes the inverse cubic root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1709

Note that in case of sparse vectors only the non-zero elements are taken into account!


hypot()

The hypot() function can be used to compute the componentwise hypotenous for a pair of dense vectors:

c = hypot( a, b ); // Computes the componentwise hypotenuous
decltype(auto) hypot(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise hypotenous for the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1412


clamp()

The clamp() function can be used to restrict all elements of a vector to a specific range:

b = clamp( a, -1.0, 1.0 ); // Restrict all elements to the range [-1..1]
decltype(auto) clamp(const DenseMatrix< MT, SO > &dm, const DT &min, const DT &max)
Restricts each single element of the dense matrix dm to the range .
Definition: DMatMapExpr.h:1740

Note that in case of sparse vectors only the non-zero elements are taken into account!


pow()

The pow() function can be used to compute the exponential value of each element of a vector. If passed a vector and a numeric exponent, the function computes the exponential value of each element of the vector using the same exponent. If passed a second vector, the function computes the componentwise exponential value:

c = pow( a, 1.2 ); // Computes the exponential value of each element
c = pow( a, b ); // Computes the componentwise exponential value
decltype(auto) pow(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise exponential value for the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1448


exp() / exp2() / exp10()

exp(), exp2() and exp10() compute the base e/2/10 exponential of each element of a vector, respectively:

b = exp( a ); // Computes the base e exponential of each element
b = exp2( a ); // Computes the base 2 exponential of each element
b = exp10( a ); // Computes the base 10 exponential of each element
decltype(auto) exp(const DenseMatrix< MT, SO > &dm)
Computes for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1801
decltype(auto) exp2(const DenseMatrix< MT, SO > &dm)
Computes for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1829
decltype(auto) exp10(const DenseMatrix< MT, SO > &dm)
Computes for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1857

Note that in case of sparse vectors only the non-zero elements are taken into account!


log() / log2() / log10() / log1p() / lgamma()

The log(), log2(), log10(), log1p() and lgamma() functions can be used to compute the natural, binary and common logarithm of each element of a vector:

b = log( a ); // Computes the natural logarithm of each element
b = log2( a ); // Computes the binary logarithm of each element
b = log10( a ); // Computes the common logarithm of each element
b = log1p( a ); // Computes the natural logarithm of x+1 of each element
b = lgamma( a ); // Computes the natural logarithm of the absolute value of the gamma function
decltype(auto) log1p(const DenseMatrix< MT, SO > &dm)
Computes the natural logarithm of x+1 for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1983
decltype(auto) log(const DenseMatrix< MT, SO > &dm)
Computes the natural logarithm for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1888
decltype(auto) log2(const DenseMatrix< MT, SO > &dm)
Computes the binary logarithm for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1919
decltype(auto) log10(const DenseMatrix< MT, SO > &dm)
Computes the common logarithm for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1950
decltype(auto) lgamma(const DenseMatrix< MT, SO > &dm)
Computes the natural logarithm of the absolute value of the gamma function for each single element of...
Definition: DMatMapExpr.h:2016


sin() / cos() / tan() / asin() / acos() / atan()

The following trigonometric functions are available for both dense and sparse vectors:

b = sin( a ); // Computes the sine of each element of the vector
b = cos( a ); // Computes the cosine of each element of the vector
b = tan( a ); // Computes the tangent of each element of the vector
b = asin( a ); // Computes the inverse sine of each element of the vector
b = acos( a ); // Computes the inverse cosine of each element of the vector
b = atan( a ); // Computes the inverse tangent of each element of the vector
decltype(auto) sin(const DenseMatrix< MT, SO > &dm)
Computes the sine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2044
decltype(auto) acos(const DenseMatrix< MT, SO > &dm)
Computes the inverse cosine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2190
decltype(auto) atan(const DenseMatrix< MT, SO > &dm)
Computes the inverse tangent for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2305
decltype(auto) asin(const DenseMatrix< MT, SO > &dm)
Computes the inverse sine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2075
decltype(auto) cos(const DenseMatrix< MT, SO > &dm)
Computes the cosine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2159
decltype(auto) tan(const DenseMatrix< MT, SO > &dm)
Computes the tangent for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2277

Note that in case of sparse vectors only the non-zero elements are taken into account!


sinh() / cosh() / tanh() / asinh() / acosh() / atanh()

The following hyperbolic functions are available for both dense and sparse vectors:

b = sinh( a ); // Computes the hyperbolic sine of each element of the vector
b = cosh( a ); // Computes the hyperbolic cosine of each element of the vector
b = tanh( a ); // Computes the hyperbolic tangent of each element of the vector
b = asinh( a ); // Computes the inverse hyperbolic sine of each element of the vector
b = acosh( a ); // Computes the inverse hyperbolic cosine of each element of the vector
b = atanh( a ); // Computes the inverse hyperbolic tangent of each element of the vector
decltype(auto) asinh(const DenseMatrix< MT, SO > &dm)
Computes the inverse hyperbolic sine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2131
decltype(auto) acosh(const DenseMatrix< MT, SO > &dm)
Computes the inverse hyperbolic cosine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2249
decltype(auto) sinh(const DenseMatrix< MT, SO > &dm)
Computes the hyperbolic sine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2103
decltype(auto) tanh(const DenseMatrix< MT, SO > &dm)
Computes the hyperbolic tangent for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2336
decltype(auto) cosh(const DenseMatrix< MT, SO > &dm)
Computes the hyperbolic cosine for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2218
decltype(auto) atanh(const DenseMatrix< MT, SO > &dm)
Computes the inverse hyperbolic tangent for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2367

Note that in case of sparse vectors only the non-zero elements are taken into account!


atan2()

The multi-valued inverse tangent is available for a pair of dense vectors:

c = atan2( a, b ); // Computes the componentwise multi-valued inverse tangent
decltype(auto) atan2(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the multi-valued inverse tangent of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1484


erf() / erfc()

The erf() and erfc() functions compute the (complementary) error function of each element of a vector:

b = erf( a ); // Computes the error function of each element
b = erfc( a ); // Computes the complementary error function of each element
decltype(auto) erfc(const DenseMatrix< MT, SO > &dm)
Computes the complementary error function for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2423
decltype(auto) erf(const DenseMatrix< MT, SO > &dm)
Computes the error function for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:2395

Note that in case of sparse vectors only the non-zero elements are taken into account!


map() / forEach()

Via the map() functions it is possible to execute componentwise custom operations on vectors. The unary map() function can be used to apply a custom operation on each element of a dense or sparse vector. For instance, the following example demonstrates a custom square root computation via a lambda:

b = map( a, []( double d ) { return std::sqrt( d ); } );
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Elementwise evaluation of the given binary operation on each single element of the dense matrices lhs...
Definition: DMatDMatMapExpr.h:1144

The N-ary map() functions can be used to apply an operation componentwise to the elements of N dense vectors (where $ N <= 6 $). The following example demonstrates the merging of two column vectors of double precision values into a vector of double precision complex numbers:

blaze::DynamicVector<double> real{ 2.1, -4.2, 1.0, 0.6 };
blaze::DynamicVector<double> imag{ 0.3, 1.4, 2.9, -3.4 };
// Creating the vector
// ( ( 2.1, 0.3) )
// ( (-4.2, 1.4) )
// ( ( 1.0, 2.9) )
// ( ( 0.6, -3.4) )
cplx = map( real, imag, []( double r, double i ){ return complex<double>( r, i ); } );
Complex data type of the Blaze library.

Applying the map() function to a column vector and a row vector results in the outer map of the two vectors. The following example demonstrates the outer sum of a column vector and a row vector:

// Results in the matrix
//
// ( 1 5 0 6 )
// A = ( 4 8 3 9 )
// ( -2 2 -3 3 )
//
blaze::StaticMatrix<int,3UL,4UL> M1 = map( v1, v2, []( int a, int b ){ return a + b; } );
Efficient implementation of a fixed-sized matrix.
Definition: StaticMatrix.h:249

Although the computation in the two previous examples can be parallelized it is not vectorized and thus cannot perform at peak performance. However, it is also possible to create vectorized custom operations. See Custom Operations for a detailed overview of the possibilities of custom operations.

Please note that unary custom operations on vectors have been introduced in Blaze 3.0 in form of the forEach() function. With the introduction of binary custom functions, the forEach() function has been renamed to map(). The forEach() function can still be used, but the function might be deprecated in future releases of Blaze.


select()

The select() function performs a componentwise, conditional selection of elements. Given the three dense vectors cond, a, and b, in case an element in the cond vector evaluates to true, the according element of a is selected, in case the cond element evaluates to false, the according element of b is selected. The following example demonstrates the use of the select() function:

blaze::DynamicVector<bool> cond{ true, false, true false };
blaze::DynamicVector<int> a{ 1, -1, 1, -1 };
blaze::DynamicVector<int> b{ -2, 2, -2, 2 };
// ... Resizing and initialization
c = select( cond, a, b ); // Results in ( 1, 2, 1, 2 )
decltype(auto) select(const DenseMatrix< MT1, SO > &cond, const DenseMatrix< MT2, SO > &lhs, const DenseMatrix< MT3, SO > &rhs)
Elementwise conditional selection of values from the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1528


Reduction Operations


reduce()

The reduce() function performs a total reduction of the elements of the given dense vector or the non-zero elements of the given sparse vector. The following examples demonstrate the total reduction of a dense and sparse vector:

// ... Resizing and initialization
const double totalsum1 = reduce( a, blaze::Add() );
const double totalsum2 = reduce( a, []( double a, double b ){ return a + b; } );
decltype(auto) reduce(const DenseMatrix< MT, SO > &dm, OP op)
Performs a custom reduction operation on the given dense matrix.
Definition: DMatReduceExpr.h:2025
Generic wrapper for the addition operator.
Definition: Add.h:85
// ... Resizing and initialization
const double totalmin1 = reduce( a, blaze::Min() );
const double totalmin2 = reduce( a, []( double a, double b ){ return blaze::min( a, b ); } );
Generic wrapper for the min() function.
Definition: Min.h:82

As demonstrated in the examples it is possible to pass any binary callable as custom reduction operation. However, for instance in the case of lambdas the vectorization of the reduction operation is compiler dependent and might not perform at peak performance. However, it is also possible to create vectorized custom operations. See Custom Operations for a detailed overview of the possibilities of custom operations.

Please note that the evaluation order of the reduce() function is unspecified. Thus the behavior is non-deterministic if the given reduction operation is not associative or not commutative. Also, the operation is undefined if the given reduction operation modifies the values.


sum()

The sum() function reduces the elements of the given dense vector or the non-zero elements of the given sparse vector by means of addition:

blaze::DynamicVector<int> a{ 1, 2, 3, 4 };
const int totalsum = sum( a ); // Results in 10
const int totalsum = sum( a ); // Results in 10

Please note that the evaluation order of the sum() function is unspecified.


prod()

The prod() function reduces the elements of the given dense vector or the non-zero elements of the given sparse vector by means of multiplication:

blaze::DynamicVector<int> a{ 1, 2, 3, 4 };
const int totalprod = prod( a ); // Results in 24
decltype(auto) prod(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of multiplication.
Definition: DMatReduceExpr.h:2229
const int totalprod = prod( a ); // Results in 24


min()

The unary min() function returns the smallest element of the given dense vector or the smallest non-zero element of the given sparse vector. It can only be used for element types that support the smaller-than relationship. In case the given vector currently has a size of 0, the returned value is the default value (e.g. 0 in case of fundamental data types).

blaze::DynamicVector<int> a{ 1, -2, 3, 0 };
const int totalmin = min( a ); // Results in -2
const int totalmin = min( a ); // Results in 1
Note
In case the sparse vector is not completely filled, the implicit zero elements are NOT taken into account. In the previous example the compressed vector has only 2 non-zero elements. However, the minimum of the vector is 1.


max()

The unary max() function returns the largest element of the given dense vector or the largest non-zero element of the given sparse vector. It can only be used for element types that support the smaller-than relationship. In case the given vector currently has a size of 0, the returned value is the default value (e.g. 0 in case of fundamental data types).

blaze::DynamicVector<int> a{ 1, -2, 3, 0 };
const int totalmax = max( a ); // Results in 3
blaze::CompressedVector<int> a{ -1, 0, -3, 0 };
const int totalmin = max( a ); // Results in -1
Note
In case the sparse vector is not completely filled, the implicit zero elements are NOT taken into account. In the previous example the compressed vector has only 2 non-zero elements. However, the maximum of the vector is -1.


argmin()

The argmin() function returns the index of the first smallest element of the given dense vector. This function can only be used for element types that support the smaller-than relationship. In case the given vector currently has a size of 0, the returned index is 0.

blaze::DynamicVector<int> a{ 1, -2, 3, 0 };
const size_t minindex = argmin( a ); // Results in 1
size_t argmin(const DenseVector< VT, TF > &dv)
Returns the index of the first smallest element of the dense vector.
Definition: DVecReduceExpr.h:542


argmax()

The argmax() function returns the index of the first largest element of the given dense vector. This function can only be used for element types that support the smaller-than relationship. In case the given vector currently has a size of 0, the returned index is 0.

blaze::DynamicVector<int> a{ 1, -2, 3, 0 };
const size_t maxindex = argmax( a ); // Results in 2
size_t argmax(const DenseVector< VT, TF > &dv)
Returns the index of the first largest element of the dense vector.
Definition: DVecReduceExpr.h:584


Norms


norm()

The norm() function computes the L2 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = norm( a );
const double norm2 = norm( b );
decltype(auto) norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:573


sqrNorm()

The sqrNorm() function computes the squared L2 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = sqrNorm( a );
const double norm2 = sqrNorm( b );
decltype(auto) sqrNorm(const DenseMatrix< MT, SO > &dm)
Computes the squared L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:599


l1Norm()

The l1Norm() function computes the squared L1 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = l1Norm( a );
const double norm2 = l1Norm( b );
decltype(auto) l1Norm(const DenseMatrix< MT, SO > &dm)
Computes the L1 norm for the given dense matrix.
Definition: DMatNormExpr.h:625


l2Norm()

The l2Norm() function computes the squared L2 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = l2Norm( a );
const double norm2 = l2Norm( b );
decltype(auto) l2Norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:651


l3Norm()

The l3Norm() function computes the squared L3 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = l3Norm( a );
const double norm2 = l3Norm( b );
decltype(auto) l3Norm(const DenseMatrix< MT, SO > &dm)
Computes the L3 norm for the given dense matrix.
Definition: DMatNormExpr.h:677


l4Norm()

The l4Norm() function computes the squared L4 norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = l4Norm( a );
const double norm2 = l4Norm( b );
decltype(auto) l4Norm(const DenseMatrix< MT, SO > &dm)
Computes the L4 norm for the given dense matrix.
Definition: DMatNormExpr.h:703


lpNorm()

The lpNorm() function computes the general Lp norm of the given dense or sparse vector, where the norm is specified by either a compile time or a runtime argument:

// ... Resizing and initialization
const double norm1 = lpNorm<2>( a ); // Compile time argument
const double norm2 = lpNorm( b, 2.3 ); // Runtime argument
decltype(auto) lpNorm(const DenseMatrix< MT, SO > &dm, ST p)
Computes the Lp norm for the given dense matrix.
Definition: DMatNormExpr.h:735


linfNorm() / maxNorm()

The linfNorm() and maxNorm() functions compute the infinity/maximum norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm1 = linfNorm( a );
const double norm2 = maxNorm( b );
decltype(auto) linfNorm(const DenseMatrix< MT, SO > &dm)
Computes the infinity norm for the given dense matrix.
Definition: DMatNormExpr.h:799
decltype(auto) maxNorm(const DenseMatrix< MT, SO > &dm)
Computes the maximum norm for the given dense matrix.
Definition: DMatNormExpr.h:825


minNorm()

The minNorm() function computes the minimum norm of the given dense or sparse vector:

// ... Resizing and initialization
const double norm = minNorm( b );
decltype(auto) minNorm(const DenseMatrix< MT, SO > &dm)
Computes the minimum norm for the given dense matrix.
Definition: DMatNormExpr.h:851


Scalar Expansion


By means of the uniform() function it is possible to expand a scalar value into a dense, uniform vector. By default, the resulting uniform vector is a column vector, but it is possible to specify the transpose flag explicitly:

int scalar = 5;
// ... Resizing and initialization
// Expansion of 'scalar' to a 3-dimensional uniform column vector
//
// ( 5 )
// ( 5 )
// ( 5 )
//
v = uniform( 3UL, scalar );
v = uniform<columnVector>( 3UL, scalar );
constexpr decltype(auto) uniform(size_t m, size_t n, T &&init)
Creating a uniform matrix.
Definition: UniformMatrix.h:1640


Vector Expansion


Via the expand() function it is possible to convert a dense or sparse vector into a matrix. A column vector is expanded into a column-major matrix, a row vector is expanded into a row-major matrix. As demonstrated by the following examples, expand() can be used with both runtime and compile time parameters:

// Expand the dense column vector ( 1 2 3 ) into a dense 3x5 column-major matrix
//
// ( 1 1 1 1 1 )
// ( 2 2 2 2 2 )
// ( 3 3 3 3 3 )
//
expand( a, 5 ); // Runtime parameter
expand<5>( a ); // Compile time parameter
// Expand the sparse row vector ( 1 0 3 0 5 ) into a sparse 3x5 row-major matrix
//
// ( 1 0 3 0 5 )
// ( 1 0 3 0 5 )
// ( 1 0 3 0 5 )
//
expand( b, 3 ); // Runtime parameter
expand<3>( b ); // Compile time parameter
decltype(auto) expand(const DenseVector< VT, TF > &dv, size_t expansion)
Expansion of the given dense vector.
Definition: DVecExpandExpr.h:746


Vector Repetition


Via the repeat() function it is possible to repeat a dense or sparse vector multiple times to represent a larger vector. Repeating a column vector results in a column vector, repeating a row vector results in a row vector. As demonstrated by the following examples, repeat() can be used with both runtime and compile time parameters:

// ... Resizing and initialization
// Repeating the dense column vector ( 1 0 -2 ) three times results in
//
// ( 1 0 -2 1 0 -2 1 0 -2 )
//
a2 = repeat( a1, 3UL );
a2 = repeat<3UL>( a1 );
// Repeating the sparse row vector ( 0 -1 7 ) three times results in
//
// ( 0 -1 7 0 -1 7 0 -1 7 )
//
b2 = repeat( b1, 3UL );
b2 = repeat<3UL>( b1 );
decltype(auto) repeat(const DenseMatrix< MT, SO > &dm, size_t m, size_t n)
Repeats the given dense matrix.
Definition: DMatRepeatExpr.h:543


Statistic Operations


mean()

The (arithmetic) mean of a dense or sparse vector can be computed via the mean() function. In case of a sparse vector, both the non-zero and zero elements are taken into account. The following example demonstrates the computation of the mean of a dense vector:

blaze::DynamicVector<int> v{ 1, 4, 3, 6, 7 };
const double m = mean( v ); // Results in 4.2 (i.e. 21/5)
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134

In case the size of the given vector is 0, a std::invalid_argument is thrown.


var()

The variance of a dense or sparse vector can be computed via the var() function. In case of a sparse vector, both the non-zero and zero elements are taken into account. The following example demonstrates the computation of the variance of a dense vector:

blaze::DynamicVector<int> v{ 1, 4, 3, 6, 7 };
const double v = var( v ); // Results in 5.7
decltype(auto) var(const DenseMatrix< MT, SO > &dm)
Computes the variance for the given dense matrix.
Definition: DMatVarExpr.h:138

In case the size of the given vector is smaller than 2, a std::invalid_argument is thrown.


stddev()

The standard deviation of a dense or sparse vector can be computed via the stddev() function. In case of a sparse vector, both the non-zero and zero elements are taken into account. The following example demonstrates the computation of the standard deviation of a dense vector:

blaze::DynamicVector<int> v{ 1, 4, 3, 6, 7 };
const double s = stddev( v ); // Results in 2.38747
decltype(auto) stddev(const DenseMatrix< MT, SO > &dm)
Computes the standard deviation for the given dense matrix.
Definition: DMatStdDevExpr.h:83

In case the size of the given vector is smaller than 2, a std::invalid_argument is thrown.


Declaration Operations


declzero()

The declzero() operation can be used to explicitly declare any vector or vector expression as zero vector:

// ... Resizing and initialization
b = declzero( a );
ZeroMatrix< ElementType_t< MT >, SO > declzero(const Matrix< MT, SO > &m)
Declares the given matrix expression m as zero matrix.
Definition: ZeroMatrix.h:1382

Any vector or vector expression that has been declared as zero vector via declzero() will gain all the benefits of a zero vector, which range from reduced runtime checking to a considerable speed-up in computations:

DynamicVector<double> a, b, c;
// ... Resizing and initialization
isZero( declzero( a ) ); // Will always return true without runtime effort
c = declzero( a ) + b; // Declare the left operand of the vector addition as a
// zero vector, i.e. no addition needs to be performed
Warning
The declzero() operation has the semantics of a cast: The caller is completely responsible and the system trusts the given information. Declaring a non-zero vector or vector expression as zero vector via the declzero() operation leads to undefined behavior (which can be violated invariants or wrong computation results)!


Vector Generators


generate()

The generate() function returns a dense vector filled elementwise via the given custom operation. By default, the returned vector is a column vector, but this setting can be changed via the BLAZE_DEFAULT_TRANSPOSE_FLAG switch (see Default Vector Storage). Alternatively it is possible to specify the transpose flag explicitly.
The following example demonstrates the use of the generate() function:

// Generates the homogeneous integer vector ( 2, 2, 2, 2, 2 )
a = generate( 5UL, []( size_t index ){ return 2; } );
// Generates the linearly spaced float vector ( 2.1, 3.2, 4.3, 5.4 )
b = generate( 4UL, []( size_t index ){ return 2.1F + 1.1F*index; } );
// Generates the logarithmically spaced double vector ( 1.0, 10.0, 100.0, 1000.0 )
c = generate<columnVector>( 4UL, []( size_t index ){ return blaze::exp10( 1.0 + 1.0*index ); } );
// Generates the vector of integer vectors ( ( 1, 2 ), ( 2, 3 ), ( 3, 4 ), ( 4, 5 ) )
d = generate<rowVector>( []( size_t index ) { return evaluate( VT{ 1, 2 } + index ); } );
decltype(auto) generate(size_t m, size_t n, OP op)
Generates a new dense matrix filled via the given custom binary operation.
Definition: DMatGenExpr.h:675


linspace()

The linspace() function returns a dense vector filled with linearly spaced elements. By default, the returned vector is a column vector, but this setting can be changed via the BLAZE_DEFAULT_TRANSPOSE_FLAG switch (see Default Vector Storage). Alternatively it is possible to specify the transpose flag explicitly.
The following example demonstrates the use of the linspace() function:

// Generates the linearly spaced integer vector ( 2, 3, 4, 5, 6 )
a = linspace( 5UL, 2, 6 );
// Generates the linearly spaced integer vector ( 6, 5, 4, 3, 2 )
b = linspace<columnVector>( 5UL, 6, 2 );
// Generates the linearly spaced float vector ( 2.1, 3.2, 4.3, 5.4 )
c = linspace<rowVector>( 4UL, 2.1F, 5.4F );
decltype(auto) linspace(size_t size, T start, T end)
Generates a new dense vector filled with linearly spaced elements.
Definition: DVecGenExpr.h:648


logspace()

The logspace() function returns a dense vector filled with logarithmically spaced elements. By default, the returned vector is a column vector, but this setting can be changed via the BLAZE_DEFAULT_TRANSPOSE_FLAG switch (see Default Vector Storage). Alternatively it is possible to specify the transpose flag explicitly.
The following example demonstrates the use of the logspace() function:

// Generates the logarithmically spaced double vector ( 1, 10, 100, 1000 )
a = logspace( 4UL, 0, 3 );
// Generates the logarithmically spaced double vector ( 1000.0, 100.0, 10.0, 1.0 )
b = logspace<rowVector>( 4UL, 3.0, 0.0 );
decltype(auto) logspace(size_t size, T start, T end)
Generates a new dense vector filled with logarithmically spaced elements.
Definition: DVecGenExpr.h:704


uniform()

The uniform() function creates a uniform vector of the given size. By default, the resulting uniform vector is a column vector, but this setting can be changed via the BLAZE_DEFAULT_TRANSPOSE_FLAG switch (see Default Vector Storage). Alternatively it is possible to specify the transpose flag explicitly.
The following example demonstrates the use of the uniform() function:

// Creates the uniform column vector ( 1, 1, 1, 1, 1 )
auto u1 = uniform( 5UL, 1 );
// Creates the uniform column vector ( 1.2, 1.2, 1.2 )
auto u2 = uniform<columnVector>( 3UL, 1.2 );
// Creates the uniform row vector ( 5U, 5U, 5U, 5U )
auto u3 = uniform<rowVector>( 4UL, 5U );


zero()

The zero() function creates a zero vector of the given element type and size. By default, the resulting zero vector is a column vector, but this setting can be changed via the BLAZE_DEFAULT_TRANSPOSE_FLAG switch (see Default Vector Storage). Alternatively it is possible to specify the transpose flag explicitly.
The following example demonstrates the use of the zero() function:

// Creates the zero column vector ( 0, 0, 0, 0, 0 )
auto z1 = zero<int>( 5UL );
// Creates the zero column vector ( 0.0, 0.0, 0.0 )
auto z2 = zero<double,columnVector>( 3UL );
// Creates the zero row vector ( 0U, 0U, 0U, 0U )
auto z3 = zero<unsigned int,rowVector>( 4UL );
constexpr decltype(auto) zero(size_t m, size_t n) noexcept
Creating a zero matrix.
Definition: ZeroMatrix.h:1356


Previous: Vector Types     Next: Matrices