From 5f49f830b2cf06b81393439de4d5d2dc6ae25382 Mon Sep 17 00:00:00 2001 From: Pradeep Garigipati Date: Sat, 12 Feb 2022 20:58:48 +0530 Subject: [PATCH 1/2] Fix clippy warnings Signed-off-by: Pradeep Garigipati --- .gitignore | 3 +++ build.rs | 19 ++++++++++++------- examples/helloworld.rs | 2 +- examples/neural_network.rs | 6 +++--- src/core/arith.rs | 8 ++++---- src/core/array.rs | 2 ++ src/core/index.rs | 6 +++--- src/core/macros.rs | 2 +- tests/error_handler.rs | 2 +- 9 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 1b0b6edb8..39a9fa998 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ Cargo.lock # ide files .idea/ .vscode/ + +#example downloads +data/ diff --git a/build.rs b/build.rs index 360fbb62f..4bbba0cae 100644 --- a/build.rs +++ b/build.rs @@ -12,6 +12,7 @@ use std::env; use std::fs; use std::fs::OpenOptions; use std::io::{ErrorKind, Read}; +use std::path::Path; use std::path::PathBuf; use std::process::Command; @@ -95,7 +96,7 @@ fn run(cmd: &mut Command, program: &str) { } } -fn read_file(file_name: &std::path::PathBuf) -> String { +fn read_file(file_name: &std::path::Path) -> String { let file_path = file_name.to_str().unwrap(); let options = OpenOptions::new() .read(true) @@ -115,7 +116,7 @@ fn read_file(file_name: &std::path::PathBuf) -> String { } } -fn read_conf(conf_file: &std::path::PathBuf) -> Config { +fn read_conf(conf_file: &std::path::Path) -> Config { let raw_conf = read_file(conf_file); let decoded: Config = serde_json::from_str(&raw_conf).unwrap(); decoded @@ -198,7 +199,7 @@ fn prep_cmake_options(conf: &Config) -> Vec { } #[cfg(windows)] -fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) { +fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) { let _ = fs::create_dir(&build_dir); let options = prep_cmake_options(conf); @@ -243,7 +244,7 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) { } #[cfg(not(windows))] -fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) { +fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) { let _ = fs::create_dir(&build_dir); let options = prep_cmake_options(conf); @@ -282,7 +283,7 @@ fn backend_exists(name: &str) -> bool { file_exists(&win_backend) || file_exists(&osx_backend) || file_exists(&linux_backend) } -fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec, Vec) { +fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec, Vec) { let mut backend_dirs: Vec = Vec::new(); let mut backends: Vec = Vec::new(); @@ -338,7 +339,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec, let mut ocl_lib_exists = false; for backend_dir in backend_dirs.iter() { - let lib_dir = PathBuf::from(backend_dir); + let lib_dir = Path::new(backend_dir); let culib_name = if cfg!(windows) { WIN_CUDA_LIB @@ -429,7 +430,11 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec, fn main() { // Setup pathing - let src = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); + let cargo_manifest_dir = match env::var("CARGO_MANIFEST_DIR") { + Ok(dir_path) => dir_path, + Err(error) => panic!("CARGO_MANIFEST_DIR environment variable is not available: {}", error), + }; + let src = Path::new(&cargo_manifest_dir); let conf_file = src.join("build.conf"); let conf = read_conf(&conf_file); diff --git a/examples/helloworld.rs b/examples/helloworld.rs index 2b9c2e4cd..5e455425d 100644 --- a/examples/helloworld.rs +++ b/examples/helloworld.rs @@ -81,7 +81,7 @@ fn main() { //print(&x.0); //print(&x.1); - let u8_cnst = &constant(1 as u8, dims); + let u8_cnst = &constant(1_u8, dims); af_print!("u8 constant array", u8_cnst); println!( "Is u8_cnst array float precision type ? {}", diff --git a/examples/neural_network.rs b/examples/neural_network.rs index e7a49cdff..4fcb92a86 100644 --- a/examples/neural_network.rs +++ b/examples/neural_network.rs @@ -241,7 +241,7 @@ mod ann { println!("Epoch: {}, Error: {}", epoch + 1, avg_error); } } - return avg_error; + avg_error } fn predict(&self, input: &Array) -> Array { @@ -312,7 +312,7 @@ mod ann { MatProp::NONE, ); - error = index(&err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]); + error = index(err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]); } } @@ -333,7 +333,7 @@ fn accuracy(predicted: &Array, target: &Array) -> f32 { &predicted_max_indices, false, )); - return 100f32 * matches as f32 / target_max_indices.elements() as f32; + 100f32 * matches as f32 / target_max_indices.elements() as f32 } fn main() { diff --git a/src/core/arith.rs b/src/core/arith.rs index a0e7e7322..3c7fcbd7f 100644 --- a/src/core/arith.rs +++ b/src/core/arith.rs @@ -668,18 +668,18 @@ where match (lo.is_scalar(), hi.is_scalar()) { (true, false) => { let l = tile(&lo, hi.dims()); - clamp_helper(&input, &l, &hi, batch) + clamp_helper(input, &l, &hi, batch) } (false, true) => { let r = tile(&hi, lo.dims()); - clamp_helper(&input, &lo, &r, batch) + clamp_helper(input, &lo, &r, batch) } (true, true) => { let l = tile(&lo, input.dims()); let r = tile(&hi, input.dims()); - clamp_helper(&input, &l, &r, batch) + clamp_helper(input, &l, &r, batch) } - _ => clamp_helper(&input, &lo, &hi, batch), + _ => clamp_helper(input, &lo, &hi, batch), } } diff --git a/src/core/array.rs b/src/core/array.rs index bae191d25..fdf262bec 100644 --- a/src/core/array.rs +++ b/src/core/array.rs @@ -682,6 +682,7 @@ where } /// Fetch Array as String + #[allow(clippy::inherent_to_string)] pub fn to_string(&self) -> String { let result: String; unsafe { @@ -704,6 +705,7 @@ where /// Used for creating Array object from native /// resource id, an 64 bit integer +#[allow(clippy::from_over_into)] impl Into> for af_array { fn into(self) -> Array { Array { diff --git a/src/core/index.rs b/src/core/index.rs index 17ec7b4aa..d87f0c1af 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -725,7 +725,7 @@ mod tests { fn non_macro_seq_assign() { set_device(0); // ANCHOR: non_macro_seq_assign - let mut a = constant(2.0 as f32, dim4!(5, 3)); + let mut a = constant(2.0_f32, dim4!(5, 3)); //print(&a); // 2.0 2.0 2.0 // 2.0 2.0 2.0 @@ -733,7 +733,7 @@ mod tests { // 2.0 2.0 2.0 // 2.0 2.0 2.0 - let b = constant(1.0 as f32, dim4!(3, 3)); + let b = constant(1.0_f32, dim4!(3, 3)); let seqs = [seq!(1:3:1), seq!()]; assign_seq(&mut a, &seqs, &b); //print(&a); @@ -800,7 +800,7 @@ mod tests { // 0.4587 0.6793 0.0346 // 0.5328 0.9347 0.0535 - let b = constant(2.0 as f32, dim4!(3, 3, 1, 1)); + let b = constant(2.0_f32, dim4!(3, 3, 1, 1)); let mut idxrs = Indexer::default(); idxrs.set_index(&indices, 0, None); // 2nd arg is indexing dimension diff --git a/src/core/macros.rs b/src/core/macros.rs index 4abba9ee7..366f0cc80 100644 --- a/src/core/macros.rs +++ b/src/core/macros.rs @@ -482,7 +482,7 @@ mod tests { let seq4gen = seq!(0:2:1); let mut a = randu::(dim4!(5, 3)); - let b = constant(2.0 as f32, dim4!(3, 3)); + let b = constant(2.0_f32, dim4!(3, 3)); eval!(a[indices, seq4gen] = b); // ANCHOR_END: macro_seq_array_assign diff --git a/tests/error_handler.rs b/tests/error_handler.rs index b0b740a4b..7b1bcb12d 100644 --- a/tests/error_handler.rs +++ b/tests/error_handler.rs @@ -24,7 +24,7 @@ fn check_error_handler_mutation() { let children = (0..4) .map(|i| { thread::Builder::new() - .name(format!("child {}", i + 1).to_string()) + .name(format!("child {}", i + 1)) .spawn(move || { let target_device = i % arrayfire::device_count(); println!( From 4e2d58d6493734e8a8a069057f9175d55c0578df Mon Sep 17 00:00:00 2001 From: Pradeep Garigipati Date: Sat, 12 Feb 2022 21:04:46 +0530 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Pradeep Garigipati --- build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 4bbba0cae..5b55757aa 100644 --- a/build.rs +++ b/build.rs @@ -430,9 +430,12 @@ fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec, Ve fn main() { // Setup pathing - let cargo_manifest_dir = match env::var("CARGO_MANIFEST_DIR") { + let cargo_manifest_dir = match env::var("CARGO_MANIFEST_DIR") { Ok(dir_path) => dir_path, - Err(error) => panic!("CARGO_MANIFEST_DIR environment variable is not available: {}", error), + Err(error) => panic!( + "CARGO_MANIFEST_DIR environment variable is not available: {}", + error + ), }; let src = Path::new(&cargo_manifest_dir); let conf_file = src.join("build.conf");