From 17288b09a02e73887c560777666e06fd52fd3649 Mon Sep 17 00:00:00 2001 From: edgar Date: Thu, 15 Feb 2024 14:03:54 +0100 Subject: [PATCH] apply clippy --- benches/color_benchmark.rs | 9 ++++----- examples/binarize.rs | 1 - examples/imgproc.rs | 1 - examples/rerun_viz.rs | 1 - src/io/functions.rs | 5 ++++- src/resize.rs | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/benches/color_benchmark.rs b/benches/color_benchmark.rs index 01843eb3..116e006a 100644 --- a/benches/color_benchmark.rs +++ b/benches/color_benchmark.rs @@ -19,7 +19,7 @@ fn gray_iter(image: &Image) -> Image { let r = image.data[[y, x, 0]]; let g = image.data[[y, x, 1]]; let b = image.data[[y, x, 2]]; - let gray_pixel = (76. * r as f32 + 150. * g as f32 + 29. * b as f32) / 255.; + let gray_pixel = (76. * r + 150. * g + 29. * b) / 255.; gray_image.data[[y, x, 0]] = gray_pixel as u8; } } @@ -27,8 +27,7 @@ fn gray_iter(image: &Image) -> Image { } fn gray_vec(image: &Image) -> Image { - // convert to f32 - let mut image_f32 = image.data.mapv(|x| x as f32); + let mut image_f32 = image.data.mapv(|x| x); // get channels let mut binding = image_f32.view_mut(); @@ -43,7 +42,7 @@ fn gray_vec(image: &Image) -> Image { } #[cfg(feature = "candle")] -fn gray_candle(image: Image) -> Image { +fn gray_candle(image: Image) -> Image { let image_data = image.data.as_slice().unwrap(); let shape = (image.image_size().height, image.image_size().width, 3); @@ -79,7 +78,7 @@ fn gray_candle(image: Image) -> Image { } }; - Image::from_shape_vec([shape.0, shape.1, shape.2], data) + Image::new(image.image_size(), data).unwrap() } fn gray_image_crate(image: &Image) -> Image { diff --git a/examples/binarize.rs b/examples/binarize.rs index 71714517..c1162ed9 100644 --- a/examples/binarize.rs +++ b/examples/binarize.rs @@ -1,5 +1,4 @@ use kornia_rs::io::functions as F; -use rerun; fn main() -> Result<(), Box> { // read the image diff --git a/examples/imgproc.rs b/examples/imgproc.rs index 434e3ab4..11287744 100644 --- a/examples/imgproc.rs +++ b/examples/imgproc.rs @@ -1,5 +1,4 @@ use kornia_rs::io::functions as F; -use rerun; fn main() -> Result<(), Box> { // read the image diff --git a/examples/rerun_viz.rs b/examples/rerun_viz.rs index af360db8..b7791c7f 100644 --- a/examples/rerun_viz.rs +++ b/examples/rerun_viz.rs @@ -1,5 +1,4 @@ use kornia_rs::io::functions as F; -use rerun; fn main() -> Result<(), Box> { // read the image diff --git a/src/io/functions.rs b/src/io/functions.rs index e512dd17..cec033fc 100644 --- a/src/io/functions.rs +++ b/src/io/functions.rs @@ -17,7 +17,10 @@ use super::jpeg::{ImageDecoder, ImageEncoder}; pub fn read_image_jpeg(file_path: &Path) -> Result> { // verify the file exists and is a JPEG if !file_path.exists() { - return Err(anyhow::anyhow!("File does not exist: {}", file_path.to_str().unwrap()).into()); + return Err(anyhow::anyhow!( + "File does not exist: {}", + file_path.to_str().unwrap() + )); } let file_path = match file_path.extension() { diff --git a/src/resize.rs b/src/resize.rs index 03b57376..98d335e5 100644 --- a/src/resize.rs +++ b/src/resize.rs @@ -222,7 +222,7 @@ mod tests { width: 4, height: 5, }, - vec![0f32; 4 * 5 * 1], + vec![0f32; 4 * 5], ) .unwrap(); let image_resized = super::resize(