#[allow(clippy::len_without_is_empty)]
pub trait Matrix<C> {
fn len(&self) -> usize;
fn coefficient(&self, term: usize, row: usize) -> C;
fn source(&self, term: usize) -> &[u8];
}
impl<C: Copy> Matrix<C> for [(&[C], &[u8])] {
#[inline]
fn len(&self) -> usize {
<[(&[C], &[u8])]>::len(self)
}
#[inline]
fn coefficient(&self, term: usize, row: usize) -> C {
self[term].0[row]
}
#[inline]
fn source(&self, term: usize) -> &[u8] {
self[term].1
}
}
#[allow(dead_code)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub struct FlatMatrix<'a, C> {
pub coefficients: &'a [C],
pub nrows: usize,
pub sources: &'a [&'a [u8]],
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
impl<C: Copy> Matrix<C> for FlatMatrix<'_, C> {
#[inline]
fn len(&self) -> usize {
self.sources.len()
}
#[inline]
fn coefficient(&self, term: usize, row: usize) -> C {
self.coefficients[term * self.nrows + row]
}
#[inline]
fn source(&self, term: usize) -> &[u8] {
self.sources[term]
}
}