Vectorized, numpy-backed tree: parent-id topology and user-defined fields in one growable structured array, with vectorized operations over node ids.
Project description
vcti-nptree
Vectorized, numpy-backed tree: parent-index topology and user-defined fields in one growable structured array, with vectorized operations over node indices.
Overview
vcti-nptree provides NpTree, a single-rooted tree whose
structure and per-node data live together in one growable numpy structured
array (backed by GrowableArray from
vcti-nputils):
- One record per node, addressed by its integer row index. The record
carries
parent_index, aflagscolumn (active / locks), and any fixed-width user fields declared at construction. parent_indexis the structure. Children and siblings are vectorized scans of that column (parent_index == n), ancestors are a short parent-chain walk, and per-node fields roll up withnp.bincount(parent_index, weights=field).- Soft deletion clears the
ACTIVEbit and leaves the row in place — nothing is moved or renumbered, so node indices stay stable for the life of the tree and every vectorized operation keeps working with deletions present.delete(..., fill=...)optionally writes a per-field "inactive" / "na" / zero / custom value so aggregations stay branchless without even consulting the mask.
It is built for vectorized operations over sets of nodes — aggregating, masking, or rolling up fields across many nodes at once, rather than walking the tree one node at a time. Nodes are addressed by integer indices and index-arrays (not opaque handles), which is what lets those operations be plain numpy.
The design and rationale are documented in docs/design.md.
Installation
pip install vcti-nptree
In requirements.txt
vcti-nptree>=1.0.0
In pyproject.toml dependencies
dependencies = [
"vcti-nptree>=1.0.0",
]
Quick Start
import numpy as np
from vcti.nptree import FieldSpec, NpTree
# Declare fixed-width user fields: a schema dtype plus the per-field default and
# inactive values (unspecified fields default to zero).
spec = FieldSpec.create(
np.dtype([("mass", "f8")]), default={"mass": 0.0}, inactive={"mass": 0.0}
)
tree = NpTree(spec) # the root is node 0
p1 = tree.create_child(tree.root)
p2 = tree.create_child(tree.root)
# Bulk-create a level of elements under the parts (one vectorized append).
tree.create_children(np.array([p1, p1, p2]), mass=np.array([3.0, 4.0, 10.0]))
# Vectorized roll-up: every node's subtree total in one pass.
totals = tree.subtree_sum("mass")
assert totals[tree.root] == 17.0 # whole tree
# Soft-delete a subtree; aggregations still work and node indices stay valid.
tree.delete(p1)
assert tree.subtree_sum("mass")[tree.root] == 10.0
Dependencies
vcti-nputils>=1.6.0—GrowableArraystorage backing.vcti-multi-valued-array>=1.5.0— the CSR / ragged container for the parent→children index.numpy>=1.26— structured-array storage and vectorized operations.numba>=0.59— compiles the per-node kernels (DFS walk orders, ordered ancestor chains).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vcti_nptree-1.0.0.tar.gz.
File metadata
- Download URL: vcti_nptree-1.0.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e54c78f24f3a10193c400d6706db003fad2c062d42d89a75786ad7c4c51e601
|
|
| MD5 |
a55e57bca6388158ed7d79c22a423c11
|
|
| BLAKE2b-256 |
3e80964473f3ce37d25e927a7989eb315885a73512f3a9c7d3d95800c29ecf17
|
Provenance
The following attestation bundles were made for vcti_nptree-1.0.0.tar.gz:
Publisher:
release.yml on vcollab/vcti-python-nptree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_nptree-1.0.0.tar.gz -
Subject digest:
3e54c78f24f3a10193c400d6706db003fad2c062d42d89a75786ad7c4c51e601 - Sigstore transparency entry: 1960991250
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-nptree@93c59c6394bf25396c03d25b0f913b330175d020 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@93c59c6394bf25396c03d25b0f913b330175d020 -
Trigger Event:
push
-
Statement type:
File details
Details for the file vcti_nptree-1.0.0-py3-none-any.whl.
File metadata
- Download URL: vcti_nptree-1.0.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bad32e404a1938d7de14d75ca6392c2137bfbdd8269408646456c912077b836
|
|
| MD5 |
9ed42fe0dd8d9b9ad6c69b42e228e997
|
|
| BLAKE2b-256 |
690f5501a892fdb0e620183c946a18c7835eabf601e436d40930e30861d78058
|
Provenance
The following attestation bundles were made for vcti_nptree-1.0.0-py3-none-any.whl:
Publisher:
release.yml on vcollab/vcti-python-nptree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_nptree-1.0.0-py3-none-any.whl -
Subject digest:
8bad32e404a1938d7de14d75ca6392c2137bfbdd8269408646456c912077b836 - Sigstore transparency entry: 1960991310
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-nptree@93c59c6394bf25396c03d25b0f913b330175d020 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@93c59c6394bf25396c03d25b0f913b330175d020 -
Trigger Event:
push
-
Statement type: