Skip to content

Fix clippy warnings #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Cargo.lock
# ide files
.idea/
.vscode/

#example downloads
data/
22 changes: 15 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -198,7 +199,7 @@ fn prep_cmake_options(conf: &Config) -> Vec<String> {
}

#[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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String>, Vec<String>) {
fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec<String>, Vec<String>) {
let mut backend_dirs: Vec<String> = Vec::new();
let mut backends: Vec<String> = Vec::new();

Expand Down Expand Up @@ -338,7 +339,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
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
Expand Down Expand Up @@ -429,7 +430,14 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,

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);

Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? {}",
Expand Down
6 changes: 3 additions & 3 deletions examples/neural_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ mod ann {
println!("Epoch: {}, Error: {}", epoch + 1, avg_error);
}
}
return avg_error;
avg_error
}

fn predict(&self, input: &Array<f32>) -> Array<f32> {
Expand Down Expand Up @@ -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)]);
}
}

Expand All @@ -333,7 +333,7 @@ fn accuracy(predicted: &Array<f32>, target: &Array<f32>) -> 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() {
Expand Down
8 changes: 4 additions & 4 deletions src/core/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ where
}

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

/// Used for creating Array object from native
/// resource id, an 64 bit integer
#[allow(clippy::from_over_into)]
impl<T: HasAfEnum> Into<Array<T>> for af_array {
fn into(self) -> Array<T> {
Array {
Expand Down
6 changes: 3 additions & 3 deletions src/core/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,15 @@ 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
// 2.0 2.0 2.0
// 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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ mod tests {
let seq4gen = seq!(0:2:1);
let mut a = randu::<f32>(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
Expand Down
2 changes: 1 addition & 1 deletion tests/error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down