TensorRSVD

TensorRSVD is a Python library for tensor-free randomized Higher-Order SVD (HOSVD), also known as the randomized Tucker decomposition.

Rather than storing the tensor as a dense array, TensorRSVD represents it as a function that returns tensor values at requested coordinates. This makes the decomposition memory-efficient, i.e., it can handle tensors that are too large to hold in memory. The library supports three array backends: NumPy (default), JAX, and CuPy. See Backends for details.

Quick start

import numpy as np
from tensorrsvd import ho_rsvd

# Tensor defined as a callable: T(x0, x1, x2) = x0 - x1 + x2
def my_tensor(x0, x1, x2):
    return x0 - x1 + x2

U_list, S_list = ho_rsvd(
    tensor=my_tensor,
    tensor_shape=(32, 32, 32),
    dtype=np.float64,
    rank=3,
    num_oversamples=10,
    num_power_iterations=2,
    num_idxs=3,
    backend="numpy",
)

U_list[m] is the \((n_m \times r_m)\) factor matrix for mode \(m\) and S_list[m] contains the corresponding mode-\(m\) singular values. See the User Guide for a full walkthrough, and the Theory page for the underlying mathematics.