Skip to main content

TensorStructural

Trait TensorStructural 

Source
pub trait TensorStructural {
    // Required methods
    fn transpose(&mut self, input: &Tensor, perm: &[usize]) -> Result<Tensor>;
    fn reshape(&mut self, input: &Tensor, shape: &[usize]) -> Result<Tensor>;
    fn broadcast_in_dim(
        &mut self,
        input: &Tensor,
        shape: &[usize],
        dims: &[usize],
    ) -> Result<Tensor>;
    fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor>;
    fn extract_diagonal(
        &mut self,
        input: &Tensor,
        axis_a: usize,
        axis_b: usize,
    ) -> Result<Tensor>;
    fn embed_diagonal(
        &mut self,
        input: &Tensor,
        axis_a: usize,
        axis_b: usize,
    ) -> Result<Tensor>;
    fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>;
    fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>;

    // Provided methods
    fn transpose_read(
        &mut self,
        input: TensorRead<'_>,
        perm: &[usize],
    ) -> Result<Tensor> { ... }
    fn reshape_read(
        &mut self,
        input: TensorRead<'_>,
        shape: &[usize],
    ) -> Result<Tensor> { ... }
    fn broadcast_in_dim_read(
        &mut self,
        input: TensorRead<'_>,
        shape: &[usize],
        dims: &[usize],
    ) -> Result<Tensor> { ... }
    fn convert(&mut self, input: &Tensor, to: DType) -> Result<Tensor> { ... }
}
Expand description

Shape, layout, and dtype transformation operations.

§Examples

use tenferro_tensor::TensorStructural;

fn accepts_structural<B: TensorStructural>(_backend: &mut B) {}

Required Methods§

Source

fn transpose(&mut self, input: &Tensor, perm: &[usize]) -> Result<Tensor>

Source

fn reshape(&mut self, input: &Tensor, shape: &[usize]) -> Result<Tensor>

Source

fn broadcast_in_dim( &mut self, input: &Tensor, shape: &[usize], dims: &[usize], ) -> Result<Tensor>

Source

fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor>

Cast a tensor to another dtype using explicit dtype projection.

Backends may truncate, narrow precision, project complex values, or use boolean truthiness according to their documented cast support.

§Examples
use tenferro_tensor::{DType, Tensor, TensorStructural};

fn cast_to_i32<B: TensorStructural>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.cast(input, DType::I32)
}
Source

fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Source

fn embed_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Source

fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Source

fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Provided Methods§

Source

fn transpose_read( &mut self, input: TensorRead<'_>, perm: &[usize], ) -> Result<Tensor>

Source

fn reshape_read( &mut self, input: TensorRead<'_>, shape: &[usize], ) -> Result<Tensor>

Source

fn broadcast_in_dim_read( &mut self, input: TensorRead<'_>, shape: &[usize], dims: &[usize], ) -> Result<Tensor>

Source

fn convert(&mut self, input: &Tensor, to: DType) -> Result<Tensor>

Convert a tensor to another dtype using checked dtype conversion.

convert accepts only conversions allowed by tenferro’s dtype-promotion lattice. Use TensorStructural::cast for explicit lossy projection.

§Examples
use tenferro_tensor::{DType, Tensor, TensorStructural};

fn convert_to_f64<B: TensorStructural>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.convert(input, DType::F64)
}

Implementors§