Owning batch of batch_size() matrices of equal (capacity) shape.
Dense (the default): column-major, element (i, j) of item b at data()[b * stride() + j * ld() + i], with ld() >= rows() and stride() >= ld() * cols(). CSR: per item, rows() + 1 row offsets (items offset_stride() apart) and nnz_capacity() values and column indices (items matrix_stride() apart), zero-based.
Storage is USM shared memory (UnifiedVector) on Device::default_device(), so it is host-accessible and device-accessible. A Matrix is a MatrixView of its own storage, so it is accepted wherever a MatrixView is and has every view member. Copy construction and copy assignment deep-copy the data; moves transfer it. The shape members are public but are not to be written.
A dense batch may be heterogeneous: set_active_dims() attaches per-item active extents no larger than the allocated rows() x cols().
| T | scalar type (float, double, std::complex<float>, std::complex<double>) |
| MType | MatrixFormat::Dense (default) or MatrixFormat::CSR |
#include <batchlas/blas/matrix.hh>
| batchlas::Matrix< T, MType >::Matrix | ( | int | rows, |
| int | cols, | ||
| int | batch_size = 1, | ||
| int | ld = 0, | ||
| int | stride = 0 ) |
Allocates an uninitialised dense batch.
| rows | rows per item |
| cols | columns per item |
| batch_size | number of items |
| ld | leading dimension; 0 means rows |
| stride | batch stride in elements; 0 means (resolved ld) * cols |
| batchlas::invalid_argument | on a negative argument, a resolved ld < rows, or a resolved stride < ld * cols |
| batchlas::Matrix< T, MType >::Matrix | ( | int | rows, |
| int | cols, | ||
| NonZeros | nnz, | ||
| int | batch_size = 1 ) |
Allocates an uninitialised CSR batch with room for nnz entries per item.
| rows | rows per item |
| cols | columns per item |
| nnz | per-item capacity; matrix_stride() == nnz, offset_stride() == rows + 1 |
| batch_size | number of items |
|
delete |
| batchlas::Matrix< T, MType >::Matrix | ( | const T * | data, |
| int | rows, | ||
| int | cols, | ||
| int | ld, | ||
| int | stride = 0, | ||
| int | batch_size = 1 ) |
Dense batch copied from existing host-readable memory.
(ld, stride) describe the source: element (i, j, b) is read from data[b * stride + j * ld + i]. The copy keeps the source's leading dimension but packs the items back to back (stride() == ld() * cols()); padding rows in the copy are zeroed and padding in the source is never read.
| data | source; must hold (batch_size-1)*stride + (cols-1)*ld + rows elements |
| rows | rows per item |
| cols | columns per item |
| ld | source leading dimension; 0 means rows |
| stride | source batch stride; 0 means (resolved ld) * cols |
| batch_size | number of items |
| batchlas::invalid_argument | on null data, rows or cols <= 0, batch_size <= 0, a resolved ld < rows, or (batch_size > 1) a stride < ld * cols |
| batchlas::Matrix< T, MType >::Matrix | ( | Span< const T > | data, |
| int | rows, | ||
| int | cols, | ||
| int | ld, | ||
| int | stride = 0, | ||
| int | batch_size = 1 ) |
Dense batch copied from a Span; as the pointer overload, plus a length check.
| batchlas::invalid_argument | also when data is shorter than the layout needs |
|
inline |
Mutable-Span (and UnifiedVector) spelling of the Span<const T> overload.
| batchlas::Matrix< T, MType >::Matrix | ( | const T * | values, |
| const int * | row_offsets, | ||
| const int * | col_indices, | ||
| int | rows, | ||
| int | cols, | ||
| NonZeros | nnz, | ||
| int | matrix_stride = 0, | ||
| int | offset_stride = 0, | ||
| int | batch_size = 1 ) |
CSR batch copied from existing host-readable arrays.
| values | matrix_stride * batch_size values |
| row_offsets | offset_stride * batch_size zero-based offsets |
| col_indices | matrix_stride * batch_size column indices |
| rows | rows per item |
| cols | columns per item |
| nnz | declared per-item non-zero count |
| matrix_stride | distance between items' value arrays; 0 means nnz. May exceed it. |
| offset_stride | distance between items' offset arrays; 0 means rows + 1 |
| batch_size | number of items |
|
delete |
Deleted so the pre-tag order (nnz before rows, cols) is a compile error.
|
inline |
|
inlinenoexcept |
|
static |
A batch of n x n identity matrices.
|
static |
Entries uniform in [-1, 1] (real and imaginary parts independently).
Deterministic: the same seed and shape give the same matrix. With hermitian, the lower triangle is overwritten with the conjugate of the upper and the diagonal made real.
| batchlas::invalid_argument | if hermitian and rows != cols |
|
static |
Random diagonally dominant sparse Hermitian batch; see csr_generators::random_sparse_hermitian_csr().
|
inlinestatic |
Random n x n triangular batch; see MatrixView::fill_triangular_random().
|
static |
A batch of zero matrices.
|
static |
A batch of all-ones matrices.
|
static |
A batch of n x n diagonal matrices, n = diag_values.size(), each with diag_values on the diagonal.
|
static |
n x n matrices with diagonal_value on the diagonal, non_diagonal_value in the uplo strict triangle and zero elsewhere.
|
static |
n x n tridiagonal Toeplitz matrices (constant diagonal, sub- and super-diagonal).
| Matrix< T, MType > batchlas::Matrix< T, MType >::to_column_major | ( | const Queue & | ctx, |
| int | row_pitch = 0 ) const |
Reinterprets this matrix's storage as row-major data and returns it column-major.
The row pitch is a parameter, never inferred. The result is packed and owns the memory the kernel writes, so the call waits on ctx before returning.
| ctx | queue for the conversion kernel |
| row_pitch | source row pitch in elements; 0 means packed (cols()), accepted only when this matrix is itself packed |
| std::invalid_argument | when the pitch is below cols(), runs past the allocation, straddles the next item, or is 0 on a non-packed matrix |
| Matrix< T, MType > batchlas::Matrix< T, MType >::to_column_major | ( | int | row_pitch = 0 | ) | const |
to_column_major() on an internal queue.
| Matrix< T, NewMType > batchlas::Matrix< T, MType >::convert_to | ( | const float_t< T > & | zero_threshold = 1e-7 | ) | const |
Copy in another storage format, on the default queue.
Dense to CSR drops entries at or below zero_threshold in magnitude (for complex, both parts) and sizes every item by the batch's largest non-zero count (see nnz()). CSR to Dense is supported; converting to the same format returns a copy.
| NewMType | target format |
| zero_threshold | magnitude at or below which a dense entry is not stored |
| batchlas::unsupported | for any other pair of formats |
| Matrix< T, MType > batchlas::Matrix< T, MType >::to_row_major | ( | const Queue & | ctx | ) | const |
Packed row-major copy (row pitch cols(), batch stride rows() * cols()).
Exactly what to_column_major() reads with its default pitch, so the two round-trip. Waits on ctx before returning.
| Matrix< T, MType > batchlas::Matrix< T, MType >::to_row_major | ( | ) | const |
to_row_major() on an internal queue.
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
This matrix as a plain MatrixView (a sliced copy); shares the backend handle.
| MatrixView< T, MType > batchlas::Matrix< T, MType >::view | ( | int | rows, |
| int | cols, | ||
| int | ld = -1, | ||
| int | stride = -1 ) const |
A dense view of the leading rows x cols block of every item.
| ld | leading dimension of the view; <= 0 keeps ld() |
| stride | batch stride of the view; <= 0 keeps stride() |
| batchlas::unsupported | on a CSR matrix |
| Matrix< U, MType > batchlas::Matrix< T, MType >::astype | ( | ) | const |
|
inline |
|
inline |
Host reference to element (row, col) of item batch anywhere in the allocated rows() x cols(), active extents ignored (MatrixView's checks them).
No bounds check beyond UnifiedVector's debug assert. The data is USM shared, so wait for any kernel writing it first.
|
inline |
| void batchlas::Matrix< T, MType >::copy_from | ( | const MatrixView< T, MType > & | src | ) |
Host copy of src into this matrix's own layout.
src has exactly this matrix's strides and capacity. | batchlas::invalid_argument | if rows, cols or batch size differ |
|
inline |
Attaches per-item active extents (copied), or clears them when both spans are empty.
Item b then occupies the leading active_rows[b] x active_cols[b] block of its allocated rows() x cols(); layout (ld, stride) is unchanged.
| batchlas::invalid_argument | unless both spans hold batch_size() entries, each in [0, rows()] and [0, cols()] respectively |
| Matrix< U, MType > batchlas::MatrixView< T, MType >::astype | ( | std::span< const int > | items | ) | const |
astype() of items only, packed in that order (item g at g * rows() * cols()).
| batchlas::out_of_range | for an item outside [0, batch_size()) |
| batchlas::invalid_argument | for a heterogeneous view |
| Event batchlas::MatrixView< T, MType >::fill | ( | const Queue & | ctx, |
| T | value ) const |
|
inline |
|
inline |
View of the sub-block rows x cols of every item; keeps ld and stride, never copies.
| batchlas::invalid_argument | if either slice is empty; batchlas::out_of_range past a dimension |
|
inline |
|
inline |
Part of row row of every item as a batched VectorView (inc = ld(), stride = stride()).
| batchlas::invalid_argument | if the slice is empty; batchlas::out_of_range past a dimension |
|
inline |
Part of column col of every item as a batched VectorView (inc = 1, stride = stride()).
| batchlas::invalid_argument | if the slice is empty; batchlas::out_of_range past a dimension |
| int batchlas::MatrixView< T, MType >::rows_ |
| int batchlas::MatrixView< T, MType >::cols_ |
| int batchlas::MatrixView< T, MType >::batch_size_ |