lu_rrule

Function lu_rrule 

Source
pub fn lu_rrule<T, C>(
    ctx: &mut C,
    tensor: &Tensor<T>,
    cotangent: &LuCotangent<T>,
    pivot: LuPivot,
) -> AdResult<Tensor<T>>
Expand description

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

The pivot argument must match the pivoting strategy used in the forward pass.

ยงExamples

use tenferro_linalg::{lu_rrule, LuCotangent, LuPivot};
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::from_slice(&[1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0], &[3, 3], col)
    .unwrap();
let cotangent = LuCotangent {
    l: Some(Tensor::ones(&[3, 3], mem, col).unwrap()),
    u: None,
};
let grad_a = lu_rrule(&mut ctx, &a, &cotangent, LuPivot::Partial).unwrap();