warp.sparse.bsr_from_triplets#

warp.sparse.bsr_from_triplets(
rows_of_blocks,
cols_of_blocks,
rows,
columns,
values,
prune_numerical_zeros=True,
)[source]#

Construct a BSR matrix with values defined by coordinate-oriented (COO) triplets.

The first dimension of the three input arrays must match and indicates the number of COO triplets. This convenience constructor always builds compact storage. To build into reserved row capacity, allocate with bsr_zeros() using row_capacity and then call bsr_set_from_triplets() with topology="padded".

This function sums duplicate coordinates. When prune_numerical_zeros=True, it omits zero-valued input blocks. The returned matrix can therefore have fewer active blocks than input triplets, while nnz initially remains equal to the input array length. Call BsrMatrix.nnz_sync() to obtain the exact compact count before slicing columns and values. Entries beyond the active count are not part of the matrix and may be uninitialized. If nonzero duplicate blocks sum to zero, the result remains an active explicit-zero block until it is pruned by bsr_compress().

Use bsr_copy() to copy a matrix or change its scalar type or block shape. Use bsr_compress() to pack active blocks into compact storage and optionally prune explicit zeros. Neither operation requires converting the matrix back to COO.

Parameters:
  • rows_of_blocks (int) – Number of rows of blocks.

  • cols_of_blocks (int) – Number of columns of blocks.

  • rows (Array[int]) – Row index for each non-zero.

  • columns (Array[int]) – Columns index for each non-zero.

  • values (Array[Scalar | BlockType[Rows, Cols, Scalar]]) – Block values for each non-zero. Must be either a one-dimensional array with data type identical to the dest matrix’s block type, or a 3d array with data type equal to the dest matrix’s scalar type.

  • prune_numerical_zeros (bool) – If True, will ignore the zero-valued blocks.