pysiglib.word_to_idx

pysiglib.word_to_idx#

Added in version v1.1.0.

word_to_idx(word, alphabet_size)[source]#

Given a word \((w_0, w_1, \ldots, w_n)\), returns the corresponding flattened index

\[\sum_{i=0}^n (w_i + 1) d^i\]
Parameters:
  • word (tuple[int, ...]) – Word

  • alphabet_size (int) – Size of the alphabet

Returns:

Flattened 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)

# Get coefficient at word
word = (0, 1)
coef_idx = pysiglib.extract_sig_coef(word, sig, dimension, degree)

# Convert word to index and get coefficient
idx = pysiglib.word_to_idx(word, dimension)
coef_word = sig[idx]

# Both methods give the same coefficient
print("Idx: ", idx, " Coefficient: ", coef_idx)
print("Word: ", word, " Coefficient: ", coef_word)

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