Skip to main content

tensorpow

tensorpow is a small Python library for working with norms, determinants and representations of tensor powers. Its main use is calculating the result of expressions of the form: $\left| \sum_{i} t_i A_i^{\otimes n} \right|p$ and $\log\left|\det \sum{i} t_i A_i^{\otimes n}\right|$, where $A_1, A_2, \dots \in M_d(\mathbb{C})$ are fixed matrices, $t_1, t_2, \dots \in \mathbb{C}$ are fixed coefficients, and $| \cdot |_p$ denotes the Schatten $p$-norm.

Base matrices can be either 2×2 (using SL(2) representation data) or 3×3 (using SU(3) representation data). The tensor power itself may be any positive integer – the library uses precomputed representation data indexed by that power. A class-based interface computes block decompositions via precomputed SL(2)/SU(3) data and evaluates quantities such as Schatten‑p norms without building the full Kronecker power.

Installation

Requires Python 3.11–3.13.

pip install tensorpow

For development:

pip install -e ".[test]"

Dependencies (numpy, scipy, sympy) are installed automatically.

Data limits

Precomputed SU(3) symmetric representation data is available for degrees 1 through 30. Larger 3×3 tensor powers require higher degrees; those cases raise a clear error.

Precomputed SL(2) data (sl2reps.txt) supports 2×2 tensor powers n ≤ 79.

GPU Acceleration

The tensorpow package supports NVIDIA GPU acceleration for operations involving 3x3 matrices to dramatically speed up large tensor power calculations (e.g. $n \ge 10$).

Because CuPy is heavily dependent on your specific CUDA version, you must manually install the appropriate CuPy wheel for your machine in addition to the optional GPU dependency:

# Install tensorpow with GPU dependencies
pip install tensorpow[gpu]

# Install the CuPy wheel matching your CUDA version (e.g. CUDA 13.x for Blackwell architectures)
pip install cupy-cuda13x

Once installed, you can pass the backend flag to schatten_p_norm_weighted or log_det_weighted:

val = calc.schatten_p_norm_weighted([A, B], n=20, p=2, backend="smart_hybrid")
ld = calc.log_det_weighted([A, B], n=20, backend="smart_hybrid")

Backend Options:

  • "cpu" (Default): Uses standard NumPy and runs entirely on the CPU.
  • "smart_hybrid": The recommended GPU implementation. It performs massive matrix exponentiation on the GPU, offloads the scaling block aggregations back to System RAM to gracefully bypass VRAM limits, and attempts to compute the final SVD on the GPU (automatically falling back to CPU SVD if it runs out of VRAM).
  • "cupy": A pure CuPy implementation that attempts to keep the entire block pipeline strictly in VRAM. This avoids PCIe transfer overhead but will easily exceed VRAM on standard cards for $n \ge 16$.

Note: using "smart_hybrid" backend with a 5070 GPU (12GB VRAM) yields results an order of magnitude faster, than "cpu". It runs out of VRAM for $n \ge 27$.

Quick start

from tensorpow import TensorPowerCalculator
import numpy as np

# Example 1: 3×3 matrices (SU(3) case)
A = np.eye(3)
B = 2 * np.eye(3)
calc = TensorPowerCalculator()           # no args
# compute Schatten‑2 norm of A⊗A - 1/2 * B⊗B (tensorpower=2) 
norm_3x3 = calc.schatten_p_norm_weighted([A, B], n=2, p=2, coeffs=[1.0, -0.5])
print(f"3×3 result: {norm_3x3}")

# Example 2: 2×2 matrices (SL(2) case)
C = np.eye(2)
D = 2 * np.eye(2)
# compute Schatten‑2 norm of C⊗C - 1/2 * D⊗D (tensorpower=2)
norm_2x2 = calc.schatten_p_norm_weighted([C, D], n=2, p=2, coeffs=[1.0, -0.5])
print(f"2×2 result: {norm_2x2}")

# Example 3: block decomposition of a single 2×2 matrix (tensor power n=5)
M = np.array([[1.0, 0.5], [0.0, 1.0]])
blocks = calc.block_decomposition(M, n=5)
# each entry is (multiplicity, block_matrix)
for mult, block in blocks:
    print(mult, block.shape)

# Example 4: normalized log-determinant 3^{-n} log|det X_n| of a three-term
# combination of positive definite 3×3 matrices (tensor power n=20)
P, Q, R = np.diag([1.1, 1.3, 1.5]), np.diag([1.4, 1.1, 1.2]), np.diag([1.2, 1.5, 1.3])
L, info = calc.log_det_weighted([P, Q, R], n=20, coeffs=[0.25, 0.25, 0.5],
                                method="cholesky", return_details=True)
print(L, info["phase"], info["kappa"])

TensorPowerCalculator exposes three public methods:

  • block_decomposition — irrep blocks of one matrix's n-th tensor power
  • schatten_p_norm_weighted — weighted Schatten-p norm of a linear combination of tensor powers (p=np.inf gives the operator norm)
  • log_det_weighted — log-absolute-determinant of a linear combination of tensor powers, normalized by default to $d^{-n}\log|\det X_n|$ (the mean log singular value)

Both 2×2 and 3×3 matrices are supported; the library dispatches to SL(2) or SU(3) representation data based on matrix dimension.

For 3×3 matrices, block_decomposition may return negative multiplicities (a virtual decomposition). Singular values of the full tensor power are not listed block-by-block; use weighted sums of singular-value powers over blocks (as schatten_p_norm_weighted does internally).

Determinants

log_det_weighted never forms the determinant itself, which over- or underflows already at moderate $n$. It sums $w_j \log|\det Y_j|$ over the (virtual) blocks $Y_j$ with the same integer weights $w_j$ used for Schatten norms, with compensated summation.

  • method="cholesky" factorizes each block in place and requires Hermitian positive definite blocks (e.g. Hermitian positive definite inputs with positive coefficients); method="lu" works for any input; method="auto" (default) tries Cholesky for Hermitian inputs with real coefficients and falls back to LU.
  • X_n is singular exactly when some virtual block is singular; the method then returns -inf.
  • With return_details=True you also get the phase of the determinant (exactly ±1 for real or Hermitian inputs), the cancellation indicator kappa $= \sum_j |w_j \ell_j| / |\sum_j w_j \ell_j|$, timings for symmetric-power evaluation, block assembly and factorization, and per-block records.
  • Accuracy is limited by the conditioning of the blocks: $\mathrm{Sym}^k(A)$ has condition number of order $\mathrm{cond}(A)^k$, as does $A^{\otimes k}$ itself.

Generating Representation Data Locally

The package relies on massive symmetric representation tensors. By default, it downloads precomputed tensors (from Zenodo) securely into your OS user data directory (e.g. ~/.local/share/tensorpow) so they are preserved across updates.

However, you can run the built-in representation generators locally on your own machine to extend the package's capabilities beyond the published limits! These symbolic generator scripts are thoroughly tested in tests/test_generation.py to ensure their output exactly matches the Zenodo baseline.

Extending SL(2) (2×2 Matrices)

The base package supports up to $n \le 79$ for 2x2 matrices (Sym^k for k = 0..79). If you need higher tensor powers, you can easily generate them:

python -m tensorpow.sl2_sym_runner --max-k 100

This multi-processed script will compute the representations and append them locally to your cached sl2reps.txt file.

Extending SU(3) (3×3 Matrices)

The base package supports up to $n \le 30$ for 3x3 matrices using compressed piM_sym_<deg>_*.npz files. If you need dimensions beyond degree 30, you can generate the sparse tensor representations locally (note: this is computationally heavy and automatically runs in parallel across all CPU cores):

python -m tensorpow.su3_sym_runner --min-k 31 --max-k 35 --workers 5

Your custom generated representation files are instantly recognized by tensorpow in your next run!

Building on the decomposition

block_decomposition exposes the irrep blocks of a single matrix's n-th tensor power. Methods such as schatten_p_norm_weighted and log_det_weighted combine block singular values or block determinants without forming the full Kronecker product; you can use the same blocks to define other functionals that are additive (or multiplicative) on orthogonal direct sums (other norms, traces, eigenvalue statistics, and so on).

Package structure

  • tensorpow/core.py – main implementation and TensorPowerCalculator, including SL(2) (2×2) and SU(3) (3×3) block decomposition logic
  • tensorpow/*_runner.py – generator tools to calculate arbitrary dimension representations locally
  • tensorpow/file_handler.py – loaders for downloaded NPZ tensors (compressed SU(3) representation data; not part of the runtime API)
  • tensorpow/sl2_loader.py – loads downloaded sl2reps.txt at runtime

Testing

Run pytest tests to exercise the small test suite.

License

GNU GPLv3 or later (see LICENSE).

Metadata

Release files for tensorpow 0.5.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 tensorpow 0.5.0
File Size Uploaded Provenance Actions
tensorpow-0.5.0.tar.gz 38.3 kB Without provenance Details for tensorpow-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tensorpow 0.5.0
File Interpreter ABI Platform Actions
tensorpow-0.5.0-py3-none-any.whl Python 3 none any Details for tensorpow-0.5.0-py3-none-any.whl

Total release size: 68.3 kB

Release files / tensorpow-0.5.0.tar.gz

Download URL tensorpow-0.5.0.tar.gz
Size 38.3 kB
Tags Source
SHA-256 checksum
How to use checksums
565cb0bac9e6174bc3f80d46ed11c4eedc0c9ac5e66f3bf87b542248af01269d
BLAKE2b-256 checksum
How to use checksums
b6270b907c847fd140887e7935ad76714530cdf98900f5638ec6335e8dba9824
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tensorpow-0.5.0-py3-none-any.whl

Download URL tensorpow-0.5.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
899f649e2027a35c2fdf3fa8dccd87674da85387e49a075896f3dfd6a71ac5b6
BLAKE2b-256 checksum
How to use checksums
cf05dd3620ebe1b96a95026336a5921bbf0737e6b3c58fbfa5406348eb64e9f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tensorpow 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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