use crate::align::Alignment;
use crate::arch::SimdArch;
use crate::bitboard::BitBoardView;
use crate::execution::ExecutionMode;
use crate::sparse::{SparseFormat, SparseView};
use crate::view::SimdView;
pub trait ComputeView {
type Element;
type Arch: SimdArch;
type Backend;
fn len(&self) -> usize;
#[inline(always)]
fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<'a, T, Arch, Align, Mode, Ref> ComputeView for SimdView<'a, T, Arch, Align, Mode, Ref>
where
Arch: SimdArch,
Align: Alignment,
Mode: ExecutionMode,
Ref: 'a,
{
type Element = T;
type Arch = Arch;
type Backend = Mode;
#[inline(always)]
fn len(&self) -> usize {
self.as_slice().len()
}
}
impl<'a, T, Format, Arch> ComputeView for SparseView<'a, T, Format, Arch>
where
Format: SparseFormat,
Arch: SimdArch,
{
type Element = T;
type Arch = Arch;
type Backend = Format;
#[inline(always)]
fn len(&self) -> usize {
self.nrows()
}
}
impl<'a, Backend, Arch, Ref> ComputeView for BitBoardView<'a, Backend, Arch, Ref>
where
Arch: SimdArch,
Ref: 'a,
{
type Element = u64;
type Arch = Arch;
type Backend = Backend;
#[inline(always)]
fn len(&self) -> usize {
self.as_slice().len()
}
}
use crate::ops::ReductionOp;
use crate::scalar::Scalar;
pub trait ComputeReduce: ComputeView
where
Self::Arch: crate::kernel::SimdKernel<Self::Element>,
Self::Element: Scalar,
{
fn compute_reduce<Op: ReductionOp<Self::Element>>(&self, op: Op) -> Self::Element;
}
impl<'a, T, Arch, Align, Mode, Ref> ComputeReduce for SimdView<'a, T, Arch, Align, Mode, Ref>
where
T: Scalar,
Arch: SimdArch + crate::kernel::SimdKernel<T>,
Align: Alignment,
Mode: ExecutionMode,
Ref: 'a,
{
#[inline(always)]
fn compute_reduce<Op: ReductionOp<T>>(&self, op: Op) -> T {
self.reduce(op)
}
}