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().

nrow#

Number of rows of blocks.

Type:

int

ncol#

Number of columns of blocks.

Type:

int

nnz#

Upper bound for the number of non-zero blocks, used for dimensioning launches. The exact number is at offsets[nrow-1]. See also nnz_sync().

Type:

int

offsets#

Array of size at least 1 + nrow such that the start and end indices of the blocks of row r are offsets[r] and offsets[r+1], respectively.

Type:

Array[int]

columns#

Array of size at least equal to nnz containing block column indices.

Type:

Array[int]

values#

Array of size at least equal to nnz containing block values.

Type:

Array[BlockType]

__init__()#

Methods

__init__()

copy_nnz_async()

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 offsets array to the host.

notify_nnz_changed([nnz])

Notify the matrix that the number of non-zeros has been changed from outside of the warp.sparse builtin functions.

transpose()

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

block_shape

Shape of the individual blocks.

block_size

Size of the individual blocks, i.e. number of rows per block times number of columns per block.

device

Device on which offsets, columns, and values are allocated -- assumed to be the same for all three arrays.

dtype

Data type for individual block values.

requires_grad

Read-only property indicating whether the matrix participates in adjoint computations.

scalar_type

Scalar type for individual block coefficients.

scalar_values

Accesses the values array as a 3d scalar array.

shape

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_shape: tuple[int, int][source]#

Shape of the individual blocks.

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 dtype: type[source]#

Data type for individual block values.

property device: Device[source]#

Device on which offsets, columns, and values are 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.

property scalar_values: array[source]#

Accesses the values array as a 3d scalar array.

uncompress_rows(out=None)[source]#

Compute the row index for each non-zero block from the compressed row offsets.

Parameters:

out (array)

Return type:

array

nnz_sync()[source]#

Synchronize the number of non-zeros from the device offsets array 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:

int

notify_nnz_changed(nnz=None)[source]#

Notify the matrix that the number of non-zeros has been changed from outside of the warp.sparse builtin 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

transpose()[source]#

Return a transposed copy of this matrix.