Skip to content

Commit

Permalink
Merge pull request #874 from rust-ndarray/process-deprecations
Browse files Browse the repository at this point in the history
Remove deprecated items `.all_close()` and `DataClone`, `ArrayView::into_slice`
  • Loading branch information
bluss committed Dec 29, 2020
2 parents a9dc5f6 + 4e2e60c commit 79392bb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 84 deletions.
1 change: 0 additions & 1 deletion src/aliases.rs
Expand Up @@ -2,7 +2,6 @@
//!

use crate::dimension::Dim;
#[allow(deprecated)]
use crate::{ArcArray, Array, ArrayView, ArrayViewMut, Ix, IxDynImpl};

/// Create a zero-dimensional index
Expand Down
12 changes: 0 additions & 12 deletions src/data_traits.rs
Expand Up @@ -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<T> DataClone for T where T: Data + RawDataClone {}

unsafe impl<A> RawData for RawViewRepr<*const A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
Expand Down
24 changes: 10 additions & 14 deletions src/impl_views/conversions.rs
Expand Up @@ -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())) }
Expand Down Expand Up @@ -120,8 +111,11 @@ 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()
self.try_into_slice().ok()
}
}

Expand Down Expand Up @@ -179,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/iterators/mod.rs
Expand Up @@ -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()),
},
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Expand Up @@ -162,9 +162,8 @@ mod data_traits;

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,
};

Expand Down
53 changes: 11 additions & 42 deletions src/numeric/impl_numeric.rs
Expand Up @@ -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<A, S, D> ArrayBase<S, D>
where
Expand Down Expand Up @@ -48,6 +46,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<Output = A> + num_traits::Zero,
{
self.sum()
}

/// Returns the [arithmetic mean] x̅ of all elements in the array:
///
/// ```text
Expand Down Expand Up @@ -75,18 +84,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<Output = A> + num_traits::Zero,
{
self.sum()
}

/// Return the product of all elements in the array.
///
/// ```
Expand Down Expand Up @@ -305,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<S2, E>(&self, rhs: &ArrayBase<S2, E>, tol: A) -> bool
where
A: Float,
S2: Data<Elem = A>,
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()
}
}
1 change: 0 additions & 1 deletion src/prelude.rs
Expand Up @@ -17,7 +17,6 @@
//! ```

#[doc(no_inline)]
#[allow(deprecated)]
pub use crate::{
ArcArray, Array, ArrayBase, ArrayView, ArrayViewMut, CowArray, RawArrayView, RawArrayViewMut,
};
Expand Down
11 changes: 0 additions & 11 deletions tests/array.rs
Expand Up @@ -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]]);
Expand Down

0 comments on commit 79392bb

Please sign in to comment.