Skip to content

Commit

Permalink
clippy and warnigs (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
kali authored Dec 18, 2022
1 parent 5a0440b commit 58d22b6
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 149 deletions.
4 changes: 2 additions & 2 deletions core/src/ops/array/gather_nd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl GatherNd {
) -> TractResult<TVec<D>> {
let mut shape: TVec<D> = indices_shape.into();
let n = shape.pop().unwrap().to_usize()?;
shape.extend(data_shape[n + self.batch_dims as usize..].iter().cloned());
shape.extend(data_shape[n + self.batch_dims..].iter().cloned());
Ok(shape)
}

Expand All @@ -26,7 +26,7 @@ impl GatherNd {
data: &Tensor,
indices: &ArrayViewD<i32>,
) {
let batch_dims = self.batch_dims as usize;
let batch_dims = self.batch_dims;
assert_eq!(output.shape()[..batch_dims], data.shape()[..batch_dims]);
assert_eq!(output.shape()[..batch_dims], indices.shape()[..batch_dims]);
let batch_size = data.shape().iter().take(batch_dims).product();
Expand Down
2 changes: 1 addition & 1 deletion core/src/ops/array/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Tile {
fn eval_t<T: Datum>(data: &TValue, multipliers: &[usize]) -> TractResult<TValue> {
let view = unsafe { data.to_array_view_unchecked::<T>() };
let output_shape: TVec<usize> =
view.shape().iter().zip(multipliers.iter()).map(|(&d, &m)| d * m as usize).collect();
view.shape().iter().zip(multipliers.iter()).map(|(&d, &m)| d * m).collect();
let output = ndarray::ArrayD::from_shape_fn(&*output_shape, |coords| {
let coords: TVec<usize> =
coords.slice().iter().zip(data.shape().iter()).map(|(&x, &d)| x % d).collect();
Expand Down
16 changes: 8 additions & 8 deletions core/src/ops/cnn/conv/depth_wise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,32 +211,32 @@ impl DepthWise {
if iter.size_hint() == (4, Some(4)) {
let (ix, v) = iter.next().unwrap();
let k0 = *kptr.add(ix);
let i0 = *iptr.offset(v as isize);
let i0 = *iptr.offset(v);
let (ix, v) = iter.next().unwrap();
let k1 = *kptr.add(ix);
let i1 = *iptr.offset(v as isize);
let i1 = *iptr.offset(v);
let (ix, v) = iter.next().unwrap();
let k2 = *kptr.add(ix);
let i2 = *iptr.offset(v as isize);
let i2 = *iptr.offset(v);
let (ix, v) = iter.next().unwrap();
let k3 = *kptr.add(ix);
let i3 = *iptr.offset(v as isize);
let i3 = *iptr.offset(v);
sum = sum + k0 * i0 + k1 * i1 + k2 * i2 + k3 * i3;
} else if iter.size_hint() == (3, Some(3)) {
let (ix, v) = iter.next().unwrap();
let k0 = *kptr.add(ix);
let i0 = *iptr.offset(v as isize);
let i0 = *iptr.offset(v);
let (ix, v) = iter.next().unwrap();
let k1 = *kptr.add(ix);
let i1 = *iptr.offset(v as isize);
let i1 = *iptr.offset(v);
let (ix, v) = iter.next().unwrap();
let k2 = *kptr.add(ix);
let i2 = *iptr.offset(v as isize);
let i2 = *iptr.offset(v);
sum = sum + k0 * i0 + k1 * i1 + k2 * i2;
} else {
for (ix, v) in iter {
let k = *kptr.add(ix);
let i = *iptr.offset(v as isize);
let i = *iptr.offset(v);
sum = sum + k * i;
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/ops/cnn/conv/im2col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl Patcher {
for ci in 0..geometry.ci_per_group {
let iptr = iptr.offset(ci as isize * c_stride);
for koffset in &geometry.pool.patch.standard_layout_data_field {
let iptr = iptr.offset(*koffset as isize);
let iptr = iptr.offset(*koffset);
for x in 0..*geometry.pool.patch.output_shape.get_unchecked(0) {
writer.write(*iptr.offset(x as isize * x_stride));
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl Patcher {
writer: &mut tract_linalg::frame::pack::KOutWriter<T>,
) {
for x in x_min..x_max {
writer.write(*iptr.offset(x as isize * x_stride_ptr));
writer.write(*iptr.offset(x * x_stride_ptr));
}
}

Expand All @@ -457,7 +457,7 @@ impl Patcher {
for ci in 0..geometry.ci_per_group {
let iptr = iptr.offset(ci as isize * c_stride_ptr);
for koffset in &geometry.pool.patch.standard_layout_data_field {
let iptr = iptr.offset(*koffset as isize);
let iptr = iptr.offset(*koffset);
for y in 0..*geometry.pool.patch.output_shape.get_unchecked(0) {
let iptr = iptr.offset(y as isize * y_stride_ptr);
for x in 0..*geometry.pool.patch.output_shape.get_unchecked(1) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/ops/cnn/conv/lazy_im2col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ impl<T: Datum + Copy> VirtualInput for LazyIm2col<T> {
self.write(
&mut writer,
k_range.start as isize..k_range.end as isize,
mn_range.start as isize..n_range.end as isize,
mn_range.start as isize..n_range.end,
)
} else {
let mut writer =
packer.write_with_k_outer(packed as *mut T, k_range.len(), n_range.len());
self.write(
&mut writer,
k_range.start as isize..k_range.end as isize,
mn_range.start as isize..n_range.end as isize,
mn_range.start as isize..n_range.end,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/ops/cnn/deconv/deconv_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl DeconvSum {
continue;
}
let temp = temp.offset(iy as isize * temp_i_stride);
let output = output.offset(oy * output_y_stride as isize);
let output = output.offset(oy * output_y_stride);
Self::main_loop_2d_inner(
output_c,
temp,
Expand Down
12 changes: 6 additions & 6 deletions core/src/ops/cnn/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ impl PatchSpec {
let mut invalid_output_zones = tvec!();
for ix in 0..self.input_shape.len() {
let min_max = data_field_min_max[ix];
let min = (-min_max.0 as usize).divceil(self.strides[ix]) as usize;
let max = (self.input_shape[ix].saturating_sub(min_max.1 as usize))
.divceil(self.strides[ix]) as usize;
let min = (-min_max.0 as usize).divceil(self.strides[ix]);
let max =
(self.input_shape[ix].saturating_sub(min_max.1 as usize)).divceil(self.strides[ix]);
if min != 0 {
let mut invalid = valid_output_zone.clone();
invalid.push(0..min);
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Patch {
input_patch_center
.iter_mut()
.zip(self.spec.strides.iter())
.for_each(|(a, &b)| *a *= b as usize);
.for_each(|(a, &b)| *a *= b);
PatchIterator::Safe(SafePatchIterator {
patch: self,
item: 0,
Expand Down Expand Up @@ -578,10 +578,10 @@ impl<'p> Scanner<'p> {
self.zone_id = 0;
self.input_center_offset = 0;
for i in 0..rank {
self.zone_id += *self.zone_coords.get_unchecked(i) as usize
self.zone_id += *self.zone_coords.get_unchecked(i)
* *self.patch.zone_strides.get_unchecked(i) as usize;
self.input_center_offset += *self.input_coords.get_unchecked(i) as isize
* *self.patch.input_storage_strides.get_unchecked(i) as isize;
* *self.patch.input_storage_strides.get_unchecked(i);
}
self.zone = self.patch.zones.get_unchecked(self.zone_id);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/ops/logic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::bool_comparison)]
#![allow(clippy::unnecessary_cast)]

use ndarray::*;

Expand Down
1 change: 1 addition & 0 deletions core/src/ops/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::clone_on_copy)]
#![allow(clippy::unnecessary_cast)]

use super::array::MultiBroadcastTo;
use crate::internal::*;
Expand Down
12 changes: 6 additions & 6 deletions core/src/ops/quant.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]

use crate::internal::*;
use crate::ops::element_wise::ElementWiseOp;
use crate::ops::math::QScale;
Expand All @@ -10,15 +12,13 @@ use super::binary::TypedBinOp;
use super::math::round_ties_to_even;

pub fn quantize_linear_f32_u8(x: f32, scale: f32, zero_point: i32) -> u8 {
(((x * scale).round() as i32) + zero_point as i32)
.max(u8::min_value() as i32)
.min(u8::max_value() as i32) as u8
(((x * scale).round() as i32) + zero_point)
.clamp(u8::min_value() as i32, u8::max_value() as i32) as u8
}

pub fn quantize_linear_f32_i8(x: f32, scale: f32, zero_point: i32) -> i8 {
(((x * scale).round() as i32) + zero_point as i32)
.max(i8::min_value() as i32)
.min(i8::max_value() as i32) as i8
(((x * scale).round() as i32) + zero_point)
.clamp(i8::min_value() as i32, i8::max_value() as i32) as i8
}

element_wise_oop!(quantize_linear_u8,
Expand Down
2 changes: 1 addition & 1 deletion core/src/optim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Optimizer {
Box::new(OpOptim("declutter", TypedOp::declutter_with_session, 0)),
Box::new(PushSliceUp),
Box::new(PushSplitDown),
Box::new(ChangeAxes::default()),
Box::<ChangeAxes>::default(),
])
}

Expand Down
2 changes: 1 addition & 1 deletion data/src/tensor/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a> TensorView<'a> {
self.strides()
.iter()
.zip(coords.as_ref())
.map(|(s, c)| *s as isize * *c as isize)
.map(|(s, c)| *s * *c as isize)
.sum::<isize>()
}

Expand Down
Loading

0 comments on commit 58d22b6

Please sign in to comment.