Function tensorinv
pub fn tensorinv<T, C>(
ctx: &mut C,
tensor: &Tensor<T>,
ind: usize,
) -> Result<Tensor<T>, Error>where
T: KernelLinalgScalar,
C: TensorLinalgContextFor<T>,
<C as TensorLinalgContextFor<T>>::Backend: 'static,Expand description
Invert a tensorized square operator.
Reshapes the tensor into a square matrix using ind to split the
dimensions, computes the inverse, and reshapes back.
ยงExamples
use tenferro_linalg::tensorinv;
use tenferro_prims::CpuContext;
use tenferro_tensor::{MemoryOrder, Tensor};
let mut ctx = CpuContext::new(1);
let col = MemoryOrder::ColumnMajor;
// Shape [2, 2] with ind=1: left product = 2, right product = 2.
let a = Tensor::<f64>::from_slice(&[1.0, 0.0, 0.0, 1.0], &[2, 2], col).unwrap();
let inv = tensorinv(&mut ctx, &a, 1).unwrap();
assert_eq!(inv.dims(), &[2, 2]);