pub fn randomized_svd<R: Rng + ?Sized>(
t: &IdxTensor,
left_inds: &[DynIndex],
options: &RsvdOptions,
rng: &mut R,
) -> Result<RsvdResult, FactorizeError>Expand description
Compute a fixed-rank randomized SVD of a materialized local tensor.
The index split and sketch have the same contract as randomized_range.
Returns directly contractible U, S, V† with min(max_bond_dim, m, n)
triplets. The projected singular values do not certify the full-input error.
Uses the supplied RNG directly and ignores global truncation defaults.
Supports dense f64/Complex64; f32/Complex32 (c32) are unsupported.
§Errors
Returns FactorizeError for invalid rank/indices, size overflow,
unsupported storage/dtype, or contraction/decomposition failure.
§Examples
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use tensor4all_core::{randomized_svd, DynIndex, IdxTensor, RsvdOptions, TensorContractionLike};
let i = DynIndex::new_dyn(2);
let j = DynIndex::new_dyn(2);
let a = IdxTensor::from_dense(vec![i.clone(), j], vec![3., 0., 0., 0.])?;
let mut rng = ChaCha8Rng::seed_from_u64(11);
let result = randomized_svd(&a, &[i], &RsvdOptions::new(1), &mut rng)?;
let reconstructed = result.u.contract_pair(&result.s)?.contract_pair(&result.vh)?;
assert!(a.sub(&reconstructed)?.maxabs()? < 1e-12);