pub fn lu_rrule<T, C>(
ctx: &mut C,
tensor: &Tensor<T>,
cotangent: &LuCotangent<T>,
pivot: LuPivot,
) -> AdResult<Tensor<T>>where
T: KernelLinalgScalar + LiftPermutationMatrixTensor<C>,
C: TensorLinalgContextFor<T> + TensorMetadataContextFor + TensorScalarContextFor<Standard<T::Real>>,
C::MetadataBackend: TensorMetadataPrims<Context = C>,
<C as TensorScalarContextFor<Standard<T::Real>>>::ScalarBackend: TensorMetadataCastPrims<T::Real, Context = C>,
C::Backend: 'static,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();