From 0cc42b572b1ddf4ae8eb453b3273b75d34c78fd1 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 24 Dec 2020 00:18:26 +0100 Subject: [PATCH 1/6] API: Remove deprecated trait DataClone Use Data + RawDataClone as replacement --- src/data_traits.rs | 12 ------------ src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/data_traits.rs b/src/data_traits.rs index a3e00c1ed..30133d70f 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -129,18 +129,6 @@ pub unsafe trait DataMut: Data + RawDataMut { } } -/// Array representation trait. -/// -/// An array representation that can be cloned and allows elements to be -/// accessed with safe code. -/// -/// ***Internal trait, see `Data`.*** -#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13.0")] -pub trait DataClone: Data + RawDataClone {} - -#[allow(deprecated)] -impl DataClone for T where T: Data + RawDataClone {} - unsafe impl RawData for RawViewRepr<*const A> { type Elem = A; fn _data_slice(&self) -> Option<&[A]> { diff --git a/src/lib.rs b/src/lib.rs index a99d6d52f..3268d8db5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,7 +164,7 @@ pub use crate::aliases::*; #[allow(deprecated)] pub use crate::data_traits::{ - Data, DataClone, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut, + Data, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut, RawDataSubst, }; From 49b315a0572fafd22a92e47fe84a25bd8f316c1f Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 24 Dec 2020 00:21:54 +0100 Subject: [PATCH 2/6] API: Mark .scalar_sum() as deprecated (Renamed to .sum()) --- src/numeric/impl_numeric.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 85f69444d..4850bd805 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -48,6 +48,17 @@ where sum } + /// Return the sum of all elements in the array. + /// + /// *This method has been renamed to `.sum()`* + #[deprecated(note="renamed to `sum`", since="0.15.0")] + pub fn scalar_sum(&self) -> A + where + A: Clone + Add + num_traits::Zero, + { + self.sum() + } + /// Returns the [arithmetic mean] x̅ of all elements in the array: /// /// ```text @@ -75,18 +86,6 @@ where } } - /// Return the sum of all elements in the array. - /// - /// *This method has been renamed to `.sum()` and will be deprecated in the - /// next version.* - // #[deprecated(note="renamed to `sum`", since="0.13")] - pub fn scalar_sum(&self) -> A - where - A: Clone + Add + num_traits::Zero, - { - self.sum() - } - /// Return the product of all elements in the array. /// /// ``` From e585262a7145ad54f356280c71bf295b399dd309 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 24 Dec 2020 00:51:15 +0100 Subject: [PATCH 3/6] API: Remove deprecated .all_close() Replaced by .abs_diff_eq (using the approx feature) --- src/numeric/impl_numeric.rs | 30 ------------------------------ tests/array.rs | 11 ----------- 2 files changed, 41 deletions(-) diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 4850bd805..6fc4f6cf4 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -13,8 +13,6 @@ use crate::imp_prelude::*; use crate::itertools::enumerate; use crate::numeric_util; -use crate::{FoldWhile, Zip}; - /// # Numerical Methods for Arrays impl ArrayBase where @@ -304,32 +302,4 @@ where { self.var_axis(axis, ddof).mapv_into(|x| x.sqrt()) } - - /// Return `true` if the arrays' elementwise differences are all within - /// the given absolute tolerance, `false` otherwise. - /// - /// If their shapes disagree, `rhs` is broadcast to the shape of `self`. - /// - /// **Panics** if broadcasting to the same shape isn’t possible. - #[deprecated( - note = "Use `abs_diff_eq` - it requires the `approx` crate feature", - since = "0.13.0" - )] - pub fn all_close(&self, rhs: &ArrayBase, tol: A) -> bool - where - A: Float, - S2: Data, - E: Dimension, - { - !Zip::from(self) - .and(rhs.broadcast_unwrap(self.raw_dim())) - .fold_while((), |_, x, y| { - if (*x - *y).abs() <= tol { - FoldWhile::Continue(()) - } else { - FoldWhile::Done(()) - } - }) - .is_done() - } } diff --git a/tests/array.rs b/tests/array.rs index db54b7e5f..436a3e972 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -1786,17 +1786,6 @@ fn test_contiguous() { assert!(b.as_slice_memory_order().is_some()); } -#[test] -#[allow(deprecated)] -fn test_all_close() { - let c = arr3(&[ - [[1., 2., 3.], [1.5, 1.5, 3.]], - [[1., 2., 3.], [1., 2.5, 3.]], - ]); - assert!(c.all_close(&aview1(&[1., 2., 3.]), 1.)); - assert!(!c.all_close(&aview1(&[1., 2., 3.]), 0.1)); -} - #[test] fn test_swap() { let mut a = arr2(&[[1, 2, 3], [4, 5, 6], [7, 8, 9]]); From dd5f840c022c948028342cda4b03a25f0f2f3086 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 24 Dec 2020 00:23:43 +0100 Subject: [PATCH 4/6] MAINT: Remove unused allow(deprecated) attr --- src/aliases.rs | 1 - src/lib.rs | 1 - src/prelude.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/aliases.rs b/src/aliases.rs index 911e745bd..d41c888a6 100644 --- a/src/aliases.rs +++ b/src/aliases.rs @@ -2,7 +2,6 @@ //! use crate::dimension::Dim; -#[allow(deprecated)] use crate::{ArcArray, Array, ArrayView, ArrayViewMut, Ix, IxDynImpl}; /// Create a zero-dimensional index diff --git a/src/lib.rs b/src/lib.rs index 3268d8db5..52265ccb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,7 +162,6 @@ mod data_traits; pub use crate::aliases::*; -#[allow(deprecated)] pub use crate::data_traits::{ Data, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut, RawDataSubst, diff --git a/src/prelude.rs b/src/prelude.rs index e25e52175..def236841 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -17,7 +17,6 @@ //! ``` #[doc(no_inline)] -#[allow(deprecated)] pub use crate::{ ArcArray, Array, ArrayBase, ArrayView, ArrayViewMut, CowArray, RawArrayView, RawArrayViewMut, }; From e071bdbe363ac8fed6a573e3eafcc34e22ab2d07 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 24 Dec 2020 01:31:52 +0100 Subject: [PATCH 5/6] API: Remove deprecated ArrayView::into_slice (use to_slice) This could really use either name - `into_slice` for the "into" semantic of preserving the lifetime parameter, or the `to_slice` name which is customary for `&self` methods. Both names have the problem that they compete with `ArrayBase::as_slice()`, but the doc has been improved to explain some of that. --- src/impl_views/conversions.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 303541b8b..3ca44d75c 100644 --- a/src/impl_views/conversions.rs +++ b/src/impl_views/conversions.rs @@ -31,18 +31,9 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. - #[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")] - #[allow(clippy::wrong_self_convention)] - pub fn into_slice(&self) -> Option<&'a [A]> { - if self.is_standard_layout() { - unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) } - } else { - None - } - } - - /// Return the array’s data as a slice, if it is contiguous and in standard order. - /// Return `None` otherwise. + /// + /// Note that while the method is similar to [`ArrayBase::as_slice()`], this method tranfers + /// the view's lifetime to the slice, so it is a bit more powerful. pub fn to_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) } @@ -120,6 +111,9 @@ where { /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. + /// + /// Note that while this is similar to [`ArrayBase::as_slice_mut()`], this method tranfers the + /// view's lifetime to the slice. pub fn into_slice(self) -> Option<&'a mut [A]> { self.into_slice_().ok() } From 4e2e60c60e164f352a9e6afae654ef08ac8ba08f Mon Sep 17 00:00:00 2001 From: bluss Date: Tue, 29 Dec 2020 02:29:22 +0100 Subject: [PATCH 6/6] FIX: Internal cleanup, rename into_slice_ -> try_into_slice --- src/impl_views/conversions.rs | 6 ++++-- src/iterators/mod.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 3ca44d75c..863d26ddb 100644 --- a/src/impl_views/conversions.rs +++ b/src/impl_views/conversions.rs @@ -115,7 +115,7 @@ where /// Note that while this is similar to [`ArrayBase::as_slice_mut()`], this method tranfers the /// view's lifetime to the slice. pub fn into_slice(self) -> Option<&'a mut [A]> { - self.into_slice_().ok() + self.try_into_slice().ok() } } @@ -173,7 +173,9 @@ where ElementsBaseMut::new(self) } - pub(crate) fn into_slice_(self) -> Result<&'a mut [A], Self> { + /// Return the array’s data as a slice, if it is contiguous and in standard order. + /// Otherwise return self in the Err branch of the result. + pub(crate) fn try_into_slice(self) -> Result<&'a mut [A], Self> { if self.is_standard_layout() { unsafe { Ok(slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len())) } } else { diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 621c141ff..8cb7a9088 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -294,7 +294,7 @@ where { pub(crate) fn new(self_: ArrayViewMut<'a, A, D>) -> Self { IterMut { - inner: match self_.into_slice_() { + inner: match self_.try_into_slice() { Ok(x) => ElementsRepr::Slice(x.iter_mut()), Err(self_) => ElementsRepr::Counted(self_.into_elements_base()), },