use crate::{backend::op_traits, dimension::dim::Dimension};
macro_rules! kernel_type_repeater {
($name: ident, $_1: tt, $_2: tt) => {
paste::paste! {
type [< $name Kernel >]: op_traits::BinaryOp;
}
};
}
pub trait Backend {
type OwnedStorage<T>: OwnedStorage
where
T: Copy;
crate::repeat_binary_ops!(kernel_type_repeater);
}
pub trait ContainerLength {
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
pub trait ContainerScalarType {
type Scalar: Copy;
}
pub trait ContainerStorageType: ContainerLength + ContainerScalarType {
type Storage: Storage;
}
pub trait ContainerStorageAccessor: ContainerStorageType {
fn get_storage(&self) -> &Self::Storage;
}
pub trait MutableContainerStorageAccessor:
ContainerStorageType + ContainerStorageAccessor
{
fn get_storage_mut(&mut self) -> &mut Self::Storage;
}
pub trait ContainerBackendType: ContainerStorageType {
type Backend: Backend;
}
pub trait Storage:
ContainerLength
+ ContainerScalarType
+ std::ops::Index<usize, Output = Self::Scalar>
+ std::ops::IndexMut<usize>
{
type OwnedStorageType: OwnedStorage;
fn fill(&mut self, value: Self::Scalar);
unsafe fn set_no_free(&mut self);
}
pub trait OwnedStorage: Storage {
type Raw;
fn new_from_shape<Dim>(shape: &Dim) -> Self
where
Dim: Dimension,
Self::Scalar: Default;
unsafe fn new_from_shape_uninit<Dim>(shape: &Dim) -> Self
where
Dim: Dimension;
unsafe fn get_raw(&self) -> Self::Raw;
}
pub trait ScalarAccessor: ContainerLength + ContainerScalarType {
fn get_scalar(&self, index: usize) -> Self::Scalar;
}
pub trait ScalarWriter: ContainerLength + ContainerScalarType {
fn write_scalar(&mut self, value: Self::Scalar, index: usize);
}