index_to_ptr
¶
index_to_ptr(index: array, size: int) -> array
Converts a vector of indices into a compressed pointer vector.
Entry i of the result is the number of elements of index that are
smaller than i. When index is sorted, the elements equal to i
are located at ptr[i]:ptr[i + 1].
With the sorted source row of an edge index, the result is the rowptr
of the CSR format. With the sorted target row, it is the colptr of the
CSC format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
array
|
A 1D array of indices in |
required |
size
|
int
|
Number of possible indices, e.g. the number of nodes. |
required |
Returns:
| Type | Description |
|---|---|
array
|
An int64 array of length |
Example:
>>> index = mx.array([0, 2, 2, 3])
>>> index_to_ptr(index, size=5)
array([0, 1, 1, 3, 4, 4], dtype=int64)
Source code in mlx_graphs/utils/sorting.py
from mlx_graphs.utils.sorting import index_to_ptr · mlx_graphs/utils/sorting.py