1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::marker::PhantomData;

use crate::{element_wise::ElementWise, num::Num};

#[derive(Debug, Default, Clone, Copy)]
pub struct CpuElementWise<T: Num> {
    _phantom: PhantomData<T>,
}

impl<T: Num> ElementWise<T> for CpuElementWise<T> {
    fn mul(
        res: *mut T,
        lhs: *const T,
        rhs: *const T,
        size: usize,
        inc_lhs: usize,
        inc_rhs: usize,
        inc_self: usize,
    ) {
        unsafe {
            let mut res = res;
            let mut lhs = lhs;
            let mut rhs = rhs;
            for _ in 0..size {
                *res = *lhs * *rhs;
                res = res.add(inc_self);
                lhs = lhs.add(inc_lhs);
                rhs = rhs.add(inc_rhs);
            }
        }
    }
}