Coordinate-aligned sparse algebra¶
Sparse algebra combines tensors by coordinate values. The row index is an ordering detail; the coordinate row is the key.
Join model¶
Let \(A\) and \(B\) be coordinate sets. The supported joins are:
The alignment result stores output coordinates plus gather rows for both
operands. Missing rows are encoded as -1 and filled by the operation.
Operation defaults¶
Operation |
Default join |
Reason |
|---|---|---|
|
|
Preserve contributions from either side. |
|
|
Preserve left-only and right-only support with fill values. |
|
|
Multiplication is usually meaningful only where both sides exist. |
|
|
Avoid introducing filled comparison values by default. |
|
|
Concatenate feature channels on shared support unless a join is supplied. |
Operator shortcuts¶
SparseTensor defines shortcuts for the common defaults:
x + yusessparse_addwith an outer join;x - yusessparse_subwith an outer join;x * yandx & yusesparse_mulwith an inner join.
Use the named functions when a branch merge requires explicit left,
right, or custom fill semantics.
Identity fast path¶
If two tensors share coordinate identity, algebra can operate directly on features:
If identity differs, alignment builds gather maps:
where \(\ell_j\) and \(r_j\) may be missing-row sentinels.
Row-changing utilities¶
prune, prune_mask, crop, and topk_rows produce row subsets.
They must transform coordinates, features, active-row metadata, and coordinate
identity together. replace_feature is the feature-only counterpart and
preserves coordinate identity when row count is unchanged.
Collation¶
sparse_collate accepts unbatched (N,3) coordinate arrays, prepends a
batch column, concatenates features, and records batch_counts. This is the
preferred entry point for building a batched sparse tensor from individual
samples.