pysiglib.word_to_idx

pysiglib.word_to_idx#

Added in version v1.1.0.

word_to_idx(word, alphabet_size, *, scalar_term=False)[source]#

Given a word \((w_0, w_1, \ldots, w_n)\), returns its flat index into a truncated signature.

With scalar_term=True the empty word \(()\) sits at index 0 and a word of length \(n+1\) is at

\[\sum_{i=0}^n (w_i + 1) d^i.\]

With scalar_term=False (default) there is no empty-word entry, so all indices shift down by 1: the single-letter word (0,) is at index 0, and the empty word is invalid.

Parameters:
  • word (tuple[int, ...]) – Word

  • alphabet_size (int) – Size of the alphabet

  • scalar_term (bool) – Whether the target signature includes the leading scalar 1. Must match the format of the sig you intend to index. Default False.

Returns:

Flat index corresponding to word

Return type:

int

Example:#

import torch
import pysiglib

length, dimension, degree = 100, 2, 3
x = torch.rand(size=(length, dimension))
sig = pysiglib.sig(x, degree)  # scalar_term=False by default

word = (0, 1)
idx = pysiglib.word_to_idx(word, dimension)
print(sig[idx])  # coefficient at word (0, 1)

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}
}