Coordinate utilities¶
Coordinate utilities cover set operations, ordering, occupancy, and alignment. For sparse tensor identity semantics, read Sparse tensor model. For value-aligned sparse algebra, read Coordinate-aligned sparse algebra and the operation API at Sparse tensor algebra.
Set operations¶
- class mlx_lattice.core.coords.set_ops.CoordinateSet(coords, active_rows)[source]¶
Bases:
objectCapacity coordinate buffer with a lazy active count.
- Parameters:
coords (array)
active_rows (array)
- coords: array¶
- active_rows: array¶
- property active_count: array¶
- mlx_lattice.core.coords.set_ops.downsample_coords(coords, stride=2)[source]¶
Downsample coordinates by integer spatial stride.
- Return type:
- Parameters:
- mlx_lattice.core.coords.set_ops.union_coords(lhs, rhs)[source]¶
Return the coordinate-set union of two coordinate arrays.
- Return type:
- Parameters:
lhs (array)
rhs (array)
- mlx_lattice.core.coords.set_ops.intersection_coords(lhs, rhs)[source]¶
Return coordinates present in both input coordinate arrays.
- Return type:
- Parameters:
lhs (array)
rhs (array)
- mlx_lattice.core.coords.set_ops.lookup_coords(coords, queries)[source]¶
Map query coordinates to row indices in
coords.Missing query rows are encoded as
-1.- Return type:
array- Parameters:
coords (array)
queries (array)
Ordering¶
- class mlx_lattice.core.coords.ordering.CoordinateOrdering(coords, order, inverse_rows)[source]¶
Bases:
objectSorted coordinate rows and the row permutation used to produce them.
- Parameters:
coords (array)
order (array)
inverse_rows (array)
- coords: array¶
- order: array¶
- inverse_rows: array¶
- mlx_lattice.core.coords.ordering.morton_codes(coords)[source]¶
Return Morton/Z-order codes for batched sparse coordinates.
- Return type:
array- Parameters:
coords (array)
- mlx_lattice.core.coords.ordering.morton_order(coords)[source]¶
Return row indices that sort coordinates by Morton order.
- Return type:
array- Parameters:
coords (array)
Occupancy¶
- class mlx_lattice.core.coords.occupancy.SparseOccupancy(coords, active_rows, occupancy)[source]¶
Bases:
objectDownsampled coordinates plus an 8-bit child occupancy mask per row.
- Parameters:
coords (array)
active_rows (array)
occupancy (array)
- coords: array¶
- active_rows: array¶
- occupancy: array¶
- property active_count: array¶
- class mlx_lattice.core.coords.occupancy.OccupancyExpansion(coords, active_rows, parent_rows, child_indices)[source]¶
Bases:
objectExpanded child coordinates with parent row and child-index metadata.
- Parameters:
coords (array)
active_rows (array)
parent_rows (array)
child_indices (array)
- coords: array¶
- active_rows: array¶
- parent_rows: array¶
- child_indices: array¶
- property active_count: array¶
- mlx_lattice.core.coords.occupancy.occupancy_downsample(coords, active_rows=None)[source]¶
Downsample coordinates and record occupied children for each parent.
- Return type:
- Parameters:
coords (array)
active_rows (array | None)
Alignment¶
- class mlx_lattice.core.coords.alignment.SparseAlignment(coords, active_rows, lhs_rows, rhs_rows)[source]¶
Bases:
objectCoordinate value alignment for two sparse tensors.
coordsis the joined coordinate support.lhs_rowsandrhs_rowsgather features from the left and right tensors into that support;-1marks a missing value for the selected join mode.- Parameters:
coords (array)
active_rows (array)
lhs_rows (array)
rhs_rows (array)
- coords: array¶
- active_rows: array¶
- lhs_rows: array¶
- rhs_rows: array¶
- property active_count: array¶
- mlx_lattice.core.coords.alignment.build_sparse_alignment(lhs_coords, lhs_active_rows, rhs_coords, rhs_active_rows, *, join='inner')[source]¶
Build value-aligned row maps between two coordinate arrays.
Coordinates must have shape
(N, 4)and matching dtype. Active-row scalars describe the valid prefix of each coordinate buffer. The native builder returns joined coordinates and row maps forinner,left,right, oroutersupport.- Return type:
- Parameters:
lhs_coords (array)
lhs_active_rows (array)
rhs_coords (array)
rhs_active_rows (array)
join (SparseJoin)