svd

Function svd 

Source
pub fn svd<T: KernelLinalgScalar, C>(
    ctx: &mut C,
    tensor: &Tensor<T>,
    options: Option<&SvdOptions>,
) -> Result<SvdResult<T, T::Real>>
Expand description

Compute the SVD of a batched matrix.

Input shape: (m, n, *).

The function internally normalizes input to column-major contiguous layout. If the input is not already contiguous, an internal copy is performed.

§Arguments

  • tensor — Input tensor of shape (m, n, *)
  • options — Optional truncation parameters

§Examples

use tenferro_device::LogicalMemorySpace;
use tenferro_linalg::{svd, SvdOptions};
use tenferro_prims::CpuContext;
use tenferro_tensor::{MemoryOrder, Tensor};

let col = MemoryOrder::ColumnMajor;
let mut ctx = CpuContext::new(1);
let a = Tensor::<f64>::zeros(&[3, 4], LogicalMemorySpace::MainMemory, col).unwrap();

let _full = svd(&mut ctx, &a, None).unwrap();
let opts = SvdOptions {
    max_rank: Some(2),
    cutoff: None,
};
let _truncated = svd(&mut ctx, &a, Some(&opts)).unwrap();

§Errors

Returns an error if the input has fewer than 2 dimensions.