Trait NormalReduce

Source
pub trait NormalReduce<T>: Sized {
    type Output;

    // Required methods
    fn sum<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
    fn sum_<S, O>(
        &self,
        axis: S,
        keep_dims: bool,
        init_out: bool,
        out: O,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>,
             O: BorrowMut<Self::Output>;
    fn prod<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
    fn min<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
    fn max<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
    fn reducel1<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
    fn sum_square<S>(
        &self,
        axis: S,
        keep_dims: bool,
    ) -> Result<Self::Output, TensorError>
       where S: Into<Axis>;
}
Expand description

A trait for normal tensor reduction operations.

Required Associated Types§

Source

type Output

The output tensor type.

Required Methods§

Source

fn sum<S>(&self, axis: S, keep_dims: bool) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Computes the sum of the elements along the specified axis.

The sum function computes the sum of elements along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to sum the elements.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self::Output>: A tensor containing the sum of elements along the specified axis.
§See Also
  • [nansum]: Computes the sum while ignoring NaN values.
Source

fn sum_<S, O>( &self, axis: S, keep_dims: bool, init_out: bool, out: O, ) -> Result<Self::Output, TensorError>
where S: Into<Axis>, O: BorrowMut<Self::Output>,

Computes the sum of the elements along the specified axis, storing the result in a pre-allocated tensor.

The sum_ function computes the sum of elements along the specified axis, and optionally initializes an output tensor to store the result.

§Parameters
  • axis: The axis along which to sum the elements.
  • keep_dims: Whether to retain the reduced dimensions in the result.
  • init_out: Whether to initialize the output tensor.
  • out: The tensor in which to store the result.
§Returns
  • anyhow::Result<Self::Output>: A tensor containing the sum of elements, with the result stored in the specified output tensor.
Source

fn prod<S>(&self, axis: S, keep_dims: bool) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Computes the product of the elements along the specified axis.

The prod function computes the product of elements along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to compute the product.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self::Output>: A tensor containing the product of elements along the specified axis.
§See Also
  • [nanprod]: Computes the product while ignoring NaN values.
Source

fn min<S>(&self, axis: S, keep_dims: bool) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Computes the minimum value along the specified axis.

The min function returns the minimum value of the elements along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to compute the minimum value.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self>: A tensor containing the minimum values along the specified axis.
§See Also
  • [max]: Computes the maximum value along the specified axis.
Source

fn max<S>(&self, axis: S, keep_dims: bool) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Computes the maximum value along the specified axis.

The max function returns the maximum value of the elements along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to compute the maximum value.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self>: A tensor containing the maximum values along the specified axis.
§See Also
  • [min]: Computes the minimum value along the specified axis.
Source

fn reducel1<S>( &self, axis: S, keep_dims: bool, ) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Reduces the tensor along the specified axis using the L1 norm (sum of absolute values).

The reducel1 function computes the L1 norm (sum of absolute values) along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to reduce the tensor.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self::Output>: A tensor with the L1 norm computed along the specified axis.
Source

fn sum_square<S>( &self, axis: S, keep_dims: bool, ) -> Result<Self::Output, TensorError>
where S: Into<Axis>,

Computes the sum of the squares of the elements along the specified axis.

The sum_square function computes the sum of the squares of the elements along the specified axis of the tensor.

§Parameters
  • axis: The axis along which to sum the squares.
  • keep_dims: Whether to retain the reduced dimensions in the result.
§Returns
  • anyhow::Result<Self::Output>: A tensor containing the sum of squares of elements along the specified axis.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: CommonBounds, const DEVICE: usize, Al> NormalReduce<T> for Tensor<T, Cpu, DEVICE, Al>
where Al: Allocator + Send + Sync + 'static, Al::Output: AllocatorOutputRetrive,

Source§

type Output = Tensor<T, Cpu, DEVICE, Al>