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 stored blocks, used for dimensioning launches. For compact matrices this is also the number of active non-zero blocks. See also
nnz_sync().- 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
- values#
Array of size at least equal to
nnzcontaining block values.- Type:
Array[BlockType]
- __init__()#
Methods
__init__()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 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 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 non-zero block from the compressed row offsets.
- 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 non-zero block count. For padded matrices, this is the total row-capacity storage size, not necessarily the active non-zero 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.- 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 a CPU APIC 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 non-zero 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