use core::ops::IndexMut;
#[cfg(feature = "std")]
use na::{DMatrix, DVector, Scalar};
pub trait Array1<T>: IndexMut<usize, Output = T> {
fn len(&self) -> usize;
#[inline]
fn is_empty(&self) -> bool {
self.len() == 0
}
#[inline]
fn get_at(&self, i: usize) -> Option<&T> {
if i < self.len() {
Some(&self[i])
} else {
None
}
}
}
#[cfg(feature = "std")]
impl<T> Array1<T> for Vec<T> {
#[inline]
fn len(&self) -> usize {
self.len()
}
}
#[cfg(feature = "std")]
impl<T> Array1<T> for DVector<T> {
#[inline]
fn len(&self) -> usize {
self.len()
}
}
pub trait Array2 {
type Item;
fn nrows(&self) -> usize;
fn ncols(&self) -> usize;
fn get(&self, i: usize, j: usize) -> Self::Item;
fn set(&mut self, i: usize, j: usize, val: Self::Item);
}
#[cfg(feature = "std")]
impl<T: Scalar> Array2 for DMatrix<T> {
type Item = T;
#[inline]
fn nrows(&self) -> usize {
self.nrows()
}
#[inline]
fn ncols(&self) -> usize {
self.ncols()
}
#[inline]
fn get(&self, i: usize, j: usize) -> Self::Item {
self[(i, j)].clone()
}
#[inline]
fn set(&mut self, i: usize, j: usize, val: Self::Item) {
self[(i, j)] = val
}
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub struct DefaultStorage;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[cfg(feature = "cuda")]
pub struct CudaStorage;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[cfg(feature = "cuda")]
pub struct CudaStoragePtr;