use std::ops::Mul; use custos::prelude::*; pub trait MulBuf: Sized + Device { fn mul(&self, lhs: &Buffer, rhs: &Buffer) -> Buffer; } impl MulBuf for CPU where T: Mul + Copy, S: Shape, D: MainMemory, { fn mul(&self, lhs: &Buffer, rhs: &Buffer) -> Buffer { let mut out = self.retrieve(lhs.len(), (lhs, rhs)); for ((lhs, rhs), out) in lhs.iter().zip(&*rhs).zip(&mut out) { *out = *lhs * *rhs; } out } } fn main() { let device = CPU::new(); let lhs = Buffer::from((&device, &[-1, 2, 3, -4, 5, 9])); let rhs = Buffer::from((&device, &[4, -1, 7, 1, -2, 4])); let out = device.mul(&lhs, &rhs); assert_eq!(out.read(), [-4, -2, 21, -4, -10, 36]); }