Skip to main content

ComputeReduce

Trait ComputeReduce 

Source
pub trait ComputeReduce: ComputeView
where Self::Arch: SimdKernel<Self::Element>, Self::Element: NumericElement,
{ // Required method fn compute_reduce<Op>(&self, op: Op) -> Self::Element where Op: ReductionOp<Self::Element>; }
Expand description

Extension trait that provides reduce() over any SimdView-backed ComputeView.

§Design

ComputeReduce is a blanket extension: it is automatically satisfied by any type that implements ComputeView with a SimdView backend. It does not add a vtable entry — the sole method reduce is #[inline(always)] and monomorphizes to the same code as calling view.reduce(op) directly.

§Examples

use hermes_simd_core::compute::{ComputeView, ComputeReduce};
use hermes_simd_core::view::SimdView;
use hermes_simd_core::ops::Sum;
use hermes_simd_intrinsics::Scalar;
use hermes_simd_core::align::Unaligned;
use hermes_simd_core::execution::Unmasked;

let data = [1.0_f32; 8];
let view: SimdView<'_, f32, Scalar, Unaligned, Unmasked, &[f32]> =
    SimdView::new(&data).unwrap();
let total: f32 = view.compute_reduce(Sum);
assert!((total - 8.0_f32).abs() < 1e-6);

Required Methods§

Source

fn compute_reduce<Op>(&self, op: Op) -> Self::Element
where Op: ReductionOp<Self::Element>,

Reduce all elements to a scalar using the given strategy.

Delegates to the SimdView::reduce implementation, which uses multi-accumulator unrolled SIMD + scalar tail handling.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<'a, T, Arch, Align, Mode, Ref> ComputeReduce for SimdView<'a, T, Arch, Align, Mode, Ref>
where T: NumericElement, Arch: SimdArch + SimdKernel<T>, Align: Alignment, Mode: ExecutionMode, Ref: 'a,