From 58d22b6386961fa3ad6ad97c2b0e4727662daec6 Mon Sep 17 00:00:00 2001 From: Mathieu Poumeyrol Date: Sun, 18 Dec 2022 11:01:21 +0100 Subject: [PATCH] clippy and warnigs (#918) --- core/src/ops/array/gather_nd.rs | 4 +- core/src/ops/array/tile.rs | 2 +- core/src/ops/cnn/conv/depth_wise.rs | 16 +++--- core/src/ops/cnn/conv/im2col.rs | 6 +-- core/src/ops/cnn/conv/lazy_im2col.rs | 4 +- core/src/ops/cnn/deconv/deconv_sum.rs | 2 +- core/src/ops/cnn/patches.rs | 12 ++--- core/src/ops/logic.rs | 1 + core/src/ops/math/mod.rs | 1 + core/src/ops/quant.rs | 12 ++--- core/src/optim/mod.rs | 2 +- data/src/tensor/view.rs | 2 +- ffi/src/lib.rs | 50 ++++++++++--------- harness/core-proptest-pulse/src/lib.rs | 4 +- harness/lstm-proptest-onnx-vs-tf/src/lib.rs | 2 +- harness/onnx-test-suite/build.rs | 2 +- harness/tf-inceptionv3/benches/inceptionv3.rs | 2 +- hir/src/ops/array/concat.rs | 4 +- hir/src/ops/array/crop.rs | 2 +- hir/src/ops/array/strided_slice.rs | 2 +- hir/src/ops/scan.rs | 4 +- kaldi/src/model.rs | 9 ++-- kaldi/src/ops.rs | 2 +- linalg/build.rs | 2 + linalg/src/frame/mmm/kernel.rs | 2 +- linalg/src/frame/mmm/mmm.rs | 2 +- linalg/src/frame/mmm/storage.rs | 49 ++++++++---------- linalg/src/generic/rounding.rs | 8 ++- linalg/src/generic/sigmoid.rs | 4 +- linalg/src/generic/tanh.rs | 4 +- nnef/src/ops/nnef/deser.rs | 8 +-- nnef/src/ser.rs | 2 +- onnx/src/ops/mod.rs | 4 +- onnx/src/ops/nn/reduce.rs | 4 +- onnx/src/ops/quant.rs | 8 +-- onnx/src/ops/resize.rs | 2 +- pulse-opl/src/concat.rs | 4 +- pulse-opl/src/pad.rs | 2 +- pulse/src/ops/array/concat.rs | 2 +- pulse/src/ops/array/slice.rs | 2 +- tensorflow/src/ops/array/pack.rs | 2 +- tensorflow/src/ops/array/pad.rs | 4 +- tensorflow/src/ops/nn/s2b/mod.rs | 2 +- tensorflow/src/ops/nn/s2b/raw.rs | 16 +++--- tensorflow/src/ops/vars.rs | 2 +- tensorflow/src/tfpb.rs | 2 +- 46 files changed, 135 insertions(+), 149 deletions(-) diff --git a/core/src/ops/array/gather_nd.rs b/core/src/ops/array/gather_nd.rs index f8f618d4e9..19423e6e6c 100644 --- a/core/src/ops/array/gather_nd.rs +++ b/core/src/ops/array/gather_nd.rs @@ -16,7 +16,7 @@ impl GatherNd { ) -> TractResult> { let mut shape: TVec = 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) } @@ -26,7 +26,7 @@ impl GatherNd { data: &Tensor, indices: &ArrayViewD, ) { - 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(); diff --git a/core/src/ops/array/tile.rs b/core/src/ops/array/tile.rs index b450e6b6b8..ff8acfa8ea 100644 --- a/core/src/ops/array/tile.rs +++ b/core/src/ops/array/tile.rs @@ -12,7 +12,7 @@ impl Tile { fn eval_t(data: &TValue, multipliers: &[usize]) -> TractResult { let view = unsafe { data.to_array_view_unchecked::() }; let output_shape: TVec = - 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 = coords.slice().iter().zip(data.shape().iter()).map(|(&x, &d)| x % d).collect(); diff --git a/core/src/ops/cnn/conv/depth_wise.rs b/core/src/ops/cnn/conv/depth_wise.rs index 30bbf43270..035579c0e2 100644 --- a/core/src/ops/cnn/conv/depth_wise.rs +++ b/core/src/ops/cnn/conv/depth_wise.rs @@ -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; } } diff --git a/core/src/ops/cnn/conv/im2col.rs b/core/src/ops/cnn/conv/im2col.rs index 11bb52a94a..1630610176 100644 --- a/core/src/ops/cnn/conv/im2col.rs +++ b/core/src/ops/cnn/conv/im2col.rs @@ -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)); } @@ -431,7 +431,7 @@ impl Patcher { writer: &mut tract_linalg::frame::pack::KOutWriter, ) { 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)); } } @@ -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) { diff --git a/core/src/ops/cnn/conv/lazy_im2col.rs b/core/src/ops/cnn/conv/lazy_im2col.rs index 22d5047896..0b709ec46e 100644 --- a/core/src/ops/cnn/conv/lazy_im2col.rs +++ b/core/src/ops/cnn/conv/lazy_im2col.rs @@ -241,7 +241,7 @@ impl VirtualInput for LazyIm2col { 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 = @@ -249,7 +249,7 @@ impl VirtualInput for LazyIm2col { 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, ) } } diff --git a/core/src/ops/cnn/deconv/deconv_sum.rs b/core/src/ops/cnn/deconv/deconv_sum.rs index 141df3d583..6ea8014366 100644 --- a/core/src/ops/cnn/deconv/deconv_sum.rs +++ b/core/src/ops/cnn/deconv/deconv_sum.rs @@ -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, diff --git a/core/src/ops/cnn/patches.rs b/core/src/ops/cnn/patches.rs index 2ead2889af..12229bc473 100644 --- a/core/src/ops/cnn/patches.rs +++ b/core/src/ops/cnn/patches.rs @@ -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); @@ -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, @@ -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); } diff --git a/core/src/ops/logic.rs b/core/src/ops/logic.rs index 4c28ad9395..fa0e91acaf 100644 --- a/core/src/ops/logic.rs +++ b/core/src/ops/logic.rs @@ -1,4 +1,5 @@ #![allow(clippy::bool_comparison)] +#![allow(clippy::unnecessary_cast)] use ndarray::*; diff --git a/core/src/ops/math/mod.rs b/core/src/ops/math/mod.rs index 7dfb513a34..38be3afe5f 100644 --- a/core/src/ops/math/mod.rs +++ b/core/src/ops/math/mod.rs @@ -1,4 +1,5 @@ #![allow(clippy::clone_on_copy)] +#![allow(clippy::unnecessary_cast)] use super::array::MultiBroadcastTo; use crate::internal::*; diff --git a/core/src/ops/quant.rs b/core/src/ops/quant.rs index d63f22d8bb..407fda4fcc 100644 --- a/core/src/ops/quant.rs +++ b/core/src/ops/quant.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use crate::internal::*; use crate::ops::element_wise::ElementWiseOp; use crate::ops::math::QScale; @@ -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, diff --git a/core/src/optim/mod.rs b/core/src/optim/mod.rs index 6d398e661e..dc347de074 100644 --- a/core/src/optim/mod.rs +++ b/core/src/optim/mod.rs @@ -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::::default(), ]) } diff --git a/data/src/tensor/view.rs b/data/src/tensor/view.rs index 062684f184..c14e9c4d66 100644 --- a/data/src/tensor/view.rs +++ b/data/src/tensor/view.rs @@ -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::() } diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 40896c2c3e..7a9ce0116a 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::missing_safety_doc)] + use anyhow::Context; use std::cell::RefCell; use std::convert::TryFrom; @@ -151,7 +153,7 @@ pub extern "C" fn tract_version() -> *const std::ffi::c_char { pub struct TractNnef(native::Nnef); #[no_mangle] -pub extern "C" fn tract_nnef_create(nnef: *mut *mut TractNnef) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_nnef_create(nnef: *mut *mut TractNnef) -> TRACT_RESULT { wrap(|| unsafe { *nnef = Box::into_raw(Box::new(TractNnef(tract_nnef::nnef()))); Ok(()) @@ -159,7 +161,7 @@ pub extern "C" fn tract_nnef_create(nnef: *mut *mut TractNnef) -> TRACT_RESULT { } #[no_mangle] -pub extern "C" fn tract_nnef_destroy(nnef: *mut *mut TractNnef) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_nnef_destroy(nnef: *mut *mut TractNnef) -> TRACT_RESULT { wrap(|| unsafe { if nnef.is_null() || (*nnef).is_null() { anyhow::bail!("Trying to destroy a null Nnef object"); @@ -171,7 +173,7 @@ pub extern "C" fn tract_nnef_destroy(nnef: *mut *mut TractNnef) -> TRACT_RESULT } #[no_mangle] -pub extern "C" fn tract_nnef_model_for_path( +pub unsafe extern "C" fn tract_nnef_model_for_path( nnef: &TractNnef, path: *const c_char, model: *mut *mut TractModel, @@ -191,7 +193,7 @@ pub extern "C" fn tract_nnef_model_for_path( pub struct TractOnnx(tract_onnx::Onnx); #[no_mangle] -pub extern "C" fn tract_onnx_create(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_onnx_create(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { wrap(|| unsafe { *ptr = Box::into_raw(Box::new(TractOnnx(onnx::onnx()))); Ok(()) @@ -199,7 +201,7 @@ pub extern "C" fn tract_onnx_create(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { } #[no_mangle] -pub extern "C" fn tract_onnx_destroy(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_onnx_destroy(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { wrap(|| unsafe { if ptr.is_null() || (*ptr).is_null() { anyhow::bail!("Trying to destroy a null Onnx object"); @@ -211,7 +213,7 @@ pub extern "C" fn tract_onnx_destroy(ptr: *mut *mut TractOnnx) -> TRACT_RESULT { } #[no_mangle] -pub extern "C" fn tract_onnx_model_for_path( +pub unsafe extern "C" fn tract_onnx_model_for_path( onnx: &TractOnnx, path: *const c_char, model: *mut *mut TractInferenceModel, @@ -231,7 +233,7 @@ pub extern "C" fn tract_onnx_model_for_path( pub struct TractInferenceModel(onnx::InferenceModel); #[no_mangle] -pub extern "C" fn tract_inference_model_into_optimized( +pub unsafe extern "C" fn tract_inference_model_into_optimized( model: *mut *mut TractInferenceModel, runnable: *mut *mut TractModel, ) -> TRACT_RESULT { @@ -248,7 +250,7 @@ pub extern "C" fn tract_inference_model_into_optimized( } #[no_mangle] -pub extern "C" fn tract_inference_model_destroy( +pub unsafe extern "C" fn tract_inference_model_destroy( model: *mut *mut TractInferenceModel, ) -> TRACT_RESULT { wrap(|| unsafe { @@ -265,7 +267,7 @@ pub extern "C" fn tract_inference_model_destroy( pub struct TractModel(TypedModel); #[no_mangle] -pub extern "C" fn tract_model_optimize(model: *mut TractModel) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_model_optimize(model: *mut TractModel) -> TRACT_RESULT { wrap(|| unsafe { if let Some(model) = model.as_mut() { model.0.optimize() @@ -279,7 +281,7 @@ pub extern "C" fn tract_model_optimize(model: *mut TractModel) -> TRACT_RESULT { /// /// This function transfers ownership of the model argument to the runnable model. #[no_mangle] -pub extern "C" fn tract_model_into_runnable( +pub unsafe extern "C" fn tract_model_into_runnable( model: *mut *mut TractModel, runnable: *mut *mut TractRunnable, ) -> TRACT_RESULT { @@ -296,7 +298,7 @@ pub extern "C" fn tract_model_into_runnable( } #[no_mangle] -pub extern "C" fn tract_model_destroy(model: *mut *mut TractModel) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_model_destroy(model: *mut *mut TractModel) -> TRACT_RESULT { wrap(|| unsafe { if model.is_null() || (*model).is_null() { anyhow::bail!("Trying to destroy a null Model"); @@ -311,7 +313,7 @@ pub extern "C" fn tract_model_destroy(model: *mut *mut TractModel) -> TRACT_RESU pub struct TractRunnable(Arc>); #[no_mangle] -pub extern "C" fn tract_runnable_spawn_state( +pub unsafe extern "C" fn tract_runnable_spawn_state( runnable: *mut TractRunnable, state: *mut *mut TractState, ) -> TRACT_RESULT { @@ -331,7 +333,7 @@ pub extern "C" fn tract_runnable_spawn_state( } #[no_mangle] -pub extern "C" fn tract_runnable_run( +pub unsafe extern "C" fn tract_runnable_run( runnable: *mut TractRunnable, inputs: *mut *mut TractValue, outputs: *mut *mut TractValue, @@ -347,7 +349,7 @@ pub extern "C" fn tract_runnable_run( } #[no_mangle] -pub extern "C" fn tract_runnable_nbio( +pub unsafe extern "C" fn tract_runnable_nbio( runnable: *mut TractRunnable, inputs: *mut usize, outputs: *mut usize, @@ -389,7 +391,7 @@ unsafe fn state_run( } #[no_mangle] -pub extern "C" fn tract_runnable_release(runnable: *mut *mut TractRunnable) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_runnable_release(runnable: *mut *mut TractRunnable) -> TRACT_RESULT { wrap(|| unsafe { if runnable.is_null() || (*runnable).is_null() { anyhow::bail!("Trying to destroy a null Runnable"); @@ -406,7 +408,7 @@ pub struct TractValue(TValue); /// This call copies the data into tract space. All the pointers only need to be alive for the /// duration of the call. #[no_mangle] -pub extern "C" fn tract_value_create( +pub unsafe extern "C" fn tract_value_create( datum_type: TractDatumType, rank: usize, shape: *const usize, @@ -425,7 +427,7 @@ pub extern "C" fn tract_value_create( } #[no_mangle] -pub extern "C" fn tract_value_destroy(value: *mut *mut TractValue) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_value_destroy(value: *mut *mut TractValue) -> TRACT_RESULT { wrap(|| unsafe { if value.is_null() || (*value).is_null() { anyhow::bail!("Trying to destroy a null Value"); @@ -439,7 +441,7 @@ pub extern "C" fn tract_value_destroy(value: *mut *mut TractValue) -> TRACT_RESU /// Inspect part of a value. Except `value`, all argument pointers can be null if only some specific bits /// are required. #[no_mangle] -pub extern "C" fn tract_value_inspect( +pub unsafe extern "C" fn tract_value_inspect( value: *mut TractValue, datum_type: *mut TractDatumType, rank: *mut usize, @@ -476,7 +478,7 @@ type NativeState = native::TypedSimpleState< pub struct TractState(NativeState); #[no_mangle] -pub extern "C" fn tract_state_run( +pub unsafe extern "C" fn tract_state_run( state: *mut TractState, inputs: *mut *mut TractValue, outputs: *mut *mut TractValue, @@ -491,7 +493,7 @@ pub extern "C" fn tract_state_run( } #[no_mangle] -pub extern "C" fn tract_state_set_input( +pub unsafe extern "C" fn tract_state_set_input( state: *mut TractState, input_id: usize, value: *mut TractValue, @@ -511,7 +513,7 @@ pub extern "C" fn tract_state_set_input( } #[no_mangle] -pub extern "C" fn tract_state_exec(state: *mut TractState) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_state_exec(state: *mut TractState) -> TRACT_RESULT { wrap(|| unsafe { if state.is_null() { anyhow::bail!("Trying to exec a null State"); @@ -524,7 +526,7 @@ pub extern "C" fn tract_state_exec(state: *mut TractState) -> TRACT_RESULT { /// Get an output tensor from the state. #[no_mangle] -pub extern "C" fn tract_state_output( +pub unsafe extern "C" fn tract_state_output( state: *mut TractState, output_id: usize, tensor: *mut *mut TractValue, @@ -541,7 +543,7 @@ pub extern "C" fn tract_state_output( } #[no_mangle] -pub extern "C" fn tract_state_reset_turn(state: *mut TractState) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_state_reset_turn(state: *mut TractState) -> TRACT_RESULT { wrap(|| unsafe { if state.is_null() { anyhow::bail!("Trying to reset turn on a null State"); @@ -553,7 +555,7 @@ pub extern "C" fn tract_state_reset_turn(state: *mut TractState) -> TRACT_RESULT } #[no_mangle] -pub extern "C" fn tract_state_destroy(state: *mut *mut TractState) -> TRACT_RESULT { +pub unsafe extern "C" fn tract_state_destroy(state: *mut *mut TractState) -> TRACT_RESULT { wrap(|| unsafe { if state.is_null() || (*state).is_null() { anyhow::bail!("Trying to destroy a null State"); diff --git a/harness/core-proptest-pulse/src/lib.rs b/harness/core-proptest-pulse/src/lib.rs index 984b6279c2..e127889fcc 100644 --- a/harness/core-proptest-pulse/src/lib.rs +++ b/harness/core-proptest-pulse/src/lib.rs @@ -101,7 +101,7 @@ fn proptest_regular_against_pulse( .unwrap(); eprintln!("GOT: {}", got); if let Some(output_len) = output_len { - if got.shape()[output_stream_axis] >= output_len.max(0) as usize + delay { + if got.shape()[output_stream_axis] >= output_len.max(0) + delay { break; } } @@ -111,7 +111,7 @@ fn proptest_regular_against_pulse( let pulsed_output = got .slice_axis( Axis(output_stream_axis), - (stream_info.delay..stream_info.delay + output_len.unwrap().max(0) as usize).into(), + (stream_info.delay..stream_info.delay + output_len.unwrap().max(0)).into(), ) .to_owned() .into_tensor(); diff --git a/harness/lstm-proptest-onnx-vs-tf/src/lib.rs b/harness/lstm-proptest-onnx-vs-tf/src/lib.rs index 9e1d2d587a..bd5b646203 100644 --- a/harness/lstm-proptest-onnx-vs-tf/src/lib.rs +++ b/harness/lstm-proptest-onnx-vs-tf/src/lib.rs @@ -301,7 +301,7 @@ fn test_b() { batch_size: 1, cell_size: 2, x: tensor3(&[[[0f32, 0.0]]]).into(), - w_xh_icfo: Array2::::zeros((4, 8)).into(), + w_xh_icfo: Array2::::zeros((4, 8)), b_icfo: arr1(&[0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]), h0: arr2(&[[0.0f32, 0.0]]), c0: arr2(&[[0.0f32, 0.0]]), diff --git a/harness/onnx-test-suite/build.rs b/harness/onnx-test-suite/build.rs index d0149ab017..ac8db70dac 100644 --- a/harness/onnx-test-suite/build.rs +++ b/harness/onnx-test-suite/build.rs @@ -39,7 +39,7 @@ pub fn ensure_onnx_git_checkout() { use fs2::FileExt; fs::create_dir_all(dir()).unwrap(); let lockfile = dir().join(".lock"); - let _lock = fs::File::create(&lockfile).unwrap().lock_exclusive(); + let _lock = fs::File::create(lockfile).unwrap().lock_exclusive(); for v in versions() { let wanted = dir().join(format!("onnx-{}", v.replace('.', "_"))); if !wanted.join("onnx/backend/test/data").exists() { diff --git a/harness/tf-inceptionv3/benches/inceptionv3.rs b/harness/tf-inceptionv3/benches/inceptionv3.rs index a167a296f0..f191b2486b 100644 --- a/harness/tf-inceptionv3/benches/inceptionv3.rs +++ b/harness/tf-inceptionv3/benches/inceptionv3.rs @@ -43,7 +43,7 @@ fn tract(bencher: &mut Criterion) { let input = tf_inceptionv3::load_image(hopper()); let plan = SimplePlan::new(tfd).unwrap(); bencher.bench_function("tract", move |b| { - b.iter(|| plan.run(tvec![input.clone().into()]).unwrap()) + b.iter(|| plan.run(tvec![input.clone()]).unwrap()) }); } diff --git a/hir/src/ops/array/concat.rs b/hir/src/ops/array/concat.rs index aed32291d0..7e465989e1 100644 --- a/hir/src/ops/array/concat.rs +++ b/hir/src/ops/array/concat.rs @@ -37,7 +37,7 @@ impl Expansion for Concat { ) -> InferenceResult { check_output_arity(outputs, 1)?; s.equals(&outputs[0].rank, &inputs[0].rank)?; - let n = inputs.len() as usize; + let n = inputs.len(); s.equals_all((0..n).map(|i| (&inputs[i].rank).bex()).collect())?; s.given_all((0..n).map(|i| (&inputs[i].datum_type).bex()), move |s, dts| { let super_type: DatumType = DatumType::super_type_for(&dts) @@ -45,7 +45,7 @@ impl Expansion for Concat { s.equals(&outputs[0].datum_type, super_type) })?; s.given(&inputs[0].rank, move |s, rank| { - let axis = self.resolve_axis(rank as i64)?; + let axis = self.resolve_axis(rank)?; s.equals( rules::expr::SumExp::new((0..n).map(|i| (&inputs[i].shape[axis]).bex()).collect()), &outputs[0].shape[axis], diff --git a/hir/src/ops/array/crop.rs b/hir/src/ops/array/crop.rs index 4549e2de60..a369c085eb 100644 --- a/hir/src/ops/array/crop.rs +++ b/hir/src/ops/array/crop.rs @@ -51,7 +51,7 @@ impl Expansion for Crop { target.wire_node( prefix, crate::ops::array::Slice::new( - self.axis as usize, + self.axis, self.start.to_dim(), len - self.end.to_dim(), ), diff --git a/hir/src/ops/array/strided_slice.rs b/hir/src/ops/array/strided_slice.rs index ace34d2cea..1f52aad444 100644 --- a/hir/src/ops/array/strided_slice.rs +++ b/hir/src/ops/array/strided_slice.rs @@ -25,7 +25,7 @@ struct Dim { impl Dim { fn soft_len(&self) -> TractResult { if let Ok(len) = (self.end.clone() - &self.begin).to_isize() { - Ok((((self.stride.abs() as i32 - 1) + len.abs() as i32) / self.stride.abs()).to_dim()) + Ok((((self.stride.abs() - 1) + len.abs() as i32) / self.stride.abs()).to_dim()) } else if self.stride == 1 { Ok(self.end.clone() - &self.begin) } else { diff --git a/hir/src/ops/scan.rs b/hir/src/ops/scan.rs index cc5a16fa73..c616b5268b 100644 --- a/hir/src/ops/scan.rs +++ b/hir/src/ops/scan.rs @@ -115,13 +115,13 @@ impl InferenceScan { if let Some(rank) = rank { if outer .shape - .unify_with(&ShapeFactoid::closed(tvec!(GenericFactoid::Any; rank as usize)))? + .unify_with(&ShapeFactoid::closed(tvec!(GenericFactoid::Any; rank)))? { changed = true; } if inner .shape - .unify_with(&ShapeFactoid::closed(tvec!(GenericFactoid::Any; rank as usize)))? + .unify_with(&ShapeFactoid::closed(tvec!(GenericFactoid::Any; rank)))? { changed = true; } diff --git a/kaldi/src/model.rs b/kaldi/src/model.rs index ee27cc2ac5..253b7ee6ab 100644 --- a/kaldi/src/model.rs +++ b/kaldi/src/model.rs @@ -125,7 +125,7 @@ impl GeneralDescriptor { } Offset(ref n, o) if *o > 0 => { let name = format!("{}-Delay", name); - let crop = *o as isize + adjust_final_offset.unwrap_or(0); + let crop = *o + adjust_final_offset.unwrap_or(0); if crop < 0 { bail!("Invalid offset adjustment (network as {}, adjustment is {}", o, crop) } @@ -245,11 +245,8 @@ impl Framework for Kaldi { } } NodeLine::DimRange(line) => { - let op = tract_hir::ops::array::Slice::new( - 1, - line.offset as usize, - (line.offset + line.dim) as usize, - ); + let op = + tract_hir::ops::array::Slice::new(1, line.offset, line.offset + line.dim); let id = model.add_node(name.to_string(), op, tvec!(InferenceFact::default()))?; line.input.wire( diff --git a/kaldi/src/ops.rs b/kaldi/src/ops.rs index 31e67e3ba3..857be23958 100644 --- a/kaldi/src/ops.rs +++ b/kaldi/src/ops.rs @@ -13,7 +13,7 @@ pub fn register_all_ops(reg: &mut KaldiOpRegister) { reg.insert(affine, affine::affine_component); } reg.insert("BackpropTruncationComponent", |_, _| { - Ok(Box::new(tract_hir::ops::identity::Identity::default())) + Ok(Box::::default()) }); reg.insert("NormalizeComponent", renorm::renorm); reg.insert("LstmNonlinearityComponent", lstm_nonlin::lstm_nonlin); diff --git a/linalg/build.rs b/linalg/build.rs index 888822d339..e9bbb05b67 100644 --- a/linalg/build.rs +++ b/linalg/build.rs @@ -1,3 +1,5 @@ +#![allow(clippy::box_default)] + use liquid_core::Runtime; use liquid_core::{Display_filter, Filter, FilterReflection, ParseFilter}; use liquid_core::{Value, ValueView}; diff --git a/linalg/src/frame/mmm/kernel.rs b/linalg/src/frame/mmm/kernel.rs index 5e86e1936b..a7a925e38d 100644 --- a/linalg/src/frame/mmm/kernel.rs +++ b/linalg/src/frame/mmm/kernel.rs @@ -22,7 +22,7 @@ where fn prefetch(ptr: *const u8, len: usize) {} fn mmm() -> Box { - Box::new(MatMatMulImpl::::default()) + Box::>::default() } } diff --git a/linalg/src/frame/mmm/mmm.rs b/linalg/src/frame/mmm/mmm.rs index 57cee13045..685d46fbd1 100644 --- a/linalg/src/frame/mmm/mmm.rs +++ b/linalg/src/frame/mmm/mmm.rs @@ -197,7 +197,7 @@ where } unsafe fn allocate_scratch_space(&self) -> Box { - Box::new(ScratchSpaceFusedNonLinear::::default()) + Box::>::default() } unsafe fn can_use_scratch_space(&self, scratch: &dyn ScratchSpace) -> bool { diff --git a/linalg/src/frame/mmm/storage.rs b/linalg/src/frame/mmm/storage.rs index aecb192534..4b10085d79 100644 --- a/linalg/src/frame/mmm/storage.rs +++ b/linalg/src/frame/mmm/storage.rs @@ -36,13 +36,12 @@ pub struct OutputStore { impl OutputStoreSpec { #[inline] pub unsafe fn wrap(&self, tensor: &TensorView) -> OutputStore { - let (mr, nr, row_byte_stride, col_byte_stride) = - self.compute_strides(tensor); + let (mr, nr, row_byte_stride, col_byte_stride) = self.compute_strides(tensor); let (m, n) = match self { - OutputStoreSpec::View { m_axis, n_axis, .. } => - ( tensor.shape()[*m_axis], - tensor.shape()[*n_axis]), - OutputStoreSpec::Strides { m,n,.. } => (*m, *n) + OutputStoreSpec::View { m_axis, n_axis, .. } => { + (tensor.shape()[*m_axis], tensor.shape()[*n_axis]) + } + OutputStoreSpec::Strides { m, n, .. } => (*m, *n), }; OutputStore { ptr: tensor.as_ptr_unchecked::() as _, @@ -53,16 +52,13 @@ impl OutputStoreSpec { item_size: tensor.datum_type().size_of(), mr, item_count: tensor.len(), - m - ,n + m, + n, } } #[inline] - unsafe fn compute_strides( - &self, - tensor: &TensorView, - ) -> (usize, usize, isize, isize) { + unsafe fn compute_strides(&self, tensor: &TensorView) -> (usize, usize, isize, isize) { let size_of = tensor.datum_type().size_of() as isize; match self { OutputStoreSpec::View { m_axis, n_axis, mr, nr, .. } => { @@ -73,13 +69,9 @@ impl OutputStoreSpec { let col_byte_stride = col_item_stride * size_of; (*mr, *nr, row_byte_stride, col_byte_stride) } - OutputStoreSpec::Strides { - row_byte_stride, - col_byte_stride, - mr, - nr, - .. - } => (*mr, *nr, *row_byte_stride, *col_byte_stride), + OutputStoreSpec::Strides { row_byte_stride, col_byte_stride, mr, nr, .. } => { + (*mr, *nr, *row_byte_stride, *col_byte_stride) + } } } } @@ -93,9 +85,9 @@ impl OutputStore { .ptr .offset(self.panel_row_byte_stride * down + self.panel_col_byte_stride * right) as *mut _, - row_byte_stride: self.row_byte_stride, - col_byte_stride: self.col_byte_stride, - item_size: self.item_size, + row_byte_stride: self.row_byte_stride, + col_byte_stride: self.col_byte_stride, + item_size: self.item_size, } } @@ -112,7 +104,7 @@ impl OutputStore { height: usize, width: usize, tile: &OutputStoreKer, - ) { + ) { if self.item_size() == 1 { self.set_from_tile_t::(down, right, height, width, tile) } else if self.item_size() == 2 { @@ -132,15 +124,16 @@ impl OutputStore { height: usize, width: usize, tile: &OutputStoreKer, - ) { + ) { let tile = tile.ptr as *mut T; - let dst = self.ptr.add(self.panel_row_byte_stride as usize * down - + self.panel_col_byte_stride as usize * right); + let dst = self.ptr.add( + self.panel_row_byte_stride as usize * down + + self.panel_col_byte_stride as usize * right, + ); for y in 0..height as isize { for x in 0..width as isize { let value = tile.offset(y + x * self.mr as isize); - let dst = - dst.offset((y * self.row_byte_stride + x * self.col_byte_stride) as isize); + let dst = dst.offset(y * self.row_byte_stride + x * self.col_byte_stride); *(dst as *mut T) = *value; } } diff --git a/linalg/src/generic/rounding.rs b/linalg/src/generic/rounding.rs index 9772d18288..4d7257a19f 100644 --- a/linalg/src/generic/rounding.rs +++ b/linalg/src/generic/rounding.rs @@ -11,8 +11,7 @@ pub struct Scaler { pub policy: RoundingPolicy, } -impl Eq for Scaler { -} +impl Eq for Scaler {} #[allow(clippy::derive_hash_xor_eq)] impl Hash for Scaler { @@ -127,7 +126,6 @@ impl Mul for f16 { } } - impl Mul for f32 { type Output = f32; @@ -245,10 +243,10 @@ impl ScaleShiftAndRound for i32 { Odd => -((self.abs() >> shift) & 0x1), _ => panic!(), }; - (self.signum() * ((self.abs() + half + nudge) >> shift)) as i32 + self.signum() * ((self.abs() + half + nudge) >> shift) } fn q_shl(self, shift: usize) -> Self { - (self << shift) as i32 + self << shift } } diff --git a/linalg/src/generic/sigmoid.rs b/linalg/src/generic/sigmoid.rs index 4d1b10efd0..0763a556dc 100644 --- a/linalg/src/generic/sigmoid.rs +++ b/linalg/src/generic/sigmoid.rs @@ -18,7 +18,7 @@ pub fn ssigmoid(x: f32) -> f32 { const BETA_2: f32 = 0.1159886749; const BETA_0: f32 = 1.0; - let x = x.max(LOW).min(HIGH); + let x = x.clamp(LOW, HIGH); let x2 = x * x; @@ -56,7 +56,7 @@ pub fn hsigmoid(x: f16) -> f16 { const BETA_2: f16 = f16::from_f32_const(0.098734); const BETA_0: f16 = f16::from_f32_const(1.0); - let x = x.max(LOW).min(HIGH); + let x = x.clamp(LOW, HIGH); let x2 = x * x; diff --git a/linalg/src/generic/tanh.rs b/linalg/src/generic/tanh.rs index e8a323dc20..114b402c75 100644 --- a/linalg/src/generic/tanh.rs +++ b/linalg/src/generic/tanh.rs @@ -19,7 +19,7 @@ pub fn stanh(x: f32) -> f32 { const BETA_2: f32 = 0.4641733162; const BETA_0: f32 = 1.0; - let x = x.max(LOW).min(HIGH); + let x = x.clamp(LOW, HIGH); let x2 = x * x; @@ -51,7 +51,7 @@ pub fn htanh(x: f16) -> f16 { const BETA_2: f16 = f16::from_f32_const(0.41401828); const BETA_0: f16 = f16::from_f32_const(1.0); - let x = x.max(LOW).min(HIGH); + let x = x.clamp(LOW, HIGH); let x2 = x * x; diff --git a/nnef/src/ops/nnef/deser.rs b/nnef/src/ops/nnef/deser.rs index de18c98917..02874df197 100644 --- a/nnef/src/ops/nnef/deser.rs +++ b/nnef/src/ops/nnef/deser.rs @@ -182,7 +182,7 @@ pub fn squeeze(builder: &mut ModelBuilder, invocation: &ResolvedInvocation) -> T .sorted() .rev() .try_fold(wire, |wire, &axis| { - builder.wire_as_outlets(ops::change_axes::AxisOp::Rm(axis as usize), &wire) + builder.wire_as_outlets(ops::change_axes::AxisOp::Rm(axis), &wire) }) .map(Value::from) } @@ -197,7 +197,7 @@ pub fn unsqueeze( axes.iter() .sorted() .try_fold(wire, |wire, &axis| { - builder.wire_as_outlets(ops::change_axes::AxisOp::Add(axis as usize), &wire) + builder.wire_as_outlets(ops::change_axes::AxisOp::Add(axis), &wire) }) .map(Value::from) } @@ -655,7 +655,7 @@ pub fn stack(builder: &mut ModelBuilder, invocation: &ResolvedInvocation) -> Tra for value in &mut values { // add unsqueeze *value = - builder.wire_as_outlets(ops::change_axes::AxisOp::Add(axis as usize), &[*value])?[0]; + builder.wire_as_outlets(ops::change_axes::AxisOp::Add(axis), &[*value])?[0]; } builder.wire(ops::array::TypedConcat::new(axis), &values) @@ -680,7 +680,7 @@ pub fn unstack(builder: &mut ModelBuilder, invocation: &ResolvedInvocation) -> T let sliced_wire = builder .wire_as_outlets(tract_core::ops::array::Slice { axis, start, end }, &wire)?; let squeezed_wire = builder - .wire_as_outlets(ops::change_axes::AxisOp::Rm(axis as usize), &sliced_wire)?; + .wire_as_outlets(ops::change_axes::AxisOp::Rm(axis), &sliced_wire)?; Ok(squeezed_wire[0]) }) .collect::>>() diff --git a/nnef/src/ser.rs b/nnef/src/ser.rs index a010babcff..9a6f9aab98 100644 --- a/nnef/src/ser.rs +++ b/nnef/src/ser.rs @@ -228,7 +228,7 @@ impl<'a> IntoAst<'a> { let doc = Document { version: "1.0".into(), extension, - fragments: fragments.into_iter().map(|(_, v)| v).collect(), + fragments: fragments.into_values().collect(), graph_def: GraphDef { id, parameters, results, body }, }; let quantization = if self.quantization.len() > 0 { Some(self.quantization) } else { None }; diff --git a/onnx/src/ops/mod.rs b/onnx/src/ops/mod.rs index c40731b9b3..b8abfd5c7c 100644 --- a/onnx/src/ops/mod.rs +++ b/onnx/src/ops/mod.rs @@ -1,7 +1,7 @@ use crate::model::{OnnxOpRegister, ParsingContext}; use crate::pb::*; use tract_hir::internal::*; -use tract_hir::ops; + mod array; mod cast; @@ -23,7 +23,7 @@ pub fn register_all_ops(reg: &mut OnnxOpRegister) { reg.insert("Cast", cast::cast); reg.insert("Constant", konst); reg.insert("Einsum", einsum::einsum); - reg.insert("Identity", |_, _| Ok((Box::new(ops::identity::Identity::default()), vec![]))); + reg.insert("Identity", |_, _| Ok((Box::::default(), vec![]))); reg.insert("Resize", resize::resize); reg.insert("NonMaxSuppression", non_max_suppression::non_max_suppression); reg.insert("Multinomial", multinomial::multinomial); diff --git a/onnx/src/ops/nn/reduce.rs b/onnx/src/ops/nn/reduce.rs index 4479b95e1a..12925f5959 100644 --- a/onnx/src/ops/nn/reduce.rs +++ b/onnx/src/ops/nn/reduce.rs @@ -53,7 +53,7 @@ impl Expansion for ReduceSum13 { s.given_2(&inputs[0].rank, &inputs[1].value, move |s, rank, axes| { let mut axes = axes.cast_to::()?.as_slice::()?.to_vec(); if axes.len() == 0 && !self.noop_with_empty_axes { - axes = (0..rank as i64).collect() + axes = (0..rank).collect() }; let op = tract_hir::ops::nn::Reduce::new( Some(axes.clone()), @@ -73,7 +73,7 @@ impl Expansion for ReduceSum13 { } else { s.given(&inputs[0].rank, move |s, rank| { let axes = - if self.noop_with_empty_axes { vec![] } else { (0..rank as i64).collect() }; + if self.noop_with_empty_axes { vec![] } else { (0..rank).collect() }; let op = tract_hir::ops::nn::Reduce::new( Some(axes.clone()), self.keep_dims, diff --git a/onnx/src/ops/quant.rs b/onnx/src/ops/quant.rs index 09007f972d..725e28fdc5 100644 --- a/onnx/src/ops/quant.rs +++ b/onnx/src/ops/quant.rs @@ -46,7 +46,6 @@ impl Expansion for QuantizeLinear { "QuantizeLinear".into() } - fn rules<'r, 'p: 'r, 's: 'r>( &'s self, s: &mut Solver<'r>, @@ -112,7 +111,6 @@ impl Expansion for DequantizeLinear { "DequantizeLinear".into() } - fn rules<'r, 'p: 'r, 's: 'r>( &'s self, s: &mut Solver<'r>, @@ -159,7 +157,7 @@ impl Expansion for DequantizeLinear { } else if zero_point.datum_type() == i8::datum_type() { Box::new(DequantizeLinearF32::new(scale, zero_point.as_slice::()?[0] as i32)) } else { - Box::new(DequantizeLinearF32::new(scale, zero_point.as_slice::()?[0] as i32)) + Box::new(DequantizeLinearF32::new(scale, zero_point.as_slice::()?[0])) }; target.wire_node(prefix, op, &[inputs[0]]) } @@ -175,7 +173,6 @@ impl Expansion for DynamicQuantizeLinear { "DynamicQuantizeLinear".into() } - fn nboutputs(&self) -> TractResult { Ok(3) } @@ -210,8 +207,7 @@ impl Expansion for DynamicQuantizeLinear { fn dynamic_quantize_linear_f32_u8(x: f32, scale: f32, zero_point: u8) -> u8 { (((x / scale).round() as i32) + zero_point as i32) - .max(u8::min_value() as i32) - .min(u8::max_value() as i32) as u8 + .clamp(u8::min_value() as i32, u8::max_value() as i32) as u8 } fn dynamic_quantize_linear_u8(scale: f32, zero_point: u8, xs: &[f32], ys: &mut [u8]) { diff --git a/onnx/src/ops/resize.rs b/onnx/src/ops/resize.rs index 0459b9f5a3..5aaf6cd694 100644 --- a/onnx/src/ops/resize.rs +++ b/onnx/src/ops/resize.rs @@ -180,7 +180,7 @@ impl EvalOp for Resize { new_shape[axis], ); let mut co_i = co_o; - let x_left = (x_in as usize).min(data.shape()[axis] - 1).max(0); + let x_left = (x_in as usize).clamp(0, data.shape()[axis] - 1); co_i[axis] = x_left; let y_left = data[&co_i]; let x_right = (x_left + 1).min(data.shape()[axis] - 1); diff --git a/pulse-opl/src/concat.rs b/pulse-opl/src/concat.rs index cf4b730d1c..f39fba3e48 100644 --- a/pulse-opl/src/concat.rs +++ b/pulse-opl/src/concat.rs @@ -32,7 +32,7 @@ impl EvalOp for PulsedSameAxisConcat { _session: &mut SessionState, _node_id: usize, ) -> TractResult>> { - Ok(Some(Box::new(PulsedSameAxisConcatState::default()))) + Ok(Some(Box::::default())) } } @@ -77,7 +77,7 @@ impl OpState for PulsedSameAxisConcatState { pre_offset )); if let Ok(l) = op.input_len.eval(&session.resolved_symbols).to_usize() { - let post_offset = op.input_delay + l as usize; + let post_offset = op.input_delay + l; dispatch_datum_by_size!(overwrite_part_of_pulse(data.datum_type())( op.axis, &mut data, diff --git a/pulse-opl/src/pad.rs b/pulse-opl/src/pad.rs index 38ea8d62ee..f542bb9003 100644 --- a/pulse-opl/src/pad.rs +++ b/pulse-opl/src/pad.rs @@ -184,7 +184,7 @@ impl EvalOp for PulsePad { _session: &mut SessionState, _node_id: usize, ) -> TractResult>> { - Ok(Some(Box::new(PulsePadOpState::default()))) + Ok(Some(Box::::default())) } } diff --git a/pulse/src/ops/array/concat.rs b/pulse/src/ops/array/concat.rs index 8c432c8e04..71d2b3d057 100644 --- a/pulse/src/ops/array/concat.rs +++ b/pulse/src/ops/array/concat.rs @@ -166,7 +166,7 @@ impl OpState for PulsedSameAxisConcatState { overwrite_part_of_pulse(op.axis, &mut data, current_pos, &op.pre_slice, pre_offset)?; if self.symbols_in_dim.iter().all(|s| session.resolved_symbols[s].is_some()) { let l = op.input_len.eval(&session.resolved_symbols).to_usize().unwrap(); - let post_offset = op.input_delay + l as usize; + let post_offset = op.input_delay + l; overwrite_part_of_pulse(op.axis, &mut data, current_pos, &op.post_slice, post_offset)?; } diff --git a/pulse/src/ops/array/slice.rs b/pulse/src/ops/array/slice.rs index db7ced2c1e..d8af2c4fbf 100644 --- a/pulse/src/ops/array/slice.rs +++ b/pulse/src/ops/array/slice.rs @@ -66,7 +66,7 @@ impl PulsedOp for PulsedAxisSlice { } fn to_typed(&self) -> Box { - Box::new(tract_core::ops::identity::Identity::default()) + Box::::default() } as_op!(); diff --git a/tensorflow/src/ops/array/pack.rs b/tensorflow/src/ops/array/pack.rs index 640fd295e0..aca6babd99 100644 --- a/tensorflow/src/ops/array/pack.rs +++ b/tensorflow/src/ops/array/pack.rs @@ -85,6 +85,6 @@ impl Expansion for Pack { )?[0]) }) .collect::>>()?; - model.wire_node(prefix, TypedConcat::new(self.axis as usize), &inputs) + model.wire_node(prefix, TypedConcat::new(self.axis), &inputs) } } diff --git a/tensorflow/src/ops/array/pad.rs b/tensorflow/src/ops/array/pad.rs index b35bb7fd00..11057929bf 100644 --- a/tensorflow/src/ops/array/pad.rs +++ b/tensorflow/src/ops/array/pad.rs @@ -10,7 +10,7 @@ pub struct Pad; impl_dyn_hash!(Pad); pub fn pad(_ctx: &ParsingContext, _pb: &NodeDef) -> TractResult> { - Ok(Box::new(Pad)) + Ok(Box::::default()) } impl Pad { @@ -36,7 +36,7 @@ impl Pad { let result = Array::from_shape_fn(shape, |index| { for i in 0..input.ndim() { if index[i] < paddings[(i, 0)] as usize - || index[i] - paddings[(i, 0)] as usize >= input.shape()[i] as usize + || index[i] - paddings[(i, 0)] as usize >= input.shape()[i] { return T::default(); } else { diff --git a/tensorflow/src/ops/nn/s2b/mod.rs b/tensorflow/src/ops/nn/s2b/mod.rs index 2b440eecbc..0746325ec1 100644 --- a/tensorflow/src/ops/nn/s2b/mod.rs +++ b/tensorflow/src/ops/nn/s2b/mod.rs @@ -98,7 +98,7 @@ fn batch_to_space( let mut data = data; for (i, crop) in crops.outer_iter().enumerate() { if crop[0] != 0 || crop[1] != 0 { - let end = data.shape()[1 + i] as usize; + let end = data.shape()[1 + i]; let range = (crop[0] as usize)..(end - crop[1] as usize); data = data.slice_axis(Axis(i + 1), range.into()).map(|x| *x).to_owned(); } diff --git a/tensorflow/src/ops/nn/s2b/raw.rs b/tensorflow/src/ops/nn/s2b/raw.rs index 5fd871d715..005935103f 100644 --- a/tensorflow/src/ops/nn/s2b/raw.rs +++ b/tensorflow/src/ops/nn/s2b/raw.rs @@ -67,11 +67,9 @@ impl InferenceRulesOp for SpaceToBatch { let mut paddings = tvec![]; for p in paddings_view.outer_iter() { let pad = match (p[0].to_usize(), p[1].to_usize()) { - (Ok(bef), Ok(aft)) => { - super::unary::PaddingStrat::FixedFixed(bef as usize, aft as usize) - } - (_, Ok(aft)) => super::unary::PaddingStrat::FlexFixed(aft as usize), - (Ok(bef), _) => super::unary::PaddingStrat::FixedFlex(bef as usize), + (Ok(bef), Ok(aft)) => super::unary::PaddingStrat::FixedFixed(bef, aft), + (_, Ok(aft)) => super::unary::PaddingStrat::FlexFixed(aft), + (Ok(bef), _) => super::unary::PaddingStrat::FixedFlex(bef), _ => bail!("Failed to unarize SpaceToBatch because of padding"), }; paddings.push(pad); @@ -162,11 +160,9 @@ impl InferenceRulesOp for BatchToSpace { .outer_iter() .map(|p| { Ok(match (p[0].to_usize(), p[1].to_usize()) { - (Ok(bef), Ok(aft)) => { - super::unary::PaddingStrat::FixedFixed(bef as usize, aft as usize) - } - (_, Ok(aft)) => super::unary::PaddingStrat::FlexFixed(aft as usize), - (Ok(bef), _) => super::unary::PaddingStrat::FixedFlex(bef as usize), + (Ok(bef), Ok(aft)) => super::unary::PaddingStrat::FixedFixed(bef, aft), + (_, Ok(aft)) => super::unary::PaddingStrat::FlexFixed(aft), + (Ok(bef), _) => super::unary::PaddingStrat::FixedFlex(bef), _ => bail!("Failed to unarize SpaceToBatch because of padding"), }) }) diff --git a/tensorflow/src/ops/vars.rs b/tensorflow/src/ops/vars.rs index 84927e656d..538e66578a 100644 --- a/tensorflow/src/ops/vars.rs +++ b/tensorflow/src/ops/vars.rs @@ -5,7 +5,7 @@ use crate::model::{ParsingContext, TfOpRegister}; use crate::tfpb::tensorflow::NodeDef; pub fn register_all_ops(reg: &mut TfOpRegister) { - reg.insert("Assign", |_, _| Ok(Box::new(Assign::default()))); + reg.insert("Assign", |_, _| Ok(Box::::default())); reg.insert("VariableV2", variable_v2); } diff --git a/tensorflow/src/tfpb.rs b/tensorflow/src/tfpb.rs index c3bb4db954..1594ebe9f7 100644 --- a/tensorflow/src/tfpb.rs +++ b/tensorflow/src/tfpb.rs @@ -47,7 +47,7 @@ impl GraphDef { } pub fn save_to>(self, p: P) -> TractResult<()> { let buf = self.write_to_bytes()?; - fs::write(p, &buf)?; + fs::write(p, buf)?; Ok(()) } }