Skip to content

Implement left/right-multiplyany in the DenseMatrix base class

Simon Praetorius requested to merge feature/dense-matrix-multiplyany into master

Summary

This is a possible solution to the problem of implementing dense matrix multiply in case the type of the matrix could be either of static or dynamic size. The solution proposed here follows the design of the mdspan proposal by having two size function in the matrix classes, the regular rows() and cols() function as before, and additionally the functions static_rows() and static_cols() that are, as the same suggests, static functions that can be implemented for all matrix types by defining the size as Std::dynamic_extent (a special value, probably equal to -1) in case the size is available only as dynamic information. This static size information can be used, for example, to implement a matrix factory with specializations of dynamic and static extents.

The essential addition in this MR is the class MatrixFactory, that is parametrized with the field type and the static sizes or the special value Std::dynamic_extent. The latter means that the matrix does not have static size. This class defines a ::type alias to denote the matrix type to construct. And a create(size_t,size_t,field_type=0) static function is provided that constructs the matrix type. The MatrixFactory is specialized for row or column size is dynamic to return a DynamicMatrix and otherwise return a FieldMatrix.

The second addition are the static functions static_rows() and static_cols() that every matrix type derived from DenseMatrix should provide. These either return the static dimensions, or the special value Std::dynamic_extent. This is a pattern learned from std::mdspan where an analog static_extent static function is defined with the same behavior.

This MR is related to !1289 and !1360 where a different approach is followed.

Edited by Simon Praetorius

Merge request reports