warp.sparse.bsr_compress#

warp.sparse.bsr_compress(
src,
prune_numerical_zeros=True,
inplace=False,
topology=None,
)[source]#

Compress the active blocks of src and return src.

Slack entries outside offsets[row]:offsets[row] + row_counts[row] are ignored. When inplace=False, the topology is rebuilt natively from active row and column data, and values are accumulated with differentiable Warp kernels. When inplace=True, entries are sorted and coalesced independently within each active row using native in-place compression without O(nnz) temporary allocation, but this path is not differentiable. In-place compression requires native support and currently supports matrices whose scalar type is float32 or float64; topology="padded" preserves the existing row capacity instead of packing active blocks into compact row storage. Compact compression sets src.row_counts to None and does not update any previously attached row-count array. Callers should not rely on buffer identity being preserved for any inplace value.

Parameters:
  • src (BsrMatrix[_MatrixBlockType[Rows, Cols, Scalar] | _ScalarBlockType[Scalar]]) – Matrix to compress.

  • prune_numerical_zeros (bool) – If True, zero-valued input blocks are ignored before coalescing.

  • inplace (bool) – If True, sort and coalesce each active row range directly in src using native in-place compression without O(nnz) temporary allocation. This path is not differentiable. With topology="compact", active blocks are also packed into compact row storage. If False, use differentiable value accumulation.

  • topology (Literal['compact', 'padded'] | None) – Topology policy for the compressed arrays. Defaults to "compact". "padded" preserves existing row capacity; it cannot report row-capacity overflow because compression never increases the active block count.

Return type:

BsrMatrix[_MatrixBlockType[Rows, Cols, Scalar] | _ScalarBlockType[Scalar]]