Run cargo clippy --fix (#250)

* Run `cargo clippy --fix`
* Run `cargo clippy --all-features --fix`
* Fix other clippy warnings
* cargo fmt

Co-authored-by: Luis Moreno <morenol@users.noreply.github.com>
This commit is contained in:
morenol
2023-01-27 06:41:18 -04:00
committed by GitHub
parent 83dcf9a8ac
commit c7353d0b57
47 changed files with 146 additions and 222 deletions
+12 -29
View File
@@ -548,7 +548,7 @@ pub trait ArrayView2<T: Debug + Display + Copy + Sized>: Array<T, (usize, usize)
let (nrows, ncols) = self.shape();
for r in 0..nrows {
let row: Vec<T> = (0..ncols).map(|c| *self.get((r, c))).collect();
writeln!(f, "{:?}", row)?
writeln!(f, "{row:?}")?
}
Ok(())
}
@@ -918,8 +918,7 @@ pub trait Array1<T: Debug + Display + Copy + Sized>: MutArrayView1<T> + Sized +
let len = self.shape();
assert!(
index.iter().all(|&i| i < len),
"All indices in `take` should be < {}",
len
"All indices in `take` should be < {len}"
);
Self::from_iterator(index.iter().map(move |&i| *self.get(i)), index.len())
}
@@ -990,10 +989,7 @@ pub trait Array1<T: Debug + Display + Copy + Sized>: MutArrayView1<T> + Sized +
};
assert!(
d1 == len,
"Can not multiply {}x{} matrix by {} vector",
nrows,
ncols,
len
"Can not multiply {nrows}x{ncols} matrix by {len} vector"
);
let mut result = Self::zeros(d2);
for i in 0..d2 {
@@ -1111,11 +1107,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
assert!(
nrows * ncols == onrows * oncols,
"Can't reshape {}x{} array into a {}x{} array",
onrows,
oncols,
nrows,
ncols
"Can't reshape {onrows}x{oncols} array into a {nrows}x{ncols} array"
);
Self::from_iterator(self.iterator(0).cloned(), nrows, ncols, axis)
@@ -1129,11 +1121,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
let (o_nrows, o_ncols) = other.shape();
assert!(
ncols == o_nrows,
"Can't multiply {}x{} and {}x{} matrices",
nrows,
ncols,
o_nrows,
o_ncols
"Can't multiply {nrows}x{ncols} and {o_nrows}x{o_ncols} matrices"
);
let inner_d = ncols;
let mut result = Self::zeros(nrows, o_ncols);
@@ -1166,7 +1154,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
_ => (nrows, ncols, o_nrows, o_ncols),
};
if d1 != d4 {
panic!("Can not multiply {}x{} by {}x{} matrices", d2, d1, d4, d3);
panic!("Can not multiply {d2}x{d1} by {d4}x{d3} matrices");
}
let mut result = Self::zeros(d2, d3);
for r in 0..d2 {
@@ -1198,10 +1186,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
};
assert!(
d2 == len,
"Can not multiply {}x{} matrix by {} vector",
nrows,
ncols,
len
"Can not multiply {nrows}x{ncols} matrix by {len} vector"
);
let mut result = Self::zeros(d1, 1);
for i in 0..d1 {
@@ -1432,8 +1417,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
0 => {
assert!(
index.iter().all(|&i| i < nrows),
"All indices in `take` should be < {}",
nrows
"All indices in `take` should be < {nrows}"
);
Self::from_iterator(
index
@@ -1448,8 +1432,7 @@ pub trait Array2<T: Debug + Display + Copy + Sized>: MutArrayView2<T> + Sized +
_ => {
assert!(
index.iter().all(|&i| i < ncols),
"All indices in `take` should be < {}",
ncols
"All indices in `take` should be < {ncols}"
);
Self::from_iterator(
(0..nrows)
@@ -1736,7 +1719,7 @@ mod tests {
let r = Vec::<f32>::rand(4);
assert!(r.iterator(0).all(|&e| e <= 1f32));
assert!(r.iterator(0).all(|&e| e >= 0f32));
assert!(r.iterator(0).map(|v| *v).sum::<f32>() > 0f32);
assert!(r.iterator(0).copied().sum::<f32>() > 0f32);
}
#[test]
@@ -1954,7 +1937,7 @@ mod tests {
DenseMatrix::from_2d_array(&[&[1, 3], &[2, 4]])
);
assert_eq!(
DenseMatrix::concatenate_2d(&[&a.clone(), &b.clone()], 0),
DenseMatrix::concatenate_2d(&[&a, &b], 0),
DenseMatrix::from_2d_array(&[&[1, 2], &[3, 4], &[5, 6], &[7, 8]])
);
assert_eq!(
@@ -2025,7 +2008,7 @@ mod tests {
let r = DenseMatrix::<f32>::rand(2, 2);
assert!(r.iterator(0).all(|&e| e <= 1f32));
assert!(r.iterator(0).all(|&e| e >= 0f32));
assert!(r.iterator(0).map(|v| *v).sum::<f32>() > 0f32);
assert!(r.iterator(0).copied().sum::<f32>() > 0f32);
}
#[test]
+9 -9
View File
@@ -581,9 +581,9 @@ mod tests {
vec![4, 5, 6],
DenseMatrix::from_slice(&(*x.slice(1..2, 0..3))).values
);
let second_row: Vec<i32> = x.slice(1..2, 0..3).iterator(0).map(|x| *x).collect();
let second_row: Vec<i32> = x.slice(1..2, 0..3).iterator(0).copied().collect();
assert_eq!(vec![4, 5, 6], second_row);
let second_col: Vec<i32> = x.slice(0..3, 1..2).iterator(0).map(|x| *x).collect();
let second_col: Vec<i32> = x.slice(0..3, 1..2).iterator(0).copied().collect();
assert_eq!(vec![2, 5, 8], second_col);
}
@@ -640,12 +640,12 @@ mod tests {
let x = DenseMatrix::<&str>::from_2d_array(&[&["1", "2", "3"], &["4", "5", "6"]]);
assert_eq!(vec!["1", "4", "2", "5", "3", "6"], x.values);
assert!(x.column_major == true);
assert!(x.column_major);
// transpose
let x = x.transpose();
assert_eq!(vec!["1", "4", "2", "5", "3", "6"], x.values);
assert!(x.column_major == false); // should change column_major
assert!(!x.column_major); // should change column_major
}
#[test]
@@ -659,7 +659,7 @@ mod tests {
vec![1, 2, 3, 4, 5, 6],
m.values.iter().map(|e| **e).collect::<Vec<i32>>()
);
assert!(m.column_major == false);
assert!(!m.column_major);
}
#[test]
@@ -667,10 +667,10 @@ mod tests {
let a = DenseMatrix::from_2d_array(&[&[1, 2, 3], &[4, 5, 6]]);
let b = DenseMatrix::from_2d_array(&[&[1, 2], &[3, 4], &[5, 6]]);
println!("{}", a);
println!("{a}");
// take column 0 and 2
assert_eq!(vec![1, 3, 4, 6], a.take(&[0, 2], 1).values);
println!("{}", b);
println!("{b}");
// take rows 0 and 2
assert_eq!(vec![1, 2, 5, 6], b.take(&[0, 2], 0).values);
}
@@ -692,11 +692,11 @@ mod tests {
let a = a.reshape(2, 6, 0);
assert_eq!(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], a.values);
assert!(a.ncols == 6 && a.nrows == 2 && a.column_major == false);
assert!(a.ncols == 6 && a.nrows == 2 && !a.column_major);
let a = a.reshape(3, 4, 1);
assert_eq!(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], a.values);
assert!(a.ncols == 4 && a.nrows == 3 && a.column_major == true);
assert!(a.ncols == 4 && a.nrows == 3 && a.column_major);
}
#[test]
+3 -3
View File
@@ -160,8 +160,8 @@ mod tests {
fn dot_product<T: Number, V: Array1<T>>(v: &V) -> T {
let vv = V::zeros(10);
let v_s = vv.slice(0..3);
let dot = v_s.dot(v);
dot
v_s.dot(v)
}
fn vector_ops<T: Number + PartialOrd, V: Array1<T>>(_: &V) -> T {
@@ -216,7 +216,7 @@ mod tests {
#[test]
fn test_mut_iterator() {
let mut x = vec![1, 2, 3];
x.iterator_mut(0).for_each(|v| *v = *v * 2);
x.iterator_mut(0).for_each(|v| *v *= 2);
assert_eq!(vec![2, 4, 6], x);
}