diff --git a/build.rs b/build.rs index 43f41849..a718fe10 100644 --- a/build.rs +++ b/build.rs @@ -113,7 +113,7 @@ fn read_file(file_name: &std::path::Path) -> String { .read(true) .write(false) .create(false) - .open(&file_path); + .open(file_path); let mut file = match options { Ok(file) => file, @@ -256,13 +256,13 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) { #[cfg(not(windows))] fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) { - let _ = fs::create_dir(&build_dir); + let _ = fs::create_dir(build_dir); let options = prep_cmake_options(conf); println!("options are {:?}", options); let mut cmake_cmd = Command::new("cmake"); - cmake_cmd.current_dir(&build_dir); + cmake_cmd.current_dir(build_dir); run( cmake_cmd @@ -277,7 +277,7 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) { ); let mut make_cmd = Command::new("make"); - make_cmd.current_dir(&build_dir); + make_cmd.current_dir(build_dir); run( make_cmd .arg(format!("-j{}", conf.build_threads)) diff --git a/examples/neural_network.rs b/examples/neural_network.rs index 4fcb92a8..69110c97 100644 --- a/examples/neural_network.rs +++ b/examples/neural_network.rs @@ -81,6 +81,7 @@ pub(crate) mod model { pub trait Model { fn predict(&self, feature: &Array) -> Array; + #[allow(clippy::too_many_arguments)] fn train( &mut self, training_features: &Array, @@ -285,7 +286,7 @@ mod ann { fn back_propagate( &mut self, - signals: &Vec>, + signals: &[Array], labels: &Array, learning_rate_alpha: f64, ) { diff --git a/opencl-interop/examples/custom_kernel.rs b/opencl-interop/examples/custom_kernel.rs index 7780a9d9..dc7c3570 100644 --- a/opencl-interop/examples/custom_kernel.rs +++ b/opencl-interop/examples/custom_kernel.rs @@ -13,7 +13,7 @@ fn main() { af::info(); let dims = af::dim4!(8); - let af_buffer = af::constant(0f32, dims.clone()); + let af_buffer = af::constant(0f32, dims); af::af_print!("af_buffer", af_buffer); let src = r#" diff --git a/opencl-interop/examples/ocl_af_app.rs b/opencl-interop/examples/ocl_af_app.rs index 24fd09ea..8cc763f9 100644 --- a/opencl-interop/examples/ocl_af_app.rs +++ b/opencl-interop/examples/ocl_af_app.rs @@ -11,12 +11,12 @@ fn main() { // Choose platform & device(s) to use. Create a context, queue, let platform_id = ocl_core::default_platform().unwrap(); - let device_ids = ocl_core::get_device_ids(&platform_id, None, None).unwrap(); + let device_ids = ocl_core::get_device_ids(platform_id, None, None).unwrap(); let device_id = device_ids[0]; let context_properties = ContextProperties::new().platform(platform_id); let context = ocl_core::create_context(Some(&context_properties), &[device_id], None, None).unwrap(); - let queue = ocl_core::create_command_queue(&context, &device_id, None).unwrap(); + let queue = ocl_core::create_command_queue(&context, device_id, None).unwrap(); let dims = [8, 1, 1]; // Create a `Buffer`: diff --git a/opencl-interop/examples/trivial.rs b/opencl-interop/examples/trivial.rs index d29020ef..dffbd3f7 100644 --- a/opencl-interop/examples/trivial.rs +++ b/opencl-interop/examples/trivial.rs @@ -18,7 +18,7 @@ fn main() { // (1) Define which platform and device(s) to use. Create a context, // queue, and program then define some dims.. let platform_id = core::default_platform().unwrap(); - let device_ids = core::get_device_ids(&platform_id, None, None).unwrap(); + let device_ids = core::get_device_ids(platform_id, None, None).unwrap(); let device_id = device_ids[0]; let context_properties = ContextProperties::new().platform(platform_id); let context = @@ -33,7 +33,7 @@ fn main() { None, ) .unwrap(); - let queue = core::create_command_queue(&context, &device_id, None).unwrap(); + let queue = core::create_command_queue(&context, device_id, None).unwrap(); let dims = [1 << 20, 1, 1]; // (2) Create a `Buffer`: diff --git a/opencl-interop/src/lib.rs b/opencl-interop/src/lib.rs index 068e9ec9..d47b0322 100644 --- a/opencl-interop/src/lib.rs +++ b/opencl-interop/src/lib.rs @@ -37,6 +37,7 @@ pub enum DeviceType { GPU = CL_DEVICE_TYPE_GPU, ACCEL = CL_DEVICE_TYPE_ACCELERATOR, ALL = CL_DEVICE_TYPE_ALL, + UNKNOWN, } extern "C" { @@ -139,8 +140,8 @@ pub fn get_device_type() -> DeviceType { let err_val = unsafe { afcl_get_device_type(&mut out as *mut c_int) }; handle_error_general(AfError::from(err_val)); match out { - -1 => unsafe { mem::transmute(out as u64) }, - _ => DeviceType::ALL, + -1 => DeviceType::UNKNOWN, + _ => unsafe { mem::transmute::(out as u64) }, } } diff --git a/src/algorithm/mod.rs b/src/algorithm/mod.rs index def42fbf..3b4f9f54 100644 --- a/src/algorithm/mod.rs +++ b/src/algorithm/mod.rs @@ -3,6 +3,8 @@ use super::core::{ HANDLE_ERROR, }; +use core::borrow::Borrow; + use libc::{c_double, c_int, c_uint}; extern "C" { @@ -145,13 +147,20 @@ extern "C" { macro_rules! dim_reduce_func_def { ($doc_str: expr, $fn_name: ident, $ffi_name: ident, $out_type: ty) => { #[doc=$doc_str] - pub fn $fn_name(input: &Array, dim: i32) -> Array<$out_type> + pub fn $fn_name(input: A, dim: i32) -> Array<$out_type> where T: HasAfEnum, $out_type: HasAfEnum, + A: Borrow>, { let mut temp: af_array = std::ptr::null_mut(); - let err_val = unsafe { $ffi_name(&mut temp as *mut af_array, input.get(), dim) }; + let err_val = unsafe { + $ffi_name( + std::ptr::from_mut::(&mut temp), + input.borrow().get(), + dim, + ) + }; HANDLE_ERROR(AfError::from(err_val)); temp.into() } @@ -783,7 +792,7 @@ all_reduce_func_def2!( /// /// - `input` is the input Array /// - `val` is the val that replaces all `NAN` values of the Array before reduction operation is -/// performed. +/// performed. /// /// # Return Values /// @@ -829,7 +838,7 @@ where /// /// - `input` is the input Array /// - `val` is the val that replaces all `NAN` values of the Array before reduction operation is -/// performed. +/// performed. /// /// # Return Values /// @@ -1238,7 +1247,7 @@ where /// - `key` is the key Array /// - `input` is the data on which scan is to be performed /// - `dim` is the dimension along which scan operation is to be performed -/// - `op` takes value of [BinaryOp](./enum.BinaryOp.html) enum indicating +/// - `op` takes value of [`BinaryOp`](./enum.BinaryOp.html) enum indicating /// the type of scan operation /// - `inclusive` says if inclusive/exclusive scan is to be performed /// @@ -1260,7 +1269,7 @@ where let mut temp: af_array = std::ptr::null_mut(); let err_val = unsafe { af_scan_by_key( - &mut temp as *mut af_array, + std::ptr::from_mut::(&mut temp), key.get(), input.get(), dim, @@ -1300,8 +1309,8 @@ macro_rules! dim_reduce_by_key_func_def { let mut out_vals: af_array = std::ptr::null_mut(); let err_val = unsafe { $ffi_name( - &mut out_keys as *mut af_array, - &mut out_vals as *mut af_array, + std::ptr::from_mut::(&mut out_keys), + std::ptr::from_mut::(&mut out_vals), keys.get(), vals.get(), dim, diff --git a/src/blas/mod.rs b/src/blas/mod.rs index 040858e4..3e070fd6 100644 --- a/src/blas/mod.rs +++ b/src/blas/mod.rs @@ -214,7 +214,7 @@ where /// /// - `arr` is the input Array /// - `conjugate` is a boolean that indicates if the transpose operation needs to be a conjugate -/// transpose +/// transpose /// /// # Return Values /// @@ -232,7 +232,7 @@ pub fn transpose(arr: &Array, conjugate: bool) -> Array { /// /// - `arr` is the input Array that has to be transposed /// - `conjugate` is a boolean that indicates if the transpose operation needs to be a conjugate -/// transpose +/// transpose pub fn transpose_inplace(arr: &mut Array, conjugate: bool) { let err_val = unsafe { af_transpose_inplace(arr.get(), conjugate) }; HANDLE_ERROR(AfError::from(err_val)); diff --git a/src/core/arith.rs b/src/core/arith.rs index d0f1dda8..46d10e8f 100644 --- a/src/core/arith.rs +++ b/src/core/arith.rs @@ -10,6 +10,7 @@ use num::Zero; use libc::c_int; use num::Complex; +use std::borrow::Borrow; use std::mem; use std::ops::Neg; use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Not, Rem, Shl, Shr, Sub}; @@ -122,11 +123,11 @@ macro_rules! unary_func { #[doc=$doc_str] /// /// This is an element wise unary operation. - pub fn $fn_name(input: &Array) -> Array< T::$out_type > + pub fn $fn_name>>(input: A) -> Array< T::$out_type > where T::$out_type: HasAfEnum { let mut temp: af_array = std::ptr::null_mut(); - let err_val = unsafe { $ffi_fn(&mut temp as *mut af_array, input.get()) }; + let err_val = unsafe { $ffi_fn(&mut temp as *mut af_array, input.borrow().get()) }; HANDLE_ERROR(AfError::from(err_val)); temp.into() @@ -251,7 +252,7 @@ unary_func!( ); macro_rules! unary_boolean_func { - [$doc_str: expr, $fn_name: ident, $ffi_fn: ident] => ( + [$doc_str: expr, $fn_name: ident, $method_name: ident, $ffi_fn: ident] => ( #[doc=$doc_str] /// /// This is an element wise unary operation. @@ -263,12 +264,22 @@ macro_rules! unary_boolean_func { temp.into() } + + impl Array { + #[doc=$doc_str] + /// + /// Element-wise unary operation. + pub fn $method_name(&self) -> Array { + crate::core::arith::$fn_name(self) + } + } ) } -unary_boolean_func!("Check if values are zero", iszero, af_iszero); -unary_boolean_func!("Check if values are infinity", isinf, af_isinf); -unary_boolean_func!("Check if values are NaN", isnan, af_isnan); +// TODO: Re-evaluate method names.. +unary_boolean_func!("Check if values are zero", iszero, zeros, af_iszero); +unary_boolean_func!("Check if values are infinity", isinf, infs, af_isinf); +unary_boolean_func!("Check if values are NaN", isnan, nans, af_isnan); macro_rules! binary_func { ($doc_str: expr, $fn_name: ident, $ffi_fn: ident) => { @@ -331,7 +342,7 @@ binary_func!( af_hypot ); -/// Type Trait to convert to an [Array](./struct.Array.html) +/// Type Trait to convert to an [`Array`](./struct.Array.html) /// /// Generic functions that overload the binary operations such as add, div, mul, rem, ge etc. are /// bound by this trait to allow combinations of scalar values and Array objects as parameters @@ -874,7 +885,9 @@ shift_spec!(Shr, shr); #[cfg(op_assign)] mod op_assign { - use super::*; + use super::{ + add, bitand, bitor, bitxor, div, mem, mul, rem, shiftl, shiftr, sub, ImplicitPromote, + }; use crate::core::{assign_gen, Array, Indexer, Seq}; use std::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign}; @@ -973,12 +986,12 @@ where } /// Perform bitwise complement on all values of Array -pub fn bitnot(input: &Array) -> Array +pub fn bitnot(input: &Array) -> Array where T: HasAfEnum + IntegralType, { let mut temp: af_array = std::ptr::null_mut(); - let err_val = unsafe { af_bitnot(&mut temp as *mut af_array, input.get()) }; + let err_val = unsafe { af_bitnot(std::ptr::from_mut::(&mut temp), input.get()) }; HANDLE_ERROR(AfError::from(err_val)); temp.into() } diff --git a/src/core/array.rs b/src/core/array.rs index 7ee6579b..9005cabf 100644 --- a/src/core/array.rs +++ b/src/core/array.rs @@ -169,7 +169,7 @@ extern "C" { /// /// ### NOTE /// -/// All operators(traits) from std::ops module implemented for Array object +/// All operators(traits) from [`std::ops`] module implemented for Array object /// carry out element wise operations. For example, `*` does multiplication of /// elements at corresponding locations in two different Arrays. pub struct Array { @@ -190,7 +190,7 @@ macro_rules! is_func { pub fn $fn_name(&self) -> bool { unsafe { let mut ret_val: bool = false; - let err_val = $ffi_fn(&mut ret_val as *mut bool, self.handle); + let err_val = $ffi_fn(std::ptr::from_mut::(&mut ret_val), self.handle); HANDLE_ERROR(AfError::from(err_val)); ret_val } @@ -214,7 +214,7 @@ where /// let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1])); /// print(&indices); /// ``` - /// An example of creating an Array from half::f16 array + /// An example of creating an Array from [`half::f16`] array /// /// ```rust /// use arrayfire::{Array, Dim4, is_half_available, print}; @@ -239,10 +239,10 @@ where let mut temp: af_array = std::ptr::null_mut(); let err_val = unsafe { af_create_array( - &mut temp as *mut af_array, - slice.as_ptr() as *const c_void, + std::ptr::from_mut::(&mut temp), + slice.as_ptr().cast::(), dims.ndims() as c_uint, - dims.get().as_ptr() as *const c_longlong, + dims.get().as_ptr().cast::(), aftype as c_uint, ) }; @@ -259,12 +259,12 @@ where let mut temp: af_array = std::ptr::null_mut(); let err_val = unsafe { af_create_strided_array( - &mut temp as *mut af_array, - slice.as_ptr() as *const c_void, + std::ptr::from_mut::(&mut temp), + slice.as_ptr().cast::(), offset as dim_t, dims.ndims() as c_uint, - dims.get().as_ptr() as *const c_longlong, - strides.get().as_ptr() as *const c_longlong, + dims.get().as_ptr().cast::(), + strides.get().as_ptr().cast::(), aftype as c_uint, 1_u32, ) @@ -287,9 +287,9 @@ where let mut temp: af_array = std::ptr::null_mut(); let err_val = unsafe { af_create_handle( - &mut temp as *mut af_array, + std::ptr::from_mut::(&mut temp), dims.ndims() as c_uint, - dims.get().as_ptr() as *const c_longlong, + dims.get().as_ptr().cast::(), aftype as c_uint, ) }; @@ -374,7 +374,7 @@ where let mut temp: af_array = std::ptr::null_mut(); let err_val = unsafe { af_device_array( - &mut temp as *mut af_array, + std::ptr::from_mut::(&mut temp), dev_ptr as *mut c_void, dims.ndims() as c_uint, dims.get().as_ptr() as *const dim_t, @@ -393,7 +393,8 @@ where /// was active when Array was created. pub fn get_backend(&self) -> Backend { let mut ret_val: u32 = 0; - let err_val = unsafe { af_get_backend_id(&mut ret_val as *mut c_uint, self.handle) }; + let err_val = + unsafe { af_get_backend_id(std::ptr::from_mut::(&mut ret_val), self.handle) }; HANDLE_ERROR(AfError::from(err_val)); match (err_val, ret_val) { (0, 1) => Backend::CPU, @@ -410,7 +411,8 @@ where /// Return the device id on which Array was created. pub fn get_device_id(&self) -> i32 { let mut ret_val: i32 = 0; - let err_val = unsafe { af_get_device_id(&mut ret_val as *mut c_int, self.handle) }; + let err_val = + unsafe { af_get_device_id(std::ptr::from_mut::(&mut ret_val), self.handle) }; HANDLE_ERROR(AfError::from(err_val)); ret_val } @@ -418,7 +420,8 @@ where /// Returns the number of elements in the Array pub fn elements(&self) -> usize { let mut ret_val: dim_t = 0; - let err_val = unsafe { af_get_elements(&mut ret_val as *mut dim_t, self.handle) }; + let err_val = + unsafe { af_get_elements(std::ptr::from_mut::(&mut ret_val), self.handle) }; HANDLE_ERROR(AfError::from(err_val)); ret_val as usize } @@ -530,6 +533,44 @@ where HANDLE_ERROR(AfError::from(err_val)); } + /// Creates a new vector and copies Array data into it + /// + /// # Examples + /// + /// ``` + /// use arrayfire::{Array, Dim4}; + /// let a = Array::new(&[1,2,3,4], Dim4::new(&[2,2,1,1])); + /// let v = a.host_vec(); + /// assert_eq!(v, vec![1,2,3,4]); + /// ``` + pub fn host_vec(&self) -> Vec { + let mut r = vec![T::default(); self.elements()]; + self.host(&mut r); + r + } + + /// Returns the value contained in this Array as a scalar if it only contains a single value + /// + /// If the Array contains exactly one element, returns Some(value). If it contains + /// more than one element, returns None. + /// + /// # Examples + /// + /// ``` + /// use arrayfire::{Array, Dim4}; + /// let a = Array::new(&[1.0f32], Dim4::new(&[1, 1, 1, 1])); + /// assert_eq!(a.scalar(), Some(1.0f32)); + /// ``` + pub fn scalar(&self) -> Option { + let n = self.elements(); + if n != 1 { + return None; + } + let mut v = [T::default(); 1]; + self.host(&mut v); + Some(v[0]) + } + /// Evaluates any pending lazy expressions that represent the data in the Array object pub fn eval(&self) { let err_val = unsafe { af_eval(self.handle) }; diff --git a/src/core/data.rs b/src/core/data.rs index 75308807..f04ea6b5 100644 --- a/src/core/data.rs +++ b/src/core/data.rs @@ -181,8 +181,8 @@ impl ConstGenerator for c32 { let err_val = unsafe { af_constant_complex( &mut temp as *mut af_array, - (*self).re as c_double, - (*self).im as c_double, + self.re as c_double, + self.im as c_double, dims.ndims() as c_uint, dims.get().as_ptr() as *const dim_t, 1, @@ -201,8 +201,8 @@ impl ConstGenerator for c64 { let err_val = unsafe { af_constant_complex( &mut temp as *mut af_array, - (*self).re as c_double, - (*self).im as c_double, + self.re as c_double, + self.im as c_double, dims.ndims() as c_uint, dims.get().as_ptr() as *const dim_t, 3, @@ -321,7 +321,7 @@ where /// /// - `dims` is the size of Array /// - `seq_dim` is the dimension along which range values are populated, all values along other -/// dimensions are just repeated +/// dimensions are just repeated /// /// # Return Values /// Array @@ -403,7 +403,7 @@ pub fn identity(dims: Dim4) -> Array { /// /// - `input` is the input Array /// - `dim` is the diagonal index relative to principal diagonal where values from input Array are -/// to be placed +/// to be placed /// /// # Return Values /// @@ -789,10 +789,10 @@ where /// # Parameters /// /// - `a` is the Array whose element will be assigned to output if corresponding element in `cond` Array is -/// `True` +/// `True` /// - `cond` is the Array with boolean values /// - `b` is the Array whose element will be assigned to output if corresponding element in `cond` Array is -/// `False` +/// `False` /// /// # Return Values /// @@ -819,10 +819,10 @@ where /// # Parameters /// /// - `a` is the scalar that is assigned to output if corresponding element in `cond` Array is -/// `True` +/// `True` /// - `cond` is the Array with conditional values /// - `b` is the Array whose element will be assigned to output if corresponding element in `cond` Array is -/// `False` +/// `False` /// /// # Return Values /// @@ -849,10 +849,10 @@ where /// # Parameters /// /// - `a` is the Array whose element will be assigned to output if corresponding element in `cond` Array is -/// `True` +/// `True` /// - `cond` is the Array with conditional values /// - `b` is the scalar that is assigned to output if corresponding element in `cond` Array is -/// `False` +/// `False` /// /// # Return Values /// @@ -881,7 +881,7 @@ where /// - `a` is the Array whose element will be replaced with element from `b` if corresponding element in `cond` Array is `True` /// - `cond` is the Array with conditional values /// - `b` is the Array whose element will replace the element in output if corresponding element in `cond` Array is -/// `False` +/// `False` /// /// # Return Values /// @@ -908,7 +908,7 @@ where /// - `a` is the Array whose element will be replaced with element from `b` if corresponding element in `cond` Array is `True` /// - `cond` is the Array with conditional values /// - `b` is the scalar that will replace the element in output if corresponding element in `cond` Array is -/// `False` +/// `False` /// /// # Return Values /// diff --git a/src/core/index.rs b/src/core/index.rs index b4a1b2a2..f3f76f4d 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -263,7 +263,7 @@ where &mut temp as *mut af_array, input.get(), seqs.len() as u32, - seqs.as_ptr() as *const SeqInternal, + seqs.as_ptr(), ) }; HANDLE_ERROR(AfError::from(err_val)); @@ -535,7 +535,7 @@ where &mut temp as *mut af_array, lhs.get() as af_array, seqs.len() as c_uint, - seqs.as_ptr() as *const SeqInternal, + seqs.as_ptr(), rhs.get() as af_array, ) }; @@ -800,7 +800,8 @@ mod tests { idxrs.set_index(&indices, 0, None); // 2nd arg is indexing dimension idxrs.set_index(&seq4gen, 1, Some(false)); // 3rd arg indicates batch operation - let _sub2 = assign_gen(&mut a, &idxrs, &b); + assign_gen(&mut a, &idxrs, &b); + // let _sub2 = assign_gen(&mut a, &idxrs, &b); //println!("a(indices, seq(0, 2, 1))"); print(&sub2); // [5 3 1 1] // 0.0000 0.2190 0.3835 diff --git a/src/core/macros.rs b/src/core/macros.rs index 366f0cc8..d150276a 100644 --- a/src/core/macros.rs +++ b/src/core/macros.rs @@ -543,8 +543,8 @@ mod tests { let inpt: Vec = (0..10).collect(); let gold: Vec = vec![2, 3, 7, 8]; - println!("input {:?}", inpt); - println!("gold {:?}", gold); + println!("input {inpt:?}"); + println!("gold {gold:?}"); let orig_arr = Array::new(&inpt, dim4!(5, 2)); diff --git a/src/core/random.rs b/src/core/random.rs index f05dd606..56413b51 100644 --- a/src/core/random.rs +++ b/src/core/random.rs @@ -53,7 +53,7 @@ pub fn set_seed(seed: u64) { pub fn get_seed() -> u64 { let mut ret_val: u64 = 0; - let err_val = unsafe { af_get_seed(&mut ret_val as *mut u64_t) }; + let err_val = unsafe { af_get_seed(std::ptr::from_mut::(&mut ret_val)) }; HANDLE_ERROR(AfError::from(err_val)); ret_val @@ -129,17 +129,17 @@ impl RandomEngine { /// /// # Parameters /// - /// - `rengine` can be value of [RandomEngineType](./enum.RandomEngineType.html) enum. + /// - `rengine` can be value of [`RandomEngineType`](./enum.RandomEngineType.html) enum. /// - `seed` is the initial seed value /// /// # Return Values /// - /// A object of type RandomEngine + /// A object of type [`RandomEngine`] pub fn new(rengine: RandomEngineType, seed: Option) -> Self { let mut temp: af_random_engine = std::ptr::null_mut(); let err_val = unsafe { af_create_random_engine( - &mut temp as *mut af_random_engine, + std::ptr::from_mut::(&mut temp), rengine as c_uint, seed.unwrap_or(0u64), ) @@ -152,7 +152,9 @@ impl RandomEngine { pub fn get_type(&self) -> RandomEngineType { let mut temp: u32 = 0; - let err_val = unsafe { af_random_engine_get_type(&mut temp as *mut c_uint, self.handle) }; + let err_val = unsafe { + af_random_engine_get_type(std::ptr::from_mut::(&mut temp), self.handle) + }; HANDLE_ERROR(AfError::from(err_val)); RandomEngineType::from(temp) @@ -162,7 +164,7 @@ impl RandomEngine { pub fn set_type(&mut self, engine_type: RandomEngineType) { let err_val = unsafe { af_random_engine_set_type( - &mut self.handle as *mut af_random_engine, + std::ptr::from_mut::(&mut self.handle), engine_type as c_uint, ) }; @@ -181,7 +183,9 @@ impl RandomEngine { pub fn get_seed(&self) -> u64 { let mut seed: u64 = 0; - let err_val = unsafe { af_random_engine_get_seed(&mut seed as *mut u64_t, self.handle) }; + let err_val = unsafe { + af_random_engine_get_seed(std::ptr::from_mut::(&mut seed), self.handle) + }; HANDLE_ERROR(AfError::from(err_val)); seed @@ -197,8 +201,12 @@ impl RandomEngine { impl Clone for RandomEngine { fn clone(&self) -> Self { let mut temp: af_random_engine = std::ptr::null_mut(); - let err_val = - unsafe { af_retain_random_engine(&mut temp as *mut af_random_engine, self.handle) }; + let err_val = unsafe { + af_retain_random_engine( + std::ptr::from_mut::(&mut temp), + self.handle, + ) + }; HANDLE_ERROR(AfError::from(err_val)); RandomEngine::from(temp) } @@ -259,10 +267,13 @@ mod afserde { /// Get default random engine pub fn get_default_random_engine() -> RandomEngine { let mut temp: af_random_engine = std::ptr::null_mut(); - let mut err_val = unsafe { af_get_default_random_engine(&mut temp as *mut af_random_engine) }; + let mut err_val = + unsafe { af_get_default_random_engine(std::ptr::from_mut::(&mut temp)) }; HANDLE_ERROR(AfError::from(err_val)); let mut handle: af_random_engine = std::ptr::null_mut(); - err_val = unsafe { af_retain_random_engine(&mut handle as *mut af_random_engine, temp) }; + err_val = unsafe { + af_retain_random_engine(std::ptr::from_mut::(&mut handle), temp) + }; HANDLE_ERROR(AfError::from(err_val)); RandomEngine { handle } } @@ -271,7 +282,7 @@ pub fn get_default_random_engine() -> RandomEngine { /// /// # Parameters /// -/// - `rtype` can take one of the values of enum [RandomEngineType](./enum.RandomEngineType.html) +/// - `rtype` can take one of the values of enum [`RandomEngineType`](./enum.RandomEngineType.html) pub fn set_default_random_engine_type(rtype: RandomEngineType) { let err_val = unsafe { af_set_default_random_engine_type(rtype as c_uint) }; HANDLE_ERROR(AfError::from(err_val)); @@ -282,7 +293,7 @@ pub fn set_default_random_engine_type(rtype: RandomEngineType) { /// # Parameters /// /// - `dims` is output array dimensions -/// - `engine` is an object of type [RandomEngine](./struct.RandomEngine.html) +/// - `engine` is an object of type [`RandomEngine`](./struct.RandomEngine.html) /// /// # Return Values /// diff --git a/src/graphics/mod.rs b/src/graphics/mod.rs index 64777e7f..aa32fb18 100644 --- a/src/graphics/mod.rs +++ b/src/graphics/mod.rs @@ -988,7 +988,7 @@ impl Window { /// /// - `points` is an Array containing list of coordinates of vector field /// - `directions` is an Array containing directions at the coordinates specified in `points` - /// Array. + /// Array. /// - `title` parameter has effect only in multiview mode, where this string /// is displayed as the respective cell/view title. pub fn draw_vector_field( diff --git a/src/image/mod.rs b/src/image/mod.rs index 0b0e3ba3..eb9223c0 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -428,7 +428,7 @@ where /// - `odim0` is the output height /// - `odim1` is the output width /// - `method` indicates which interpolation method to use for resizing. It uses enum -/// [InterpType](./enum.InterpType.html) to identify the interpolation method. +/// [InterpType](./enum.InterpType.html) to identify the interpolation method. /// /// # Return Values /// @@ -476,7 +476,7 @@ pub fn resize( /// - `odim0` is the output height /// - `odim1` is the output width /// - `method` indicates which interpolation method to use for resizing. It uses enum -/// [InterpType](./enum.InterpType.html) to identify the interpolation method. +/// [InterpType](./enum.InterpType.html) to identify the interpolation method. /// - `is_inverse` indicates if to apply inverse/forward transform /// /// # Return Values @@ -530,7 +530,7 @@ pub fn transform( /// - `theta` is the amount of angle (in radians) image should be rotated /// - `crop` indicates if the rotated image has to be cropped to original size /// - `method` indicates which interpolation method to use for rotating the image. It uses enum -/// [InterpType](./enum.InterpType.html) to identify the interpolation method. +/// [InterpType](./enum.InterpType.html) to identify the interpolation method. /// /// # Return Values /// @@ -666,7 +666,7 @@ pub fn scale( /// - `odim0` is the output length along first dimension /// - `odim1` is the output length along second dimension /// - `method` indicates which interpolation method to use for rotating the image. It uses enum -/// [InterpType](./enum.InterpType.html) to identify the interpolation method. +/// [InterpType](./enum.InterpType.html) to identify the interpolation method. /// - `is_inverse` indicates if to apply inverse/forward transform /// /// # Return Values @@ -1036,7 +1036,7 @@ pub fn gaussian_kernel(rows: i32, cols: i32, sigma_r: f64, sigma_c: f64) -> Arra /// - `input` is the input image /// - `tospace` is the target color space. Takes values of [ColorSpace](./enum.ColorSpace.html) /// - `fromspace` is the source image color space. Takes values of -/// [ColorSpace](./enum.ColorSpace.html) +/// [ColorSpace](./enum.ColorSpace.html) /// /// # Return Values /// @@ -1422,7 +1422,7 @@ where /// /// - `input` is the input image in YCbCr color space /// - `standard` is the [YCbCr standard](./enum.YCCStd.html) in which input image color space is -/// present. +/// present. /// /// # Return Values /// @@ -1488,7 +1488,7 @@ where /// /// - `input` is the input image /// - `moment` is the type of moment to be computed, takes a value of -/// [enum](./enum.MomentType.html) +/// [enum](./enum.MomentType.html) /// /// # Return Values /// @@ -1509,7 +1509,7 @@ where /// /// - `input` is the input image /// - `moment` is the type of moment to be computed, takes a value of -/// [enum](./enum.MomentType.html) +/// [enum](./enum.MomentType.html) /// /// # Return Values /// diff --git a/src/lapack/mod.rs b/src/lapack/mod.rs index 1866108f..6fa49786 100644 --- a/src/lapack/mod.rs +++ b/src/lapack/mod.rs @@ -101,7 +101,7 @@ where /// # Parameters /// /// - `in` is the input/output matrix. This will contain random data after the function call is -/// complete. +/// complete. /// /// # Return Values /// @@ -440,9 +440,9 @@ where /// - `input` is the input matrix /// - `ntype` is specifies the required norm type using enum [NormType](./enum.NormType.html) /// - `p` specifies the value of *P* when `ntype` is one of VECTOR_P, MATRIX_L_PQ. It is ignored -/// for other values of `ntype` +/// for other values of `ntype` /// - `q` specifies the value of *Q* when `ntype` is MATRIX_L_PQ. This parameter is ignored if -/// `ntype` is anything else. +/// `ntype` is anything else. /// /// # Return Values /// diff --git a/src/lib.rs b/src/lib.rs index 509fefa2..ffe65753 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,6 @@ )] #![warn(missing_docs)] #![allow(non_camel_case_types)] - #[macro_use] extern crate lazy_static; diff --git a/src/signal/mod.rs b/src/signal/mod.rs index 1a1529a2..42820a36 100644 --- a/src/signal/mod.rs +++ b/src/signal/mod.rs @@ -185,7 +185,7 @@ extern "C" { /// - `input` is the input Array /// - `pos` Array contains the interpolation locations /// - `method` indicates the type of interpolation method that be used. It is of type enum -/// [InterpType](./enum.InterpType.html) +/// [InterpType](./enum.InterpType.html) /// - `off_grid` is the value that will set in the output Array when certain index is out of bounds /// /// # Return Values @@ -248,7 +248,7 @@ pub fn approx1_v2( /// - `start` is the first index along `interp_dim` /// - `step` is the uniform spacing value between subsequent indices along `interp_dim` /// - `method` indicates the type of interpolation method that be used. It is of type enum -/// [InterpType](./enum.InterpType.html) +/// [InterpType](./enum.InterpType.html) /// - `off_grid` is the value that will set in the output Array when certain index is out of bounds /// /// # Return Values @@ -322,7 +322,7 @@ pub fn approx1_uniform_v2( /// - `pos0` Array contains the interpolation locations for first dimension /// - `pos1` Array contains the interpolation locations for second dimension /// - `method` indicates the type of interpolation method that be used. It is of type enum -/// [InterpType](./enum.InterpType.html) +/// [InterpType](./enum.InterpType.html) /// - `off_grid` is the value that will set in the output Array when certain index is out of bounds /// /// # Return Values @@ -393,7 +393,7 @@ pub fn approx2_v2( /// - `start0` is the first index along `interp_dim1` /// - `step0` is the uniform spacing value between subsequent indices along `interp_dim1` /// - `method` indicates the type of interpolation method that be used. It is of type enum -/// [InterpType](./enum.InterpType.html) +/// [InterpType](./enum.InterpType.html) /// - `off_grid` is the value that will set in the output Array when certain index is out of bounds /// /// # Return Values @@ -492,9 +492,9 @@ pub fn set_fft_plan_cache_size(cache_size: usize) { /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signals - used for either truncating or padding the input -/// signals +/// signals /// /// # Return Values /// @@ -516,7 +516,7 @@ where /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signal first dimension - used for either truncating or padding the input /// - `odim1` is the length of output signal second dimension - used for either truncating or padding the input /// @@ -553,7 +553,7 @@ where /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signal first dimension - used for either truncating or padding the input /// - `odim1` is the length of output signal second dimension - used for either truncating or padding the input /// - `odim2` is the length of output signal third dimension - used for either truncating or padding the input @@ -593,9 +593,9 @@ where /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signals - used for either truncating or padding the input -/// signals +/// signals /// /// # Return Values /// @@ -617,7 +617,7 @@ where /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signal first dimension - used for either truncating or padding the input /// - `odim1` is the length of output signal second dimension - used for either truncating or padding the input /// @@ -654,7 +654,7 @@ where /// /// - `input` is the input Array /// - `norm_factor` is the normalization factor with which the input is scaled before the -/// transformation is applied +/// transformation is applied /// - `odim0` is the length of output signal first dimension - used for either truncating or padding the input /// - `odim1` is the length of output signal second dimension - used for either truncating or padding the input /// - `odim2` is the length of output signal third dimension - used for either truncating or padding the input diff --git a/src/vision/mod.rs b/src/vision/mod.rs index 35be9105..61c340e7 100644 --- a/src/vision/mod.rs +++ b/src/vision/mod.rs @@ -214,14 +214,14 @@ impl Drop for Features { /// /// - `input` - the input image Array /// - `thr` - FAST threshold for which pixel of the circle around the center pixel is considered to -/// be greater or smaller +/// be greater or smaller /// - `arc_len` - length of arc (or sequential segment) to be tested, must be within range [9-16] /// - `non_max` - performs non-maximal supression if true /// - `feat_ratio` - maximum ratio of features to detect, the maximum number of features is -/// calculated by `feature_ratio * num of elements`. The maximum number of features is not based on -/// the score, instead, features detected after the limit is reached are discarded. +/// calculated by `feature_ratio * num of elements`. The maximum number of features is not based on +/// the score, instead, features detected after the limit is reached are discarded. /// - `edge` - is the length of the edges in the image to be discarded by FAST(minimum is 3, as the -/// radius of the circle) +/// radius of the circle) /// /// # Return Values /// @@ -314,13 +314,13 @@ where /// /// - `input` - the input image Array /// - `fast_thr` - FAST threshold for which a pixel of the circle around the central pixel is -/// considered to be brighter or darker +/// considered to be brighter or darker /// - `max_feat` - maximum number of features to hold /// - `scl_fctr` - factor to downsample the input image, meaning that each level with hold prior -/// level dimensions divided by `scl_fctr` +/// level dimensions divided by `scl_fctr` /// - `levels` - number of levels to be computed for the image pyramid /// - `blur_img` - blur image with a Gaussian filter with sigma=2 before computing descriptors to -/// increase robustness against noise if true +/// increase robustness against noise if true /// /// # Return Values /// @@ -370,7 +370,7 @@ where /// - `query` - Array containing the data to be queried /// - `train` - Array containing the data to be used as training data /// - `dist_dims` - indicates the dimension to analyze for distance (the dimension indicated here -/// must be of equal length for both query and train arrays) +/// must be of equal length for both query and train arrays) /// - `n_dist` - is the number of smallest distances to return (currently, only values <= 256 are supported) /// /// @@ -536,10 +536,10 @@ where /// /// Importance of the parameters, t and g is explained below: /// -/// - t determines how similar points have to be to the nucleusbefore they are considered to be a -/// part of the univalue segment -/// - g determines the minimum size of the univalue segment. For a large enough g, SUSAN operator -/// becomes an edge dectector. +/// - `t` determines how similar points have to be to the nucleusbefore they are considered to be a +/// part of the univalue segment +/// - `g` determines the minimum size of the univalue segment. For a large enough g, SUSAN operator +/// becomes an edge dectector. /// /// # Parameters ///