Skip to content

Commit 64fecf7

Browse files
committed
WIP: make matrix data generic (broken intermediate state)
1 parent 0e9bff8 commit 64fecf7

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/bycolumn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crate::{Matrix, Number, Vector, iter::ColumnIter, ops::{MatrixAggregate, Get
88

99
#[repr(transparent)]
1010
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
11-
pub struct IntoByColumn<const X: usize, const Y: usize, T: Number=f64>
11+
pub struct IntoByColumn<const X: usize, const Y: usize, T: Number=f64, D: AsRef<[T; X * Y]>>
1212
where [T; X * Y]: Sized
1313
{
14-
pub matrix: Matrix<X, Y, T>
14+
pub matrix: Matrix<X, Y, T, D>
1515
}
1616

1717
impl<const X: usize, const Y: usize, T: Number> IntoByColumn<X, Y, T>

src/matrix.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use crate::range::{RangeIter, Range};
1313

1414
#[repr(transparent)]
1515
#[derive(Clone, Hash, PartialOrd, Ord)]
16-
pub struct Matrix<const X: usize, const Y: usize, T: Number=f64>
16+
pub struct Matrix<const X: usize, const Y: usize, T: Number=f64, D: AsRef<[T; X * Y]>=Box<[T; X * Y]>>
1717
where [T; X * Y]: Sized
1818
{
19-
data: Box<[T; X * Y]>
19+
data: D
2020
}
2121

22-
impl<const X: usize, const Y: usize, T: Number> Matrix<X, Y, T>
22+
impl<const X: usize, const Y: usize, T: Number, D: AsRef<[T; X * Y]>> Matrix<X, Y, T, D>
2323
where [T; X * Y]: Sized
2424
{
2525
pub const X: usize = X;
@@ -118,17 +118,18 @@ where [T; X * Y]: Sized
118118

119119
#[inline]
120120
pub fn data(&self) -> &[T; X * Y] {
121-
&self.data
121+
self.data.as_ref()
122122
}
123123

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

129130
#[inline]
130-
pub fn into_data(self) -> [T; X * Y] {
131-
*self.data
131+
pub fn into_data(self) -> D {
132+
self.data
132133
}
133134

134135
#[inline]
@@ -327,13 +328,13 @@ where [T; X * Y]: Sized
327328
}
328329
}
329330

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

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

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

0 commit comments

Comments
 (0)