pub fn norm_rrule<T, C>(
ctx: &mut C,
tensor: &Tensor<T>,
cotangent: &Tensor<T>,
kind: NormKind,
) -> AdResult<Tensor<T>>where
T: KernelLinalgScalar + KernelLinalgScalar<Real = T> + Float,
C: TensorLinalgContextFor<T> + TensorScalarContextFor<Standard<T>>,
<C as TensorScalarContextFor<Standard<T>>>::ScalarBackend: TensorAnalyticPrims<Standard<T>, Context = C>,
C::Backend: 'static,Expand description
Reverse-mode AD rule for norm (VJP / pullback).
ยงExamples
use tenferro_linalg::{norm_rrule, NormKind};
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 = Tensor::<f64>::ones(&[], mem, col).unwrap();
let grad_a = norm_rrule(&mut ctx, &a, &cotangent, NormKind::Fro).unwrap();