inv_rrule

Function inv_rrule 

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

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

Ā = -A⁻ᵀ · cotangent · A⁻ᵀ.

§Examples

use tenferro_linalg::inv_rrule;
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>::eye(3, mem, col).unwrap();
let cotangent = Tensor::<f64>::ones(&[3, 3], mem, col).unwrap();
let grad_a = inv_rrule(&mut ctx, &a, &cotangent).unwrap();