Skip to content

Commit 60f0ba9

Browse files
authored
Fix clippy warnings (#313)
1 parent 236dca8 commit 60f0ba9

File tree

9 files changed

+33
-20
lines changed

9 files changed

+33
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Cargo.lock
1414
# ide files
1515
.idea/
1616
.vscode/
17+
18+
#example downloads
19+
data/

build.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::env;
1212
use std::fs;
1313
use std::fs::OpenOptions;
1414
use std::io::{ErrorKind, Read};
15+
use std::path::Path;
1516
use std::path::PathBuf;
1617
use std::process::Command;
1718

@@ -95,7 +96,7 @@ fn run(cmd: &mut Command, program: &str) {
9596
}
9697
}
9798

98-
fn read_file(file_name: &std::path::PathBuf) -> String {
99+
fn read_file(file_name: &std::path::Path) -> String {
99100
let file_path = file_name.to_str().unwrap();
100101
let options = OpenOptions::new()
101102
.read(true)
@@ -115,7 +116,7 @@ fn read_file(file_name: &std::path::PathBuf) -> String {
115116
}
116117
}
117118

118-
fn read_conf(conf_file: &std::path::PathBuf) -> Config {
119+
fn read_conf(conf_file: &std::path::Path) -> Config {
119120
let raw_conf = read_file(conf_file);
120121
let decoded: Config = serde_json::from_str(&raw_conf).unwrap();
121122
decoded
@@ -198,7 +199,7 @@ fn prep_cmake_options(conf: &Config) -> Vec<String> {
198199
}
199200

200201
#[cfg(windows)]
201-
fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
202+
fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) {
202203
let _ = fs::create_dir(&build_dir);
203204

204205
let options = prep_cmake_options(conf);
@@ -243,7 +244,7 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
243244
}
244245

245246
#[cfg(not(windows))]
246-
fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
247+
fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) {
247248
let _ = fs::create_dir(&build_dir);
248249

249250
let options = prep_cmake_options(conf);
@@ -282,7 +283,7 @@ fn backend_exists(name: &str) -> bool {
282283
file_exists(&win_backend) || file_exists(&osx_backend) || file_exists(&linux_backend)
283284
}
284285

285-
fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>, Vec<String>) {
286+
fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec<String>, Vec<String>) {
286287
let mut backend_dirs: Vec<String> = Vec::new();
287288
let mut backends: Vec<String> = Vec::new();
288289

@@ -338,7 +339,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
338339
let mut ocl_lib_exists = false;
339340

340341
for backend_dir in backend_dirs.iter() {
341-
let lib_dir = PathBuf::from(backend_dir);
342+
let lib_dir = Path::new(backend_dir);
342343

343344
let culib_name = if cfg!(windows) {
344345
WIN_CUDA_LIB
@@ -429,7 +430,14 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
429430

430431
fn main() {
431432
// Setup pathing
432-
let src = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
433+
let cargo_manifest_dir = match env::var("CARGO_MANIFEST_DIR") {
434+
Ok(dir_path) => dir_path,
435+
Err(error) => panic!(
436+
"CARGO_MANIFEST_DIR environment variable is not available: {}",
437+
error
438+
),
439+
};
440+
let src = Path::new(&cargo_manifest_dir);
433441
let conf_file = src.join("build.conf");
434442
let conf = read_conf(&conf_file);
435443

examples/helloworld.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn main() {
8181
//print(&x.0);
8282
//print(&x.1);
8383

84-
let u8_cnst = &constant(1 as u8, dims);
84+
let u8_cnst = &constant(1_u8, dims);
8585
af_print!("u8 constant array", u8_cnst);
8686
println!(
8787
"Is u8_cnst array float precision type ? {}",

examples/neural_network.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod ann {
241241
println!("Epoch: {}, Error: {}", epoch + 1, avg_error);
242242
}
243243
}
244-
return avg_error;
244+
avg_error
245245
}
246246

247247
fn predict(&self, input: &Array<f32>) -> Array<f32> {
@@ -312,7 +312,7 @@ mod ann {
312312
MatProp::NONE,
313313
);
314314

315-
error = index(&err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]);
315+
error = index(err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]);
316316
}
317317
}
318318

@@ -333,7 +333,7 @@ fn accuracy(predicted: &Array<f32>, target: &Array<f32>) -> f32 {
333333
&predicted_max_indices,
334334
false,
335335
));
336-
return 100f32 * matches as f32 / target_max_indices.elements() as f32;
336+
100f32 * matches as f32 / target_max_indices.elements() as f32
337337
}
338338

339339
fn main() {

src/core/arith.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,18 +668,18 @@ where
668668
match (lo.is_scalar(), hi.is_scalar()) {
669669
(true, false) => {
670670
let l = tile(&lo, hi.dims());
671-
clamp_helper(&input, &l, &hi, batch)
671+
clamp_helper(input, &l, &hi, batch)
672672
}
673673
(false, true) => {
674674
let r = tile(&hi, lo.dims());
675-
clamp_helper(&input, &lo, &r, batch)
675+
clamp_helper(input, &lo, &r, batch)
676676
}
677677
(true, true) => {
678678
let l = tile(&lo, input.dims());
679679
let r = tile(&hi, input.dims());
680-
clamp_helper(&input, &l, &r, batch)
680+
clamp_helper(input, &l, &r, batch)
681681
}
682-
_ => clamp_helper(&input, &lo, &hi, batch),
682+
_ => clamp_helper(input, &lo, &hi, batch),
683683
}
684684
}
685685

src/core/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ where
682682
}
683683

684684
/// Fetch Array as String
685+
#[allow(clippy::inherent_to_string)]
685686
pub fn to_string(&self) -> String {
686687
let result: String;
687688
unsafe {
@@ -704,6 +705,7 @@ where
704705

705706
/// Used for creating Array object from native
706707
/// resource id, an 64 bit integer
708+
#[allow(clippy::from_over_into)]
707709
impl<T: HasAfEnum> Into<Array<T>> for af_array {
708710
fn into(self) -> Array<T> {
709711
Array {

src/core/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,15 @@ mod tests {
725725
fn non_macro_seq_assign() {
726726
set_device(0);
727727
// ANCHOR: non_macro_seq_assign
728-
let mut a = constant(2.0 as f32, dim4!(5, 3));
728+
let mut a = constant(2.0_f32, dim4!(5, 3));
729729
//print(&a);
730730
// 2.0 2.0 2.0
731731
// 2.0 2.0 2.0
732732
// 2.0 2.0 2.0
733733
// 2.0 2.0 2.0
734734
// 2.0 2.0 2.0
735735

736-
let b = constant(1.0 as f32, dim4!(3, 3));
736+
let b = constant(1.0_f32, dim4!(3, 3));
737737
let seqs = [seq!(1:3:1), seq!()];
738738
assign_seq(&mut a, &seqs, &b);
739739
//print(&a);
@@ -800,7 +800,7 @@ mod tests {
800800
// 0.4587 0.6793 0.0346
801801
// 0.5328 0.9347 0.0535
802802

803-
let b = constant(2.0 as f32, dim4!(3, 3, 1, 1));
803+
let b = constant(2.0_f32, dim4!(3, 3, 1, 1));
804804

805805
let mut idxrs = Indexer::default();
806806
idxrs.set_index(&indices, 0, None); // 2nd arg is indexing dimension

src/core/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ mod tests {
482482
let seq4gen = seq!(0:2:1);
483483
let mut a = randu::<f32>(dim4!(5, 3));
484484

485-
let b = constant(2.0 as f32, dim4!(3, 3));
485+
let b = constant(2.0_f32, dim4!(3, 3));
486486

487487
eval!(a[indices, seq4gen] = b);
488488
// ANCHOR_END: macro_seq_array_assign

tests/error_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn check_error_handler_mutation() {
2424
let children = (0..4)
2525
.map(|i| {
2626
thread::Builder::new()
27-
.name(format!("child {}", i + 1).to_string())
27+
.name(format!("child {}", i + 1))
2828
.spawn(move || {
2929
let target_device = i % arrayfire::device_count();
3030
println!(

0 commit comments

Comments
 (0)