Skip to content

Fix clippy warnings. #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/arrayformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
write!(f, "]")?;
}
write!(f, ",")?;
write!(f, "\n")?;
writeln!(f)?;
for _ in 0..ndim - n {
write!(f, " ")?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/data_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
Self::ensure_unique(&mut self_);
let data = OwnedRepr(Arc::try_unwrap(self_.data.0).ok().unwrap());
ArrayBase {
data: data,
data,
ptr: self_.ptr,
dim: self_.dim,
strides: self_.strides,
Expand Down
7 changes: 4 additions & 3 deletions src/dimension/axes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::{Dimension, Axis, Ix, Ixs};

/// Create a new Axes iterator
Expand All @@ -7,7 +6,7 @@ pub fn axes_of<'a, D>(d: &'a D, strides: &'a D) -> Axes<'a, D>
{
Axes {
dim: d,
strides: strides,
strides,
start: 0,
end: d.ndim(),
}
Expand Down Expand Up @@ -56,6 +55,9 @@ impl AxisDescription {
/// Return stride
#[inline(always)]
pub fn stride(self) -> Ixs { self.2 }
/// Returns True if axis is of length 0
#[inline(always)]
pub fn is_empty(self) -> bool { self.len() == 0 }
}

copy_and_clone!(['a, D] Axes<'a, D>);
Expand Down Expand Up @@ -128,4 +130,3 @@ impl IncOps for usize {
*self
}
}

3 changes: 1 addition & 2 deletions src/dimension/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Axis(pub usize);
impl Axis {
/// Return the index of the axis.
#[inline(always)]
pub fn index(&self) -> usize { self.0 }
pub fn index(self) -> usize { self.0 }
}

copy_and_clone!{Axis}
Expand All @@ -39,4 +39,3 @@ macro_rules! derive_cmp {

derive_cmp!{PartialEq for Axis, eq -> bool}
derive_cmp!{PartialOrd for Axis, partial_cmp -> Option<Ordering>}

3 changes: 1 addition & 2 deletions src/dimension/dim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<I> Dim<I> {
/// Private constructor and accessors for Dim
pub(crate) fn new(index: I) -> Dim<I> {
Dim {
index: index,
index,
}
}
#[inline(always)]
Expand Down Expand Up @@ -181,4 +181,3 @@ impl_op!(Sub, sub, SubAssign, sub_assign, sub);
impl_single_op!(Sub, sub, SubAssign, sub_assign, sub);
impl_op!(Mul, mul, MulAssign, mul_assign, mul);
impl_scalar_op!(Mul, mul, MulAssign, mul_assign, mul);

2 changes: 1 addition & 1 deletion src/dimension/dimension_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ macro_rules! impl_insert_axis_array(
debug_assert!(axis.index() <= $n);
let mut out = [1; $n + 1];
out[0..axis.index()].copy_from_slice(&self.slice()[0..axis.index()]);
out[axis.index()+1..$n+1].copy_from_slice(&self.slice()[axis.index()..$n]);
out[axis.index()+1..=$n].copy_from_slice(&self.slice()[axis.index()..$n]);
Dim(out)
}
);
Expand Down
12 changes: 5 additions & 7 deletions src/dimension/dynindeximpl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use std::ops::{
Index,
IndexMut,
Expand Down Expand Up @@ -59,9 +58,8 @@ impl<T: Copy + Zero> IxDynRepr<T> {
pub fn copy_from(x: &[T]) -> Self {
if x.len() <= CAP {
let mut arr = [T::zero(); CAP];
for i in 0..x.len() {
arr[i] = x[i];
}
// copy x elements to arr
arr[..x.len()].clone_from_slice(&x[..]);
IxDynRepr::Inline(x.len() as _, arr)
} else {
Self::from(x)
Expand Down Expand Up @@ -134,7 +132,7 @@ impl IxDynImpl {
if len < CAP {
let mut out = [1; CAP];
out[0..i].copy_from_slice(&self[0..i]);
out[i+1..len+1].copy_from_slice(&self[i..len]);
out[i+1..=len].copy_from_slice(&self[i..len]);
IxDynRepr::Inline((len + 1) as u32, out)
} else {
let mut out = Vec::with_capacity(len + 1);
Expand Down Expand Up @@ -218,7 +216,7 @@ impl<'a> IntoIterator for &'a IxDynImpl {
type IntoIter = <&'a [Ix] as IntoIterator>::IntoIter;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self[..].into_iter()
self[..].iter()
}
}

Expand All @@ -233,7 +231,7 @@ impl IxDyn {
/// Create a new dimension value with `n` axes, all zeros
#[inline]
pub fn zeros(n: usize) -> IxDyn {
const ZEROS: &'static [usize] = &[0; 4];
const ZEROS: &[usize] = &[0; 4];
if n <= ZEROS.len() {
Dim(&ZEROS[..n])
} else {
Expand Down
11 changes: 4 additions & 7 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,11 @@ pub trait DimensionExt {
/// Get the dimension at `axis`.
///
/// *Panics* if `axis` is out of bounds.
#[inline]
fn axis(&self, axis: Axis) -> Ix;

/// Set the dimension at `axis`.
///
/// *Panics* if `axis` is out of bounds.
#[inline]
fn set_axis(&mut self, axis: Axis, value: Ix);
}

Expand Down Expand Up @@ -520,12 +518,11 @@ fn slice_min_max(axis_len: usize, slice: Slice) -> Option<(usize, usize)> {
let (start, end, step) = to_abs_slice(axis_len, slice);
if start == end {
None
}
else if step > 0 {
Some((start, end - 1 - (end - start - 1) % (step as usize)))
} else {
if step > 0 {
Some((start, end - 1 - (end - start - 1) % (step as usize)))
} else {
Some((start + (end - start - 1) % (-step as usize), end - 1))
}
Some((start + (end - start - 1) % (-step as usize), end - 1))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/impl_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ impl<A, S> ArrayBase<S, Ix1>
}
}
}

4 changes: 2 additions & 2 deletions src/impl_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl<S: RawDataClone, D: Clone> Clone for ArrayBase<S, D> {
unsafe {
let (data, ptr) = self.data.clone_with_ptr(self.ptr);
ArrayBase {
data: data,
ptr: ptr,
data,
ptr,
dim: self.dim.clone(),
strides: self.strides.clone(),
}
Expand Down
6 changes: 3 additions & 3 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<S, A, D> ArrayBase<S, D>
unsafe { Self::from_shape_vec_unchecked(shape, v) }
} else {
let dim = shape.dim.clone();
let v = to_vec_mapped(indexes::indices_iter_f(dim).into_iter(), f);
let v = to_vec_mapped(indexes::indices_iter_f(dim), f);
unsafe { Self::from_shape_vec_unchecked(shape, v) }
}
}
Expand Down Expand Up @@ -342,8 +342,8 @@ impl<S, A, D> ArrayBase<S, D>
ArrayBase {
ptr: v.as_mut_ptr(),
data: DataOwned::new(v),
strides: strides,
dim: dim
strides,
dim
}
}

Expand Down
30 changes: 14 additions & 16 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where
{
let data = self.data.into_shared();
ArrayBase {
data: data,
data,
ptr: self.ptr,
dim: self.dim,
strides: self.strides,
Expand Down Expand Up @@ -353,9 +353,9 @@ where
let mut new_dim = Do::zeros(out_ndim);
let mut new_strides = Do::zeros(out_ndim);
izip!(self.dim.slice(), self.strides.slice(), indices)
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
&SliceOrIndex::Slice {..} => Some((d, s)),
&SliceOrIndex::Index(_) => None,
.filter_map(|(d, s, slice_or_index)| match *slice_or_index {
SliceOrIndex::Slice {..} => Some((d, s)),
SliceOrIndex::Index(_) => None,
})
.zip(izip!(new_dim.slice_mut(), new_strides.slice_mut()))
.for_each(|((d, s), (new_d, new_s))| {
Expand Down Expand Up @@ -391,11 +391,11 @@ where
indices
.iter()
.enumerate()
.for_each(|(axis, slice_or_index)| match slice_or_index {
&SliceOrIndex::Slice { start, end, step } => {
.for_each(|(axis, slice_or_index)| match *slice_or_index {
SliceOrIndex::Slice { start, end, step } => {
self.slice_axis_inplace(Axis(axis), Slice { start, end, step })
}
&SliceOrIndex::Index(index) => {
SliceOrIndex::Index(index) => {
let i_usize = abs_index(self.len_of(Axis(axis)), index);
self.collapse_axis(Axis(axis), i_usize)
}
Expand Down Expand Up @@ -1101,8 +1101,7 @@ where
/* empty shape has len 1 */
let len = self.dim.slice().iter().cloned().min().unwrap_or(1);
let stride = self.strides()
.iter()
.fold(0, |sum, s| sum + s);
.iter().sum();
(len, stride)
}

Expand Down Expand Up @@ -1166,9 +1165,8 @@ where
/// contiguous in memory, it has custom strides, etc.
pub fn is_standard_layout(&self) -> bool {
fn is_standard_layout<D: Dimension>(dim: &D, strides: &D) -> bool {
match D::NDIM {
Some(1) => return strides[0] == 1 || dim[0] <= 1,
_ => { }
if let Some(1) = D::NDIM {
return strides[0] == 1 || dim[0] <= 1;
}
if dim.slice().iter().any(|&d| d == 0) {
return true;
Expand Down Expand Up @@ -1379,7 +1377,7 @@ where
dim: shape,
}
} else {
let v = self.iter().map(|x| x.clone()).collect::<Vec<A>>();
let v = self.iter().cloned().collect::<Vec<A>>();
unsafe {
ArrayBase::from_shape_vec_unchecked(shape, v)
}
Expand Down Expand Up @@ -1425,8 +1423,8 @@ where
return Ok(ArrayBase {
data: self.data,
ptr: self.ptr,
dim: dim,
strides: strides,
dim,
strides,
});
}
}
Expand Down Expand Up @@ -1737,7 +1735,7 @@ where
Some(slc) => {
let ptr = slc.as_ptr() as *mut A;
let end = unsafe {
ptr.offset(slc.len() as isize)
ptr.add(slc.len())
};
self.ptr >= ptr && self.ptr <= end
}
Expand Down
8 changes: 4 additions & 4 deletions src/impl_raw_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
RawArrayView {
data: RawViewRepr::new(),
ptr: ptr as *mut A,
dim: dim,
dim,
strides: strides,
}
}
Expand Down Expand Up @@ -118,9 +118,9 @@ where
pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self {
RawArrayViewMut {
data: RawViewRepr::new(),
ptr: ptr,
dim: dim,
strides: strides,
ptr,
dim,
strides,
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/impl_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ impl<'a, A, D> ArrayView<'a, A, D>
ArrayView {
data: ViewRepr::new(),
ptr: ptr as *mut A,
dim: dim,
strides: strides,
dim,
strides,
}
}

Expand Down Expand Up @@ -533,9 +533,9 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
}
ArrayViewMut {
data: ViewRepr::new(),
ptr: ptr,
dim: dim,
strides: strides,
ptr,
dim,
strides,
}
}

Expand Down Expand Up @@ -586,4 +586,3 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
AxisIterMut::new(self, Axis(0))
}
}

10 changes: 5 additions & 5 deletions src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn indices<E>(shape: E) -> Indices<E::Dim>
let dim = shape.into_dimension();
Indices {
start: E::Dim::zeros(dim.ndim()),
dim: dim,
dim,
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ impl<D> IntoIterator for Indices<D>
let sz = self.dim.size();
let index = if sz != 0 { Some(self.start) } else { None };
IndicesIter {
index: index,
index,
dim: self.dim,
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<D: Dimension + Copy> NdProducer for Indices<D> {

#[doc(hidden)]
fn raw_dim(&self) -> Self::Dim {
self.dim.clone()
self.dim
}

#[doc(hidden)]
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<D: Dimension + Copy> NdProducer for Indices<D> {
unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr {
let mut index = *i;
index += &self.start;
IndexPtr { index: index }
IndexPtr { index }
}

#[doc(hidden)]
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn indices_iter_f<E>(shape: E) -> IndicesIterF<E::Dim>
IndicesIterF {
has_remaining: dim.size_checked() != Some(0),
index: zero,
dim: dim,
dim,
}
}

Expand Down
Loading