Trait ApplyFunction

Source
pub trait ApplyFunction<T, S: Shape = (), D: Device = Self>: Device {
    // Required method
    fn apply_fn<F>(
        &self,
        buf: &Buffer<'_, T, D, S>,
        f: impl Fn(Resolve<T>) -> F,
    ) -> Buffer<'_, T, Self, S>
       where F: Eval<T> + MayToCLSource;
}
Expand description

Applies a function to a buffer and returns a new buffer.

Required Methods§

Source

fn apply_fn<F>( &self, buf: &Buffer<'_, T, D, S>, f: impl Fn(Resolve<T>) -> F, ) -> Buffer<'_, T, Self, S>
where F: Eval<T> + MayToCLSource,

Applies a function to a buffer and returns a new buffer.

§Example
use custos::{CPU, Buffer, ApplyFunction, Combiner};

let device = CPU::new();
let a = Buffer::from((&device, [1., 2., 3., 3., 2., 1.,]));

let out = device.apply_fn(&a, |x| x.mul(2.));
assert_eq!(&*out, &[2., 4., 6., 6., 4., 2.,]);

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, D, S> ApplyFunction<T, S, D> for CPU
where T: Copy + Default + ToVal, D: MainMemory, S: Shape,

Source§

impl<T, D, S> ApplyFunction<T, S, D> for Stack
where T: Copy + Default + ToVal, D: MainMemory, S: Shape,

Source§

impl<T, S> ApplyFunction<T, S> for OpenCL
where T: CDatatype + Number, S: Shape,