From 2fe682c0f3e8363b4a737670d0fdc304be81e100 Mon Sep 17 00:00:00 2001 From: William Watkins Date: Fri, 3 Feb 2023 16:13:30 +0100 Subject: [PATCH 1/4] updated versions of ndarray and nalgebra 03/02/2023 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0708991..8dfdcc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ default = ["nalgebra", "nalgebra_std", "ndarray", "image"] nalgebra_std = ["nalgebra/std"] [dependencies] -ndarray = { version = "0.15.4", default-features = false, optional = true } -nalgebra = { version = "0.30.1", default-features = false, optional = true } +ndarray = { version = "0.15.6", default-features = false, optional = true } +nalgebra = { version = "0.32.1", default-features = false, optional = true } image = { version = "0.24.0", default-features = false, optional = true } [package.metadata.docs.rs] From 9f99f0497fde15d59aad9f22cdec035d25a8a643 Mon Sep 17 00:00:00 2001 From: William Watkins Date: Fri, 3 Feb 2023 16:14:30 +0100 Subject: [PATCH 2/4] fixes --- src/tondarray/image_impl.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tondarray/image_impl.rs b/src/tondarray/image_impl.rs index d025113..651a41b 100644 --- a/src/tondarray/image_impl.rs +++ b/src/tondarray/image_impl.rs @@ -70,7 +70,7 @@ where } = self.sample_layout(); let shape = (height as usize, width as usize); let strides = (height_stride, width_stride); - ArrayView2::from_shape(shape.strides(strides), &**self).unwrap() + ArrayView2::from_shape(shape.strides(strides), self).unwrap() } } @@ -102,7 +102,7 @@ where } = self.sample_layout(); let shape = (height as usize, width as usize); let strides = (height_stride, width_stride); - ArrayViewMut2::from_shape(shape.strides(strides), &mut **self).unwrap() + ArrayViewMut2::from_shape(shape.strides(strides), self).unwrap() } } @@ -170,7 +170,7 @@ where } = self.sample_layout(); let shape = (channels as usize, height as usize, width as usize); let strides = (channel_stride, height_stride, width_stride); - ArrayView3::from_shape(shape.strides(strides), &**self).unwrap() + ArrayView3::from_shape(shape.strides(strides), self).unwrap() } } @@ -201,6 +201,6 @@ where } = self.sample_layout(); let shape = (channels as usize, height as usize, width as usize); let strides = (channel_stride, height_stride, width_stride); - ArrayViewMut3::from_shape(shape.strides(strides), &mut **self).unwrap() + ArrayViewMut3::from_shape(shape.strides(strides), self).unwrap() } } From 05108abbec7de0d7a84256f303a56eae12bf52a4 Mon Sep 17 00:00:00 2001 From: William Watkins Date: Fri, 3 Feb 2023 16:22:39 +0100 Subject: [PATCH 3/4] updated code with new nalgebra variable names --- src/tonalgebra/ndarray_impl.rs | 44 +++++++++++++++++----------------- src/tondarray/nalgebra_impl.rs | 22 ++++++++--------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/tonalgebra/ndarray_impl.rs b/src/tonalgebra/ndarray_impl.rs index a467d4a..d90b777 100644 --- a/src/tonalgebra/ndarray_impl.rs +++ b/src/tonalgebra/ndarray_impl.rs @@ -3,7 +3,7 @@ use super::*; use core::convert::TryFrom; -use nalgebra::Dynamic as Dy; +use nalgebra::Dyn; /// ``` /// use nshare::ToNalgebra; @@ -17,16 +17,16 @@ impl<'a, T> ToNalgebra for ndarray::ArrayView1<'a, T> where T: nalgebra::Scalar, { - type Out = nalgebra::DVectorSlice<'a, T>; + type Out = nalgebra::DVectorView<'a, T>; fn into_nalgebra(self) -> Self::Out { - let len = Dy::new(self.len()); + let len = Dyn(self.len()); let ptr = self.as_ptr(); let stride: usize = TryFrom::try_from(self.strides()[0]).expect("Negative stride"); let storage = unsafe { - nalgebra::SliceStorage::from_raw_parts( + nalgebra::ViewStorage::from_raw_parts( ptr, (len, nalgebra::Const::<1>), - (nalgebra::Const::<1>, Dy::new(stride)), + (nalgebra::Const::<1>, Dyn(stride)), ) }; nalgebra::Matrix::from_data(storage) @@ -44,18 +44,18 @@ impl<'a, T> ToNalgebra for ndarray::ArrayViewMut1<'a, T> where T: nalgebra::Scalar, { - type Out = nalgebra::DVectorSliceMut<'a, T>; + type Out = nalgebra::DVectorViewMut<'a, T>; fn into_nalgebra(mut self) -> Self::Out { - let len = Dy::new(self.len()); + let len = Dyn(self.len()); let stride: usize = TryFrom::try_from(self.strides()[0]).expect("Negative stride"); let ptr = self.as_mut_ptr(); let storage = unsafe { // Drop to not have simultaneously the ndarray and nalgebra valid. drop(self); - nalgebra::SliceStorageMut::from_raw_parts( + nalgebra::ViewStorageMut::from_raw_parts( ptr, (len, nalgebra::Const::<1>), - (nalgebra::Const::<1>, Dy::new(stride)), + (nalgebra::Const::<1>, Dyn(stride)), ) }; nalgebra::Matrix::from_data(storage) @@ -76,7 +76,7 @@ where { type Out = nalgebra::DVector; fn into_nalgebra(self) -> Self::Out { - let len = Dy::new(self.len()); + let len = Dyn(self.len()); Self::Out::from_vec_generic(len, nalgebra::Const::<1>, self.into_raw_vec()) } } @@ -99,19 +99,19 @@ impl<'a, T> ToNalgebra for ndarray::ArrayView2<'a, T> where T: nalgebra::Scalar, { - type Out = nalgebra::DMatrixSlice<'a, T, Dy, Dy>; + type Out = nalgebra::DMatrixView<'a, T, Dyn, Dyn>; fn into_nalgebra(self) -> Self::Out { - let nrows = Dy::new(self.nrows()); - let ncols = Dy::new(self.ncols()); + let nrows = Dyn(self.nrows()); + let ncols = Dyn(self.ncols()); let ptr = self.as_ptr(); let stride_row: usize = TryFrom::try_from(self.strides()[0]).expect("Negative row stride"); let stride_col: usize = TryFrom::try_from(self.strides()[1]).expect("Negative column stride"); let storage = unsafe { - nalgebra::SliceStorage::from_raw_parts( + nalgebra::ViewStorage::from_raw_parts( ptr, (nrows, ncols), - (Dy::new(stride_row), Dy::new(stride_col)), + (Dyn(stride_row), Dyn(stride_col)), ) }; nalgebra::Matrix::from_data(storage) @@ -136,10 +136,10 @@ impl<'a, T> ToNalgebra for ndarray::ArrayViewMut2<'a, T> where T: nalgebra::Scalar, { - type Out = nalgebra::DMatrixSliceMut<'a, T, Dy, Dy>; + type Out = nalgebra::DMatrixViewMut <'a, T, Dyn, Dyn>; fn into_nalgebra(mut self) -> Self::Out { - let nrows = Dy::new(self.nrows()); - let ncols = Dy::new(self.ncols()); + let nrows = Dyn(self.nrows()); + let ncols = Dyn(self.ncols()); let stride_row: usize = TryFrom::try_from(self.strides()[0]).expect("Negative row stride"); let stride_col: usize = TryFrom::try_from(self.strides()[1]).expect("Negative column stride"); @@ -147,10 +147,10 @@ where let storage = unsafe { // Drop to not have simultaneously the ndarray and nalgebra valid. drop(self); - nalgebra::SliceStorageMut::from_raw_parts( + nalgebra::ViewStorageMut::from_raw_parts( ptr, (nrows, ncols), - (Dy::new(stride_row), Dy::new(stride_col)), + (Dyn(stride_row), Dyn(stride_col)), ) }; nalgebra::Matrix::from_data(storage) @@ -178,8 +178,8 @@ where type Out = nalgebra::DMatrix; fn into_nalgebra(self) -> Self::Out { let std_layout = self.is_standard_layout(); - let nrows = Dy::new(self.nrows()); - let ncols = Dy::new(self.ncols()); + let nrows = Dyn(self.nrows()); + let ncols = Dyn(self.ncols()); let mut res = Self::Out::from_vec_generic(nrows, ncols, self.into_raw_vec()); if std_layout { // This can be expensive, but we have no choice since nalgebra VecStorage is always diff --git a/src/tondarray/nalgebra_impl.rs b/src/tondarray/nalgebra_impl.rs index 99aaebe..30c81fb 100644 --- a/src/tondarray/nalgebra_impl.rs +++ b/src/tondarray/nalgebra_impl.rs @@ -4,7 +4,7 @@ use super::*; use nalgebra::{ dimension::U1, storage::{Storage, StorageMut}, - Dim, Matrix, Scalar, SliceStorage, SliceStorageMut, Vector, + Dim, Matrix, Scalar, ViewStorage, ViewStorageMut, Vector, }; use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, ShapeBuilder}; @@ -76,7 +76,7 @@ where /// assert_eq!(arr.dim(), 4); /// ``` impl<'a, N: Scalar, R: Dim, RStride: Dim, CStride: Dim> ToNdarray1 - for Vector> + for Vector> { type Out = ArrayView1<'a, N>; @@ -101,7 +101,7 @@ impl<'a, N: Scalar, R: Dim, RStride: Dim, CStride: Dim> ToNdarray1 /// assert!(m.iter().eq(&[0.0, 0.2, 0.0, 0.4])); /// ``` impl<'a, N: Scalar, R: Dim, RStride: Dim, CStride: Dim> ToNdarray1 - for Matrix> + for Matrix> { type Out = ArrayViewMut1<'a, N>; @@ -186,7 +186,7 @@ where /// assert_eq!(arr.dim(), (1, 4)); /// ``` impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 - for Matrix> + for Matrix> { type Out = ArrayView2<'a, N>; @@ -209,7 +209,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 /// assert!(m.row(1).iter().eq(&[0.0; 4])); /// ``` impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 - for Matrix> + for Matrix> { type Out = ArrayViewMut2<'a, N>; @@ -226,7 +226,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 #[cfg(feature = "nalgebra_std")] mod std_impl { use super::*; - use nalgebra::{allocator::Allocator, DVector, DefaultAllocator, Dynamic, VecStorage}; + use nalgebra::{allocator::Allocator, DVector, DefaultAllocator, Dyn, VecStorage}; use ndarray::{Array1, Array2}; /// ``` /// use nshare::ToNdarray1; @@ -240,7 +240,7 @@ mod std_impl { /// assert_eq!(arr.dim(), 4); /// assert!(arr.iter().eq(&[0.1, 0.2, 0.3, 0.4])); /// ``` - impl<'a, N: Scalar> ToNdarray1 for DVector { + impl ToNdarray1 for DVector { type Out = Array1; fn into_ndarray1(self) -> Self::Out { @@ -250,11 +250,11 @@ mod std_impl { /// ``` /// use nshare::ToNdarray2; - /// use nalgebra::{Matrix, dimension::{U4, Dynamic}}; + /// use nalgebra::{Matrix, dimension::{U4, Dyn}}; /// use ndarray::s; /// /// // Note: from_vec takes data column-by-column ! - /// let m = Matrix::::from_vec(3, 4, vec![ + /// let m = Matrix::::from_vec(3, 4, vec![ /// 0.1, 0.2, 0.3, /// 0.5, 0.6, 0.7, /// 1.1, 1.2, 1.3, @@ -264,9 +264,9 @@ mod std_impl { /// assert!(arr.slice(s![.., 0]).iter().eq(&[0.1, 0.2, 0.3])); /// assert!(arr.slice(s![0, ..]).iter().eq(&[0.1, 0.5, 1.1, 1.5])); /// ``` - impl<'a, N: Scalar> ToNdarray2 for Matrix> + impl ToNdarray2 for Matrix> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { type Out = Array2; From b18b0c9d0a17deec38fe888dbd28ee21216098e7 Mon Sep 17 00:00:00 2001 From: William Watkins Date: Fri, 3 Feb 2023 17:02:23 +0100 Subject: [PATCH 4/4] fix linting problem --- src/tonalgebra/ndarray_impl.rs | 2 +- src/tondarray/nalgebra_impl.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tonalgebra/ndarray_impl.rs b/src/tonalgebra/ndarray_impl.rs index d90b777..0710b47 100644 --- a/src/tonalgebra/ndarray_impl.rs +++ b/src/tonalgebra/ndarray_impl.rs @@ -136,7 +136,7 @@ impl<'a, T> ToNalgebra for ndarray::ArrayViewMut2<'a, T> where T: nalgebra::Scalar, { - type Out = nalgebra::DMatrixViewMut <'a, T, Dyn, Dyn>; + type Out = nalgebra::DMatrixViewMut<'a, T, Dyn, Dyn>; fn into_nalgebra(mut self) -> Self::Out { let nrows = Dyn(self.nrows()); let ncols = Dyn(self.ncols()); diff --git a/src/tondarray/nalgebra_impl.rs b/src/tondarray/nalgebra_impl.rs index 30c81fb..f07c859 100644 --- a/src/tondarray/nalgebra_impl.rs +++ b/src/tondarray/nalgebra_impl.rs @@ -4,7 +4,7 @@ use super::*; use nalgebra::{ dimension::U1, storage::{Storage, StorageMut}, - Dim, Matrix, Scalar, ViewStorage, ViewStorageMut, Vector, + Dim, Matrix, Scalar, Vector, ViewStorage, ViewStorageMut, }; use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, ShapeBuilder};