![]() |
batmat
0.0.15
Batched linear algebra routines
|
#include <batmat/matrix/matrix.hpp>
Class for a batch of matrices that owns its storage.
| T | Element value type. |
| I | Index type. |
| S | Inner stride (batch size). |
| D | Depth type. |
| O | Storage order (column or row major). |
| A | Batch alignment type. |
Definition at line 52 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 54 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 55 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::layout_type = typename view_type::layout_type |
Definition at line 56 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::plain_layout_type = typename layout_type::PlainLayout |
Definition at line 57 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::value_type = T |
Definition at line 58 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::index_type = typename layout_type::index_type |
Definition at line 59 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 60 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::depth_type = typename layout_type::depth_type |
Definition at line 61 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 62 of file matrix.hpp.
| using batmat::matrix::Matrix< T, I, S, D, O, A >::alignment_type = A |
Definition at line 63 of file matrix.hpp.
|
default |
|
inline |
Definition at line 117 of file matrix.hpp.
|
inline |
Definition at line 118 of file matrix.hpp.
|
inline |
Definition at line 120 of file matrix.hpp.
|
inline |
Definition at line 121 of file matrix.hpp.
|
inline |
Copy the values from another matrix.
Definition at line 123 of file matrix.hpp.
|
inlinenoexcept |
Definition at line 126 of file matrix.hpp.
|
inline |
Definition at line 136 of file matrix.hpp.
|
inlinestaticconstexprprivate |
Definition at line 75 of file matrix.hpp.
|
inlinestaticnodiscardprivate |
Definition at line 83 of file matrix.hpp.
|
inlinestaticnodiscardprivate |
Definition at line 87 of file matrix.hpp.
|
inlineprivate |
Definition at line 91 of file matrix.hpp.
|
inlineprivate |
Definition at line 100 of file matrix.hpp.
|
inlinenoexcept |
Cheap move assignment. No data is copied.
Definition at line 128 of file matrix.hpp.
|
inline |
Resize the matrix to a new layout, reallocating if the padded size changes.
Definition at line 139 of file matrix.hpp.
|
inlinenodiscard |
Access a single element at layer l, row r and column c.
Definition at line 153 of file matrix.hpp.
|
inlinenodiscard |
Access a single element at layer l, row r and column c.
Definition at line 157 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 167 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 169 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 171 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 173 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n batches starting at batch b, with a stride of stride layers.
Definition at line 175 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n batches starting at batch b, with a stride of stride layers.
Definition at line 179 of file matrix.hpp.
|
inlinenodiscard |
Access a single layer l as a non-batched view.
Definition at line 189 of file matrix.hpp.
|
inlinenodiscard |
Access a single layer l as a non-batched view.
Definition at line 194 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 199 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 204 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 209 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 214 of file matrix.hpp.
|
inlinenodiscard |
Get a pointer to the first element of the first layer.
Definition at line 224 of file matrix.hpp.
|
inlinenodiscard |
Get a pointer to the first element of the first layer.
Definition at line 226 of file matrix.hpp.
|
inlinenodiscard |
Iterate linearly (in storage order) over all elements of the view.
Definition at line 228 of file matrix.hpp.
|
inlinenodiscard |
Iterate linearly (in storage order) over all elements of the view.
Definition at line 230 of file matrix.hpp.
|
inlinenodiscard |
Sentinel for begin().
Definition at line 232 of file matrix.hpp.
|
inlinenodiscard |
Sentinel for begin().
Definition at line 234 of file matrix.hpp.
|
inlinenodiscard |
Definition at line 241 of file matrix.hpp.
|
inlinenodiscard |
Total number of elements in the view (excluding padding).
Definition at line 243 of file matrix.hpp.
|
inlinenodiscard |
Total number of elements in the view (including all padding).
Definition at line 245 of file matrix.hpp.
|
inlinenodiscard |
Number of layers in the view (i.e. depth).
Definition at line 247 of file matrix.hpp.
|
inlinenodiscard |
The depth rounded up to a multiple of the batch size.
Definition at line 249 of file matrix.hpp.
|
inlinenodiscard |
Number of batches in the view, i.e. ceil_depth() / batch_size().
Definition at line 251 of file matrix.hpp.
|
inlinenodiscard |
Number of rows of the matrices.
Definition at line 253 of file matrix.hpp.
|
inlinenodiscard |
Number of columns of the matrices.
Definition at line 255 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 257 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 259 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 267 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 269 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 271 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 273 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 275 of file matrix.hpp.
|
inlinenodiscard |
Whether the layer_stride() == outer_stride() * outer_size().
Definition at line 277 of file matrix.hpp.
|
inlinenodiscard |
Whether the outer_stride() == inner_stride() * inner_size().
Definition at line 279 of file matrix.hpp.
|
inlinenodiscard |
Whether the inner_stride() == 1. Always true.
Definition at line 281 of file matrix.hpp.
|
inlinenodiscard |
The batch size, i.e. the number of layers in each batch. Equals the inner stride.
Definition at line 283 of file matrix.hpp.
|
inlinenodiscard |
Reshape the view to the given dimensions. The total size should not change.
Definition at line 291 of file matrix.hpp.
|
inlinenodiscard |
Reshape the view to the given dimensions. The total size should not change.
Definition at line 295 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n rows.
Definition at line 299 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n rows.
Definition at line 301 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n columns.
Definition at line 303 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the first n columns.
Definition at line 305 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n rows.
Definition at line 307 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n rows.
Definition at line 309 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n columns.
Definition at line 311 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the last n columns.
Definition at line 313 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 315 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 317 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 321 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n rows starting at row r.
Definition at line 327 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 333 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 335 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 339 of file matrix.hpp.
|
inlinenodiscard |
Get a view of n columns starting at column c.
Definition at line 345 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-left nr by nc block of the matrices.
Definition at line 351 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-left nr by nc block of the matrices.
Definition at line 353 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-right nr by nc block of the matrices.
Definition at line 357 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the top-right nr by nc block of the matrices.
Definition at line 359 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-left nr by nc block of the matrices.
Definition at line 363 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-left nr by nc block of the matrices.
Definition at line 367 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-right nr by nc block of the matrices.
Definition at line 371 of file matrix.hpp.
|
inlinenodiscard |
Get a view of the bottom-right nr by nc block of the matrices.
Definition at line 375 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 379 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 383 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 387 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 389 of file matrix.hpp.
|
inline |
Copy the values of another matrix, resizing if necessary.
Definition at line 397 of file matrix.hpp.
|
inline |
Copy the values from a compatible view, resizing if necessary.
Definition at line 411 of file matrix.hpp.
|
inline |
Definition at line 417 of file matrix.hpp.
|
inline |
Definition at line 419 of file matrix.hpp.
|
inline |
Definition at line 421 of file matrix.hpp.
|
inline |
Definition at line 424 of file matrix.hpp.
|
inline |
Definition at line 430 of file matrix.hpp.
|
inlinenodiscard |
Returns the same view. For consistency with Matrix.
Definition at line 441 of file matrix.hpp.
|
inlinenodiscard |
Returns the same view. For consistency with Matrix.
Definition at line 443 of file matrix.hpp.
|
inlinenodiscard |
Explicit conversion to a const view.
Definition at line 445 of file matrix.hpp.
|
inline |
Definition at line 447 of file matrix.hpp.
|
inline |
Definition at line 448 of file matrix.hpp.
|
inline |
Definition at line 449 of file matrix.hpp.
|
inline |
Definition at line 450 of file matrix.hpp.
|
inline |
Definition at line 451 of file matrix.hpp.
|
inline |
Definition at line 456 of file matrix.hpp.
|
inline |
Definition at line 461 of file matrix.hpp.
|
inline |
Definition at line 466 of file matrix.hpp.
|
staticconstexpr |
Definition at line 64 of file matrix.hpp.
|
staticconstexpr |
Definition at line 65 of file matrix.hpp.
|
staticconstexpr |
Definition at line 66 of file matrix.hpp.
|
staticconstexpr |
Definition at line 67 of file matrix.hpp.
|
staticconstexpr |
Definition at line 69 of file matrix.hpp.
|
private |
Definition at line 73 of file matrix.hpp.