use super::super::reduction;
use super::super::CpuBackend;
use crate::backend_ops::ops::ReductionOp;
use crate::backend_ops::traits::ReductionOps;
use coeus_core::{CpuAddressableStorageMut, FloatElement, Layout, Scalar};
unsafe impl<T: Scalar + leto_ops::Scalar, B: CpuBackend> ReductionOps<T> for B
where
B::DeviceBuffer<T>: CpuAddressableStorageMut<T>,
B::DeviceBuffer<i64>: CpuAddressableStorageMut<i64>,
{
#[inline]
fn reduce(
&self,
op: ReductionOp,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error> {
reduction::reduce(self, op, a, a_layout, axis, c, c_layout)
}
fn reduce_mean(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: FloatElement,
{
reduction::reduce_mean(self, a, a_layout, axis, c, c_layout)
}
fn reduce_prod(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: FloatElement,
{
reduction::reduce_prod(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn argmax(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<i64>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::argmax(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn argmin(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<i64>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::argmin(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn topk(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
k: usize,
axis: usize,
largest: bool,
values: &mut Self::DeviceBuffer<T>,
values_layout: &Layout,
indices: &mut Self::DeviceBuffer<i64>,
indices_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::topk(
self,
a,
a_layout,
k,
axis,
largest,
values,
values_layout,
indices,
indices_layout,
)
}
#[inline]
fn cumsum(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::cumsum(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn suffix_sum(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::suffix_sum(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn cumprod(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::cumprod(self, a, a_layout, axis, c, c_layout)
}
#[inline]
fn suffix_prod(
&self,
a: &Self::DeviceBuffer<T>,
a_layout: &Layout,
axis: usize,
c: &mut Self::DeviceBuffer<T>,
c_layout: &Layout,
) -> Result<(), Self::Error>
where
T: leto_ops::Scalar,
{
reduction::suffix_prod(self, a, a_layout, axis, c, c_layout)
}
}