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#
Host-side upper bound on the number of stored block slots used by sparse operations, including for dimensioning launches. Topology-changing operations may leave this larger than the active block count, even for compact matrices. The backing arrays may have additional allocated capacity. Call
nnz_sync()before usingnnzas an exact count.- Type:
- offsets#
Array of size at least
1 + nrowsuch that the start and capacity end indices of rowrareoffsets[r]andoffsets[r+1], respectively.- Type:
Array[int]
- row_counts#
Optional array of size at least
nrowcontaining the active block count of each row. Active blocks of rowrare stored inoffsets[r]:offsets[r] + row_counts[r]. For compact matrices,row_countsisNone, in which case all storage in each row is active.- Type:
Array[int] | None
- columns#
Array of size at least equal to
nnzcontaining block column indices. Entries outside active row ranges are not part of the matrix and may be uninitialized.- Type:
Array[int]
- values#
Array of size at least equal to
nnzcontaining block values. Entries outside active row ranges are not part of the matrix and may be uninitialized. Active entries may also be uninitialized after topology-only or structure-only operations.- Type:
Array[BlockType]
Methods
Clear the asynchronous sparse status code.
Start the asynchronous transfer of
offsets[nrow]from the device offsets array to host.nnz_sync()Synchronize the stored block upper bound from the device
offsetsarray to the host.notify_nnz_changed([nnz, nnz_capacity])Notify the matrix that sparse storage metadata changed outside
warp.sparse.Return a human-readable message for
status_sync().Return the asynchronous sparse status code, synchronizing if needed.
Return a transposed copy of this matrix.
uncompress_rows([out])Compute the row index for each stored block slot 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 matrix arrays are allocated.
Data type for individual block values.
Read-only property indicating whether the matrix participates in adjoint computations.
Scalar type for individual block coefficients.
Access 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 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 stored block slot from the compressed row offsets.
The method writes
nnzentries. Whenoutis omitted, it allocates an array of that length. Entries outside active row ranges are-1. Whenoutis provided, entries beyondnnzare unchanged. For a compact matrix, usennz_sync()before treating the result as COO row data:nnz = matrix.nnz_sync() rows = matrix.uncompress_rows()[:nnz]
- nnz_sync()[source]#
Synchronize the stored block upper bound from the device
offsetsarray to the host.Ensures that any ongoing transfer of
offsets[nrow]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
offsets[nrow], and returns it. For compact matrices, this is the active stored block count. For padded matrices, this is the total row-capacity storage size, not necessarily the active block count.See also
notify_nnz_changed().- Raises:
RuntimeError – If called during a live CUDA graph capture because reading
offsets[nrow]requires a device-to-host transfer.NotImplementedError – If called during CPU graph capture after a topology update has been recorded. Query the count after replay instead.
- Return type:
- status_sync()[source]#
Return the asynchronous sparse status code, synchronizing if needed.
The status code is sticky: sparse operations can set it, but successful operations do not clear it. Use
clear_status()before an operation when checking only that operation’s status.- Raises:
RuntimeError – If called during a live CUDA graph capture because reading the status requires a device-to-host transfer.
NotImplementedError – If called during CPU graph capture, because a status update recorded in the capture is applied only on replay. Query the status after graph replay.
- Return type:
- status_message()[source]#
Return a human-readable message for
status_sync().- Return type:
- notify_nnz_changed(nnz=None, nnz_capacity=None)[source]#
Notify the matrix that sparse storage metadata changed outside
warp.sparse.Call this after modifying
offsetsor the host-sidennzupper bound directly. If assigning a new offsets array, also updaterow_countsfor padded matrices, or set it toNonefor compact matrices.- Parameters:
nnz (int | None) – New stored block count upper bound. If omitted, read from
offsets[nrow]unless nnz_capacity is provided. The caller is responsible for ensuring it is greater or equal tooffsets[nrow].nnz_capacity (int | None) – Optional storage pre-allocation size. If omitted, default to nnz. The caller is responsible for ensuring it is greater or equal to the true
offsets[nrow]value.
- Return type:
None
- copy_nnz_async()[source]#
Start the asynchronous transfer of
offsets[nrow]from the device offsets array to host.Deprecated; prefer
notify_nnz_changed()instead, which will make sure to resize arrays if necessary.- Return type:
None