Skip to content

Commit a2b8188

Browse files
committed
Fix clippy warnings rust-ndarray#642
1 parent 6551df0 commit a2b8188

16 files changed

+99
-83
lines changed

src/arrayformat.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,9 @@ enum PrintableCell {
5151
// where indexes are being omitted.
5252
fn to_be_printed(length: usize, limit: usize) -> Vec<PrintableCell> {
5353
if length <= 2 * limit {
54-
(0..length)
55-
.map(PrintableCell::ElementIndex)
56-
.collect()
54+
(0..length).map(PrintableCell::ElementIndex).collect()
5755
} else {
58-
let mut v: Vec<PrintableCell> =
59-
(0..limit).map(PrintableCell::ElementIndex).collect();
56+
let mut v: Vec<PrintableCell> = (0..limit).map(PrintableCell::ElementIndex).collect();
6057
v.push(PrintableCell::Ellipses);
6158
v.extend((length - limit..length).map(PrintableCell::ElementIndex));
6259
v

src/dimension/dimension_trait.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ pub trait Dimension:
360360
}
361361

362362
// Dimension impls
363-
363+
#[allow(clippy::range_plus_one)]
364364
macro_rules! impl_insert_axis_array(
365365
($n:expr) => (
366366
fn insert_axis(&self, axis: Axis) -> Self::Larger {
367367
debug_assert!(axis.index() <= $n);
368368
let mut out = [1; $n + 1];
369369
out[0..axis.index()].copy_from_slice(&self.slice()[0..axis.index()]);
370-
out[axis.index()+1..$n+1].copy_from_slice(&self.slice()[axis.index()..$n]);
370+
out[axis.index()+1..=$n].copy_from_slice(&self.slice()[axis.index()..$n]);
371371
Dim(out)
372372
}
373373
);
@@ -659,6 +659,7 @@ impl Dimension for Dim<[Ix; 2]> {
659659
}
660660

661661
/// Return stride offset for this dimension and index.
662+
#[allow(clippy::many_single_char_names)]
662663
#[inline]
663664
fn stride_offset_checked(&self, strides: &Self, index: &Self) -> Option<isize> {
664665
let m = get!(self, 0);
@@ -743,6 +744,7 @@ impl Dimension for Dim<[Ix; 3]> {
743744
}
744745

745746
/// Self is an index, return the stride offset
747+
#[allow(clippy::many_single_char_names)]
746748
#[inline]
747749
fn stride_offset(index: &Self, strides: &Self) -> isize {
748750
let i = get!(index, 0);
@@ -755,6 +757,7 @@ impl Dimension for Dim<[Ix; 3]> {
755757
}
756758

757759
/// Return stride offset for this dimension and index.
760+
#[allow(clippy::many_single_char_names)]
758761
#[inline]
759762
fn stride_offset_checked(&self, strides: &Self, index: &Self) -> Option<isize> {
760763
let m = get!(self, 0);

src/dimension/dynindeximpl.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ impl<T: Copy + Zero> IxDynRepr<T> {
4848
pub fn copy_from(x: &[T]) -> Self {
4949
if x.len() <= CAP {
5050
let mut arr = [T::zero(); CAP];
51-
for i in 0..x.len() {
52-
arr[i] = x[i];
53-
}
51+
arr[..x.len()].clone_from_slice(&x[..]);
52+
//for i in 0..x.len() {
53+
// arr[i] = x[i];
54+
//}
5455
IxDynRepr::Inline(x.len() as _, arr)
5556
} else {
5657
Self::from(x)
@@ -121,7 +122,7 @@ impl IxDynImpl {
121122
IxDynImpl(if len < CAP {
122123
let mut out = [1; CAP];
123124
out[0..i].copy_from_slice(&self[0..i]);
124-
out[i + 1..len + 1].copy_from_slice(&self[i..len]);
125+
out[i + 1..=len].copy_from_slice(&self[i..len]);
125126
IxDynRepr::Inline((len + 1) as u32, out)
126127
} else {
127128
let mut out = Vec::with_capacity(len + 1);
@@ -206,7 +207,8 @@ impl<'a> IntoIterator for &'a IxDynImpl {
206207
type IntoIter = <&'a [Ix] as IntoIterator>::IntoIter;
207208
#[inline]
208209
fn into_iter(self) -> Self::IntoIter {
209-
self[..].into_iter()
210+
//self[..].into_iter()
211+
self[..].iter()
210212
}
211213
}
212214

src/dimension/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ pub fn do_slice(dim: &mut usize, stride: &mut usize, slice: Slice) -> isize {
420420
/// nonnegative.
421421
///
422422
/// See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
423+
#[allow(clippy::many_single_char_names)]
423424
fn extended_gcd(a: isize, b: isize) -> (isize, (isize, isize)) {
424425
if a == 0 {
425426
(b.abs(), (0, b.signum()))
@@ -456,6 +457,7 @@ fn extended_gcd(a: isize, b: isize) -> (isize, (isize, isize)) {
456457
///
457458
/// See https://en.wikipedia.org/wiki/Diophantine_equation#One_equation
458459
/// and https://math.stackexchange.com/questions/1656120#1656138
460+
#[allow(clippy::many_single_char_names)]
459461
fn solve_linear_diophantine_eq(a: isize, b: isize, c: isize) -> Option<(isize, isize)> {
460462
debug_assert_ne!(a, 0);
461463
debug_assert_ne!(b, 0);
@@ -535,14 +537,21 @@ fn arith_seq_intersect(
535537
/// If the slice is empty, then returns `None`, otherwise returns `Some((min, max))`.
536538
fn slice_min_max(axis_len: usize, slice: Slice) -> Option<(usize, usize)> {
537539
let (start, end, step) = to_abs_slice(axis_len, slice);
540+
//if start == end {
541+
// None
542+
//} else {
543+
// if step > 0 {
544+
// Some((start, end - 1 - (end - start - 1) % (step as usize)))
545+
// } else {
546+
// Some((start + (end - start - 1) % (-step as usize), end - 1))
547+
// }
548+
//}
538549
if start == end {
539550
None
551+
} else if step > 0 {
552+
Some((start, end - 1 - (end - start - 1) % (step as usize)))
540553
} else {
541-
if step > 0 {
542-
Some((start, end - 1 - (end - start - 1) % (step as usize)))
543-
} else {
544-
Some((start + (end - start - 1) % (-step as usize), end - 1))
545-
}
554+
Some((start + (end - start - 1) % (-step as usize), end - 1))
546555
}
547556
}
548557

src/geomspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
Some(Geomspace {
9797
sign: a.signum(),
9898
start: log_a,
99-
step: step,
99+
step,
100100
index: 0,
101101
len: n,
102102
})

src/impl_1d.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ where
1515
S: RawData<Elem = A>,
1616
{
1717
/// Return an vector with the elements of the one-dimensional array.
18+
#[allow(clippy::map_clone)]
1819
pub fn to_vec(&self) -> Vec<A>
1920
where
2021
A: Clone,

src/impl_clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl<S: RawDataClone, D: Clone> Clone for ArrayBase<S, D> {
1313
unsafe {
1414
let (data, ptr) = self.data.clone_with_ptr(self.ptr);
1515
ArrayBase {
16-
data: data,
17-
ptr: ptr,
16+
data,
17+
ptr,
1818
dim: self.dim.clone(),
1919
strides: self.strides.clone(),
2020
}

src/impl_constructors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ where
6262
/// let array = Array::from_iter((0..5).map(|x| x * x));
6363
/// assert!(array == arr1(&[0, 1, 4, 9, 16]))
6464
/// ```
65+
#[allow(clippy::should_implement_trait)]
6566
pub fn from_iter<I>(iterable: I) -> Self
6667
where
6768
I: IntoIterator<Item = A>,
@@ -212,7 +213,7 @@ macro_rules! size_of_shape_checked_unwrap {
212213
($dim:expr) => {
213214
match dimension::size_of_shape_checked($dim) {
214215
Ok(sz) => sz,
215-
Err(_) => panic!(
216+
Err(_e) => panic!(
216217
"ndarray: Shape too large, product of non-zero axis lengths \
217218
overflows isize in shape {:?}",
218219
$dim
@@ -315,6 +316,7 @@ where
315316
/// visited in arbitrary order.
316317
///
317318
/// **Panics** if the product of non-zero axis lengths overflows `isize`.
319+
#[allow(clippy::identity_conversion)]
318320
pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
319321
where
320322
Sh: ShapeBuilder<Dim = D>,
@@ -422,8 +424,8 @@ where
422424
ArrayBase {
423425
ptr: v.as_mut_ptr(),
424426
data: DataOwned::new(v),
425-
strides: strides,
426-
dim: dim,
427+
strides,
428+
dim,
427429
}
428430
}
429431

src/impl_methods.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ where
225225
{
226226
let data = self.data.into_shared();
227227
ArrayBase {
228-
data: data,
228+
data,
229229
ptr: self.ptr,
230230
dim: self.dim,
231231
strides: self.strides,
@@ -373,9 +373,9 @@ where
373373
let mut new_dim = Do::zeros(out_ndim);
374374
let mut new_strides = Do::zeros(out_ndim);
375375
izip!(self.dim.slice(), self.strides.slice(), indices)
376-
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
377-
&SliceOrIndex::Slice { .. } => Some((d, s)),
378-
&SliceOrIndex::Index(_) => None,
376+
.filter_map(|(d, s, slice_or_index)| match *slice_or_index {
377+
SliceOrIndex::Slice { .. } => Some((d, s)),
378+
SliceOrIndex::Index(_) => None,
379379
})
380380
.zip(izip!(new_dim.slice_mut(), new_strides.slice_mut()))
381381
.for_each(|((d, s), (new_d, new_s))| {
@@ -411,11 +411,11 @@ where
411411
indices
412412
.iter()
413413
.enumerate()
414-
.for_each(|(axis, slice_or_index)| match slice_or_index {
415-
&SliceOrIndex::Slice { start, end, step } => {
414+
.for_each(|(axis, slice_or_index)| match *slice_or_index {
415+
SliceOrIndex::Slice { start, end, step } => {
416416
self.slice_axis_inplace(Axis(axis), Slice { start, end, step })
417417
}
418-
&SliceOrIndex::Index(index) => {
418+
SliceOrIndex::Index(index) => {
419419
let i_usize = abs_index(self.len_of(Axis(axis)), index);
420420
self.collapse_axis(Axis(axis), i_usize)
421421
}
@@ -1195,10 +1195,13 @@ where
11951195
/// contiguous in memory, it has custom strides, etc.
11961196
pub fn is_standard_layout(&self) -> bool {
11971197
fn is_standard_layout<D: Dimension>(dim: &D, strides: &D) -> bool {
1198-
match D::NDIM {
1199-
Some(1) => return strides[0] == 1 || dim[0] <= 1,
1200-
_ => {}
1201-
}
1198+
if let Some(1) = D::NDIM {
1199+
return strides[0] == 1 || dim[0] <= 1;
1200+
};
1201+
//match D::NDIM {
1202+
// Some(1) => return strides[0] == 1 || dim[0] <= 1,
1203+
// _ => {}
1204+
//}
12021205
if dim.slice().iter().any(|&d| d == 0) {
12031206
return true;
12041207
}
@@ -1426,6 +1429,7 @@ where
14261429
/// [3., 4.]])
14271430
/// );
14281431
/// ```
1432+
#[allow(clippy::map_clone)]
14291433
pub fn reshape<E>(&self, shape: E) -> ArrayBase<S, E::Dim>
14301434
where
14311435
S: DataShared + DataOwned,
@@ -1495,8 +1499,8 @@ where
14951499
return Ok(ArrayBase {
14961500
data: self.data,
14971501
ptr: self.ptr,
1498-
dim: dim,
1499-
strides: strides,
1502+
dim,
1503+
strides,
15001504
});
15011505
}
15021506
}

src/impl_raw_views.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ where
1515
RawArrayView {
1616
data: RawViewRepr::new(),
1717
ptr: ptr as *mut A,
18-
dim: dim,
19-
strides: strides,
18+
dim,
19+
strides,
2020
}
2121
}
2222

@@ -118,9 +118,9 @@ where
118118
pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self {
119119
RawArrayViewMut {
120120
data: RawViewRepr::new(),
121-
ptr: ptr,
122-
dim: dim,
123-
strides: strides,
121+
ptr,
122+
dim,
123+
strides,
124124
}
125125
}
126126

0 commit comments

Comments
 (0)