Skip to main content

randomized_range_in

Function randomized_range_in 

Source
pub fn randomized_range_in<R: Rng + ?Sized>(
    t: &IdxTensor,
    left_inds: &[DynIndex],
    rank: usize,
    options: &RangeOptions,
    rng: &mut R,
    context: &ExecutionContext,
) -> Result<IdxTensor, FactorizeError>
Expand description

Find a Gaussian range basis in a caller-owned execution context.

The rank, index split, oversampling and return contract match randomized_range. Inputs and sketches remain in context; validation precedes RNG advancement. Use zero oversampling for a rank-rank projector.

§Errors

Returns FactorizeError for invalid rank/indices, unsupported storage, foreign contexts, size overflow, or a backend failure.

§Examples

use std::sync::Arc;
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use tensor4all_core::{randomized_range_in, DynIndex, ExecutionContext, IdxTensor, RangeOptions};
use tensor4all_tensorbackend::{CpuBackend, CpuExecutionContext};
let context = ExecutionContext::Cpu(Arc::new(CpuExecutionContext::from_backend(CpuBackend::with_threads(1)?)));
let i = DynIndex::new_dyn(2);
let j = DynIndex::new_dyn(2);
let a = IdxTensor::from_dense_in(&context, vec![i.clone(), j], vec![3., 0., 0., 0.])?;
let mut rng = ChaCha8Rng::seed_from_u64(11);
let options = RangeOptions { oversampling: 0, power_iterations: 0 };
let q = randomized_range_in(&a, &[i], 1, &options, &mut rng, &context)?;
let values = q.to_vec::<f64>()?;
assert!((values[0].abs() - 1.).abs() < 1e-12 && values[1].abs() < 1e-12);