pysiglib.idx_to_tree

pysiglib.idx_to_tree#

idx_to_tree(idx, dimension, degree, *, planar=False, scalar_term=False)[source]#

Inverse of tree_to_idx(). Given a flat index in the branched-signature coefficient vector, returns the corresponding basis element.

With scalar_term=True, index 0 maps to the empty tree (None). With scalar_term=False (default), all indices shift down by 1 (index 0 maps to the first non-empty tree) and the empty tree is unreachable.

Parameters:
  • idx (int) – Flat index in the branched signature vector.

  • dimension (int) – Path dimension (alphabet size).

  • degree (int) – Maximum number of nodes (same as degree in branched_sig()).

  • planar (bool) – If True, interpret idx in the planar ordered-forest enumeration matching branched_sig(..., planar=True).

  • scalar_term (bool) – Whether the source branched signature includes the leading scalar 1 at index 0. Must match the format of the bsig the index was taken from. Default False.

In the planar case, the returned tuple is an ordered forest, represented as (tree_1, tree_2, ...).

Returns:

Decorated rooted tree, ordered forest, or None for empty tree when scalar_term=True.

Return type:

tuple or None

Example:#

import pysiglib

tree = pysiglib.idx_to_tree(3, dimension=2, degree=3)
print(tree)

Citation#

If you found this library useful in your research, please consider citing the paper:

@article{shmelev2025pysiglib,
  title={pySigLib-Fast Signature-Based Computations on CPU and GPU},
  author={Shmelev, Daniil and Salvi, Cristopher},
  journal={arXiv preprint arXiv:2509.10613},
  year={2025}
}