![]() |
Blaze
3.6
|
Efficient implementation of a uniform matrix.The UniformMatrix class template is the representation of an arbitrary sized uniform matrix with elements of arbitrary type. The type of the elements and the storage order of the matrix can be specified via the two template parameters: More...
#include <UniformMatrix.h>
Inherits blaze::Expression< DenseMatrix< UniformMatrix< Type, SO >, SO > >.
Classes | |
struct | Rebind |
Rebind mechanism to obtain a UniformMatrix with different data/element type. More... | |
struct | Resize |
Resize mechanism to obtain a UniformMatrix with different fixed dimensions. More... | |
Public Types | |
using | This = UniformMatrix< Type, SO > |
Type of this UniformMatrix instance. | |
using | BaseType = DenseMatrix< This, SO > |
Base type of this UniformMatrix instance. | |
using | ResultType = This |
Result type for expression template evaluations. | |
using | OppositeType = UniformMatrix< Type,!SO > |
Result type with opposite storage order for expression template evaluations. | |
using | TransposeType = UniformMatrix< Type,!SO > |
Transpose type for expression template evaluations. | |
using | ElementType = Type |
Type of the matrix elements. | |
using | SIMDType = SIMDTrait_t< ElementType > |
SIMD 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 = UniformIterator< const Type, aligned > |
Iterator over non-constant elements. | |
using | ConstIterator = UniformIterator< const Type, aligned > |
Iterator over constant elements. | |
using | MatrixType = MT |
Type of the matrix. | |
Public Member Functions | |
template<typename MT , bool SO2> | |
UniformMatrix< Type, SO > & | operator= (const Matrix< MT, SO2 > &rhs) |
Assignment operator for different matrices. More... | |
template<typename MT , bool SO2> | |
UniformMatrix< Type, SO > & | operator+= (const Matrix< MT, SO2 > &rhs) |
Addition assignment operator for the addition of a matrix ( ![]() | |
template<typename MT , bool SO2> | |
UniformMatrix< Type, SO > & | operator-= (const Matrix< MT, SO2 > &rhs) |
Subtraction assignment operator for the subtraction of a matrix ( ![]() | |
template<typename MT , bool SO2> | |
UniformMatrix< Type, SO > & | operator%= (const Matrix< MT, SO2 > &rhs) |
Schur product assignment operator for the multiplication of a matrix ( ![]() | |
template<typename MT , bool SO2> | |
UniformMatrix< Type, SO > & | operator *= (const Matrix< MT, SO2 > &rhs) |
Multiplication assignment operator for the multiplication of a matrix ( ![]() | |
template<typename Other > | |
UniformMatrix< Type, SO > & | scale (const Other &scalar) |
Scaling of the matrix by the scalar value scalar ( ![]() | |
BLAZE_ALWAYS_INLINE constexpr MatrixType & | operator~ () noexcept |
Conversion operator for non-constant matrices. More... | |
BLAZE_ALWAYS_INLINE constexpr const MatrixType & | operator~ () const noexcept |
Conversion operator for constant matrices. More... | |
Constructors | |
constexpr | UniformMatrix () noexcept |
The default constructor for UniformMatrix. | |
constexpr | UniformMatrix (size_t m, size_t n) |
Constructor for a matrix of size ![]() | |
constexpr | UniformMatrix (size_t m, size_t n, const Type &init) |
Constructor for a homogenous initialization of all ![]() | |
template<typename MT , bool SO2> | |
UniformMatrix (const Matrix< MT, SO2 > &m) | |
Conversion constructor from different matrices. More... | |
UniformMatrix (const UniformMatrix &m)=default | |
UniformMatrix (UniformMatrix &&m)=default | |
Destructor | |
~UniformMatrix ()=default | |
Data access functions | |
constexpr 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... | |
constexpr ConstPointer | data () const noexcept |
Low-level data access to the matrix elements. More... | |
constexpr ConstPointer | data (size_t i) const noexcept |
Low-level data access to the matrix elements of row/column i. More... | |
constexpr ConstIterator | begin (size_t i) const noexcept |
Returns an iterator to the first element of row/column i. More... | |
constexpr ConstIterator | cbegin (size_t i) const noexcept |
Returns an iterator to the first element of row/column i. More... | |
constexpr ConstIterator | end (size_t i) const noexcept |
Returns an iterator just past the last element of row/column i. More... | |
constexpr ConstIterator | cend (size_t i) const noexcept |
Returns an iterator just past the last element of row/column i. More... | |
Assignment operators | |
constexpr UniformMatrix & | operator= (const Type &rhs) |
Homogenous assignment to all matrix elements. More... | |
UniformMatrix & | operator= (const UniformMatrix &)=default |
UniformMatrix & | operator= (UniformMatrix &&)=default |
template<typename MT , bool SO2> | |
UniformMatrix & | operator= (const Matrix< MT, SO2 > &rhs) |
template<typename MT , bool SO2> | |
UniformMatrix & | operator+= (const Matrix< MT, SO2 > &rhs) |
template<typename MT , bool SO2> | |
UniformMatrix & | operator-= (const Matrix< MT, SO2 > &rhs) |
template<typename MT , bool SO2> | |
UniformMatrix & | operator%= (const Matrix< MT, SO2 > &rhs) |
template<typename MT , bool SO2> | |
UniformMatrix & | operator *= (const Matrix< MT, SO2 > &rhs) |
template<typename ST > | |
auto | operator *= (ST rhs) -> EnableIf_t< IsNumeric_v< ST >, UniformMatrix & > |
Multiplication assignment operator for the multiplication between a matrix and a scalar value ( ![]() | |
template<typename ST > | |
auto | operator/= (ST rhs) -> EnableIf_t< IsNumeric_v< ST >, UniformMatrix & > |
Division assignment operator for the division between a matrix and a scalar value ( ![]() | |
Utility functions | |
constexpr size_t | rows () const noexcept |
Returns the current number of rows of the matrix. More... | |
constexpr size_t | columns () const noexcept |
Returns the current number of columns of the matrix. More... | |
constexpr size_t | spacing () const noexcept |
Returns the spacing between the beginning of two rows/columns. More... | |
constexpr size_t | capacity () const noexcept |
Returns the maximum capacity of the matrix. More... | |
constexpr size_t | capacity (size_t i) const noexcept |
Returns the current capacity of the specified row/column. 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/column. More... | |
constexpr void | reset () |
Reset to the default initial values. More... | |
constexpr void | clear () |
Clearing the ![]() | |
constexpr void | resize (size_t m, size_t n, bool preserve=true) |
Changing the size of the matrix. More... | |
constexpr void | extend (size_t m, size_t n, bool preserve=true) |
Extending the size of the matrix. More... | |
constexpr void | swap (UniformMatrix &m) noexcept |
Swapping the contents of two matrices. More... | |
Numeric functions | |
constexpr UniformMatrix & | transpose () |
In-place transpose of the matrix. More... | |
constexpr UniformMatrix & | ctranspose () |
In-place conjugate transpose of the matrix. More... | |
template<typename Other > | |
UniformMatrix & | scale (const Other &scalar) |
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... | |
bool | isAligned () const noexcept |
Returns whether the matrix is properly aligned in memory. More... | |
bool | canSMPAssign () const noexcept |
Returns whether the matrix can be used in SMP assignments. More... | |
BLAZE_ALWAYS_INLINE SIMDType | load (size_t i, size_t j) const noexcept |
Load of a SIMD element of the matrix. More... | |
BLAZE_ALWAYS_INLINE SIMDType | loada (size_t i, size_t j) const noexcept |
Aligned load of a SIMD element of the matrix. More... | |
BLAZE_ALWAYS_INLINE SIMDType | loadu (size_t i, size_t j) const noexcept |
Unaligned load of a SIMD element of the matrix. More... | |
Static Public Attributes | |
static constexpr bool | simdEnabled = IsVectorizable_v<Type> |
Compilation flag for SIMD optimization. More... | |
static constexpr bool | smpAssignable = !IsSMPAssignable_v<Type> |
Compilation flag for SMP assignments. More... | |
static constexpr bool | storageOrder = SO |
Storage order of the matrix. | |
Private Attributes | |
Member variables | |
size_t | m_ |
The current number of rows of the matrix. | |
size_t | n_ |
The current number of columns of the matrix. | |
Type | value_ |
The value of all elements of the uniform matrix. | |
Static Private Attributes | |
static constexpr size_t | SIMDSIZE = SIMDTrait<ElementType>::size |
The number of elements packed within a single SIMD element. | |
Efficient implementation of a uniform matrix.
The UniformMatrix class template is the representation of an arbitrary sized uniform matrix with elements of arbitrary type. The type of the elements and the storage order of the matrix can be specified via the two template parameters:
Depending on the storage order, the matrix elements are either stored in a row-wise fashion or in a column-wise fashion. Given the 2x3 matrix
in case of row-major order the elements are stored in the order
In case of column-major order the elements are stored in the order
The use of UniformMatrix is very natural and intuitive. 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 UniformMatrix:
|
inlineexplicit |
Constructor for a matrix of size .
m | The number of rows of the matrix. |
n | The number of columns of the matrix. |
|
inlineexplicit |
Constructor for a homogenous initialization of all matrix elements.
m | The number of rows of the matrix. |
n | The number of columns of the matrix. |
init | The initial value of the matrix elements. |
All matrix elements are initialized with the specified value.
|
inline |
Conversion constructor from different matrices.
m | Matrix to be copied. |
std::invalid_argument | Invalid setup of uniform vector. |
The matrix is sized according to the given uniform matrix and initialized as a copy of this matrix.
|
inline |
Checked access to the matrix elements.
i | Access index for the row. The index has to be in the range ![]() |
j | Access index for the column. The index has to be in the range ![]() |
std::out_of_range | Invalid matrix access index. |
In contrast to the subscript operator this function always performs a check of the given access indices.
|
inlinenoexcept |
Returns an iterator to the first element of row/column i.
i | The row/column index. |
This function returns a row/column iterator to the first element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first element of column i.
|
inlinenoexcept |
Returns whether the matrix can alias with the given address alias.
alias | The alias to be checked. |
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.
|
inlinenoexcept |
Returns whether the matrix can be used in SMP assignments.
This function returns whether the matrix can be used in SMP assignments. In contrast to the smpAssignable member enumeration, which is based solely on compile time information, this function additionally provides runtime information (as for instance the current number of rows and/or columns of the matrix).
|
inlinenoexcept |
Returns the maximum capacity of the matrix.
|
inlinenoexcept |
Returns the current capacity of the specified row/column.
i | The index of the row/column. |
This function returns the current capacity of the specified row/column. In case the storage order is set to rowMajor the function returns the capacity of row i, in case the storage flag is set to columnMajor the function returns the capacity of column i.
|
inlinenoexcept |
Returns an iterator to the first element of row/column i.
i | The row/column index. |
This function returns a row/column iterator to the first element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first element of column i.
|
inlinenoexcept |
Returns an iterator just past the last element of row/column i.
i | The row/column index. |
This function returns an row/column iterator just past the last element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last element of column i.
|
inline |
|
inlinenoexcept |
Returns the current number of columns of the matrix.
|
inline |
In-place conjugate transpose of the matrix.
|
inlinenoexcept |
Low-level data access to the matrix elements.
This function returns a pointer to the internal storage of the uniform matrix. Note that you can NOT assume that all matrix elements lie adjacent to each other! The uniform 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.
|
inlinenoexcept |
Low-level data access to the matrix elements of row/column i.
i | The row/column index. |
This function returns a pointer to the internal storage for the elements in row/column i.
|
inlinenoexcept |
Returns an iterator just past the last element of row/column i.
i | The row/column index. |
This function returns an row/column iterator just past the last element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last element of column i.
|
inline |
Extending the size of the matrix.
m | Number of additional rows. |
n | Number of additional columns. |
preserve | true if the old values of the matrix should be preserved, false if not. |
This function increases the matrix size by m rows and n columns. Note that this function potentially changes all matrix elements. In order to preserve the old matrix values, the preserve flag can be set to true.
|
inlinenoexcept |
Returns whether the matrix is aliased with the given address alias.
alias | The alias to be checked. |
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.
|
inlinenoexcept |
Returns whether the matrix is properly aligned in memory.
This function returns whether the matrix is guaranteed to be properly aligned in memory, i.e. whether the beginning and the end of each row/column of the matrix are guaranteed to conform to the alignment restrictions of the element type Type.
|
noexcept |
Load of a SIMD element of the matrix.
i | Access index for the row. The index has to be in the range [0..M-1]. |
j | Access index for the column. The index has to be in the range [0..N-1]. |
This function performs a load of a specific SIMD element of the dense matrix. The row index must be smaller than the number of rows and the column index must be smaller then the number of columns. Additionally, the column index (in case of a row-major matrix) or the row index (in case of a column-major matrix) must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
noexcept |
Aligned load of a SIMD element of the matrix.
i | Access index for the row. The index has to be in the range [0..M-1]. |
j | Access index for the column. The index has to be in the range [0..N-1]. |
This function performs an aligned load of a specific SIMD element of the dense matrix. The row index must be smaller than the number of rows and the column index must be smaller than the number of columns. Additionally, the column index (in case of a row-major matrix) or the row index (in case of a column-major matrix) must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
noexcept |
Unaligned load of a SIMD element of the matrix.
i | Access index for the row. The index has to be in the range [0..M-1]. |
j | Access index for the column. The index has to be in the range [0..N-1]. |
This function performs an unaligned load of a specific SIMD element of the dense matrix. The row index must be smaller than the number of rows and the column index must be smaller than the number of columns. Additionally, the column index (in case of a row-major matrix) or the row index (in case of a column-major matrix) must be a multiple of the number of values inside the SIMD element. This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors.
|
inline |
Returns the total number of non-zero elements in the matrix.
|
inline |
Returns the number of non-zero elements in the specified row/column.
i | The index of the row/column. |
This function returns the current number of non-zero elements in the specified row/column. In case the storage order is set to rowMajor the function returns the number of non-zero elements in row i, in case the storage flag is set to columnMajor the function returns the number of non-zero elements in column i.
|
inline |
Multiplication assignment operator for the multiplication between a matrix and a scalar value ( ).
scalar | The right-hand side scalar value for the multiplication. |
|
inline |
Multiplication assignment operator for the multiplication of a matrix ( ).
rhs | The right-hand side matrix for the multiplication. |
std::invalid_argument | Matrix sizes do not match. |
In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.
|
inline |
Schur product assignment operator for the multiplication of a matrix ( ).
rhs | The right-hand side matrix for the Schur product. |
std::invalid_argument | Matrix sizes do not match. |
In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.
|
inlinenoexcept |
2D-access to the matrix elements.
i | Access index for the row. The index has to be in the range ![]() |
j | Access index for the column. The index has to be in the range ![]() |
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.
|
inline |
Addition assignment operator for the addition of a matrix ( ).
rhs | The right-hand side matrix to be added to the matrix. |
std::invalid_argument | Matrix sizes do not match. |
In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.
|
inline |
Subtraction assignment operator for the subtraction of a matrix ( ).
rhs | The right-hand side matrix to be subtracted from the matrix. |
std::invalid_argument | Matrix sizes do not match. |
In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.
|
inline |
Division assignment operator for the division between a matrix and a scalar value ( ).
scalar | The right-hand side scalar value for the division. |
|
inline |
Homogenous assignment to all matrix elements.
rhs | Scalar value to be assigned to all matrix elements. |
|
inline |
Assignment operator for different matrices.
rhs | Matrix to be copied. |
The matrix is resized according to the given matrix and initialized as a copy of this matrix.
|
inlinenoexceptinherited |
Conversion operator for non-constant matrices.
|
inlinenoexceptinherited |
Conversion operator for constant matrices.
|
inline |
Reset to the default initial values.
void constexpr blaze::UniformMatrix< Type, SO >::resize | ( | size_t | m, |
size_t | n, | ||
bool | preserve = true |
||
) |
Changing the size of the matrix.
m | The new number of rows of the matrix. |
n | The new number of columns of the matrix. |
preserve | true if the old values of the matrix should be preserved, false if not. |
This function resizes the matrix using the given size to . Note that this function may invalidate all existing views (submatrices, rows, columns, ...) on the matrix if it is used to shrink the matrix. Additionally, the resize operation potentially changes all matrix elements. In order to preserve the old matrix values, the preserve flag can be set to true.
|
inlinenoexcept |
Returns the current number of rows of the matrix.
|
inline |
Scaling of the matrix by the scalar value scalar ( ).
scalar | The scalar value for the matrix scaling. |
This function scales the matrix by applying the given scalar value scalar to each element of the matrix. For built-in and complex
data types it has the same effect as using the multiplication assignment operator:
|
inlinenoexcept |
Returns the spacing between the beginning of two rows/columns.
This function returns the spacing between the beginning of two rows/columns, i.e. the total number of elements of a row/column. In case the storage order is set to rowMajor the function returns the spacing between two rows, in case the storage flag is set to columnMajor the function returns the spacing between two columns.
|
inlinenoexcept |
Swapping the contents of two matrices.
m | The matrix to be swapped. |
|
inline |
In-place transpose of the matrix.
|
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.
|
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).