tril

Function tril 

Source
pub fn tril<T, C>(
    _ctx: &mut C,
    tensor: &Tensor<T>,
    diagonal: isize,
) -> Result<Tensor<T>>
Expand description

Extract the lower triangular part of a matrix (or batch of matrices).

Elements above the diagonal-th diagonal are set to zero. The context parameter enables future GPU-backend dispatch.

The diagonal parameter controls which diagonal is the boundary:

  • 0 is the main diagonal
  • positive values move above the main diagonal
  • negative values move below the main diagonal

§Errors

Returns an error if the tensor has fewer than 2 dimensions or if backend dispatch fails.

§Examples

use tenferro_device::LogicalMemorySpace;
use tenferro_prims::{tensor_ops, CpuContext};
use tenferro_tensor::{MemoryOrder, Tensor};

let mut ctx = CpuContext::new(1);
let a = Tensor::<f64>::ones(
    &[3, 3],
    LogicalMemorySpace::MainMemory,
    MemoryOrder::ColumnMajor,
).unwrap();
let lower = tensor_ops::tril(&mut ctx, &a, 0).unwrap();
assert_eq!(lower.dims(), &[3, 3]);