mirror of
https://github.com/pykeio/ort
synced 2026-04-25 16:34:55 +02:00
refactor: fix a few deepsource issues
This commit is contained in:
41
build.rs
41
build.rs
@@ -271,15 +271,12 @@ fn copy_libraries(lib_dir: &Path, out_dir: &Path) {
|
||||
|
||||
let lib_files = fs::read_dir(lib_dir).unwrap();
|
||||
for lib_file in lib_files.filter(|e| {
|
||||
e.as_ref()
|
||||
.ok()
|
||||
.map(|e| {
|
||||
e.file_type().map(|e| e.is_file()).unwrap_or(false)
|
||||
&& [".dll", ".so", ".dylib"]
|
||||
.into_iter()
|
||||
.any(|v| e.path().into_os_string().into_string().unwrap().contains(v))
|
||||
})
|
||||
.unwrap_or(false)
|
||||
e.as_ref().ok().map_or(false, |e| {
|
||||
e.file_type().map_or(false, |e| !e.is_dir())
|
||||
&& [".dll", ".so", ".dylib"]
|
||||
.into_iter()
|
||||
.any(|v| e.path().into_os_string().into_string().unwrap().contains(v))
|
||||
})
|
||||
}) {
|
||||
let lib_file = lib_file.unwrap();
|
||||
let lib_path = lib_file.path();
|
||||
@@ -317,8 +314,7 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
|
||||
|
||||
match strategy
|
||||
.as_ref()
|
||||
.map(String::as_str)
|
||||
.unwrap_or_else(|_| if cfg!(feature = "prefer-compile-strategy") { "compile" } else { "download" })
|
||||
.map_or_else(|_| if cfg!(feature = "prefer-compile-strategy") { "compile" } else { "download" }, String::as_str)
|
||||
{
|
||||
"download" => {
|
||||
if target.contains("macos") {
|
||||
@@ -433,16 +429,19 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
|
||||
.expect("error running `protoc --help`");
|
||||
|
||||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let _cmake_toolchain = env::var(ORT_ENV_CMAKE_TOOLCHAIN).map(PathBuf::from).unwrap_or(
|
||||
if cfg!(target_os = "linux") && target.contains("aarch64") && target.contains("linux") {
|
||||
root.join("toolchains").join("default-aarch64-linux-gnu.cmake")
|
||||
} else if cfg!(target_os = "linux") && target.contains("aarch64") && target.contains("windows") {
|
||||
root.join("toolchains").join("default-aarch64-w64-mingw32.cmake")
|
||||
} else if cfg!(target_os = "linux") && target.contains("x86_64") && target.contains("windows") {
|
||||
root.join("toolchains").join("default-x86_64-w64-mingw32.cmake")
|
||||
} else {
|
||||
PathBuf::new()
|
||||
}
|
||||
let _cmake_toolchain = env::var(ORT_ENV_CMAKE_TOOLCHAIN).map_or_else(
|
||||
|_| {
|
||||
if cfg!(target_os = "linux") && target.contains("aarch64") && target.contains("linux") {
|
||||
root.join("toolchains").join("default-aarch64-linux-gnu.cmake")
|
||||
} else if cfg!(target_os = "linux") && target.contains("aarch64") && target.contains("windows") {
|
||||
root.join("toolchains").join("default-aarch64-w64-mingw32.cmake")
|
||||
} else if cfg!(target_os = "linux") && target.contains("x86_64") && target.contains("windows") {
|
||||
root.join("toolchains").join("default-x86_64-w64-mingw32.cmake")
|
||||
} else {
|
||||
PathBuf::default()
|
||||
}
|
||||
},
|
||||
PathBuf::from
|
||||
);
|
||||
|
||||
if cfg!(target_os = "linux") && target.contains("windows") && target.contains("aarch64") {
|
||||
|
||||
@@ -133,7 +133,7 @@ pub(crate) fn apply_execution_providers(options: *mut sys::OrtSessionOptions, ex
|
||||
let init_args = ep.options.clone();
|
||||
match ep.provider.as_str() {
|
||||
"CPUExecutionProvider" => {
|
||||
let use_arena = init_args.get("use_arena").map(|s| s.parse::<bool>().unwrap_or(false)).unwrap_or(false);
|
||||
let use_arena = init_args.get("use_arena").map_or(false, |s| s.parse::<bool>().unwrap_or(false));
|
||||
let status = unsafe { OrtSessionOptionsAppendExecutionProvider_CPU(options, use_arena.into()) };
|
||||
if status_to_result_and_log("CPU", status).is_ok() {
|
||||
return; // EP found
|
||||
@@ -185,7 +185,7 @@ pub(crate) fn apply_execution_providers(options: *mut sys::OrtSessionOptions, ex
|
||||
}
|
||||
#[cfg(feature = "acl")]
|
||||
"AclExecutionProvider" => {
|
||||
let use_arena = init_args.get("use_arena").map(|s| s.parse::<bool>().unwrap_or(false)).unwrap_or(false);
|
||||
let use_arena = init_args.get("use_arena").map_or(false, |s| s.parse::<bool>().unwrap_or(false));
|
||||
let status = unsafe { OrtSessionOptionsAppendExecutionProvider_ACL(options, use_arena.into()) };
|
||||
if status_to_result_and_log("ACL", status).is_ok() {
|
||||
return; // EP found
|
||||
@@ -193,7 +193,7 @@ pub(crate) fn apply_execution_providers(options: *mut sys::OrtSessionOptions, ex
|
||||
}
|
||||
#[cfg(feature = "onednn")]
|
||||
"DnnlExecutionProvider" => {
|
||||
let use_arena = init_args.get("use_arena").map(|s| s.parse::<bool>().unwrap_or(false)).unwrap_or(false);
|
||||
let use_arena = init_args.get("use_arena").map_or(false, |s| s.parse::<bool>().unwrap_or(false));
|
||||
let status = unsafe { OrtSessionOptionsAppendExecutionProvider_Dnnl(options, use_arena.into()) };
|
||||
if status_to_result_and_log("oneDNN", status).is_ok() {
|
||||
return; // EP found
|
||||
|
||||
Reference in New Issue
Block a user