Skip to main content

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, a flags column (active / locks), and any fixed-width user fields declared at construction.
  • parent_index is 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 with np.bincount(parent_index, weights=field).
  • Soft deletion clears the ACTIVE bit 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>=2.0.0

In pyproject.toml dependencies

dependencies = [
    "vcti-nptree>=2.0.0",
]

Quick Start

import numpy as np
from vcti.tree.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 — GrowableArray storage 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).

Metadata

Release files for vcti-nptree 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-nptree 2.0.0
File Size Uploaded
vcti_nptree-2.0.0.tar.gz 31.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcti-nptree 2.0.0
File Interpreter ABI Platform
vcti_nptree-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.1 kB

Release files / vcti_nptree-2.0.0.tar.gz

Download URL vcti_nptree-2.0.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a0c417bc3f11552a9ddda0ae020c6e3be49b195f1529f4ffb217ec3c6a62a8d6
BLAKE2b-256 checksum
How to use checksums
ed7f3cad47ab82d32426ba856423815259b0de22c9b3b433e7b70059cd93c4eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

Release files / vcti_nptree-2.0.0-py3-none-any.whl

Download URL vcti_nptree-2.0.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a85559f2ec2619eb0a24cd225d08b77cd42c094e14d75599a6d6d66f64b00d3f
BLAKE2b-256 checksum
How to use checksums
c51b8ff36fca77d1c378683b57ee1369bb14a74d670f6846b228d58bfe633844
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page