warp.sparse.BsrMatrix#
- class warp.sparse.BsrMatrix[source]#
Untyped base class for BSR and CSR matrices.
Should not be constructed directly but through functions such as
bsr_zeros().- nnz#
Upper bound for the number of non-zero blocks, used for dimensioning launches. The exact number is at
offsets[nrow-1]. See alsonnz_sync().- Type:
- offsets#
Array of size at least
1 + nrowsuch that the start and end indices of the blocks of rowrareoffsets[r]andoffsets[r+1], respectively.- Type:
Array[int]
- values#
Array of size at least equal to
nnzcontaining block values.- Type:
Array[BlockType]
- __init__()#
Methods
__init__()Starts the asynchronous transfer of the exact nnz from the device offsets array to host and records an event for completion.
nnz_sync()Synchronize the number of non-zeros from the device
offsetsarray to the host.notify_nnz_changed([nnz])Notify the matrix that the number of non-zeros has been changed from outside of the
warp.sparsebuiltin functions.Return a transposed copy of this matrix.
uncompress_rows([out])Compute the row index for each non-zero block from the compressed row offsets.
Attributes
Shape of the individual blocks.
Size of the individual blocks, i.e. number of rows per block times number of columns per block.
Device on which
offsets,columns, andvaluesare allocated -- assumed to be the same for all three arrays.Data type for individual block values.
Read-only property indicating whether the matrix participates in adjoint computations.
Scalar type for individual block coefficients.
Accesses the
valuesarray as a 3d scalar array.Shape of the matrix, i.e. number of rows/columns of blocks times number of rows/columns per block.
- property scalar_type: Scalar[source]#
Scalar type for individual block coefficients. For CSR matrices, this is the same as the block type.
- property block_size: int[source]#
Size of the individual blocks, i.e. number of rows per block times number of columns per block.
- property shape: tuple[int, int][source]#
Shape of the matrix, i.e. number of rows/columns of blocks times number of rows/columns per block.
- property device: Device[source]#
Device on which
offsets,columns, andvaluesare allocated – assumed to be the same for all three arrays.
- property requires_grad: bool[source]#
Read-only property indicating whether the matrix participates in adjoint computations.
- uncompress_rows(out=None)[source]#
Compute the row index for each non-zero block from the compressed row offsets.
- nnz_sync()[source]#
Synchronize the number of non-zeros from the device
offsetsarray to the host.Ensures that any ongoing transfer of the exact nnz number from the device offsets array to the host has completed, or, if none has been scheduled yet, starts a new transfer and waits for it to complete.
Then updates the host-side nnz upper bound to match the exact one, and returns it.
See also
notify_nnz_changed().- Return type:
- notify_nnz_changed(nnz=None)[source]#
Notify the matrix that the number of non-zeros has been changed from outside of the
warp.sparsebuiltin functions.Should be called in particular when the offsets array has been modified, or when the nnz upper bound has changed. Makes sure that the matrix is properly resized and starts the asynchronous transfer of the actual non-zero count.
- Parameters:
nnz (int | None) – The new upper-bound for the number of non-zeros. If not provided, it will be read from the device offsets array (requires a synchronization).
- Return type:
None
- copy_nnz_async()[source]#
Starts the asynchronous transfer of the exact nnz from the device offsets array to host and records an event for completion.
Deprecated; prefer
notify_nnz_changed()instead, which will make sure to resize arrays if necessary.- Return type:
None