skbio.tree.BPTree.numba_arrays#

BPTree.numba_arrays(gpu=None)[source]#

The tree’s arrays, for the Numba navigation functions.

Parameters:
gpumodule, optional

A Numba GPU module (numba_cuda_mlir.cuda or numba.cuda on NVIDIA, numba.hip on AMD) to place the arrays on a GPU: that of the tree’s data if it is on one, else the module’s current device. By default they stay on the host, for CPU code.

Returns:
tuple

An opaque bundle T of the tree’s topology and navigation index, passed to the functions of skbio.tree.bp.numba as their first argument, e.g. nav.parent(T, i). T.size is the number of parentheses.

Notes

On the host, T holds read-only views of the tree’s own arrays: no copy is made. On a GPU, they are uploaded on the first call and cached on the tree, so later calls (and the batch operations with engine="numba") reuse them. This is so whether or not the tree was created from an array on the device.

The topology cannot change once the tree exists, so T stays valid as long as the tree. Node attributes can be replaced (e.g. with set_lengths), which is why they are not part of T: pass lengths or edges to a kernel as arguments of their own.

Examples

>>> from skbio.tree import BPTree
>>> tree = BPTree.read(["((a:1,b:2)c:3,(d:4,e:5)f:6)root;"])
>>> T = tree.numba_arrays()
>>> T.size
14