Classes | Public Types | Public Member Functions | Private Types | List of all members
blaze::CustomMatrix< Type, AF, PF, SO > Class Template Reference

Efficient implementation of a customizable matrix.The CustomMatrix class template provides the functionality to represent an external array of elements of arbitrary type and a fixed size as a native Blaze dense matrix data structure. Thus in contrast to all other dense matrix types a custom matrix does not perform any kind of memory allocation by itself, but it is provided with an existing array of element during construction. A custom matrix can therefore be considered an alias to the existing array. More...

#include <CustomMatrix.h>

Inherits blaze::DenseMatrix< CustomMatrix< Type, AF, PF, SO >, SO >.

Classes

struct  Rebind
 Rebind mechanism to obtain a CustomMatrix with different data/element type. More...
 

Public Types

enum  : bool { simdEnabled = IsVectorizable<Type>::value }
 Compilation flag for SIMD optimization. More...
 
enum  : bool { smpAssignable = !IsSMPAssignable<Type>::value }
 Compilation flag for SMP assignments. More...
 
typedef CustomMatrix< Type, AF, PF, SO > This
 Type of this CustomMatrix instance.
 
typedef DenseMatrix< This, SO > BaseType
 Base type of this CustomMatrix instance.
 
typedef DynamicMatrix< Type, SO > ResultType
 Result type for expression template evaluations.
 
typedef DynamicMatrix< Type,!SO > OppositeType
 Result type with opposite storage order for expression template evaluations.
 
typedef DynamicMatrix< Type,!SO > TransposeType
 Transpose type for expression template evaluations.
 
typedef Type ElementType
 Type of the matrix elements.
 
typedef SIMDTrait_< ElementTypeSIMDType
 SIMD type of the matrix elements.
 
typedef const Type & ReturnType
 Return type for expression template evaluations.
 
typedef const ThisCompositeType
 Data type for composite expression templates.
 
typedef Type & Reference
 Reference to a non-constant matrix value.
 
typedef const Type & ConstReference
 Reference to a constant matrix value.
 
typedef Type * Pointer
 Pointer to a non-constant matrix value.
 
typedef const Type * ConstPointer
 Pointer to a constant matrix value.
 
typedef DenseIterator< Type, AF > Iterator
 Iterator over non-constant elements.
 
typedef DenseIterator< const Type, AF > ConstIterator
 Iterator over constant elements.
 
typedef MT MatrixType
 Type of the matrix.
 

Public Member Functions

template<typename Other , size_t M, size_t N>
CustomMatrix< Type, AF, PF, SO > & operator= (const Other(&array)[M][N])
 Array assignment to all matrix elements. More...
 
template<typename MT , bool SO2>
CustomMatrix< Type, AF, PF, SO > & operator= (const Matrix< MT, SO2 > &rhs)
 Assignment operator for different matrices. More...
 
template<typename MT , bool SO2>
CustomMatrix< Type, AF, PF, SO > & operator+= (const Matrix< MT, SO2 > &rhs)
 Addition assignment operator for the addition of a matrix ( $ A+=B $). More...
 
template<typename MT , bool SO2>
CustomMatrix< Type, AF, PF, SO > & operator-= (const Matrix< MT, SO2 > &rhs)
 Subtraction assignment operator for the subtraction of a matrix ( $ A-=B $). More...
 
template<typename MT , bool SO2>
CustomMatrix< Type, AF, PF, SO > & operator*= (const Matrix< MT, SO2 > &rhs)
 Multiplication assignment operator for the multiplication of a matrix ( $ A*=B $). More...
 
template<typename Other >
EnableIf_< IsNumeric< Other >, CustomMatrix< Type, AF, PF, SO > > & operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a matrix and a scalar value ( $ A*=s $). More...
 
template<typename Other >
EnableIf_< IsNumeric< Other >, CustomMatrix< Type, AF, PF, SO > > & operator/= (Other rhs)
 Division assignment operator for the division of a matrix by a scalar value ( $ A/=s $). More...
 
template<typename Other >
CustomMatrix< Type, AF, PF, SO > & scale (const Other &scalar)
 Scaling of the matrix by the scalar value scalar ( $ A=B*s $). More...
 
template<typename MT >
DisableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedAssign< MT > > assign (const DenseMatrix< MT, SO > &rhs)
 Default implementation of the assignment of a row-major dense matrix. More...
 
template<typename MT >
EnableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedAssign< MT > > assign (const DenseMatrix< MT, SO > &rhs)
 SIMD optimized implementation of the assignment of a row-major dense matrix. More...
 
template<typename MT >
DisableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedAddAssign< MT > > addAssign (const DenseMatrix< MT, SO > &rhs)
 Default implementation of the addition assignment of a row-major dense matrix. More...
 
template<typename MT >
EnableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedAddAssign< MT > > addAssign (const DenseMatrix< MT, SO > &rhs)
 SIMD optimized implementation of the addition assignment of a row-major dense matrix. More...
 
template<typename MT >
DisableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedSubAssign< MT > > subAssign (const DenseMatrix< MT, SO > &rhs)
 Default implementation of the subtraction assignment of a row-major dense matrix. More...
 
template<typename MT >
EnableIf_< typename CustomMatrix< Type, AF, PF, SO >::BLAZE_TEMPLATE VectorizedSubAssign< MT > > subAssign (const DenseMatrix< MT, SO > &rhs)
 SIMD optimized implementation of the subtraction assignment of a row-major dense matrix. More...
 
BLAZE_ALWAYS_INLINE MatrixTypeoperator~ () noexcept
 Conversion operator for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE const MatrixTypeoperator~ () const noexcept
 Conversion operator for constant matrices. More...
 
Constructors
 CustomMatrix ()
 The default constructor for CustomMatrix.
 
 CustomMatrix (Type *ptr, size_t m, size_t n)
 Constructor for a matrix of size $ m \times n $. More...
 
 CustomMatrix (Type *ptr, size_t m, size_t n, size_t nn)
 Constructor for a matrix of size $ m \times n $. More...
 
template<typename Deleter , typename = EnableIf_< IsClass<Deleter> >>
 CustomMatrix (Type *ptr, size_t m, size_t n, Deleter D)
 Constructor for a matrix of size $ m \times n $. More...
 
template<typename Deleter >
 CustomMatrix (Type *ptr, size_t m, size_t n, size_t nn, Deleter D)
 Constructor for a matrix of size $ m \times n $. More...
 
 CustomMatrix (const CustomMatrix &m)
 The copy constructor for CustomMatrix. More...
 
 CustomMatrix (CustomMatrix &&m) noexcept
 The move constructor for CustomMatrix. More...
 
Data access functions
Reference operator() (size_t i, size_t j) noexcept
 2D-access to the matrix elements. More...
 
ConstReference operator() (size_t i, size_t j) const noexcept
 2D-access to the matrix elements. More...
 
Reference at (size_t i, size_t j)
 Checked access to the matrix elements. More...
 
ConstReference at (size_t i, size_t j) const
 Checked access to the matrix elements. More...
 
Pointer data () noexcept
 Low-level data access to the matrix elements. More...
 
ConstPointer data () const noexcept
 Low-level data access to the matrix elements. More...
 
Pointer data (size_t i) noexcept
 Low-level data access to the matrix elements of row/column i. More...
 
ConstPointer data (size_t i) const noexcept
 Low-level data access to the matrix elements of row/column i. More...
 
Iterator begin (size_t i) noexcept
 Returns an iterator to the first element of row/column i. More...
 
ConstIterator begin (size_t i) const noexcept
 Returns an iterator to the first element of row/column i. More...
 
ConstIterator cbegin (size_t i) const noexcept
 Returns an iterator to the first element of row/column i. More...
 
Iterator end (size_t i) noexcept
 Returns an iterator just past the last element of row/column i. More...
 
ConstIterator end (size_t i) const noexcept
 Returns an iterator just past the last element of row/column i. More...
 
ConstIterator cend (size_t i) const noexcept
 Returns an iterator just past the last element of row/column i. More...
 
Assignment operators
CustomMatrixoperator= (const Type &set)
 Homogenous assignment to all matrix elements. More...
 
CustomMatrixoperator= (initializer_list< initializer_list< Type > > list)
 List assignment to all matrix elements. More...
 
template<typename Other , size_t M, size_t N>
CustomMatrixoperator= (const Other(&array)[M][N])
 
CustomMatrixoperator= (const CustomMatrix &rhs)
 Copy assignment operator for CustomMatrix. More...
 
CustomMatrixoperator= (CustomMatrix &&rhs) noexcept
 Move assignment operator for CustomMatrix. More...
 
template<typename MT , bool SO2>
CustomMatrixoperator= (const Matrix< MT, SO2 > &rhs)
 
template<typename MT , bool SO2>
CustomMatrixoperator+= (const Matrix< MT, SO2 > &rhs)
 
template<typename MT , bool SO2>
CustomMatrixoperator-= (const Matrix< MT, SO2 > &rhs)
 
template<typename MT , bool SO2>
CustomMatrixoperator*= (const Matrix< MT, SO2 > &rhs)
 
template<typename Other >
EnableIf_< IsNumeric< Other >, CustomMatrix > & operator*= (Other rhs)
 
template<typename Other >
EnableIf_< IsNumeric< Other >, CustomMatrix > & operator/= (Other rhs)
 
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/columns. 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/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...
 
void reset ()
 Reset to the default initial values. More...
 
void reset (size_t i)
 Reset the specified row/column to the default initial values. More...
 
void clear ()
 Clearing the $ M \times N $ matrix. More...
 
CustomMatrixtranspose ()
 In-place transpose of the matrix. More...
 
CustomMatrixctranspose ()
 In-place conjugate transpose of the matrix. More...
 
template<typename Other >
CustomMatrixscale (const Other &scalar)
 
void swap (CustomMatrix &m) noexcept
 Swapping the contents of two matrices. More...
 
Resource management functions
void reset (Type *ptr, size_t m, size_t n)
 Resets the custom matrix and replaces the array of elements with the given array. More...
 
void reset (Type *ptr, size_t m, size_t n, size_t nn)
 Resets the custom matrix and replaces the array of elements with the given array. More...
 
template<typename Deleter , typename = EnableIf_< IsClass<Deleter> >>
void reset (Type *ptr, size_t m, size_t n, Deleter d)
 Resets the custom matrix and replaces the array of elements with the given array. More...
 
template<typename Deleter >
void reset (Type *ptr, size_t m, size_t n, size_t nn, Deleter d)
 Resets the custom matrix and replaces the array of elements with the given array. 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...
 
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...
 
BLAZE_ALWAYS_INLINE void store (size_t i, size_t j, const SIMDType &value) noexcept
 Store of a SIMD element of the matrix. More...
 
BLAZE_ALWAYS_INLINE void storea (size_t i, size_t j, const SIMDType &value) noexcept
 Aligned store of a SIMD element of the matrix. More...
 
BLAZE_ALWAYS_INLINE void storeu (size_t i, size_t j, const SIMDType &value) noexcept
 Unaligned store of a SIMD element of the matrix. More...
 
BLAZE_ALWAYS_INLINE void stream (size_t i, size_t j, const SIMDType &value) noexcept
 Aligned, non-temporal store of a SIMD element of the matrix. More...
 
template<typename MT >
DisableIf_< VectorizedAssign< MT > > assign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
EnableIf_< VectorizedAssign< MT > > assign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
void assign (const DenseMatrix< MT,!SO > &rhs)
 Default implementation of the assignment of a column-major dense matrix. More...
 
template<typename MT >
void assign (const SparseMatrix< MT, SO > &rhs)
 Default implementation of the assignment of a row-major sparse matrix. More...
 
template<typename MT >
void assign (const SparseMatrix< MT,!SO > &rhs)
 Default implementation of the assignment of a column-major sparse matrix. More...
 
template<typename MT >
DisableIf_< VectorizedAddAssign< MT > > addAssign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
EnableIf_< VectorizedAddAssign< MT > > addAssign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
void addAssign (const DenseMatrix< MT,!SO > &rhs)
 Default implementation of the addition assignment of a column-major dense matrix. More...
 
template<typename MT >
void addAssign (const SparseMatrix< MT, SO > &rhs)
 Default implementation of the addition assignment of a row-major sparse matrix. More...
 
template<typename MT >
void addAssign (const SparseMatrix< MT,!SO > &rhs)
 Default implementation of the addition assignment of a column-major sparse matrix. More...
 
template<typename MT >
DisableIf_< VectorizedSubAssign< MT > > subAssign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
EnableIf_< VectorizedSubAssign< MT > > subAssign (const DenseMatrix< MT, SO > &rhs)
 
template<typename MT >
void subAssign (const DenseMatrix< MT,!SO > &rhs)
 Default implementation of the subtraction assignment of a column-major dense matrix. More...
 
template<typename MT >
void subAssign (const SparseMatrix< MT, SO > &rhs)
 Default implementation of the subtraction assignment of a row-major sparse matrix. More...
 
template<typename MT >
void subAssign (const SparseMatrix< MT,!SO > &rhs)
 Default implementation of the subtraction assignment of a column-major sparse matrix. More...
 

Private Types

enum  : size_t { SIMDSIZE = SIMDTrait<ElementType>::size }
 The number of elements packed within a single SIMD element.
 

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.
 
size_t nn_
 The number of elements between two rows.
 
boost::shared_array< Type > v_
 The dynamically allocated matrix elements. More...
 

Detailed Description

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
class blaze::CustomMatrix< Type, AF, PF, SO >

Efficient implementation of a customizable matrix.

The CustomMatrix class template provides the functionality to represent an external array of elements of arbitrary type and a fixed size as a native Blaze dense matrix data structure. Thus in contrast to all other dense matrix types a custom matrix does not perform any kind of memory allocation by itself, but it is provided with an existing array of element during construction. A custom matrix can therefore be considered an alias to the existing array.

The type of the elements, the properties of the given array of elements and the storage order of the matrix can be specified via the following four template parameters:

template< typename Type, bool AF, bool PF, bool SO >

The following examples give an impression of several possible types of custom matrices:

// Definition of a custom row-major matrix for unaligned, unpadded integer arrays
typedef CustomMatrix<int,unaligned,unpadded,rowMajor> UnalignedUnpadded;
// Definition of a custom column-major matrix for unaligned but padded 'float' arrays
typedef CustomMatrix<float,unaligned,padded,columnMajor> UnalignedPadded;
// Definition of a custom row-major matrix for aligned, unpadded 'double' arrays
typedef CustomMatrix<double,aligned,unpadded,rowMajor> AlignedUnpadded;
// Definition of a custom column-major matrix for aligned, padded 'complex<double>' arrays
typedef CustomMatrix<complex<double>,aligned,padded,columnMajor> AlignedPadded;


Special Properties of Custom Matrices

In comparison with the remaining Blaze dense matrix types CustomMatrix has several special characteristics. All of these result from the fact that a custom matrix is not performing any kind of memory allocation, but instead is given an existing array of elements. The following sections discuss all of these characteristics:

  1. Memory Management
  2. Copy Operations
  3. Alignment
  4. Padding


Memory Management

The CustomMatrix class template acts as an adaptor for an existing array of elements. As such it provides everything that is required to use the array just like a native Blaze dense matrix data structure. However, this flexibility comes with the price that the user of a custom matrix is responsible for the resource management.

When constructing a custom matrix there are two choices: Either a user manually manages the array of elements outside the custom matrix, or alternatively passes the responsibility for the memory management to an instance of CustomMatrix. In the second case the CustomMatrix class employs shared ownership between all copies of the custom matrix, which reference the same array.

The following examples give an impression of several possible custom matrices:

// Definition of a 3x4 custom row-major matrix with unaligned, unpadded and externally
// managed integer array. Note that the std::vector must be guaranteed to outlive the
// custom matrix!
std::vector<int> vec( 12UL );
CustomMatrix<int,unaligned,unpadded> A( &vec[0], 3UL, 4UL );
// Definition of a 3x4 custom row-major matrix for unaligned, unpadded integer arrays.
// The responsibility for the memory management is passed to the custom matrix by
// providing a deleter of type 'blaze::ArrayDelete' that is used during the destruction
// of the custom matrix.
CustomMatrix<int,unaligned,unpadded,rowMajor> B( new int[12], 3UL, 4UL, ArrayDelete() );
// Definition of a custom 8x12 matrix for an aligned and padded integer array of
// capacity 128 (including 8 padding elements per row). The memory management is passed
// to the custom matrix by providing a deleter of type 'blaze::Deallocate'.
CustomMatrix<int,aligned,padded> C( allocate<int>( 128UL ), 8UL, 12UL, 16UL, Deallocate() );

It is possible to pass any type of deleter to the constructor. The deleter is only required to provide a function call operator that can be passed the pointer to the managed array. As an example the following code snipped shows the implementation of two native Blaze deleters blaze::ArrayDelete and blaze::Deallocate:

namespace blaze {
struct ArrayDelete
{
template< typename Type >
inline void operator()( Type ptr ) const { boost::checked_array_delete( ptr ); }
};
struct Deallocate
{
template< typename Type >
inline void operator()( Type ptr ) const { deallocate( ptr ); }
};
} // namespace blaze


Copy Operations

As with all dense matrices it is possible to copy construct a custom matrix:

typedef CustomMatrix<int,unaligned,unpadded> CustomType;
std::vector<int> vec( 6UL, 10 ); // Vector of 6 integers of the value 10
CustomType A( &vec[0], 2UL, 3UL ); // Represent the std::vector as Blaze dense matrix
a[1] = 20; // Also modifies the std::vector
CustomType B( a ); // Creating a copy of vector a
b[2] = 20; // Also affect matrix A and the std::vector

It is important to note that a custom matrix acts as a reference to the specified array. Thus the result of the copy constructor is a new custom matrix that is referencing and representing the same array as the original custom matrix. In case a deleter has been provided to the first custom matrix, both matrices share the responsibility to destroy the array when the last matrix goes out of scope.

In contrast to copy construction, just as with references, copy assignment does not change which array is referenced by the custom matrices, but modifies the values of the array:

std::vector<int> vec2( 6UL, 4 ); // Vector of 6 integers of the value 4
CustomType C( &vec2[0], 2UL, 3UL ); // Represent the std::vector as Blaze dense matrix
A = C; // Copy assignment: Set all values of matrix A and B to 4.


Alignment

In case the custom matrix is specified as aligned the passed array must adhere to some alignment restrictions based on the alignment requirements of the used data type and the used instruction set (SSE, AVX, ...). The restriction applies to the first element of each row/column: In case of a row-major matrix the first element of each row must be properly aligned, in case of a column-major matrix the first element of each column must be properly aligned. For instance, if a row-major matrix is used and AVX is active the first element of each row must be 32-bit aligned:

int* array = blaze::allocate<int>( 40UL ); // Is guaranteed to be 32-bit aligned
CustomMatrix<int,aligned,padded,rowMajor> A( array, 5UL, 6UL, 8UL, Deallocate() );

In the example, the row-major matrix has six columns. However, since with AVX eight integer values are loaded together the matrix is padded with two additional elements. This guarantees that the first element of each row is 32-bit aligned. In case the alignment requirements are violated, a std::invalid_argument exception is thrown.


Padding

Adding padding elements to the end of an array can have a significant impact on performance. For instance, assuming that AVX is available, then two aligned, padded, 3x3 double precision matrices can be added via three SIMD addition operations:

typedef CustomMatrix<double,aligned,padded> CustomType;
// Creating padded custom 3x3 matrix with an additional padding element in each row
CustomType A( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
CustomType B( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
CustomType C( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
// ... Initialization
C = A + B; // AVX-based matrix addition

In this example, maximum performance is possible. However, in case no padding elements are inserted a scalar addition has to be used:

typedef CustomMatrix<double,aligned,unpadded> CustomType;
// Creating unpadded custom 3x3 matrix
CustomType A( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
CustomType B( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
CustomType C( allocate<double>( 12UL ), 3UL, 3UL, 4UL, Deallocate() );
// ... Initialization
C = A + B; // Scalar matrix addition

Note that the construction of padded and unpadded aligned matrices looks identical. However, in case of padded matrices, Blaze will zero initialize the padding element and use them in all computations in order to achieve maximum performance. In case of an unpadded matrix Blaze will ignore the elements with the downside that it is not possible to load a complete row to an AVX register, which makes it necessary to fall back to a scalar addition.

The number of padding elements is required to be sufficient with respect to the available instruction set: In case of an aligned padded custom matrix the added padding elements must guarantee that the total number of elements in each row/column is a multiple of the SIMD vector width. In case of an unaligned padded matrix the number of padding elements can be greater or equal the number of padding elements of an aligned padded custom matrix. In case the padding is insufficient with respect to the available instruction set, a std::invalid_argument exception is thrown.


Arithmetic Operations

The use of custom matrices in arithmetic operations is designed to be as natural and intuitive as possible. All operations (addition, subtraction, multiplication, scaling, ...) can be expressed similar to a text book representation. Also, custom matrices can be combined with all other dense and sparse vectors and matrices. The following example gives an impression of the use of CustomMatrix:

// Non-initialized custom 2x3 row-major matrix. All given arrays are considered to be
// unaligned and unpadded. The memory is managed via 'ArrayDelete'.
CustomMatrix<double,unaligned,unpadded> A( new double[6], 2UL, 3UL, blaze::ArrayDelete() );
A(0,0) = 1.0; A(0,1) = 2.0; A(0,2) = 3.0; // Initialization of the first row
A(1,0) = 4.0; A(1,1) = 5.0; A(1,2) = 6.0; // Initialization of the second row
// Non-initialized custom 2x3 row-major matrix with padding elements. All given arrays are
// required to be properly aligned and padded. The memory is managed via 'Deallocate'.
CustomMatrix<double,aligned,padded> B( allocate<double>( 16UL ), 2UL, 3UL, 8UL, Deallocate() );
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
A *= 2.0; // In-place scaling of matrix A
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

Member Enumeration Documentation

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
anonymous enum : bool

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.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
anonymous enum : bool

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).

Constructor & Destructor Documentation

template<typename Type , bool AF, bool PF, bool SO>
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( Type *  ptr,
size_t  m,
size_t  n 
)
inlineexplicit

Constructor for a matrix of size $ m \times n $.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This constructor creates an unpadded custom matrix of size $ m \times n $. The construction fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
This constructor is NOT available for padded custom matrices!
The custom matrix does NOT take responsibility for the given array of elements!
template<typename Type , bool AF, bool PF, bool SO>
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( Type *  ptr,
size_t  m,
size_t  n,
size_t  nn 
)
inlineexplicit

Constructor for a matrix of size $ m \times n $.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
nnThe total number of elements between two rows/columns.
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This constructor creates a custom matrix of size $ m \times n $. The construction fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...);
  • ... the specified spacing nn is insufficient for the given data type Type and the available instruction set.

In all failure cases a std::invalid_argument exception is thrown.

Note
The custom matrix does NOT take responsibility for the given array of elements!
template<typename Type , bool AF, bool PF, bool SO>
template<typename Deleter , typename >
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( Type *  ptr,
size_t  m,
size_t  n,
Deleter  d 
)
inlineexplicit

Constructor for a matrix of size $ m \times n $.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
dThe deleter to destroy the array of elements.
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This constructor creates an unpadded custom matrix of size $ m \times n $. The construction fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
This constructor is NOT available for padded custom matrices!
template<typename Type , bool AF, bool PF, bool SO>
template<typename Deleter >
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( Type *  ptr,
size_t  m,
size_t  n,
size_t  nn,
Deleter  d 
)
inlineexplicit

Constructor for a matrix of size $ m \times n $.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
nnThe total number of elements between two rows/columns.
dThe deleter to destroy the array of elements.
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This constructor creates a custom matrix of size $ m \times n $. The construction fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...);
  • ... the specified spacing nn is insufficient for the given data type Type and the available instruction set.

In all failure cases a std::invalid_argument exception is thrown.

template<typename Type , bool AF, bool PF, bool SO>
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( const CustomMatrix< Type, AF, PF, SO > &  m)
inline

The copy constructor for CustomMatrix.

Parameters
mMatrix to be copied.

The copy constructor initializes the custom matrix as an exact copy of the given custom matrix.

template<typename Type , bool AF, bool PF, bool SO>
blaze::CustomMatrix< Type, AF, PF, SO >::CustomMatrix ( CustomMatrix< Type, AF, PF, SO > &&  m)
inlinenoexcept

The move constructor for CustomMatrix.

Parameters
mThe matrix to be moved into this instance.

Member Function Documentation

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::addAssign ( const DenseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the addition assignment of a column-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::addAssign ( const SparseMatrix< MT, SO > &  rhs)
inline

Default implementation of the addition assignment of a row-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::addAssign ( const SparseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the addition assignment of a column-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
DisableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::addAssign ( const DenseMatrix< MT, SO > &  rhs)
inline

Default implementation of the addition assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
EnableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::addAssign ( const DenseMatrix< MT, SO > &  rhs)
inline

SIMD optimized implementation of the addition assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::assign ( const DenseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the assignment of a column-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::assign ( const SparseMatrix< MT, SO > &  rhs)
inline

Default implementation of the assignment of a row-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::assign ( const SparseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the assignment of a column-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
DisableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::assign ( const DenseMatrix< MT, SO > &  rhs)
inline

Default implementation of the assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
EnableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::assign ( const DenseMatrix< MT, SO > &  rhs)
inline

SIMD optimized implementation of the assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Reference blaze::CustomMatrix< Type, AF, PF, SO >::at ( size_t  i,
size_t  j 
)
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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstReference blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Iterator blaze::CustomMatrix< Type, AF, PF, SO >::begin ( size_t  i)
inlinenoexcept

Returns an iterator to the first element of row/column i.

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

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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstIterator blaze::CustomMatrix< Type, AF, PF, SO >::begin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first element of row/column i.

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

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.

template<typename Type , bool AF, bool PF, bool SO>
template<typename Other >
bool blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type , bool AF, bool PF, bool SO>
bool blaze::CustomMatrix< Type, AF, PF, SO >::canSMPAssign ( ) const
inlinenoexcept

Returns whether the matrix can be used in SMP assignments.

Returns
true in case the matrix can be used in SMP assignments, false if not.

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).

template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the matrix.

Returns
The capacity of the matrix.
template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::capacity ( size_t  i) const
inlinenoexcept

Returns the current capacity of the specified row/column.

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

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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstIterator blaze::CustomMatrix< Type, AF, PF, SO >::cbegin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first element of row/column i.

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

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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstIterator blaze::CustomMatrix< Type, AF, PF, SO >::cend ( size_t  i) const
inlinenoexcept

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

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

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.

template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::clear ( )
inline

Clearing the $ M \times N $ matrix.

Returns
void

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

template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::columns ( ) const
inlinenoexcept

Returns the current number of columns of the matrix.

Returns
The number of columns of the matrix.
template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::ctranspose ( )
inline

In-place conjugate transpose of the matrix.

Returns
Reference to the transposed matrix.
Exceptions
std::logic_errorImpossible transpose operation.

In case the matrix is not a square matrix, a std::logic_error exception is thrown.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Pointer blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstPointer blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Pointer blaze::CustomMatrix< Type, AF, PF, SO >::data ( size_t  i)
inlinenoexcept

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

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

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

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstPointer blaze::CustomMatrix< Type, AF, PF, SO >::data ( size_t  i) const
inlinenoexcept

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

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

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

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Iterator blaze::CustomMatrix< Type, AF, PF, SO >::end ( size_t  i)
inlinenoexcept

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

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

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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstIterator blaze::CustomMatrix< Type, AF, PF, SO >::end ( size_t  i) const
inlinenoexcept

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

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

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.

template<typename Type , bool AF, bool PF, bool SO>
template<typename Other >
bool blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type , bool AF, bool PF, bool SO>
bool blaze::CustomMatrix< Type, AF, PF, SO >::isAligned ( ) const
inlinenoexcept

Returns whether the matrix is properly aligned in memory.

Returns
true in case the matrix is aligned, false if not.

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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE CustomMatrix< Type, AF, PF, SO >::SIMDType blaze::CustomMatrix< Type, AF, PF, SO >::load ( size_t  i,
size_t  j 
) const
noexcept

Load of a SIMD element of the matrix.

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
The loaded SIMD element.

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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE CustomMatrix< Type, AF, PF, SO >::SIMDType blaze::CustomMatrix< Type, AF, PF, SO >::loada ( size_t  i,
size_t  j 
) const
noexcept

Aligned load of a SIMD element of the matrix.

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
The loaded SIMD element.

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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE CustomMatrix< Type, AF, PF, SO >::SIMDType blaze::CustomMatrix< Type, AF, PF, SO >::loadu ( size_t  i,
size_t  j 
) const
noexcept

Unaligned load of a SIMD element of the matrix.

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
The loaded SIMD element.

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.

template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::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.
template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::nonZeros ( size_t  i) const
inline

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

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

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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::Reference blaze::CustomMatrix< Type, AF, PF, SO >::operator() ( size_t  i,
size_t  j 
)
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.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO >::ConstReference blaze::CustomMatrix< Type, AF, PF, SO >::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.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT , bool SO2>
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::operator*= ( const Matrix< MT, SO2 > &  rhs)
inline

Multiplication assignment operator for the multiplication of a matrix ( $ A*=B $).

Parameters
rhsThe right-hand side matrix for the multiplication.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two given matrices don't match, a std::invalid_argument is thrown.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename Other >
EnableIf_<IsNumeric<Other>, CustomMatrix<Type,AF,PF,SO> >& blaze::CustomMatrix< Type, AF, PF, SO >::operator*= ( Other  rhs)
inline

Multiplication assignment operator for the multiplication between a matrix and a scalar value ( $ A*=s $).

Parameters
rhsThe right-hand side scalar value for the multiplication.
Returns
Reference to the matrix.
template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT , bool SO2>
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::operator+= ( const Matrix< MT, SO2 > &  rhs)
inline

Addition assignment operator for the addition of a matrix ( $ A+=B $).

Parameters
rhsThe right-hand side matrix to be added to the matrix.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT , bool SO2>
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::operator-= ( const Matrix< MT, SO2 > &  rhs)
inline

Subtraction assignment operator for the subtraction of a matrix ( $ A-=B $).

Parameters
rhsThe right-hand side matrix to be subtracted from the matrix.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename Other >
EnableIf_<IsNumeric<Other>, CustomMatrix<Type,AF,PF,SO> >& blaze::CustomMatrix< Type, AF, PF, SO >::operator/= ( Other  rhs)
inline

Division assignment operator for the division of a matrix by a scalar value ( $ A/=s $).

Parameters
rhsThe right-hand side scalar value for the division.
Returns
Reference to the matrix.
template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( const Type &  rhs)
inline

Homogenous assignment to all matrix elements.

Parameters
rhsScalar value to be assigned to all matrix elements.
Returns
Reference to the assigned matrix.
template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( initializer_list< initializer_list< Type > >  list)
inline

List assignment to all matrix elements.

Parameters
listThe initializer list.
Exceptions
std::invalid_argumentInvalid assignment to static matrix.

This assignment operator offers the option to directly assign to all elements of the matrix by means of an initializer list:

const int array[9] = { 0, 0, 0,
0, 0, 0,
0, 0, 0 };
A = { { 1, 2, 3 },
{ 4, 5 },
{ 7, 8, 9 } };

The matrix elements are assigned the values from the given initializer list. Missing values are initialized as default (as e.g. the value 6 in the example). Note that in case the size of the top-level initializer list exceeds the number of rows or the size of any nested list exceeds the number of columns, a std::invalid_argument exception is thrown.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( const CustomMatrix< Type, AF, PF, SO > &  rhs)
inline

Copy assignment operator for CustomMatrix.

Parameters
rhsMatrix to be copied.
Returns
Reference to the assigned matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

The matrix is initialized as a copy of the given matrix. In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( CustomMatrix< Type, AF, PF, SO > &&  rhs)
inlinenoexcept

Move assignment operator for CustomMatrix.

Parameters
rhsMatrix to be copied.
Returns
Reference to the assigned matrix.
template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename Other , size_t M, size_t N>
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( const Other(&)  array[M][N])
inline

Array assignment to all matrix elements.

Parameters
array$ M \times N $ dimensional array for the assignment.
Returns
Reference to the assigned matrix.
Exceptions
std::invalid_argumentInvalid array size.

This assignment operator offers the option to directly set all elements of the matrix:

const int array[9] = { 0, 0, 0,
0, 0, 0,
0, 0, 0 };
const int init[3][3] = { { 1, 2, 3 },
{ 4, 5 },
{ 7, 8, 9 } };
A = init;

The matrix is assigned the values from the given array. Missing values are initialized with default values (as e.g. the value 6 in the example). Note that the size of the array must match the size of the custom matrix. Otherwise a std::invalid_argument exception is thrown. Also note that after the assignment array will have the same entries as init.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT , bool SO2>
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::operator= ( const Matrix< MT, SO2 > &  rhs)
inline

Assignment operator for different matrices.

Parameters
rhsMatrix to be copied.
Returns
Reference to the assigned matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

The matrix is initialized as a copy of the given matrix. In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

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

Conversion operator for non-constant matrices.

Returns
Reference of the actual type of the matrix.
template<typename MT, bool SO>
BLAZE_ALWAYS_INLINE const MatrixType& blaze::Matrix< MT, SO >::operator~ ( ) const
inlinenoexceptinherited

Conversion operator for constant matrices.

Returns
Constant reference of the actual type of the matrix.
template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( )
inline

Reset to the default initial values.

Returns
void
template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( size_t  i)
inline

Reset the specified row/column to the default initial values.

Parameters
iThe index of the row/column.
Returns
void

This function resets the values in the specified row/column to their default value. In case the storage order is set to rowMajor the function resets the values in row i, in case the storage order is set to columnMajor the function resets the values in column i. Note that the capacity of the row/column remains unchanged.

template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( Type *  ptr,
size_t  m,
size_t  n 
)
inline

Resets the custom matrix and replaces the array of elements with the given array.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
Returns
void
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This function resets the custom matrix to the given array of elements of size $ m \times n $. The function fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
This function is NOT available for padded custom matrices!
In case a deleter was specified, the previously referenced array will only be destroyed when the last custom matrix referencing the array goes out of scope.
The custom matrix does NOT take responsibility for the new array of elements!
template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( Type *  ptr,
size_t  m,
size_t  n,
size_t  nn 
)
inline

Resets the custom matrix and replaces the array of elements with the given array.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
nnThe total number of elements between two rows/columns.
Returns
void
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This function resets the custom matrix to the given array of elements of size $ m \times n $. The function fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
In case a deleter was specified, the previously referenced array will only be destroyed when the last custom matrix referencing the array goes out of scope.
The custom matrix does NOT take responsibility for the new array of elements!
template<typename Type , bool AF, bool PF, bool SO>
template<typename Deleter , typename >
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( Type *  ptr,
size_t  m,
size_t  n,
Deleter  d 
)
inline

Resets the custom matrix and replaces the array of elements with the given array.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
dThe deleter to destroy the array of elements.
Returns
void
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This function resets the custom matrix to the given array of elements of size $ m \times n $. The function fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
This function is NOT available for padded custom matrices!
In case a deleter was specified, the previously referenced array will only be destroyed when the last custom matrix referencing the array goes out of scope.
template<typename Type , bool AF, bool PF, bool SO>
template<typename Deleter >
void blaze::CustomMatrix< Type, AF, PF, SO >::reset ( Type *  ptr,
size_t  m,
size_t  n,
size_t  nn,
Deleter  d 
)
inline

Resets the custom matrix and replaces the array of elements with the given array.

Parameters
ptrThe array of elements to be used by the matrix.
mThe number of rows of the array of elements.
nThe number of columns of the array of elements.
nnThe total number of elements between two rows/columns.
dThe deleter to destroy the array of elements.
Returns
void
Exceptions
std::invalid_argumentInvalid setup of custom matrix.

This function resets the custom matrix to the given array of elements of size $ m \times n $. The function fails if ...

  • ... the passed pointer is nullptr;
  • ... the alignment flag AF is set to aligned, but the passed pointer is not properly aligned according to the available instruction set (SSE, AVX, ...).

In all failure cases a std::invalid_argument exception is thrown.

Note
In case a deleter was specified, the previously referenced array will only be destroyed when the last custom matrix referencing the array goes out of scope.
template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::rows ( ) const
inlinenoexcept

Returns the current number of rows of the matrix.

Returns
The number of rows of the matrix.
template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename Other >
CustomMatrix<Type,AF,PF,SO>& blaze::CustomMatrix< Type, AF, PF, SO >::scale ( const Other &  scalar)
inline

Scaling of the matrix by the scalar value scalar ( $ A=B*s $).

Parameters
scalarThe scalar value for the matrix scaling.
Returns
Reference to the matrix.
template<typename Type , bool AF, bool PF, bool SO>
size_t blaze::CustomMatrix< Type, AF, PF, SO >::spacing ( ) const
inlinenoexcept

Returns the spacing between the beginning of two rows/columns.

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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE void blaze::CustomMatrix< Type, AF, PF, SO >::store ( size_t  i,
size_t  j,
const SIMDType value 
)
noexcept

Store of a SIMD element of the matrix.

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].
valueThe SIMD element to be stored.
Returns
void

This function performs a store 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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE void blaze::CustomMatrix< Type, AF, PF, SO >::storea ( size_t  i,
size_t  j,
const SIMDType value 
)
noexcept

Aligned store of a SIMD element of the matrix.

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].
valueThe SIMD element to be stored.
Returns
void

This function performs an aligned store 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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE void blaze::CustomMatrix< Type, AF, PF, SO >::storeu ( size_t  i,
size_t  j,
const SIMDType value 
)
noexcept

Unaligned store of a SIMD element of the matrix.

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].
valueThe SIMD element to be stored.
Returns
void

This function performs an unaligned store 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.

template<typename Type , bool AF, bool PF, bool SO>
BLAZE_ALWAYS_INLINE void blaze::CustomMatrix< Type, AF, PF, SO >::stream ( size_t  i,
size_t  j,
const SIMDType value 
)
noexcept

Aligned, non-temporal store of a SIMD element of the matrix.

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].
valueThe SIMD element to be stored.
Returns
void

This function performs an aligned, non-temporal store 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.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::subAssign ( const DenseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the subtraction assignment of a column-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::subAssign ( const SparseMatrix< MT, SO > &  rhs)
inline

Default implementation of the subtraction assignment of a row-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
template<typename MT >
void blaze::CustomMatrix< Type, AF, PF, SO >::subAssign ( const SparseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the subtraction assignment of a column-major sparse matrix.

Parameters
rhsThe right-hand side sparse matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
DisableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::subAssign ( const DenseMatrix< MT, SO > &  rhs)
inline

Default implementation of the subtraction assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
template<typename MT >
EnableIf_<typename CustomMatrix<Type,AF,PF,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> > blaze::CustomMatrix< Type, AF, PF, SO >::subAssign ( const DenseMatrix< MT, SO > &  rhs)
inline

SIMD optimized implementation of the subtraction assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

template<typename Type , bool AF, bool PF, bool SO>
void blaze::CustomMatrix< Type, AF, PF, SO >::swap ( CustomMatrix< Type, AF, PF, SO > &  m)
inlinenoexcept

Swapping the contents of two matrices.

Parameters
mThe matrix to be swapped.
Returns
void
template<typename Type , bool AF, bool PF, bool SO>
CustomMatrix< Type, AF, PF, SO > & blaze::CustomMatrix< Type, AF, PF, SO >::transpose ( )
inline

In-place transpose of the matrix.

Returns
Reference to the transposed matrix.
Exceptions
std::logic_errorImpossible transpose operation.

In case the matrix is not a square matrix, a std::logic_error exception is thrown.

Member Data Documentation

template<typename Type, bool AF, bool PF, bool SO = defaultStorageOrder>
boost::shared_array<Type> blaze::CustomMatrix< Type, AF, PF, SO >::v_
private

The dynamically allocated matrix elements.

Access to the matrix elements is gained via the function call operator. In case of row-major order 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)\]

.


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