You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/numba.md
+15-20Lines changed: 15 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,10 +42,9 @@ conda install numba
42
42
The numba integration provides:
43
43
44
44
-**{class}`NumbaTreeSequence`**: A Numba-compatible representation of tree sequence data
45
-
-**{class}`NumbaTreeIndex`**: A class for efficient tree iteration
46
-
-**{class}`NumbaEdgeRange`**: Container class for edge ranges during iteration
47
-
-**{class}`NumbaChildIndex`**: A class for efficiently finding child edges of nodes
48
-
-**{class}`NumbaParentIndex`**: A class for efficiently finding parent edges of nodes
45
+
-**{class}`TreeIndex`**: A class for efficient tree iteration
46
+
-**{class}`EdgeRange`**: Container class for edge ranges during iteration
47
+
-**{class}`ParentIndex`**: Container for parent edge index information
49
48
50
49
These classes are designed to work within Numba's `@njit` decorated functions,
51
50
allowing you to write high-performance tree sequence analysis code.
@@ -78,11 +77,11 @@ print(type(numba_ts))
78
77
79
78
## Tree Iteration
80
79
81
-
Tree iteration can be performed in `numba.njit` compiled functions using the {class}`NumbaTreeIndex` class.
80
+
Tree iteration can be performed in `numba.njit` compiled functions using the {class}`TreeIndex` class.
82
81
This class provides `next()` and `prev()` methods for forward and backward iteration through the trees in a tree sequence. Its `in_range` and `out_range` attributes provide the edges that must be added or removed to form the current
83
82
tree from the previous tree, along with the current tree `interval` and its sites and mutations through `site_range` and `mutation_range`.
84
83
85
-
A `NumbaTreeIndex` instance can be obtained from a `NumbaTreeSequence` using the `tree_index()` method. The initial state of this is of a "null" tree outside the range of the tree sequence, the first call to `next()` or `prev()` will be to the first, or last tree sequence tree respectively. After that, the `in_range` and `out_range` attributes will provide the edges that must be added or removed to form the current tree from the previous tree. For example
84
+
A `TreeIndex` instance can be obtained from a {class}`NumbaTreeSequence` using the {meth}`~NumbaTreeSequence.tree_index` method. The initial state of this is of a "null" tree outside the range of the tree sequence, the first call to `next()` or `prev()` will be to the first, or last tree sequence tree respectively. After that, the `in_range` and `out_range` attributes will provide the edges that must be added or removed to form the current tree from the previous tree. For example
86
85
`tree_index.in_range.order[in_range.start:in_range.stop]` will give the edge ids that are new in the current tree, and `tree_index.out_range.order[out_range.start:out_range.stop]` will give the edge ids that are no longer present in the current tree. `tree_index.site_range` and
87
86
`tree_index.mutation_range` give the indexes into the tree sequences site and mutation arrays.
Beyond iterating through trees, you may need to traverse the ARG vertically. The {class}`NumbaChildIndex`and {class}`NumbaParentIndex` classes provide efficient access to parent-child relationships in the edge table within `numba.njit` functions.
258
+
Beyond iterating through trees, you may need to traverse the ARG vertically. The {meth}`~NumbaTreeSequence.child_index` method and {class}`ParentIndex` class provide efficient access to parent-child relationships in the edge table within `numba.njit` functions.
260
259
261
-
The {class}`NumbaChildIndex`allows you to efficiently find all edges where a given node is the parent. Since edges are already sorted by parent in the tskit data model, this is implemented using simple range indexing. For any node `u`, `child_range[u]` gives a tuple of the start and stop indices in the tskit edge table where node `u` is the parent.
260
+
The {meth}`~NumbaTreeSequence.child_index` method returns an array that allows you to efficiently find all edges where a given node is the parent. Since edges are already sorted by parent in the tskit data model, this is implemented using simple range indexing. For any node `u`, the returned array `child_index[u]` gives a tuple of the start and stop indices in the tskit edge table where node `u` is the parent.
262
261
263
-
The {class}`NumbaParentIndex`allows you to efficiently find all edges where a given node is the child. Since edges are not sorted by child in the edge table, this class builds a custom index that sorts edge IDs by child node (and then by left coordinate). For any node `u`, `parent_range[u]` gives a tuple of the start and stop indices in the `parent_index` array, and `parent_index[start:stop]` gives the actual tskit edge IDs.
262
+
The {meth}`~NumbaTreeSequence.parent_index` method creates a {class}`ParentIndex` that allows you to efficiently find all edges where a given node is the child. Since edges are not sorted by child in the edge table, the returned class contains a custom index that sorts edge IDs by child node (and then by left coordinate). For any node `u`, `parent_index.index_range[u]` gives a tuple of the start and stop indices in the `edge_index` array, and `parent_index.edge_index[start:stop]` gives the actual tskit edge IDs.
264
263
265
-
Both indexes can be obtained from a `NumbaTreeSequence`:
264
+
Both can be obtained from a {class}`NumbaTreeSequence`:
266
265
267
266
```{code-cell} python
268
267
# Get the indexes
269
268
child_index = numba_ts.child_index()
270
269
parent_index = numba_ts.parent_index()
271
270
272
271
# Example: find all edges where node 5 is the parent
273
-
start, stop = child_index.child_range[5]
272
+
start, stop = child_index[5]
274
273
print(f"Node 5 has {stop - start} child edges")
275
274
276
275
# Example: find all edges where node 3 is the child
277
-
start, stop = parent_index.parent_range[3]
276
+
start, stop = parent_index.index_range[3]
278
277
print(f"Node 3 appears as child in {stop - start} edges")
0 commit comments