Blaze  3.6
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | List of all members
blaze::InitializerMatrix< Type > Class Template Reference

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 of the matrix can be specified via the single template parameters: More...

#include <InitializerMatrix.h>

Inherits blaze::DenseMatrix< InitializerMatrix< Type >, 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 >
 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 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 = MT
 Type of the matrix.
 

Public Member Functions

BLAZE_ALWAYS_INLINE constexpr MatrixTypeoperator~ () noexcept
 Conversion operator for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr const MatrixTypeoperator~ () const noexcept
 Conversion operator for constant matrices. More...
 
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...
 
Expression template evaluation functions
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...
 

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 = SO
 Storage order of the matrix.
 

Private Types

using ListType = initializer_list< initializer_list< Type > >
 Type of the represented initializer list.
 

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>
class blaze::InitializerMatrix< Type >

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 of the matrix can be specified via the single template parameters:

template< typename Type >

Type specifies the type of the matrix elements. InitializerMatrix can be used with any non-cv-qualified, non-reference, non-pointer element type.

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

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 } }

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

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:

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

Constructor & Destructor Documentation

◆ InitializerMatrix() [1/2]

template<typename Type >
blaze::InitializerMatrix< Type >::InitializerMatrix ( initializer_list< initializer_list< Type > >  list)
inlineexplicitnoexcept

Constructor for InitializerMatrix.

Parameters
listThe initializer list represented by the matrix.

◆ InitializerMatrix() [2/2]

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

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 >
InitializerMatrix< Type >::ConstReference blaze::InitializerMatrix< Type >::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 >
InitializerMatrix< Type >::ConstIterator blaze::InitializerMatrix< Type >::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 >
template<typename Other >
bool blaze::InitializerMatrix< Type >::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 >
size_t blaze::InitializerMatrix< Type >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the matrix.

Returns
The capacity of the matrix.

◆ capacity() [2/2]

template<typename Type >
size_t blaze::InitializerMatrix< Type >::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 >
InitializerMatrix< Type >::ConstIterator blaze::InitializerMatrix< Type >::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 >
InitializerMatrix< Type >::ConstIterator blaze::InitializerMatrix< Type >::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 >
size_t blaze::InitializerMatrix< Type >::columns ( ) const
inlinenoexcept

Returns the current number of columns of the matrix.

Returns
The number of columns of the matrix.

◆ data() [1/2]

template<typename Type >
InitializerMatrix< Type >::ConstPointer blaze::InitializerMatrix< Type >::data ( ) const
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 >
InitializerMatrix< Type >::ConstPointer blaze::InitializerMatrix< Type >::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 >
InitializerMatrix< Type >::ConstIterator blaze::InitializerMatrix< Type >::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 >
template<typename Other >
bool blaze::InitializerMatrix< Type >::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 >
size_t blaze::InitializerMatrix< Type >::nonZeros ( ) const
inline

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

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

◆ nonZeros() [2/2]

template<typename Type >
size_t blaze::InitializerMatrix< Type >::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.

◆ operator()()

template<typename Type >
InitializerMatrix< Type >::ConstReference blaze::InitializerMatrix< Type >::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]

template<typename MT, bool SO>
BLAZE_ALWAYS_INLINE constexpr MatrixType& blaze::Matrix< MT, SO >::operator~ ( )
inlinenoexceptinherited

Conversion operator for non-constant matrices.

Returns
Reference of the actual type of the matrix.

◆ operator~() [2/2]

template<typename MT, bool SO>
BLAZE_ALWAYS_INLINE constexpr const MatrixType& blaze::Matrix< MT, SO >::operator~ ( ) const
inlinenoexceptinherited

Conversion operator for constant matrices.

Returns
Constant reference of the actual type of the matrix.

◆ rows()

template<typename Type >
size_t blaze::InitializerMatrix< Type >::rows ( ) const
inlinenoexcept

Returns the current number of rows of the matrix.

Returns
The number of rows of the matrix.

◆ spacing()

template<typename Type >
size_t blaze::InitializerMatrix< Type >::spacing ( ) const
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 >
void blaze::InitializerMatrix< Type >::swap ( InitializerMatrix< Type > &  m)
inlinenoexcept

Swapping the contents of two matrices.

Parameters
mThe matrix to be swapped.
Returns
void

Member Data Documentation

◆ list_

template<typename Type>
ListType blaze::InitializerMatrix< Type >::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>
constexpr bool blaze::InitializerMatrix< Type >::simdEnabled = false
static

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>
constexpr bool blaze::InitializerMatrix< Type >::smpAssignable = false
static

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 file: