Skip to content

Update nalgebra version to 0.32.1. latest as of 03/02/2023 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
44 changes: 22 additions & 22 deletions src/tonalgebra/ndarray_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::*;

use core::convert::TryFrom;
use nalgebra::Dynamic as Dy;
use nalgebra::Dyn;

/// ```
/// use nshare::ToNalgebra;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -76,7 +76,7 @@ where
{
type Out = nalgebra::DVector<T>;
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())
}
}
Expand All @@ -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)
Expand All @@ -136,21 +136,21 @@ 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");
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,
(nrows, ncols),
(Dy::new(stride_row), Dy::new(stride_col)),
(Dyn(stride_row), Dyn(stride_col)),
)
};
nalgebra::Matrix::from_data(storage)
Expand Down Expand Up @@ -178,8 +178,8 @@ where
type Out = nalgebra::DMatrix<T>;
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
Expand Down
8 changes: 4 additions & 4 deletions src/tondarray/image_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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()
}
}
22 changes: 11 additions & 11 deletions src/tondarray/nalgebra_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use nalgebra::{
dimension::U1,
storage::{Storage, StorageMut},
Dim, Matrix, Scalar, SliceStorage, SliceStorageMut, Vector,
Dim, Matrix, Scalar, Vector, ViewStorage, ViewStorageMut,
};
use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, ShapeBuilder};

Expand Down Expand Up @@ -76,7 +76,7 @@ where
/// assert_eq!(arr.dim(), 4);
/// ```
impl<'a, N: Scalar, R: Dim, RStride: Dim, CStride: Dim> ToNdarray1
for Vector<N, R, SliceStorage<'a, N, R, U1, RStride, CStride>>
for Vector<N, R, ViewStorage<'a, N, R, U1, RStride, CStride>>
{
type Out = ArrayView1<'a, N>;

Expand All @@ -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<N, R, U1, SliceStorageMut<'a, N, R, U1, RStride, CStride>>
for Matrix<N, R, U1, ViewStorageMut<'a, N, R, U1, RStride, CStride>>
{
type Out = ArrayViewMut1<'a, N>;

Expand Down Expand Up @@ -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<N, R, C, SliceStorage<'a, N, R, C, RStride, CStride>>
for Matrix<N, R, C, ViewStorage<'a, N, R, C, RStride, CStride>>
{
type Out = ArrayView2<'a, N>;

Expand All @@ -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<N, R, C, SliceStorageMut<'a, N, R, C, RStride, CStride>>
for Matrix<N, R, C, ViewStorageMut<'a, N, R, C, RStride, CStride>>
{
type Out = ArrayViewMut2<'a, N>;

Expand All @@ -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;
Expand All @@ -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<N> {
impl<N: Scalar> ToNdarray1 for DVector<N> {
type Out = Array1<N>;

fn into_ndarray1(self) -> Self::Out {
Expand All @@ -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::<f32, Dynamic, Dynamic, _>::from_vec(3, 4, vec![
/// let m = Matrix::<f32, Dyn, Dyn, _>::from_vec(3, 4, vec![
/// 0.1, 0.2, 0.3,
/// 0.5, 0.6, 0.7,
/// 1.1, 1.2, 1.3,
Expand All @@ -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<N, Dynamic, Dynamic, VecStorage<N, Dynamic, Dynamic>>
impl<N: Scalar> ToNdarray2 for Matrix<N, Dyn, Dyn, VecStorage<N, Dyn, Dyn>>
where
DefaultAllocator: Allocator<N, Dynamic, Dynamic, Buffer = VecStorage<N, Dynamic, Dynamic>>,
DefaultAllocator: Allocator<N, Dyn, Dyn, Buffer = VecStorage<N, Dyn, Dyn>>,
{
type Out = Array2<N>;

Expand Down