Skip to content

Commit 3014f0a

Browse files
committed
Address clippy warnings in wrapper source code
1 parent 0d065ba commit 3014f0a

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

src/algorithm/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,14 +1524,12 @@ mod tests {
15241524
println!("reduction of bool matrix: {:?}", sum_all(&b));
15251525

15261526
println!(
1527-
"reduction of complex f32 matrix after replacing nan with {}: {:?}",
1528-
1.0,
1527+
"reduction of complex f32 matrix after replacing nan with 1.0: {:?}",
15291528
product_nan_all(&a, 1.0)
15301529
);
15311530

15321531
println!(
1533-
"reduction of bool matrix after replacing nan with {}: {:?}",
1534-
0.0,
1532+
"reduction of bool matrix after replacing nan with 0.0: {:?}",
15351533
sum_nan_all(&b, 0.0)
15361534
);
15371535
}

src/core/array.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ where
252252
dims.get().as_ptr() as *const c_longlong,
253253
strides.get().as_ptr() as *const c_longlong,
254254
aftype as c_uint,
255-
1 as c_uint,
255+
1_u32,
256256
);
257257
HANDLE_ERROR(AfError::from(err_val));
258258
temp.into()
@@ -482,7 +482,7 @@ where
482482
}
483483

484484
/// Returns the native FFI handle for Rust object `Array`
485-
pub unsafe fn get(&self) -> af_array {
485+
pub(crate) unsafe fn get(&self) -> af_array {
486486
self.handle
487487
}
488488

@@ -644,6 +644,11 @@ where
644644
/// Get the device pointer and lock the buffer in memory manager
645645
///
646646
/// The device pointer is not freed by memory manager until unlock is called.
647+
///
648+
/// # Safety
649+
///
650+
/// Using the function returns a pointer(CPU)/GPU-memory-pointer(CUDA)/cl_mem(OpenCL).
651+
/// Use this function only when you know what to do further with returned object.
647652
pub unsafe fn device_ptr(&self) -> void_ptr {
648653
let mut temp: void_ptr = std::ptr::null_mut();
649654
let err_val = af_get_device_ptr(&mut temp as *mut void_ptr, self.handle);
@@ -792,10 +797,7 @@ pub fn print_gen<T: HasAfEnum>(msg: String, input: &Array<T>, precision: Option<
792797
let err_val = af_print_array_gen(
793798
emptystring.to_bytes_with_nul().as_ptr() as *const c_char,
794799
input.get(),
795-
match precision {
796-
Some(p) => p,
797-
None => 4,
798-
} as c_int,
800+
precision.unwrap_or(4),
799801
);
800802
HANDLE_ERROR(AfError::from(err_val));
801803
}

src/core/data.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,11 @@ where
577577
// of only two more axes can be provided. Hence the below condition.
578578
assert!(left_over_new_axes.len() <= 2);
579579

580-
for a_idx in 0..left_over_new_axes.len() {
581-
new_axes[2 + a_idx] = left_over_new_axes[a_idx];
582-
}
580+
new_axes[2..(left_over_new_axes.len() + 2)].clone_from_slice(&left_over_new_axes[..]);
583581
}
584582
None => {
585-
for a_idx in 2..4 {
583+
let left_over_indices: Vec<usize> = (2..4).collect();
584+
for a_idx in left_over_indices {
586585
new_axes[a_idx] = a_idx as u64;
587586
}
588587
}

src/core/device.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ pub fn info_string(verbose: bool) -> String {
112112
/// # Return Values
113113
/// A tuple of `String` indicating the name, platform, toolkit and compute.
114114
pub fn device_info() -> (String, String, String, String) {
115-
let mut name = [0 as c_char; 64];
116-
let mut platform = [0 as c_char; 10];
117-
let mut toolkit = [0 as c_char; 64];
118-
let mut compute = [0 as c_char; 10];
115+
let mut name: [c_char; 64] = [0; 64];
116+
let mut platform: [c_char; 10] = [0; 10];
117+
let mut toolkit: [c_char; 64] = [0; 64];
118+
let mut compute: [c_char; 10] = [0; 10];
119119
unsafe {
120120
let err_val = af_device_info(
121121
&mut name[0],
@@ -320,6 +320,12 @@ pub fn sync(device: i32) {
320320
}
321321

322322
/// Allocate non-pageable memory on HOST memory
323+
///
324+
/// # Safety
325+
///
326+
/// Non-pageable memory allocations should be done by users
327+
/// who understand the consequences of such allocations on other
328+
/// tasks running on the system.
323329
pub unsafe fn alloc_pinned(bytes: usize) -> void_ptr {
324330
let mut out: void_ptr = std::ptr::null_mut();
325331
let err_val = af_alloc_pinned(&mut out as *mut void_ptr, bytes as dim_t);
@@ -328,6 +334,12 @@ pub unsafe fn alloc_pinned(bytes: usize) -> void_ptr {
328334
}
329335

330336
/// Free the pointer returned by [alloc_pinned](./fn.alloc_pinned.html)
337+
///
338+
/// # Safety
339+
///
340+
/// This function is intended to be called on pointers that were earlier
341+
/// allocated using [alloc_pinned](./fn.alloc_pinned.html). Any other values
342+
/// passed as argument would result in undefined behavior.
331343
pub unsafe fn free_pinned(ptr: void_ptr) {
332344
let err_val = af_free_pinned(ptr);
333345
HANDLE_ERROR(AfError::from(err_val));

src/core/index.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ where
169169
idxr.get(),
170170
&SeqInternal::from_seq(self) as *const SeqInternal,
171171
dim as dim_t,
172-
match is_batch {
173-
Some(value) => value,
174-
None => false,
175-
},
172+
is_batch.unwrap_or(false),
176173
);
177174
HANDLE_ERROR(AfError::from(err_val));
178175
}
@@ -230,7 +227,7 @@ impl<'object> Indexer<'object> {
230227
}
231228

232229
/// Get native(ArrayFire) resource handle
233-
pub unsafe fn get(&self) -> af_index_t {
230+
unsafe fn get(&self) -> af_index_t {
234231
self.handle
235232
}
236233
}

src/core/random.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ impl RandomEngine {
143143
let err_val = af_create_random_engine(
144144
&mut temp as *mut af_random_engine,
145145
rengine as c_uint,
146-
match seed {
147-
Some(s) => s,
148-
None => 0,
149-
} as u64_t,
146+
seed.unwrap_or(0u64),
150147
);
151148
HANDLE_ERROR(AfError::from(err_val));
152149
RandomEngine { handle: temp }
@@ -194,7 +191,7 @@ impl RandomEngine {
194191
}
195192

196193
/// Returns the native FFI handle for Rust object `RandomEngine`
197-
pub unsafe fn get(&self) -> af_random_engine {
194+
unsafe fn get(&self) -> af_random_engine {
198195
self.handle
199196
}
200197
}
@@ -274,7 +271,7 @@ pub fn get_default_random_engine() -> RandomEngine {
274271
let mut handle: af_random_engine = std::ptr::null_mut();
275272
err_val = af_retain_random_engine(&mut handle as *mut af_random_engine, temp);
276273
HANDLE_ERROR(AfError::from(err_val));
277-
RandomEngine { handle: handle }
274+
RandomEngine { handle }
278275
}
279276
}
280277

0 commit comments

Comments
 (0)