Skip to content

Commit

Permalink
WIP: make matrix data generic (broken intermediate state)
Browse files Browse the repository at this point in the history
  • Loading branch information
panzi committed Oct 31, 2023
1 parent 0e9bff8 commit 64fecf7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/bycolumn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{Matrix, Number, Vector, iter::ColumnIter, ops::{MatrixAggregate, Get

#[repr(transparent)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct IntoByColumn<const X: usize, const Y: usize, T: Number=f64>
pub struct IntoByColumn<const X: usize, const Y: usize, T: Number=f64, D: AsRef<[T; X * Y]>>
where [T; X * Y]: Sized
{
pub matrix: Matrix<X, Y, T>
pub matrix: Matrix<X, Y, T, D>
}

impl<const X: usize, const Y: usize, T: Number> IntoByColumn<X, Y, T>
Expand Down
23 changes: 12 additions & 11 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::range::{RangeIter, Range};

#[repr(transparent)]
#[derive(Clone, Hash, PartialOrd, Ord)]
pub struct Matrix<const X: usize, const Y: usize, T: Number=f64>
pub struct Matrix<const X: usize, const Y: usize, T: Number=f64, D: AsRef<[T; X * Y]>=Box<[T; X * Y]>>
where [T; X * Y]: Sized
{
data: Box<[T; X * Y]>
data: D
}

impl<const X: usize, const Y: usize, T: Number> Matrix<X, Y, T>
impl<const X: usize, const Y: usize, T: Number, D: AsRef<[T; X * Y]>> Matrix<X, Y, T, D>
where [T; X * Y]: Sized
{
pub const X: usize = X;
Expand Down Expand Up @@ -118,17 +118,18 @@ where [T; X * Y]: Sized

#[inline]
pub fn data(&self) -> &[T; X * Y] {
&self.data
self.data.as_ref()
}

#[inline]
pub fn data_mut(&mut self) -> &mut [T; X * Y] {
&mut self.data
pub fn data_mut(&mut self) -> &mut [T; X * Y]
where D: AsMut<[T; X * Y]> {
self.data.as_mut()
}

#[inline]
pub fn into_data(self) -> [T; X * Y] {
*self.data
pub fn into_data(self) -> D {
self.data
}

#[inline]
Expand Down Expand Up @@ -327,13 +328,13 @@ where [T; X * Y]: Sized
}
}

impl<const X: usize, const Y: usize, T: Number> Tap for Matrix<X, Y, T>
impl<const X: usize, const Y: usize, T: Number, D: AsRef<[T; X * Y]>> Tap for Matrix<X, Y, T, D>
where [T; X * Y]: Sized {}

impl<const X: usize, const Y: usize, T: Number> Pipe for Matrix<X, Y, T>
impl<const X: usize, const Y: usize, T: Number, D: AsRef<[T; X * Y]>> Pipe for Matrix<X, Y, T, D>
where [T; X * Y]: Sized {}

impl<const X: usize, const Y: usize, T: Number> MatrixAggregate<X, Y, T> for Matrix<X, Y, T>
impl<const X: usize, const Y: usize, T: Number, D: AsRef<[T; X * Y]>> MatrixAggregate<X, Y, T> for Matrix<X, Y, T, D>
where [T; X * Y]: Sized {
#[inline]
fn fold<F, B>(&self, init: B, mut f: F) -> Vector<Y, B>
Expand Down

0 comments on commit 64fecf7

Please sign in to comment.