svd_rrule

Function svd_rrule 

Source
pub fn svd_rrule<T, C>(
    ctx: &mut C,
    tensor: &Tensor<T>,
    cotangent: &SvdCotangent<T, T::Real>,
    options: Option<&SvdOptions>,
) -> AdResult<Tensor<T>>
Expand description

Reverse-mode AD rule for SVD (VJP / pullback).

Computes the gradient of the input given cotangents for the SVD outputs. Uses the F-matrix approach (Mathieu 2019).

ยงExamples

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

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

let cotangent = SvdCotangent {
    u: None,
    s: Some(Tensor::ones(&[3], mem, col).unwrap()),
    vt: None,
};
let grad_a = svd_rrule(&mut ctx, &a, &cotangent, None).unwrap();