chsvlib
chsv helper source code
FixedMatrix< Val, ColumnCount, RowCount, Alloc, Derived_t, ExecutionPolicy > Class Template Reference

Specializes the Matrix template for fixed-sized matrices. More...

#include <chsvmath.h>

Inheritance diagram for FixedMatrix< Val, ColumnCount, RowCount, Alloc, Derived_t, ExecutionPolicy >:
Collaboration diagram for FixedMatrix< Val, ColumnCount, RowCount, Alloc, Derived_t, ExecutionPolicy >:

Public Types

typedef MyBase::derived_type derived_type
 A type alias for a class inheriting and implementing the behaviour of the fixed-sized matrix if any, or FixedMatrix itself otherwise.
 
typedef MyBase::value_type value_type
 A type of a matrix element.
 
typedef MyBase::allocator_type allocator_type
 A type of an allocator used to manage storage for matrix elements.
 
typedef MyBase::size_type size_type
 An integral type of size values used with the matrix instances.
 
typedef MyBase::policy_type policy_type
 A policy of a matrix implementation. To access specific sub-policies use matrix_execution_policy_traits.
 
typedef MyBase::difference_type difference_type
 A signed integral type used for specifying differences between memory addresses.
 
typedef MyBase::pointer pointer
 A type of a pointer to a matrix element.
 
typedef MyBase::const_pointer const_pointer
 A type of a non-modifiable pointer to a matrix element.
 
typedef MyBase::reference reference
 A type of a reference to a matrix element.
 
typedef MyBase::const_reference const_reference
 A type of a non-modifiable reference to a matrix element.
 
typedef MyBase::iterator iterator
 A type of a random-access iterator associated with columns of a matrix.
 
typedef MyBase::const_iterator const_iterator
 A type of a read-only random-access iterator associated with columns of a matrix.
 
typedef MyBase::reverse_iterator reverse_iterator
 A type of a reverse random-access iterator associated with columns of a matrix.
 
typedef MyBase::const_reverse_iterator const_reverse_iterator
 A type of a read-only reverse random-access iterator associated with columns of a matrix.
 
typedef FixedMatrix_category< FixedMatrix >::algebraic_category algebraic_category
 A conditionally defined marker of an algebraic group which the whole matrix appertains to.
 
typedef MyBase::interpret_array_as_matrix_rows_set_t interpret_array_as_matrix_rows_set_t
 A type of a mark used in constructor overloading to specify how to interpret a set of array elements: as an array of rows or an array of columns. The type is used to specify the former (default) case.
 
typedef MyBase::interpret_array_as_matrix_columns_set_t interpret_array_as_matrix_columns_set_t
 A type of a mark used in constructor overloading to specify how to interpret a set of array elements: as an array of rows or an array of columns. The type is used to specify the latter case.
 

Public Member Functions

 FixedMatrix ()=default
 Default constructor.
 
 FixedMatrix (const value_type &value, const allocator_type &alloc)
 Creates a matrix such that all elements appertaining to the main diagonal of the created matrix are initialized with a given value. More...
 
 FixedMatrix (const value_type &value)
 Creates a matrix such that all elements appertaining to the main diagonal of the created matrix are initialized with a given value. More...
 
template<class Val2 , class Alloc2 , class Derived2_t , class Policy2_t >
 FixedMatrix (const FixedMatrix< Val2, columns_number, rows_number, Alloc2, Derived2_t, Policy2_t > &r)
 Constructs a copy of given matrix transformed from some other instantiation of the FixedMatrix template with the same dimensions as the constructed one. More...
 
template<class Derived2_t , class Policy2_t >
 FixedMatrix (FixedMatrix< value_type, columns_number, rows_number, allocator_type, Derived2_t, Policy2_t > &&r)
 A moving constructor from a matrix with arbitrary implementing type and policy but same types of elements and an allocator. More...
 
 FixedMatrix (std::initializer_list< std::initializer_list< value_type >> lst, const allocator_type &alloc=allocator_type())
 Creates a matrix from an initializer list of rows which, in turn, are also specified using initializer list mechanism with elements of a type convertible to value_type. More...
 
template<class InputIterator >
 FixedMatrix (InputIterator itBegin, InputIterator itEnd, const allocator_type &alloc=allocator_type())
 Constructs a matrix from a range of matrices or matrix columns specified by a pair of input iterators. More...
 
template<class InputIterator >
 FixedMatrix (const Chusov::Memory::iterator_range< InputIterator > &range, const allocator_type &alloc=allocator_type())
 Constructs a matrix from a range of matrices or matrix columns specified by an instantiation of the Chusov::Memory::iterator_range template for input iterators. More...
 
template<class input_iterator_t , class array_interpretation_t >
 FixedMatrix (input_iterator_t itBegin, input_iterator_t itEnd, array_interpretation_t array_interpretation, const allocator_type &alloc=allocator_type())
 Constructs a fixed-size matrix from a specified set of elements given by a pair of iterators row-by-row. . More...
 
template<class value_t >
 FixedMatrix (value_t(&Arr2)[columns_number][rows_number], const allocator_type &alloc=allocator_type())
 Constructs a matrix from a two dimensional array of elements. More...
 
template<class value_t , class array_interpretation_t >
 FixedMatrix (value_t *pVector, array_interpretation_t vector_interpretation, const allocator_type &alloc=allocator_type())
 Creates a fixed size matrix from a vector of data pointed to by parameters of the constructor. The data is interpreted as data of adjacent rows of the matrix. More...
 
template<class value_t , class alloc_t , class array_interpretation_t >
 FixedMatrix (const std::vector< value_t, alloc_t > &v, array_interpretation_t vector_interpretation, const allocator_type &alloc=allocator_type())
 Creates a fixed size matrix from a set of its elements given by a vector object. . More...
 
template<class value_t >
 FixedMatrix (value_t *pVector, const allocator_type &alloc=allocator_type())
 Creates a matrix from a vector of raw data pointed to by parameters of the constructor. More...
 
template<class value_t , class alloc_t >
 FixedMatrix (const std::vector< value_t, alloc_t > &v, const allocator_type &alloc=allocator_type())
 Creates a matrix from a set of its elements given by a vector object. More...
 
template<class Val2 , class Alloc2 , class Derived2 , class Policy2 >
 FixedMatrix (const Matrix< Val2, Alloc2, Derived2, Policy2 > &right)
 Constructs a fixed matrix object as a copy of a matrix with dimensions not defined at a compile time. More...
 
template<class Derived2 , class Policy2 >
 FixedMatrix (Matrix< value_type, allocator_type, Derived2, Policy2 > &&right)
 A moving constructor from a matrix with arbitrary implementing type and policy but same types of elements and an allocator. More...
 
FixedMatrix< value_type, rows_number, columns_number, allocator_type, void, policy_typeTranspose () const
 Redefines matrix transposition interface to return a fixed-size matrix. More...
 
Matrix< value_type, allocator_type, void, policy_typeRemoveColumns (size_type iColumnBegin=0, size_type iColumnEnd=columns_number) const
 Removes columns from a matrix given by a half-interval [iColumnBegin, iColumnEnd). More...
 
Matrix< value_type, allocator_type, void, policy_typeRemoveRows (size_type iRowBegin=0, size_type iRowEnd=rows_number) const
 Removes rows from a matrix given by a half-interval [iRowBegin, iRowEnd). More...
 
void TransposeMe ()=delete
 Deleted self-transposition for fixed sized matrices.
 
void AugmentMe ()=delete
 Deleted column augmentation to a matrix of fixed size.
 
void RemoveColumnsMe (size_type=0, size_type=0)=delete
 Deleted own column removal for a matrix of fixed size.
 
void RemoveRowsMe (size_type=0, size_type=0)=delete
 Deleted own row removal for a matrix of fixed size.
 

Static Public Attributes

static constexpr size_type rows_number = size_type(RowCount)
 A statically defined constant equal to a number of rows in the matrix.
 
static constexpr size_type columns_number = size_type(ColumnCount)
 
static const interpret_array_as_matrix_rows_set_t interpret_array_as_matrix_rows_set = MyBase::interpret_array_as_matrix_rows_set
 An integral mark used in constructor overloading to specify how to interpret a set of array elements: as an array of rows or an array of columns. The value is used to specify the former (default) case.
 
static const interpret_array_as_matrix_columns_set_t interpret_array_as_matrix_columns_set = MyBase::interpret_array_as_matrix_columns_set
 An integral mark used in constructor overloading to specify how to interpret a set of array elements: as an array of rows or an array of columns. The value is used to specify the latter case.
 

Detailed Description

template<class Val, std::size_t ColumnCount, std::size_t RowCount, class Alloc = std::allocator<Val>, class Derived_t = void, class ExecutionPolicy = default_matrix_execution_policy>
class Chusov::Math::FixedMatrix< Val, ColumnCount, RowCount, Alloc, Derived_t, ExecutionPolicy >

Specializes the Matrix template for fixed-sized matrices.

Template Parameters
Valis a type of a matrix element.
ColumnCountis a compile-time integral columns number to be stored by a matrix of the type.
RowCountis a compile-time integral rows number to be stored by a matrix of the type.
Allocis a type of an allocator object used for managing a storage of the matrix elements. A type chosen by default is std::allocator instantiation for Val.
Derived_tis a statically defined most-derived type of the matrix. It can redefine functions of the matrix, and providing this parameter the class template exploits static polymorphism. The type can be defined as void (default value) in order to make exclude polymorphism and to call the implementations of the methods provided by class, hence making inheritance optional.
ExecutionPolicyis a matrix implementation policy marker. See Matrix for the information on that.

The template provides several specializations for algebraic/non-algebraic element types (that is a type of Val) as well as for square/non-square matrices.

It is supposed that any improvements in performance will be made as specializations of the template.

For example, Intel SIMD-extensions can be used in implementations of the following specialization:

template <class Alloc = std::allocator<double>>
FixedMatrix<double, 3, 3, Alloc, void, true>

To optimize various specializations of the FixedMatrix template one might either define the whole class specialization or define external non member functions which implement various operatons. For instance, the following code is actually provided externally to optimize addition of 3x3 matrices through SSE2 vector intrinsics:

template <class alloc_1, class derived_1, class alloc_2, class derived_2>
FixedMatrix<double, 3, 3, alloc_1, void> operator+(const FixedMatrix<double, 3, 3, alloc_1, derived_1>& left, const FixedMatrix<double, 3, 3, alloc_2, derived_2>& right)
{
FixedMatrix<double, 3, 3, alloc_1, void> res;
__m128d val_l, val_1, val_2;
val_l = _mm_load_sd(&left[0][0]), val_1 = _mm_loadh_pd(val_l, &left[0][1]);
val_l = _mm_load_sd(&right[0][0]), val_2 = _mm_loadh_pd(val_l, &right[0][1]);
val_l = _mm_add_pd(val_1, val_2);
_mm_storel_pd(&res[0][0], val_l); _mm_storeh_pd(&res[0][1], val_l);
val_l = _mm_load_sd(&left[0][2]), val_1 = _mm_loadh_pd(val_l, &left[1][0]);
val_l = _mm_load_sd(&right[0][2]), val_2 = _mm_loadh_pd(val_l, &right[1][0]);
val_l = _mm_add_pd(val_1, val_2);
_mm_storel_pd(&res[0][2], val_l); _mm_storeh_pd(&res[1][0], val_l);
val_l = _mm_load_sd(&left[1][1]), val_1 = _mm_loadh_pd(val_l, &left[1][2]);
val_l = _mm_load_sd(&right[1][1]), val_2 = _mm_loadh_pd(val_l, &right[1][2]);
val_l = _mm_add_pd(val_1, val_2);
_mm_storel_pd(&res[1][1], val_l); _mm_storeh_pd(&res[1][2], val_l);
val_l = _mm_load_sd(&left[2][0]), val_1 = _mm_loadh_pd(val_l, &left[2][1]);
val_l = _mm_load_sd(&right[2][0]), val_2 = _mm_loadh_pd(val_l, &right[2][1]);
val_l = _mm_add_pd(val_1, val_2);
_mm_storel_pd(&res[2][0], val_l); _mm_storeh_pd(&res[2][1], val_l);
res[2][2] = left[2][2] + right[2][2];
}
Matrix< common_value, common_allocator, void, common_policy > operator+(const Matrix< val1_t, alloc1_t, der1_t, policy1_t > &left, const Matrix< val2_t, alloc2_t, der2_t, policy2_t > &right)
Adds up two matrices.

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