Skip to content

Commit 4b89918

Browse files
committed
Fix docs
1 parent 2dd59d7 commit 4b89918

File tree

2 files changed

+74
-68
lines changed

2 files changed

+74
-68
lines changed

docs/numba.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ conda install numba
3939

4040
## Overview
4141

42-
The numba integration provides:
43-
44-
- **{class}`NumbaTreeSequence`**: A Numba-compatible representation of tree sequence data
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
48-
49-
These classes are designed to work within Numba's `@njit` decorated functions,
50-
allowing you to write high-performance tree sequence analysis code.
42+
The numba integration provides a {class}`tskit.TreeSequence` wrapper class {class}`NumbaTreeSequence`.
43+
This class can be used directly in `numba.njit` compiled functions, and provides several efficient
44+
methods for tree traversal:
45+
46+
- **{meth}`~NumbaTreeSequence.tree_index`**: For efficient iteration through the trees in the sequence
47+
- **{meth}`~NumbaTreeSequence.parent_index`**: For efficient access to parent edge information, to
48+
traverse upwards through the ARG.
49+
- **{meth}`~NumbaTreeSequence.child_index`**: For efficient access to child edge information, to
50+
traverse downwards through the ARG.
51+
52+
These methods are optimised to work within Numba's `@njit` decorated functions,
53+
allowing you to write high-performance tree sequence analysis code in a plain Python style.
5154

5255
## Basic Usage
5356

python/tskit/jit/numba.py

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class EdgeRange:
4343
4444
Attributes
4545
----------
46-
start : int32
46+
start : int
4747
Starting index of the edge range (inclusive).
48-
stop : int32
48+
stop : int
4949
Stopping index of the edge range (exclusive).
50-
order : int32[]
51-
Array containing edge IDs in the order they should be processed.
50+
order : numpy.ndarray
51+
Array (dtype=np.int32) containing edge IDs in the order they should be processed.
5252
The edge ids in this range are order[start:stop].
5353
"""
5454

@@ -70,10 +70,11 @@ class ParentIndex:
7070
7171
Attributes
7272
----------
73-
edge_index : int32[num_edges]
74-
Array of edge IDs sorted by child node and left coordinate.
75-
index_range : int32[num_nodes, 2]
76-
For each node, the [start, stop) range in edge_index where this node is child.
73+
edge_index : numpy.ndarray
74+
Array (dtype=np.int32) of edge IDs sorted by child node and left coordinate.
75+
index_range : numpy.ndarray
76+
Array (dtype=np.int32, shape=(num_nodes, 2)) where each row contains the
77+
[start, stop) range in edge_index where this node is the child.
7778
"""
7879

7980
def __init__(self, edge_index, index_range):
@@ -97,20 +98,20 @@ class TreeIndex:
9798
----------
9899
ts : NumbaTreeSequence
99100
Reference to the tree sequence being traversed.
100-
index : int32
101+
index : int
101102
Current tree index. -1 indicates no current tree (null state).
102-
direction : int32
103+
direction : int
103104
Traversal direction: tskit.FORWARD or tskit.REVERSE. tskit.NULL
104105
if uninitialised.
105-
interval : tuple of float64
106+
interval : tuple
106107
Genomic interval (left, right) covered by the current tree.
107-
in_range : NumbaEdgeRange
108+
in_range : EdgeRange
108109
Edges being added to form this current tree, relative to the last state
109-
out_range : NumbaEdgeRange
110+
out_range : EdgeRange
110111
Edges being removed to form this current tree, relative to the last state
111-
site_range : tuple of int32
112+
site_range : tuple
112113
Range of sites in the current tree (start, stop).
113-
mutation_range : tuple of int32
114+
mutation_range : tuple
114115
Range of mutations in the current tree (start, stop).
115116
116117
Example
@@ -316,54 +317,56 @@ class NumbaTreeSequence:
316317
317318
Attributes
318319
----------
319-
num_trees : int32
320+
num_trees : int
320321
Number of trees in the tree sequence.
321-
num_nodes : int32
322+
num_nodes : int
322323
Number of nodes in the tree sequence.
323-
num_samples : int32
324+
num_samples : int
324325
Number of samples in the tree sequence.
325-
num_edges : int32
326+
num_edges : int
326327
Number of edges in the tree sequence.
327-
num_sites : int32
328+
num_sites : int
328329
Number of sites in the tree sequence.
329-
num_mutations : int32
330+
num_mutations : int
330331
Number of mutations in the tree sequence.
331-
sequence_length : float64
332+
sequence_length : float
332333
Total sequence length of the tree sequence.
333-
edges_left : float64[]
334-
Left coordinates of edges.
335-
edges_right : float64[]
336-
Right coordinates of edges.
337-
edges_parent : int32[]
338-
Parent node IDs for each edge.
339-
edges_child : int32[]
340-
Child node IDs for each edge.
341-
nodes_time : float64[]
342-
Time values for each node.
343-
nodes_flags : uint32[]
344-
Flag values for each node.
345-
nodes_population : int32[]
346-
Population IDs for each node.
347-
nodes_individual : int32[]
348-
Individual IDs for each node.
349-
individuals_flags : uint32[]
350-
Flag values for each individual.
351-
sites_position : float64[]
352-
Positions of sites along the sequence.
353-
mutations_site : int32[]
354-
Site IDs for each mutation.
355-
mutations_node : int32[]
356-
Node IDs for each mutation.
357-
mutations_parent : int32[]
358-
Parent mutation IDs.
359-
mutations_time : float64[]
360-
Time values for each mutation.
361-
breakpoints : float64[]
362-
Genomic positions where trees change.
363-
indexes_edge_insertion_order : int32[]
364-
Order in which edges are inserted during tree building.
365-
indexes_edge_removal_order : int32[]
366-
Order in which edges are removed during tree building.
334+
edges_left : numpy.ndarray
335+
Array (dtype=np.float64) of left coordinates of edges.
336+
edges_right : numpy.ndarray
337+
Array (dtype=np.float64) of right coordinates of edges.
338+
edges_parent : numpy.ndarray
339+
Array (dtype=np.int32) of parent node IDs for each edge.
340+
edges_child : numpy.ndarray
341+
Array (dtype=np.int32) of child node IDs for each edge.
342+
nodes_time : numpy.ndarray
343+
Array (dtype=np.float64) of time values for each node.
344+
nodes_flags : numpy.ndarray
345+
Array (dtype=np.uint32) of flag values for each node.
346+
nodes_population : numpy.ndarray
347+
Array (dtype=np.int32) of population IDs for each node.
348+
nodes_individual : numpy.ndarray
349+
Array (dtype=np.int32) of individual IDs for each node.
350+
individuals_flags : numpy.ndarray
351+
Array (dtype=np.uint32) of flag values for each individual.
352+
sites_position : numpy.ndarray
353+
Array (dtype=np.float64) of positions of sites along the sequence.
354+
mutations_site : numpy.ndarray
355+
Array (dtype=np.int32) of site IDs for each mutation.
356+
mutations_node : numpy.ndarray
357+
Array (dtype=np.int32) of node IDs for each mutation.
358+
mutations_parent : numpy.ndarray
359+
Array (dtype=np.int32) of parent mutation IDs.
360+
mutations_time : numpy.ndarray
361+
Array (dtype=np.float64) of time values for each mutation.
362+
breakpoints : numpy.ndarray
363+
Array (dtype=np.float64) of genomic positions where trees change.
364+
indexes_edge_insertion_order : numpy.ndarray
365+
Array (dtype=np.int32) specifying the order in which edges are inserted
366+
during tree building.
367+
indexes_edge_removal_order : numpy.ndarray
368+
Array (dtype=np.int32) specifying the order in which edges are removed
369+
during tree building.
367370
368371
"""
369372

@@ -443,9 +446,9 @@ def child_index(self):
443446
"""
444447
Create child index array for finding child edges of nodes.
445448
446-
:return: Array where each row [node] contains [start, stop) range of edges
447-
where this node is the parent.
448-
:rtype: int32[num_nodes, 2]
449+
:return: A numpy array (dtype=np.int32, shape=(num_nodes, 2)) where each row
450+
contains the [start, stop) range of edges where this node is the parent.
451+
:rtype: numpy.ndarray
449452
"""
450453
child_range = np.full((self.num_nodes, 2), -1, dtype=np.int32)
451454
edges_parent = self.edges_parent

0 commit comments

Comments
 (0)