pub trait MapFn<A, D>: Sync {
// Required method
fn call(&self, a: A) -> D;
// Provided method
fn class(&self) -> KernelClass { ... }
}Expand description
An element function that carries its KernelClass.
map_into and its siblings gate their parallel fork on the serial time of the
region, which is the element count times the throughput of the function’s class.
A plain closure or function item is a KernelClass::Map (a few arithmetic
operations per element) through the blanket implementation, so existing callers
are unchanged. A caller whose function is expensive declares it with
Classed, usually through KernelClass::with, so a region too short to pay
for a fork as arithmetic is still forked when each element costs a libm call.
The trait is implemented for every Fn(A) -> D + Sync and for Classed; it is
not meant to be implemented by hand.
§Examples
use strided_basic::execution::KernelClass;
use strided_basic::{map_into, Exec, StridedView, StridedViewMut};
let src = vec![0.0f64, 1.0, 2.0];
let mut out = vec![0.0f64; 3];
let mut dest = StridedViewMut::new(&mut out, &[3], &[1], 0).unwrap();
let source = StridedView::<f64>::new(&src, &[3], &[1], 0).unwrap();
// `exp` costs about as much as ten arithmetic operations: say so.
let exp = KernelClass::Transcendental.with(|x: f64| x.exp());
map_into(&mut dest, &source, exp, Exec::serial()).unwrap();
assert_eq!(out[0], 1.0);Required Methods§
Provided Methods§
Sourcefn class(&self) -> KernelClass
fn class(&self) -> KernelClass
Serial cost class the parallel gate charges per element; Map by default.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".