Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,17 +850,17 @@ mod test
#[test]
fn max_abs_offset_check_overflow_examples()
{
let dim = (1, ::std::isize::MAX as usize, 1).into_dimension();
let dim = (1, isize::MAX as usize, 1).into_dimension();
let strides = (1, 1, 1).into_dimension();
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap();
let dim = (1, ::std::isize::MAX as usize, 2).into_dimension();
let dim = (1, isize::MAX as usize, 2).into_dimension();
let strides = (1, 1, 1).into_dimension();
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap_err();
let dim = (0, 2, 2).into_dimension();
let strides = (1, ::std::isize::MAX as usize, 1).into_dimension();
let strides = (1, isize::MAX as usize, 1).into_dimension();
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap_err();
let dim = (0, 2, 2).into_dimension();
let strides = (1, ::std::isize::MAX as usize / 4, 1).into_dimension();
let strides = (1, isize::MAX as usize / 4, 1).into_dimension();
max_abs_offset_check_overflow::<i32, _>(&dim, &strides).unwrap_err();
}

Expand Down
30 changes: 15 additions & 15 deletions src/impl_owned_array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::num::NonZeroUsize;
use core::ptr::NonNull;
use std::mem;
use std::mem::MaybeUninit;
Expand Down Expand Up @@ -36,22 +37,21 @@ impl<A> Array<A, Ix0>
/// ```
pub fn into_scalar(self) -> A
{
let size = mem::size_of::<A>();
if size == 0 {
let size = match NonZeroUsize::new(mem::size_of::<A>()) {
Some(size) => size,
// Any index in the `Vec` is fine since all elements are identical.
self.data.into_vec().remove(0)
} else {
// Find the index in the `Vec` corresponding to `self.ptr`.
// (This is necessary because the element in the array might not be
// the first element in the `Vec`, such as if the array was created
// by `array![1, 2, 3, 4].slice_move(s![2])`.)
let first = self.parts.ptr.as_ptr() as usize;
let base = self.data.as_ptr() as usize;
let index = (first - base) / size;
debug_assert_eq!((first - base) % size, 0);
// Remove the element at the index and return it.
self.data.into_vec().remove(index)
}
None => return self.data.into_vec().remove(0),
};
// Find the index in the `Vec` corresponding to `self.ptr`.
// (This is necessary because the element in the array might not be
// the first element in the `Vec`, such as if the array was created
// by `array![1, 2, 3, 4].slice_move(s![2])`.)
let first = self.parts.ptr.as_ptr() as usize;
let base = self.data.as_ptr() as usize;
let index = (first - base) / size;
debug_assert_eq!((first - base) % size.get(), 0);
// Remove the element at the index and return it.
self.data.into_vec().remove(index)
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ where D: Dimension
#[inline]
fn next(&mut self) -> Option<Self::Item>
{
let index = match self.index {
None => return None,
Some(ref ix) => ix.clone(),
};
let index = self.index.as_ref()?.clone();
self.index = self.dim.next_for(index.clone());
Some(index.into_pattern())
}
Expand Down
15 changes: 3 additions & 12 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ impl<A, D: Dimension> Iterator for Baseiter<A, D>
#[inline]
fn next(&mut self) -> Option<Self::Item>
{
let index = match self.index {
None => return None,
Some(ref ix) => ix.clone(),
};
let index = self.index.as_ref()?.clone();
let offset = D::stride_offset(&index, &self.strides);
self.index = self.dim.next_for(index);
unsafe { Some(self.ptr.offset(offset)) }
Expand Down Expand Up @@ -515,10 +512,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIter<'a, A, D>
#[inline]
fn next(&mut self) -> Option<Self::Item>
{
let index = match self.0.inner.index {
None => return None,
Some(ref ix) => ix.clone(),
};
let index = self.0.inner.index.as_ref()?.clone();
match self.0.next() {
None => None,
Some(elem) => Some((index.into_pattern(), elem)),
Expand Down Expand Up @@ -698,10 +692,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIterMut<'a, A, D>
#[inline]
fn next(&mut self) -> Option<Self::Item>
{
let index = match self.0.inner.index {
None => return None,
Some(ref ix) => ix.clone(),
};
let index = self.0.inner.index.as_ref()?.clone();
match self.0.next() {
None => None,
Some(elem) => Some((index.into_pattern(), elem)),
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
clippy::deref_addrof,
clippy::manual_map, // is not an error
clippy::while_let_on_iterator, // is not an error
clippy::from_iter_instead_of_collect, // using from_iter is good style
clippy::incompatible_msrv, // false positive PointerExt::offset
)]
#![doc(test(attr(deny(warnings))))]
Expand Down
2 changes: 0 additions & 2 deletions src/tri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ where
#[cfg(test)]
mod tests
{
use core::isize;

use crate::{array, dimension, Array0, Array1, Array2, Array3, ShapeBuilder};
use alloc::vec;

Expand Down
7 changes: 3 additions & 4 deletions tests/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use approx::assert_abs_diff_eq;
use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis};
use std::f64;

#[test]
fn test_mean_with_nan_values()
Expand Down Expand Up @@ -176,7 +175,7 @@ fn var_too_large_ddof()
fn var_nan_ddof()
{
let a = Array2::<f64>::zeros((2, 3));
let v = a.var(::std::f64::NAN);
let v = a.var(f64::NAN);
assert!(v.is_nan());
}

Expand Down Expand Up @@ -219,7 +218,7 @@ fn std_too_large_ddof()
fn std_nan_ddof()
{
let a = Array2::<f64>::zeros((2, 3));
let v = a.std(::std::f64::NAN);
let v = a.std(f64::NAN);
assert!(v.is_nan());
}

Expand Down Expand Up @@ -375,7 +374,7 @@ fn var_axis_too_large_ddof()
fn var_axis_nan_ddof()
{
let a = Array2::<f64>::zeros((2, 3));
let v = a.var_axis(Axis(1), ::std::f64::NAN);
let v = a.var_axis(Axis(1), f64::NAN);
assert_eq!(v.shape(), &[2]);
v.mapv(|x| assert!(x.is_nan()));
}
Expand Down
Loading