Skip to content

Commit

Permalink
Update to nalgebra 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur authored and adamreichold committed Jan 16, 2023
1 parent 65b6693 commit bf93c9d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "BSD-2-Clause"
[dependencies]
half = { version = "2.0", default-features = false, optional = true }
libc = "0.2"
nalgebra = { version = "0.31", default-features = false, optional = true }
nalgebra = { version = "0.32", default-features = false, optional = true }
num-complex = ">= 0.2, < 0.5"
num-integer = "0.1"
num-traits = "0.2"
Expand All @@ -27,7 +27,7 @@ rustc-hash = "1.1"

[dev-dependencies]
pyo3 = { version = "0.17", default-features = false, features = ["auto-initialize"] }
nalgebra = { version = "0.31", default-features = false, features = ["std"] }
nalgebra = { version = "0.32", default-features = false, features = ["std"] }

[package.metadata.docs.rs]
all-features = true
12 changes: 6 additions & 6 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,15 +1101,15 @@ where
Some((shape, strides))
}

/// Try to convert this array into a [`nalgebra::MatrixSlice`] using the given shape and strides.
/// Try to convert this array into a [`nalgebra::MatrixView`] using the given shape and strides.
///
/// # Safety
///
/// Calling this method invalidates all exclusive references to the internal data, e.g. `ArrayViewMut` or `MatrixSliceMut`.
#[doc(alias = "nalgebra")]
pub unsafe fn try_as_matrix<R, C, RStride, CStride>(
&self,
) -> Option<nalgebra::MatrixSlice<N, R, C, RStride, CStride>>
) -> Option<nalgebra::MatrixView<N, R, C, RStride, CStride>>
where
R: nalgebra::Dim,
C: nalgebra::Dim,
Expand All @@ -1118,20 +1118,20 @@ where
{
let (shape, strides) = self.try_as_matrix_shape_strides()?;

let storage = nalgebra::SliceStorage::from_raw_parts(self.data(), shape, strides);
let storage = nalgebra::ViewStorage::from_raw_parts(self.data(), shape, strides);

Some(nalgebra::Matrix::from_data(storage))
}

/// Try to convert this array into a [`nalgebra::MatrixSliceMut`] using the given shape and strides.
/// Try to convert this array into a [`nalgebra::MatrixViewMut`] using the given shape and strides.
///
/// # Safety
///
/// Calling this method invalidates all other references to the internal data, e.g. `ArrayView`, `MatrixSlice`, `ArrayViewMut` or `MatrixSliceMut`.
#[doc(alias = "nalgebra")]
pub unsafe fn try_as_matrix_mut<R, C, RStride, CStride>(
&self,
) -> Option<nalgebra::MatrixSliceMut<N, R, C, RStride, CStride>>
) -> Option<nalgebra::MatrixViewMut<N, R, C, RStride, CStride>>
where
R: nalgebra::Dim,
C: nalgebra::Dim,
Expand All @@ -1140,7 +1140,7 @@ where
{
let (shape, strides) = self.try_as_matrix_shape_strides()?;

let storage = nalgebra::SliceStorageMut::from_raw_parts(self.data(), shape, strides);
let storage = nalgebra::ViewStorageMut::from_raw_parts(self.data(), shape, strides);

Some(nalgebra::Matrix::from_data(storage))
}
Expand Down
28 changes: 12 additions & 16 deletions src/borrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ where
N: nalgebra::Scalar + Element,
D: Dimension,
{
/// Try to convert this array into a [`nalgebra::MatrixSlice`] using the given shape and strides.
/// Try to convert this array into a [`nalgebra::MatrixView`] using the given shape and strides.
#[doc(alias = "nalgebra")]
pub fn try_as_matrix<R, C, RStride, CStride>(
&self,
) -> Option<nalgebra::MatrixSlice<N, R, C, RStride, CStride>>
) -> Option<nalgebra::MatrixView<N, R, C, RStride, CStride>>
where
R: nalgebra::Dim,
C: nalgebra::Dim,
Expand All @@ -294,13 +294,13 @@ impl<'py, N> PyReadonlyArray<'py, N, Ix1>
where
N: nalgebra::Scalar + Element,
{
/// Convert this one-dimensional array into a [`nalgebra::DMatrixSlice`] using dynamic strides.
/// Convert this one-dimensional array into a [`nalgebra::DMatrixView`] using dynamic strides.
///
/// # Panics
///
/// Panics if the array has negative strides.
#[doc(alias = "nalgebra")]
pub fn as_matrix(&self) -> nalgebra::DMatrixSlice<N, nalgebra::Dynamic, nalgebra::Dynamic> {
pub fn as_matrix(&self) -> nalgebra::DMatrixView<N, nalgebra::Dyn, nalgebra::Dyn> {
self.try_as_matrix().unwrap()
}
}
Expand All @@ -310,13 +310,13 @@ impl<'py, N> PyReadonlyArray<'py, N, Ix2>
where
N: nalgebra::Scalar + Element,
{
/// Convert this two-dimensional array into a [`nalgebra::DMatrixSlice`] using dynamic strides.
/// Convert this two-dimensional array into a [`nalgebra::DMatrixView`] using dynamic strides.
///
/// # Panics
///
/// Panics if the array has negative strides.
#[doc(alias = "nalgebra")]
pub fn as_matrix(&self) -> nalgebra::DMatrixSlice<N, nalgebra::Dynamic, nalgebra::Dynamic> {
pub fn as_matrix(&self) -> nalgebra::DMatrixView<N, nalgebra::Dyn, nalgebra::Dyn> {
self.try_as_matrix().unwrap()
}
}
Expand Down Expand Up @@ -456,11 +456,11 @@ where
N: nalgebra::Scalar + Element,
D: Dimension,
{
/// Try to convert this array into a [`nalgebra::MatrixSliceMut`] using the given shape and strides.
/// Try to convert this array into a [`nalgebra::MatrixViewMut`] using the given shape and strides.
#[doc(alias = "nalgebra")]
pub fn try_as_matrix_mut<R, C, RStride, CStride>(
&self,
) -> Option<nalgebra::MatrixSliceMut<N, R, C, RStride, CStride>>
) -> Option<nalgebra::MatrixViewMut<N, R, C, RStride, CStride>>
where
R: nalgebra::Dim,
C: nalgebra::Dim,
Expand All @@ -476,15 +476,13 @@ impl<'py, N> PyReadwriteArray<'py, N, Ix1>
where
N: nalgebra::Scalar + Element,
{
/// Convert this one-dimensional array into a [`nalgebra::DMatrixSliceMut`] using dynamic strides.
/// Convert this one-dimensional array into a [`nalgebra::DMatrixViewMut`] using dynamic strides.
///
/// # Panics
///
/// Panics if the array has negative strides.
#[doc(alias = "nalgebra")]
pub fn as_matrix_mut(
&self,
) -> nalgebra::DMatrixSliceMut<N, nalgebra::Dynamic, nalgebra::Dynamic> {
pub fn as_matrix_mut(&self) -> nalgebra::DMatrixViewMut<N, nalgebra::Dyn, nalgebra::Dyn> {
self.try_as_matrix_mut().unwrap()
}
}
Expand All @@ -494,15 +492,13 @@ impl<'py, N> PyReadwriteArray<'py, N, Ix2>
where
N: nalgebra::Scalar + Element,
{
/// Convert this two-dimensional array into a [`nalgebra::DMatrixSliceMut`] using dynamic strides.
/// Convert this two-dimensional array into a [`nalgebra::DMatrixViewMut`] using dynamic strides.
///
/// # Panics
///
/// Panics if the array has negative strides.
#[doc(alias = "nalgebra")]
pub fn as_matrix_mut(
&self,
) -> nalgebra::DMatrixSliceMut<N, nalgebra::Dynamic, nalgebra::Dynamic> {
pub fn as_matrix_mut(&self) -> nalgebra::DMatrixViewMut<N, nalgebra::Dyn, nalgebra::Dyn> {
self.try_as_matrix_mut().unwrap()
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn matrix_from_numpy() {
let matrix = array.as_matrix();
assert_eq!(matrix, nalgebra::Matrix3::new(0, 1, 2, 3, 4, 5, 6, 7, 8));

let matrix: nalgebra::MatrixSlice<
let matrix: nalgebra::MatrixView<
i32,
nalgebra::Const<3>,
nalgebra::Const<3>,
Expand All @@ -371,7 +371,7 @@ fn matrix_from_numpy() {
let matrix = array.as_matrix_mut();
assert_eq!(matrix, nalgebra::Matrix3::new(0, 1, 2, 3, 4, 5, 6, 7, 8));

let matrix: nalgebra::MatrixSliceMut<
let matrix: nalgebra::MatrixViewMut<
i32,
nalgebra::Const<3>,
nalgebra::Const<3>,
Expand All @@ -391,7 +391,7 @@ fn matrix_from_numpy() {
let matrix = array.as_matrix();
assert_eq!(matrix, nalgebra::Matrix3x1::new(0, 1, 2));

let matrix: nalgebra::MatrixSlice<i32, nalgebra::Const<3>, nalgebra::Const<1>> =
let matrix: nalgebra::MatrixView<i32, nalgebra::Const<3>, nalgebra::Const<1>> =
array.try_as_matrix().unwrap();
assert_eq!(matrix, nalgebra::Matrix3x1::new(0, 1, 2));
}
Expand All @@ -402,7 +402,7 @@ fn matrix_from_numpy() {
let matrix = array.as_matrix_mut();
assert_eq!(matrix, nalgebra::Matrix3x1::new(0, 1, 2));

let matrix: nalgebra::MatrixSliceMut<i32, nalgebra::Const<3>, nalgebra::Const<1>> =
let matrix: nalgebra::MatrixViewMut<i32, nalgebra::Const<3>, nalgebra::Const<1>> =
array.try_as_matrix_mut().unwrap();
assert_eq!(matrix, nalgebra::Matrix3x1::new(0, 1, 2));
}
Expand All @@ -412,7 +412,7 @@ fn matrix_from_numpy() {
let array = PyArray::<i32, _>::zeros(py, (2, 2, 2), false);
let array = array.readonly();

let matrix: Option<nalgebra::DMatrixSlice<i32, nalgebra::Dynamic, nalgebra::Dynamic>> =
let matrix: Option<nalgebra::DMatrixView<i32, nalgebra::Dyn, nalgebra::Dyn>> =
array.try_as_matrix();
assert!(matrix.is_none());
});
Expand All @@ -426,7 +426,7 @@ fn matrix_from_numpy() {
.unwrap();
let array = array.readonly();

let matrix: Option<nalgebra::DMatrixSlice<i32, nalgebra::Dynamic, nalgebra::Dynamic>> =
let matrix: Option<nalgebra::DMatrixView<i32, nalgebra::Dyn, nalgebra::Dyn>> =
array.try_as_matrix();
assert!(matrix.is_none());
});
Expand All @@ -436,7 +436,7 @@ fn matrix_from_numpy() {
let array = array.readonly();

let matrix: Option<
nalgebra::MatrixSlice<
nalgebra::MatrixView<
i32,
nalgebra::Const<2>,
nalgebra::Const<3>,
Expand All @@ -447,7 +447,7 @@ fn matrix_from_numpy() {
assert!(matrix.is_none());

let matrix: Option<
nalgebra::MatrixSlice<
nalgebra::MatrixView<
i32,
nalgebra::Const<3>,
nalgebra::Const<2>,
Expand All @@ -458,7 +458,7 @@ fn matrix_from_numpy() {
assert!(matrix.is_none());

let matrix: Option<
nalgebra::MatrixSlice<
nalgebra::MatrixView<
i32,
nalgebra::Const<3>,
nalgebra::Const<3>,
Expand All @@ -469,7 +469,7 @@ fn matrix_from_numpy() {
assert!(matrix.is_none());

let matrix: Option<
nalgebra::MatrixSlice<
nalgebra::MatrixView<
i32,
nalgebra::Const<3>,
nalgebra::Const<3>,
Expand Down

0 comments on commit bf93c9d

Please sign in to comment.