pub fn svd_with_in<T>(
t: &IdxTensor,
left_inds: &[DynIndex],
options: &SvdOptions,
context: &ExecutionContext,
) -> Result<(IdxTensor, IdxTensor, IdxTensor), SvdError>Expand description
Compute SVD decomposition in a caller-owned execution context.
The factorization, truncation slicing, and result assembly all execute in
context. With a CUDA context only the singular-value decision vector
crosses the explicit readback boundary; with a CPU context the decision
uses the same host read as svd_with.
§Arguments
t- Input tensor, which must belong tocontext.left_inds- Indices to place on the left (row) side of the unfolded matrix.options- SVD options including truncation policy and bond cap.context- Caller-owned execution context owning the input and results.
§Examples
use std::sync::Arc;
use tensor4all_core::svd::{SvdOptions, svd_with_in};
use tensor4all_core::{DynIndex, ExecutionContext, IdxTensor, SvdTruncationPolicy};
use tensor4all_tensorbackend::CpuExecutionContext;
use tenferro_cpu::CpuBackend;
let context = ExecutionContext::Cpu(Arc::new(
CpuExecutionContext::from_backend(CpuBackend::new()),
));
let i = DynIndex::new_dyn(4);
let j = DynIndex::new_dyn(4);
let mut data = vec![0.0_f64; 16];
data[0] = 1.0;
let tensor = IdxTensor::from_dense_in(&context, vec![i.clone(), j.clone()], data)?;
let opts = SvdOptions::new().with_policy(SvdTruncationPolicy::new(1e-10));
let (u, s, _v) = svd_with_in::<f64>(&tensor, &[i.clone()], &opts, &context)?;
assert_eq!(s.dims()[0], 1);
assert_eq!(u.dims()[0], 4);§Errors
Returns SvdError when the tensor does not belong to context, when the
indices or options are invalid, or when the factorization or explicit
decision readback fails.