![]() |
batmat
0.0.16
Batched linear algebra routines
|
#include <batmat/matrix/matrix.hpp>
Owning array of matrices, stored in an efficient batched format.
| T | Element value type. |
| I | Index and size type. Usually std::ptrdiff_t or int. |
| S | Inner stride type (batch size). Usually std::integral_constant<I, N> for some N. |
| D | Batch depth type. Usually equal to S for a single batch, or I for a dynamic depth. |
| O | Matrix storage order, RowMajor or ColMajor. |
| A | Batch alignment type. Should be std::integral_constant<I, N> for some N that is a multiple of the alignment requirements of T. To enable vectorization, this should be std::integral_constant<I, alignof(T) * S::value>, which is the default. |
Definition at line 59 of file matrix.hpp.
Constructors, assignment and resizing | |
| Matrix ()=default | |
| Matrix (layout_type layout) | |
| Matrix (layout_type layout, uninitialized_t init) | |
| Matrix (plain_layout_type p) | |
| Matrix (plain_layout_type p, uninitialized_t init) | |
| Matrix (const Matrix &o) | |
| Copy the values from another matrix. | |
| Matrix (Matrix &&o) noexcept | |
| Matrix & | operator= (Matrix &&o) noexcept |
| Cheap move assignment. No data is copied. | |
| ~Matrix () | |
| void | resize (layout_type new_layout) |
| Resize the matrix to a new layout, reallocating if the padded size changes. | |
Element access | |
| value_type & | operator() (index_type l, index_type r, index_type c) |
Access a single element at layer l, row r and column c. | |
| const value_type & | operator() (index_type l, index_type r, index_type c) const |
Access a single element at layer l, row r and column c. | |
Batch-wise slicing | |
| auto | batch (index_type b) |
Access a batch of batch_size() layers, starting at batch index b (i.e. | |
| auto | batch (index_type b) const |
Access a batch of batch_size() layers, starting at batch index b (i.e. | |
| auto | batch_dyn (index_type b) |
| Same as batch(), but returns a view with a dynamic batch size. | |
| auto | batch_dyn (index_type b) const |
| Same as batch(), but returns a view with a dynamic batch size. | |
| auto | middle_batches (index_type b, index_type n, index_type stride=1) |
Get a view of n batches starting at batch b, with a stride of stride layers. | |
| auto | middle_batches (index_type b, index_type n, index_type stride=1) const |
Get a view of n batches starting at batch b, with a stride of stride layers. | |
Layer-wise slicing | |
| guanaqo::MatrixView< T, I, standard_stride_type, O > | operator() (index_type l) |
Access a single layer l as a non-batched view. | |
| guanaqo::MatrixView< const T, I, standard_stride_type, O > | operator() (index_type l) const |
Access a single layer l as a non-batched view. | |
| template<class N> | |
| auto | first_layers (N n) |
Get a view of the first n layers. Note that n can be a compile-time constant. | |
| template<class N> | |
| auto | first_layers (N n) const |
Get a view of the first n layers. Note that n can be a compile-time constant. | |
| template<class N> | |
| auto | middle_layers (index_type l, N n) |
Get a view of n layers starting at layer l. | |
| template<class N> | |
| auto | middle_layers (index_type l, N n) const |
Get a view of n layers starting at layer l. | |
Iterators and buffer access | |
| value_type * | data () |
| Get a pointer to the first element of the first layer. | |
| const value_type * | data () const |
| Get a pointer to the first element of the first layer. | |
| auto | begin () |
| Iterate linearly (in storage order) over all elements of the view. | |
| auto | begin () const |
| Iterate linearly (in storage order) over all elements of the view. | |
| auto | end () |
| Sentinel for begin(). | |
| auto | end () const |
| Sentinel for begin(). | |
Dimensions | |
| layout_type | layout () const |
| index_type | size () const |
| Total number of elements in the view (excluding padding). | |
| index_type | padded_size () const |
| Total number of elements in the view (including all padding). | |
| depth_type | depth () const |
| Number of layers in the view (i.e. depth). | |
| index_type | ceil_depth () const |
| The depth rounded up to a multiple of the batch size. | |
| index_type | num_batches () const |
| Number of batches in the view, i.e. ceil_depth() / batch_size(). | |
| index_type | rows () const |
| Number of rows of the matrices. | |
| index_type | cols () const |
| Number of columns of the matrices. | |
| index_type | outer_size () const |
| The size of the outer dimension, i.e. | |
| index_type | inner_size () const |
| The size of the inner dimension, i.e. | |
Strides | |
| index_type | outer_stride () const |
| Outer stride of the matrices (leading dimension in BLAS parlance). | |
| constexpr auto | inner_stride () const |
| The inner stride of the matrices. | |
| constexpr auto | row_stride () const |
| The row stride of the matrices, i.e. | |
| constexpr auto | col_stride () const |
| The column stride of the matrices, i.e. | |
| index_type | layer_stride () const |
| The layer stride, i.e. | |
| bool | has_full_layer_stride () const |
| Whether the layer_stride() == outer_stride() * outer_size(). | |
| bool | has_full_outer_stride () const |
| Whether the outer_stride() == inner_stride() * inner_size(). | |
| bool | has_full_inner_stride () const |
| Whether the inner_stride() == 1. Always true. | |
| batch_size_type | batch_size () const |
| The batch size, i.e. the number of layers in each batch. Equals the inner stride. | |
Reshaping and slicing | |
| auto | reshaped (index_type rows, index_type cols) |
| Reshape the view to the given dimensions. The total size should not change. | |
| auto | reshaped (index_type rows, index_type cols) const |
| Reshape the view to the given dimensions. The total size should not change. | |
| auto | top_rows (index_type n) |
Get a view of the first n rows. | |
| auto | top_rows (index_type n) const |
Get a view of the first n rows. | |
| auto | left_cols (index_type n) |
Get a view of the first n columns. | |
| auto | left_cols (index_type n) const |
Get a view of the first n columns. | |
| auto | bottom_rows (index_type n) |
Get a view of the last n rows. | |
| auto | bottom_rows (index_type n) const |
Get a view of the last n rows. | |
| auto | right_cols (index_type n) |
Get a view of the last n columns. | |
| auto | right_cols (index_type n) const |
Get a view of the last n columns. | |
| auto | middle_rows (index_type r, index_type n) |
Get a view of n rows starting at row r. | |
| auto | middle_rows (index_type r, index_type n) const |
Get a view of n rows starting at row r. | |
| auto | middle_rows (index_type r, index_type n, index_type stride) |
Get a view of n rows starting at row r. | |
| auto | middle_rows (index_type r, index_type n, index_type stride) const |
Get a view of n rows starting at row r. | |
| auto | middle_cols (index_type c, index_type n) |
Get a view of n columns starting at column c. | |
| auto | middle_cols (index_type c, index_type n) const |
Get a view of n columns starting at column c. | |
| auto | middle_cols (index_type c, index_type n, index_type stride) |
Get a view of n columns starting at column c. | |
| auto | middle_cols (index_type c, index_type n, index_type stride) const |
Get a view of n columns starting at column c. | |
| auto | top_left (index_type nr, index_type nc) |
Get a view of the top-left nr by nc block of the matrices. | |
| auto | top_left (index_type nr, index_type nc) const |
Get a view of the top-left nr by nc block of the matrices. | |
| auto | top_right (index_type nr, index_type nc) |
Get a view of the top-right nr by nc block of the matrices. | |
| auto | top_right (index_type nr, index_type nc) const |
Get a view of the top-right nr by nc block of the matrices. | |
| auto | bottom_left (index_type nr, index_type nc) |
Get a view of the bottom-left nr by nc block of the matrices. | |
| auto | bottom_left (index_type nr, index_type nc) const |
Get a view of the bottom-left nr by nc block of the matrices. | |
| auto | bottom_right (index_type nr, index_type nc) |
Get a view of the bottom-right nr by nc block of the matrices. | |
| auto | bottom_right (index_type nr, index_type nc) const |
Get a view of the bottom-right nr by nc block of the matrices. | |
| auto | block (index_type r, index_type c, index_type nr, index_type nc) |
Get a view of the nr by nc block of the matrices starting at row r and column c. | |
| auto | block (index_type r, index_type c, index_type nr, index_type nc) const |
Get a view of the nr by nc block of the matrices starting at row r and column c. | |
| auto | transposed () |
| Get a transposed view of the matrices. | |
| auto | transposed () const |
| Get a transposed view of the matrices. | |
Value manipulation | |
| Matrix & | operator= (const Matrix &o) |
| Copy the values of another matrix, resizing if necessary. | |
| template<class U, class J, class R, class E, class M> | |
| Matrix & | operator= (View< U, J, R, E, M, O > other) |
| Copy the values from a compatible view, resizing if necessary. | |
| void | set_constant (value_type t) |
| void | add_to_diagonal (const value_type &t) |
| void | negate () |
| template<class Other> | |
| void | copy_values (const Other &other) |
| template<class U, class J, class R, class E, class M> | |
| Matrix & | operator+= (View< U, J, R, E, M, O > other) |
View conversions | |
| view_type | view () |
| Returns the same view. For consistency with Matrix. | |
| const_view_type | view () const |
| Returns the same view. For consistency with Matrix. | |
| auto | as_const () const |
| Explicit conversion to a const view. | |
| operator view_type () | |
| operator const_view_type () const | |
| operator View< T, I, S, D, I, O > () | |
| operator View< const T, I, S, D, I, O > () const | |
| operator View< T, I, S, integral_value_type_t< D >, DefaultStride, O > () | |
| operator View< const T, I, S, integral_value_type_t< D >, DefaultStride, O > () const | |
| operator guanaqo::MatrixView< T, I, standard_stride_type, O > () | |
| operator guanaqo::MatrixView< const T, I, standard_stride_type, O > () const | |
Public Types | |
| using | view_type = View<T, I, S, D, DefaultStride, O> |
| using | const_view_type = typename view_type::const_view_type |
| using | layout_type = typename view_type::layout_type |
| using | plain_layout_type = typename layout_type::PlainLayout |
| using | value_type = T |
| using | index_type = typename layout_type::index_type |
| using | batch_size_type = typename layout_type::batch_size_type |
| using | depth_type = typename layout_type::depth_type |
| using | standard_stride_type = typename layout_type::standard_stride_type |
| using | alignment_type = A |
Static Public Attributes | |
| static constexpr StorageOrder | storage_order = view_type::storage_order |
| static constexpr bool | is_column_major = view_type::is_column_major |
| static constexpr bool | is_row_major = view_type::is_row_major |
| static constexpr bool | has_single_batch_at_compile_time |
| static constexpr bool | has_single_layer_at_compile_time |
Private Member Functions | |
| void | clear () |
| template<class U, class J, class R, class E, class M> | |
| void | assign_from_view (View< U, J, R, E, M, O > other) |
Static Private Member Functions | |
| static constexpr auto | default_alignment (layout_type layout) |
| static auto | allocate (layout_type layout) |
| static auto | allocate (layout_type layout, uninitialized_t init) |
Private Attributes | |
| view_type | view_ |
| using batmat::matrix::Matrix< T, I, S, D, O, A >::view_type = View<T, I, S, D, DefaultStride, O> |
Definition at line 61 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::const_view_type = typename view_type::const_view_type |
Definition at line 62 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::layout_type = typename view_type::layout_type |
Definition at line 63 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::plain_layout_type = typename layout_type::PlainLayout |
Definition at line 64 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::value_type = T |
Definition at line 65 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::index_type = typename layout_type::index_type |
Definition at line 66 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::batch_size_type = typename layout_type::batch_size_type |
Definition at line 67 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::depth_type = typename layout_type::depth_type |
Definition at line 68 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::standard_stride_type = typename layout_type::standard_stride_type |
Definition at line 69 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::alignment_type = A |
Definition at line 70 of file matrix.hpp.
|
default |
|
inline |
Definition at line 124 of file matrix.hpp.
|
inline |
Definition at line 125 of file matrix.hpp.
|
inline |
Definition at line 127 of file matrix.hpp.
|
inline |
Definition at line 128 of file matrix.hpp.
|
inline |
Copy the values from another matrix.
Definition at line 130 of file matrix.hpp.
|
inlinenoexcept |
Definition at line 133 of file matrix.hpp.
|
inline |
Definition at line 143 of file matrix.hpp.
|
inlinestaticconstexprprivate |
Definition at line 82 of file matrix.hpp.
|
inlinestaticnodiscardprivate |
Definition at line 90 of file matrix.hpp.
|
inlinestaticnodiscardprivate |
Definition at line 94 of file matrix.hpp.
|
inlineprivate |
Definition at line 98 of file matrix.hpp.
|
inlineprivate |
Definition at line 107 of file matrix.hpp.
|
inlinenoexcept |
Cheap move assignment. No data is copied.
Definition at line 135 of file matrix.hpp.
|
inline |
Resize the matrix to a new layout, reallocating if the padded size changes.
Definition at line 146 of file matrix.hpp.
|
inlinenodiscard |
Access a single element at layer l, row r and column c.
Definition at line 160 of file matrix.hpp.
|
inlinenodiscard |
Access a single element at layer l, row r and column c.
Definition at line 164 of file matrix.hpp.
|
inlinenodiscard |
Access a batch of batch_size() layers, starting at batch index b (i.e.
starting at layer b * batch_size()).
Definition at line 174 of file matrix.hpp.
|
inlinenodiscard |
Access a batch of batch_size() layers, starting at batch index b (i.e.
starting at layer b * batch_size()).
Definition at line 176 of file matrix.hpp.
|
inlinenodiscard |
Same as batch(), but returns a view with a dynamic batch size.
If the total depth is not a multiple of the batch size, the last batch will have a smaller size.
Definition at line 178 of file matrix.hpp.
|
inlinenodiscard |
Same as batch(), but returns a view with a dynamic batch size.
If the total depth is not a multiple of the batch size, the last batch will have a smaller size.
Definition at line 180 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n batches starting at batch b, with a stride of stride layers.
Definition at line 182 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n batches starting at batch b, with a stride of stride layers.
Definition at line 186 of file matrix.hpp.
|
inlinenodiscard |
Access a single layer l as a non-batched view.
Definition at line 196 of file matrix.hpp.
|
inlinenodiscard |
Access a single layer l as a non-batched view.
Definition at line 201 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n layers. Note that n can be a compile-time constant.
Definition at line 206 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n layers. Note that n can be a compile-time constant.
Definition at line 211 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n layers starting at layer l.
Note that n can be a compile-time constant.
Definition at line 216 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n layers starting at layer l.
Note that n can be a compile-time constant.
Definition at line 221 of file matrix.hpp.
|
inlinenodiscard |
Get a pointer to the first element of the first layer.
Definition at line 231 of file matrix.hpp.
|
inlinenodiscard |
Get a pointer to the first element of the first layer.
Definition at line 233 of file matrix.hpp.
|
inlinenodiscard |
Iterate linearly (in storage order) over all elements of the view.
Definition at line 235 of file matrix.hpp.
|
inlinenodiscard |
Iterate linearly (in storage order) over all elements of the view.
Definition at line 237 of file matrix.hpp.
|
inlinenodiscard |
Sentinel for begin().
Definition at line 239 of file matrix.hpp.
|
inlinenodiscard |
Sentinel for begin().
Definition at line 241 of file matrix.hpp.
|
inlinenodiscard |
Definition at line 248 of file matrix.hpp.
|
inlinenodiscard |
Total number of elements in the view (excluding padding).
Definition at line 250 of file matrix.hpp.
|
inlinenodiscard |
Total number of elements in the view (including all padding).
Definition at line 252 of file matrix.hpp.
|
inlinenodiscard |
Number of layers in the view (i.e. depth).
Definition at line 254 of file matrix.hpp.
|
inlinenodiscard |
The depth rounded up to a multiple of the batch size.
Definition at line 256 of file matrix.hpp.
|
inlinenodiscard |
Number of batches in the view, i.e. ceil_depth() / batch_size().
Definition at line 258 of file matrix.hpp.
|
inlinenodiscard |
Number of rows of the matrices.
Definition at line 260 of file matrix.hpp.
|
inlinenodiscard |
Number of columns of the matrices.
Definition at line 262 of file matrix.hpp.
|
inlinenodiscard |
The size of the outer dimension, i.e.
the number of columns for column-major storage, or the number of rows for row-major storage.
Definition at line 264 of file matrix.hpp.
|
inlinenodiscard |
The size of the inner dimension, i.e.
the number of rows for column-major storage, or the number of columns for row-major storage.
Definition at line 266 of file matrix.hpp.
|
inlinenodiscard |
Outer stride of the matrices (leading dimension in BLAS parlance).
Should be multiplied by the batch size to get the actual number of elements.
Definition at line 274 of file matrix.hpp.
|
inlinenodiscardconstexpr |
The inner stride of the matrices.
Should be multiplied by the batch size to get the actual number of elements.
Definition at line 276 of file matrix.hpp.
|
inlinenodiscardconstexpr |
The row stride of the matrices, i.e.
the distance between elements in consecutive rows in a given column. Should be multiplied by the batch size to get the actual number of elements.
Definition at line 278 of file matrix.hpp.
|
inlinenodiscardconstexpr |
The column stride of the matrices, i.e.
the distance between elements in consecutive columns in a given row. Should be multiplied by the batch size to get the actual number of elements.
Definition at line 280 of file matrix.hpp.
|
inlinenodiscard |
The layer stride, i.e.
the distance between the first layer of one batch and the first layer of the next batch. Should be multiplied by the batch size to get the actual number of elements.
Definition at line 282 of file matrix.hpp.
|
inlinenodiscard |
Whether the layer_stride() == outer_stride() * outer_size().
Definition at line 284 of file matrix.hpp.
|
inlinenodiscard |
Whether the outer_stride() == inner_stride() * inner_size().
Definition at line 286 of file matrix.hpp.
|
inlinenodiscard |
Whether the inner_stride() == 1. Always true.
Definition at line 288 of file matrix.hpp.
|
inlinenodiscard |
The batch size, i.e. the number of layers in each batch. Equals the inner stride.
Definition at line 290 of file matrix.hpp.
|
inlinenodiscard |
Reshape the view to the given dimensions. The total size should not change.
Definition at line 298 of file matrix.hpp.
|
inlinenodiscard |
Reshape the view to the given dimensions. The total size should not change.
Definition at line 302 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n rows.
Definition at line 306 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n rows.
Definition at line 308 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n columns.
Definition at line 310 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n columns.
Definition at line 312 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n rows.
Definition at line 314 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n rows.
Definition at line 316 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n columns.
Definition at line 318 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n columns.
Definition at line 320 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 322 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 324 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 328 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 334 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 340 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 342 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 346 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 352 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-left nr by nc block of the matrices.
Definition at line 358 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-left nr by nc block of the matrices.
Definition at line 360 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-right nr by nc block of the matrices.
Definition at line 364 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-right nr by nc block of the matrices.
Definition at line 366 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-left nr by nc block of the matrices.
Definition at line 370 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-left nr by nc block of the matrices.
Definition at line 374 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-right nr by nc block of the matrices.
Definition at line 378 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-right nr by nc block of the matrices.
Definition at line 382 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the nr by nc block of the matrices starting at row r and column c.
Definition at line 386 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the nr by nc block of the matrices starting at row r and column c.
Definition at line 390 of file matrix.hpp.
|
inlinenodiscard |
Get a transposed view of the matrices.
Note that the data itself is not modified, the returned view simply accesses the same data with rows and column indices swapped.
Definition at line 394 of file matrix.hpp.
|
inlinenodiscard |
Get a transposed view of the matrices.
Note that the data itself is not modified, the returned view simply accesses the same data with rows and column indices swapped.
Definition at line 396 of file matrix.hpp.
|
inline |
Copy the values of another matrix, resizing if necessary.
Definition at line 404 of file matrix.hpp.
|
inline |
Copy the values from a compatible view, resizing if necessary.
Definition at line 418 of file matrix.hpp.
|
inline |
Definition at line 424 of file matrix.hpp.
|
inline |
Definition at line 426 of file matrix.hpp.
|
inline |
Definition at line 428 of file matrix.hpp.
|
inline |
Definition at line 431 of file matrix.hpp.
|
inline |
Definition at line 437 of file matrix.hpp.
|
inlinenodiscard |
Returns the same view. For consistency with Matrix.
Definition at line 448 of file matrix.hpp.
|
inlinenodiscard |
Returns the same view. For consistency with Matrix.
Definition at line 450 of file matrix.hpp.
|
inlinenodiscard |
Explicit conversion to a const view.
Definition at line 452 of file matrix.hpp.
|
inline |
Definition at line 454 of file matrix.hpp.
|
inline |
Definition at line 455 of file matrix.hpp.
|
inline |
Definition at line 456 of file matrix.hpp.
|
inline |
Definition at line 457 of file matrix.hpp.
|
inline |
Definition at line 458 of file matrix.hpp.
|
inline |
Definition at line 463 of file matrix.hpp.
|
inline |
Definition at line 468 of file matrix.hpp.
|
inline |
Definition at line 473 of file matrix.hpp.
|
staticconstexpr |
Definition at line 71 of file matrix.hpp.
|
staticconstexpr |
Definition at line 72 of file matrix.hpp.
|
staticconstexpr |
Definition at line 73 of file matrix.hpp.
|
staticconstexpr |
Definition at line 74 of file matrix.hpp.
|
staticconstexpr |
Definition at line 76 of file matrix.hpp.
|
private |
Definition at line 80 of file matrix.hpp.