Skip to content

Commit 79392bb

Browse files
authored
Merge pull request #874 from rust-ndarray/process-deprecations
Remove deprecated items `.all_close()` and `DataClone`, `ArrayView::into_slice`
2 parents a9dc5f6 + 4e2e60c commit 79392bb

File tree

8 files changed

+23
-84
lines changed

8 files changed

+23
-84
lines changed

src/aliases.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
44
use crate::dimension::Dim;
5-
#[allow(deprecated)]
65
use crate::{ArcArray, Array, ArrayView, ArrayViewMut, Ix, IxDynImpl};
76

87
/// Create a zero-dimensional index

src/data_traits.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,6 @@ pub unsafe trait DataMut: Data + RawDataMut {
129129
}
130130
}
131131

132-
/// Array representation trait.
133-
///
134-
/// An array representation that can be cloned and allows elements to be
135-
/// accessed with safe code.
136-
///
137-
/// ***Internal trait, see `Data`.***
138-
#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13.0")]
139-
pub trait DataClone: Data + RawDataClone {}
140-
141-
#[allow(deprecated)]
142-
impl<T> DataClone for T where T: Data + RawDataClone {}
143-
144132
unsafe impl<A> RawData for RawViewRepr<*const A> {
145133
type Elem = A;
146134
fn _data_slice(&self) -> Option<&[A]> {

src/impl_views/conversions.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,9 @@ where
3131

3232
/// Return the array’s data as a slice, if it is contiguous and in standard order.
3333
/// Return `None` otherwise.
34-
#[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")]
35-
#[allow(clippy::wrong_self_convention)]
36-
pub fn into_slice(&self) -> Option<&'a [A]> {
37-
if self.is_standard_layout() {
38-
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
39-
} else {
40-
None
41-
}
42-
}
43-
44-
/// Return the array’s data as a slice, if it is contiguous and in standard order.
45-
/// Return `None` otherwise.
34+
///
35+
/// Note that while the method is similar to [`ArrayBase::as_slice()`], this method tranfers
36+
/// the view's lifetime to the slice, so it is a bit more powerful.
4637
pub fn to_slice(&self) -> Option<&'a [A]> {
4738
if self.is_standard_layout() {
4839
unsafe { Some(slice::from_raw_parts(self.ptr.as_ptr(), self.len())) }
@@ -120,8 +111,11 @@ where
120111
{
121112
/// Return the array’s data as a slice, if it is contiguous and in standard order.
122113
/// Return `None` otherwise.
114+
///
115+
/// Note that while this is similar to [`ArrayBase::as_slice_mut()`], this method tranfers the
116+
/// view's lifetime to the slice.
123117
pub fn into_slice(self) -> Option<&'a mut [A]> {
124-
self.into_slice_().ok()
118+
self.try_into_slice().ok()
125119
}
126120
}
127121

@@ -179,7 +173,9 @@ where
179173
ElementsBaseMut::new(self)
180174
}
181175

182-
pub(crate) fn into_slice_(self) -> Result<&'a mut [A], Self> {
176+
/// Return the array’s data as a slice, if it is contiguous and in standard order.
177+
/// Otherwise return self in the Err branch of the result.
178+
pub(crate) fn try_into_slice(self) -> Result<&'a mut [A], Self> {
183179
if self.is_standard_layout() {
184180
unsafe { Ok(slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len())) }
185181
} else {

src/iterators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ where
294294
{
295295
pub(crate) fn new(self_: ArrayViewMut<'a, A, D>) -> Self {
296296
IterMut {
297-
inner: match self_.into_slice_() {
297+
inner: match self_.try_into_slice() {
298298
Ok(x) => ElementsRepr::Slice(x.iter_mut()),
299299
Err(self_) => ElementsRepr::Counted(self_.into_elements_base()),
300300
},

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ mod data_traits;
162162

163163
pub use crate::aliases::*;
164164

165-
#[allow(deprecated)]
166165
pub use crate::data_traits::{
167-
Data, DataClone, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut,
166+
Data, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut,
168167
RawDataSubst,
169168
};
170169

src/numeric/impl_numeric.rs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use crate::imp_prelude::*;
1313
use crate::itertools::enumerate;
1414
use crate::numeric_util;
1515

16-
use crate::{FoldWhile, Zip};
17-
1816
/// # Numerical Methods for Arrays
1917
impl<A, S, D> ArrayBase<S, D>
2018
where
@@ -48,6 +46,17 @@ where
4846
sum
4947
}
5048

49+
/// Return the sum of all elements in the array.
50+
///
51+
/// *This method has been renamed to `.sum()`*
52+
#[deprecated(note="renamed to `sum`", since="0.15.0")]
53+
pub fn scalar_sum(&self) -> A
54+
where
55+
A: Clone + Add<Output = A> + num_traits::Zero,
56+
{
57+
self.sum()
58+
}
59+
5160
/// Returns the [arithmetic mean] x̅ of all elements in the array:
5261
///
5362
/// ```text
@@ -75,18 +84,6 @@ where
7584
}
7685
}
7786

78-
/// Return the sum of all elements in the array.
79-
///
80-
/// *This method has been renamed to `.sum()` and will be deprecated in the
81-
/// next version.*
82-
// #[deprecated(note="renamed to `sum`", since="0.13")]
83-
pub fn scalar_sum(&self) -> A
84-
where
85-
A: Clone + Add<Output = A> + num_traits::Zero,
86-
{
87-
self.sum()
88-
}
89-
9087
/// Return the product of all elements in the array.
9188
///
9289
/// ```
@@ -305,32 +302,4 @@ where
305302
{
306303
self.var_axis(axis, ddof).mapv_into(|x| x.sqrt())
307304
}
308-
309-
/// Return `true` if the arrays' elementwise differences are all within
310-
/// the given absolute tolerance, `false` otherwise.
311-
///
312-
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
313-
///
314-
/// **Panics** if broadcasting to the same shape isn’t possible.
315-
#[deprecated(
316-
note = "Use `abs_diff_eq` - it requires the `approx` crate feature",
317-
since = "0.13.0"
318-
)]
319-
pub fn all_close<S2, E>(&self, rhs: &ArrayBase<S2, E>, tol: A) -> bool
320-
where
321-
A: Float,
322-
S2: Data<Elem = A>,
323-
E: Dimension,
324-
{
325-
!Zip::from(self)
326-
.and(rhs.broadcast_unwrap(self.raw_dim()))
327-
.fold_while((), |_, x, y| {
328-
if (*x - *y).abs() <= tol {
329-
FoldWhile::Continue(())
330-
} else {
331-
FoldWhile::Done(())
332-
}
333-
})
334-
.is_done()
335-
}
336305
}

src/prelude.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//! ```
1818
1919
#[doc(no_inline)]
20-
#[allow(deprecated)]
2120
pub use crate::{
2221
ArcArray, Array, ArrayBase, ArrayView, ArrayViewMut, CowArray, RawArrayView, RawArrayViewMut,
2322
};

tests/array.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,17 +1786,6 @@ fn test_contiguous() {
17861786
assert!(b.as_slice_memory_order().is_some());
17871787
}
17881788

1789-
#[test]
1790-
#[allow(deprecated)]
1791-
fn test_all_close() {
1792-
let c = arr3(&[
1793-
[[1., 2., 3.], [1.5, 1.5, 3.]],
1794-
[[1., 2., 3.], [1., 2.5, 3.]],
1795-
]);
1796-
assert!(c.all_close(&aview1(&[1., 2., 3.]), 1.));
1797-
assert!(!c.all_close(&aview1(&[1., 2., 3.]), 0.1));
1798-
}
1799-
18001789
#[test]
18011790
fn test_swap() {
18021791
let mut a = arr2(&[[1, 2, 3], [4, 5, 6], [7, 8, 9]]);

0 commit comments

Comments
 (0)