Blaze 3.9
Classes | Public Types | Static Public Attributes | List of all members
blaze::InitializerMatrix< Type, Tag > Class Template Reference

Dense matrix representation of an initializer list. More...

#include <InitializerMatrix.h>

Inherits blaze::DenseMatrix< InitializerMatrix< Type, Tag >, false >.

Classes

struct  Rebind
 Rebind mechanism to obtain a InitializerMatrix with different data/element type. More...
 
struct  Resize
 Resize mechanism to obtain a InitializerMatrix with different fixed dimensions. More...
 

Public Types

using This = InitializerMatrix< Type, Tag >
 Type of this InitializerMatrix instance.
 
using BaseType = DenseMatrix< This, false >
 Base type of this InitializerMatrix instance.
 
using ResultType = DynamicMatrix< Type, false >
 Result type for expression template evaluations.
 
using OppositeType = DynamicMatrix< Type, true >
 Result type with opposite storage order for expression template evaluations.
 
using TransposeType = DynamicMatrix< Type, true >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the matrix elements.
 
using TagType = Tag
 Tag type of this InitializerVector instance.
 
using ReturnType = const Type &
 Return type for expression template evaluations.
 
using CompositeType = const This &
 Data type for composite expression templates.
 
using Reference = const Type &
 Reference to a non-constant matrix value.
 
using ConstReference = const Type &
 Reference to a constant matrix value.
 
using Pointer = const Type *
 Pointer to a non-constant matrix value.
 
using ConstPointer = const Type *
 Pointer to a constant matrix value.
 
using Iterator = InitializerIterator< Type >
 Iterator over non-constant elements.
 
using ConstIterator = InitializerIterator< Type >
 Iterator over constant elements.
 
using MatrixType = InitializerMatrix< Type, Tag >
 Type of the matrix.
 

Public Member Functions

Constructors
 InitializerMatrix (initializer_list< initializer_list< Type > > list) noexcept
 Constructor for InitializerMatrix. More...
 
 InitializerMatrix (initializer_list< initializer_list< Type > > list, size_t n)
 Constructor for InitializerMatrix. More...
 
 InitializerMatrix (const InitializerMatrix &)=default
 
Destructor
 ~InitializerMatrix ()=default
 
Data access functions
ConstReference operator() (size_t i, size_t j) const noexcept
 2D-access to the matrix elements. More...
 
ConstReference at (size_t i, size_t j) const
 Checked access to the matrix elements. More...
 
ConstPointer data () const noexcept
 Low-level data access to the matrix elements. More...
 
ConstPointer data (size_t i) const noexcept
 Low-level data access to the matrix elements of row i. More...
 
ConstIterator begin (size_t i) const noexcept
 Returns an iterator to the first element of row i. More...
 
ConstIterator cbegin (size_t i) const noexcept
 Returns an iterator to the first element of row i. More...
 
ConstIterator end (size_t i) const noexcept
 Returns an iterator just past the last element of row i. More...
 
ConstIterator cend (size_t i) const noexcept
 Returns an iterator just past the last element of row i. More...
 
Assignment operators
InitializerMatrixoperator= (const InitializerMatrix &)=delete
 
Utility functions
size_t rows () const noexcept
 Returns the current number of rows of the matrix. More...
 
size_t columns () const noexcept
 Returns the current number of columns of the matrix. More...
 
size_t spacing () const noexcept
 Returns the spacing between the beginning of two rows. More...
 
size_t capacity () const noexcept
 Returns the maximum capacity of the matrix. More...
 
size_t capacity (size_t i) const noexcept
 Returns the current capacity of the specified row. More...
 
size_t nonZeros () const
 Returns the total number of non-zero elements in the matrix. More...
 
size_t nonZeros (size_t i) const
 Returns the number of non-zero elements in the specified row. More...
 
void swap (InitializerMatrix &m) noexcept
 Swapping the contents of two matrices. More...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr InitializerMatrix< Type, Tag > & operator~ () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr const InitializerMatrix< Type, Tag > & operator~ () const noexcept
 CRTP-based conversion operation for constant matrices. More...
 
constexpr InitializerMatrix< Type, Tag > & operator* () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
constexpr const InitializerMatrix< Type, Tag > & operator* () const noexcept
 CRTP-based conversion operation for constant matrices. More...
 

Static Public Attributes

static constexpr bool simdEnabled = false
 Compilation flag for SIMD optimization. More...
 
static constexpr bool smpAssignable = false
 Compilation flag for SMP assignments. More...
 
static constexpr bool storageOrder
 Storage order of the matrix.
 

Expression template evaluation functions

using ListType = initializer_list< initializer_list< Type > >
 Type of the represented initializer list.
 
template<typename Other >
bool canAlias (const Other *alias) const noexcept
 Returns whether the matrix can alias with the given address alias. More...
 
template<typename Other >
bool isAliased (const Other *alias) const noexcept
 Returns whether the matrix is aliased with the given address alias. More...
 

Member variables

size_t m_
 The current number of rows of the matrix.
 
size_t n_
 The current number of columns of the matrix.
 
ListType list_
 The initializer list represented by the matrix. More...
 
static const Type zero_ {}
 Neutral element for accesses to zero elements.
 

Detailed Description

template<typename Type, typename Tag>
class blaze::InitializerMatrix< Type, Tag >

Dense matrix representation of an initializer list.

The InitializerMatrix class template is a dense matrix representation of an (extended) initializer list of arbitrary type. The type of the elements and the group tag of the matrix can be specified via the two template parameters:

namespace blaze {
template< typename Type, typename Tag >
} // namespace blaze
InitializerMatrix(initializer_list< initializer_list< Type > > list) noexcept
Constructor for InitializerMatrix.
Definition: InitializerMatrix.h:370

On construction, an InitializerMatrix is immediately bound to an initializer list:

const blaze::initializer_list< initializer_list<int> > list = { { 2, 6, -1 },
{ 3, 5 } };
blaze::InitializerMatrix<int> A( list ); // Representation of the initializer list as dense matrix
Dense matrix representation of an initializer list.
Definition: InitializerMatrix.h:185

It is possible to only represent an extended initializer list by explicitly specifying the number of columns:

const initializer_list< initializer_list<int> > list = { { 2, 6, -1 },
{ 3, 5 } };
blaze::InitializerVector<int> B( list, 3UL ); // Representation of the original initializer list
blaze::InitializerVector<int> C( list, 4UL ); // Representing the initializer list { { 2, 6, -1, 0 }, { 3, 5, 0, 0 } }
Dense vector representation of an initializer list.
Definition: InitializerVector.h:182
Initializer list type of the Blaze library.

Since an InitializerMatrix represents a specific initializer list, its lifetime is bound to the lifetime of the according initializer list. When the initializer list goes out of scope access to the initializer list via an InitializerMatrix results in undefined behavior:

blaze::InitializerMatrix<int> D{ { 1, 2, 3 }, { 4, 5, 6 } }; // Undefined behavior!
blaze::InitializerMatrix<int> E( { { 0, 3, 2 }, { -1, 1 } }, 3UL ); // Undefined behavior!

Also, an InitializerMatrix can only be used on the right of an assignment as its elements are considered to be immutable. The following example gives an impression on the usage of an InitializerMatrix:

const blaze::initializer_list< initializer_list<int> > list = { { 2, 6, -1 },
{ 3, 5 } };
blaze::InitializerMatrix<int> F( list ); // Representation of the initializer list as dense matrix
G = F; // Initialize vector G via vector F
F = G; // Compilation error! Cannot assign to an initializer matrix
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242

An initializer matrix can be used as operand in arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of row-major and column-major dense and sparse matrices with fitting element types. The following example gives an impression of the use of InitializerMatrix:

using blaze::initializer_list;
const blaze::initializer_list< initializer_list<double> > list = { { 1.0, 2.0, 3.0 },
{ 4.0, 5.0, 6.0 } };
InitializerMatrix<double> A( list );
DynamicMatrix<float,columnMajor> B( 2, 3 ); // Default constructed column-major single precision 2x3 matrix
B(0,0) = 1.0; B(0,1) = 3.0; B(0,2) = 5.0; // Initialization of the first row
B(1,0) = 2.0; B(1,1) = 4.0; B(1,2) = 6.0; // Initialization of the second row
CompressedMatrix<float> C( 2, 3 ); // Empty row-major sparse single precision matrix
DynamicMatrix<float> D( 3, 2, 4.0F ); // Directly, homogeneously initialized single precision 3x2 matrix
DynamicMatrix<double,rowMajor> E( A ); // Creation of a new row-major matrix as a copy of A
DynamicMatrix<double,columnMajor> F; // Creation of a default column-major matrix
E = A + B; // Matrix addition and assignment to a row-major matrix
F = A - C; // Matrix subtraction and assignment to a column-major matrix
F = A * D; // Matrix multiplication between two matrices of different element types
E = 2.0 * B; // Scaling of matrix B
F = D * 2.0; // Scaling of matrix D
E += A - B; // Addition assignment
E -= A + C; // Subtraction assignment
F *= A * D; // Multiplication assignment
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99

Constructor & Destructor Documentation

◆ InitializerMatrix() [1/2]

template<typename Type , typename Tag >
blaze::InitializerMatrix< Type, Tag >::InitializerMatrix ( initializer_list< initializer_list< Type > >  list)
inlinenoexcept

Constructor for InitializerMatrix.

Parameters
listThe initializer list represented by the matrix.

◆ InitializerMatrix() [2/2]

template<typename Type , typename Tag >
blaze::InitializerMatrix< Type, Tag >::InitializerMatrix ( initializer_list< initializer_list< Type > >  list,
size_t  n 
)
inline

Constructor for InitializerMatrix.

Parameters
listThe initializer list represented by the matrix.
nThe number of columns of the matrix.
Exceptions
std::invalid_argumentInvalid initializer list dimension.

Member Function Documentation

◆ at()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstReference blaze::InitializerMatrix< Type, Tag >::at ( size_t  i,
size_t  j 
) const
inline

Checked access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid matrix access index.

In contrast to the subscript operator this function always performs a check of the given access indices.

◆ begin()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstIterator blaze::InitializerMatrix< Type, Tag >::begin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first element of row i.

Parameters
iThe row index.
Returns
Iterator to the first element of row i.

This function returns a row iterator to the first element of row i.

◆ canAlias()

template<typename Type , typename Tag >
template<typename Other >
bool blaze::InitializerMatrix< Type, Tag >::canAlias ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix can alias with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address can alias with the matrix. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.

◆ capacity() [1/2]

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::capacity
inlinenoexcept

Returns the maximum capacity of the matrix.

Returns
The capacity of the matrix.

◆ capacity() [2/2]

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::capacity ( size_t  i) const
inlinenoexcept

Returns the current capacity of the specified row.

Parameters
iThe index of the row.
Returns
The current capacity of row i.

This function returns the current capacity of the specified row.

◆ cbegin()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstIterator blaze::InitializerMatrix< Type, Tag >::cbegin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first element of row i.

Parameters
iThe row index.
Returns
Iterator to the first element of row i.

This function returns a row iterator to the first element of row i

◆ cend()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstIterator blaze::InitializerMatrix< Type, Tag >::cend ( size_t  i) const
inlinenoexcept

Returns an iterator just past the last element of row i.

Parameters
iThe row index.
Returns
Iterator just past the last element of row i.

This function returns an row iterator just past the last element of row i.

◆ columns()

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::columns
inlinenoexcept

Returns the current number of columns of the matrix.

Returns
The number of columns of the matrix.

◆ data() [1/2]

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstPointer blaze::InitializerMatrix< Type, Tag >::data
inlinenoexcept

Low-level data access to the matrix elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the dynamic matrix. Note that you can NOT assume that all matrix elements lie adjacent to each other! The dynamic matrix may use techniques such as padding to improve the alignment of the data. Whereas the number of elements within a row/column are given by the rows() and columns() member functions, respectively, the total number of elements including padding is given by the spacing() member function.

◆ data() [2/2]

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstPointer blaze::InitializerMatrix< Type, Tag >::data ( size_t  i) const
inlinenoexcept

Low-level data access to the matrix elements of row i.

Parameters
iThe row index.
Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage for the elements in row i.

◆ end()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstIterator blaze::InitializerMatrix< Type, Tag >::end ( size_t  i) const
inlinenoexcept

Returns an iterator just past the last element of row i.

Parameters
iThe row index.
Returns
Iterator just past the last element of row i.

This function returns an row iterator just past the last element of row i.

◆ isAliased()

template<typename Type , typename Tag >
template<typename Other >
bool blaze::InitializerMatrix< Type, Tag >::isAliased ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix is aliased with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address is aliased with the matrix. In contrast to the canAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.

◆ nonZeros() [1/2]

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::nonZeros
inline

Returns the total number of non-zero elements in the matrix.

Returns
The number of non-zero elements in the dense matrix.

This function returns the number of non-zero elements in the matrix (i.e. the elements that compare unequal to their default value). Note that the number of non-zero elements is always less than or equal to the total number of elements in the matrix.

◆ nonZeros() [2/2]

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::nonZeros ( size_t  i) const
inline

Returns the number of non-zero elements in the specified row.

Parameters
iThe index of the row.
Returns
The number of non-zero elements of row i.

This function returns the current number of non-zero elements in the specified row (i.e. the elements that compare unequal to their default value).

◆ operator()()

template<typename Type , typename Tag >
InitializerMatrix< Type, Tag >::ConstReference blaze::InitializerMatrix< Type, Tag >::operator() ( size_t  i,
size_t  j 
) const
inlinenoexcept

2D-access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access indices.

◆ operator*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const InitializerMatrix< Type, Tag > & blaze::Matrix< InitializerMatrix< Type, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator*() [2/2]

BLAZE_ALWAYS_INLINE constexpr InitializerMatrix< Type, Tag > & blaze::Matrix< InitializerMatrix< Type, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE constexpr const InitializerMatrix< Type, Tag > & blaze::Matrix< InitializerMatrix< Type, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator~() [2/2]

BLAZE_ALWAYS_INLINE constexpr InitializerMatrix< Type, Tag > & blaze::Matrix< InitializerMatrix< Type, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ rows()

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::rows
inlinenoexcept

Returns the current number of rows of the matrix.

Returns
The number of rows of the matrix.

◆ spacing()

template<typename Type , typename Tag >
size_t blaze::InitializerMatrix< Type, Tag >::spacing
inlinenoexcept

Returns the spacing between the beginning of two rows.

Returns
The spacing between the beginning of two rows.

This function returns the spacing between the beginning of two rows, i.e. the total number of elements of a row.

◆ swap()

template<typename Type , typename Tag >
void blaze::InitializerMatrix< Type, Tag >::swap ( InitializerMatrix< Type, Tag > &  m)
inlinenoexcept

Swapping the contents of two matrices.

Parameters
mThe matrix to be swapped.
Returns
void

Member Data Documentation

◆ list_

template<typename Type , typename Tag >
ListType blaze::InitializerMatrix< Type, Tag >::list_
private

The initializer list represented by the matrix.

Access to the matrix elements is gained via the function call operator. The memory layout of the elements is

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

.

◆ simdEnabled

template<typename Type , typename Tag >
constexpr bool blaze::InitializerMatrix< Type, Tag >::simdEnabled = false
staticconstexpr

Compilation flag for SIMD optimization.

The simdEnabled compilation flag indicates whether expressions the matrix is involved in can be optimized via SIMD operations. In case the element type of the matrix is a vectorizable data type, the simdEnabled compilation flag is set to true, otherwise it is set to false.

◆ smpAssignable

template<typename Type , typename Tag >
constexpr bool blaze::InitializerMatrix< Type, Tag >::smpAssignable = false
staticconstexpr

Compilation flag for SMP assignments.

The smpAssignable compilation flag indicates whether the matrix can be used in SMP (shared memory parallel) assignments (both on the left-hand and right-hand side of the assignment).


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