Skip to main content

TensorReduction

Trait TensorReduction 

Source
pub trait TensorReduction {
    // Required methods
    fn reduce_sum(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>;
    fn reduce_prod(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>;
    fn reduce_max(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>;
    fn reduce_min(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>;

    // Provided methods
    fn reduce_sum_read(
        &mut self,
        input: TensorRead<'_>,
        axes: &[usize],
    ) -> Result<Tensor> { ... }
    fn reduce_prod_read(
        &mut self,
        input: TensorRead<'_>,
        axes: &[usize],
    ) -> Result<Tensor> { ... }
    fn reduce_max_read(
        &mut self,
        input: TensorRead<'_>,
        axes: &[usize],
    ) -> Result<Tensor> { ... }
    fn reduce_min_read(
        &mut self,
        input: TensorRead<'_>,
        axes: &[usize],
    ) -> Result<Tensor> { ... }
}
Expand description

Reduction operations.

Reducing over an axis whose extent is zero returns an error for every reduction operation. Passing an empty axes slice is a no-op for the public reductions and returns the input values unchanged. Internal mapped reductions document their own empty-axis semantics.

§Examples

use tenferro_tensor::TensorReduction;

fn accepts_reduction<B: TensorReduction>(_backend: &mut B) {}

Required Methods§

Source

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

§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Provided Methods§

Source

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

Sum elements across axes from an owned tensor or borrowed view.

§Examples
use tenferro_tensor::{Tensor, TensorRead, TensorReduction};

fn sum_owned<B: TensorReduction>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.reduce_sum_read(TensorRead::from_tensor(input), &[0])
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

Multiply elements across axes from an owned tensor or borrowed view.

§Examples
use tenferro_tensor::{Tensor, TensorRead, TensorReduction};

fn prod_owned<B: TensorReduction>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.reduce_prod_read(TensorRead::from_tensor(input), &[0])
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

Take maximum values across axes from an owned tensor or borrowed view.

§Examples
use tenferro_tensor::{Tensor, TensorRead, TensorReduction};

fn max_owned<B: TensorReduction>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.reduce_max_read(TensorRead::from_tensor(input), &[0])
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

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

Take minimum values across axes from an owned tensor or borrowed view.

§Examples
use tenferro_tensor::{Tensor, TensorRead, TensorReduction};

fn min_owned<B: TensorReduction>(
    backend: &mut B,
    input: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    backend.reduce_min_read(TensorRead::from_tensor(input), &[0])
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§