Module tensor_ops

Module tensor_ops 

Source
Expand description

GPU-generic free functions for tensor data operations.

These functions expose triu, tril, cat, and stack as context-bearing free functions in tenferro-prims, which is the correct layer for GPU-dispatch-aware tensor operations.

Design note: tenferro-tensor does NOT depend on tenferro-prims (the dependency goes the other way), so these must be free functions here, not methods on Tensor.

Current implementation: Delegates to existing Tensor methods for CPU (the context parameter is unused in the current CPU path). When GPU backends are wired, these functions will dispatch through the context to the appropriate backend kernels.

§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 upper = tensor_ops::triu(&mut ctx, &a, 0).unwrap();
let lower = tensor_ops::tril(&mut ctx, &a, 0).unwrap();

Functions§

cat
Concatenate tensors along an existing dimension.
stack
Stack tensors along a new dimension.
tril
Extract the lower triangular part of a matrix (or batch of matrices).
triu
Extract the upper triangular part of a matrix (or batch of matrices).