pub fn randomized_range<R: Rng + ?Sized>(
t: &IdxTensor,
left_inds: &[DynIndex],
rank: usize,
options: &RangeOptions,
rng: &mut R,
) -> Result<IdxTensor, FactorizeError>Expand description
Find an orthonormal basis for a dense tensor’s left-index range.
left_inds must be a nonempty proper subset of the full index values.
Returns Q with these indices and a fresh bond of dimension
min(rank + options.oversampling, m, n). Q Q† is a bond projector.
Consumes Gaussian samples directly from rng; global QR defaults are ignored.
Only dense f64 and Complex64 are supported; f32 and Complex32 (c32)
return FactorizeError::UnsupportedStorage before advancing the RNG.
§Errors
Returns FactorizeError for zero rank, invalid/duplicate indices, size
overflow, unsupported storage/dtype, or a backend failure.
§Examples
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use tensor4all_core::{randomized_range, DynIndex, IdxTensor, RangeOptions, 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 q = randomized_range(&a, &[i], 1, &RangeOptions { oversampling: 0, power_iterations: 0 }, &mut rng)?;
let projected = q.contract_pair(&q.conj().contract_pair(&a)?)?;
assert!(a.sub(&projected)?.maxabs()? < 1e-12);