Skip to content

use self #193

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 1 commit into from
Mar 27, 2019
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
10 changes: 5 additions & 5 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ where
/// print(&indices);
/// ```
#[allow(unused_mut)]
pub fn new(slice: &[T], dims: Dim4) -> Array<T> {
pub fn new(slice: &[T], dims: Dim4) -> Self {
let aftype = T::get_af_dtype();
let mut temp: i64 = 0;
unsafe {
Expand All @@ -193,7 +193,7 @@ where
///
/// The data pointed by the slice passed to this function can possibily be offseted using an additional `offset` parameter.
#[allow(unused_mut)]
pub fn new_strided(slice: &[T], offset: i64, dims: Dim4, strides: Dim4) -> Array<T> {
pub fn new_strided(slice: &[T], offset: i64, dims: Dim4, strides: Dim4) -> Self {
let aftype = T::get_af_dtype();
let mut temp: i64 = 0;
unsafe {
Expand Down Expand Up @@ -221,7 +221,7 @@ where
/// let garbageVals = Array::<f32>::new_empty(Dim4::new(&[3, 1, 1, 1]));
/// ```
#[allow(unused_mut)]
pub fn new_empty(dims: Dim4) -> Array<T> {
pub fn new_empty(dims: Dim4) -> Self {
let aftype = T::get_af_dtype();
unsafe {
let mut temp: i64 = 0;
Expand Down Expand Up @@ -375,7 +375,7 @@ where
/// Makes an copy of the Array
///
/// This does a deep copy of the data into a new Array
pub fn copy(&self) -> Array<T> {
pub fn copy(&self) -> Self {
unsafe {
let mut temp: i64 = 0;
let err_val = af_copy_array(&mut temp as MutAfArray, self.handle as AfArray);
Expand Down Expand Up @@ -522,7 +522,7 @@ impl<T> Clone for Array<T>
where
T: HasAfEnum,
{
fn clone(&self) -> Array<T> {
fn clone(&self) -> Self {
unsafe {
let mut temp: i64 = 0;
let ret_val = af_retain_array(&mut temp as MutAfArray, self.handle as AfArray);
Expand Down
8 changes: 4 additions & 4 deletions src/dim4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub struct Dim4 {

/// Default trait for Dim4 returns an Array of dimensions [1, 1, 1, 1]
impl Default for Dim4 {
fn default() -> Dim4 {
Dim4 { dims: [1, 1, 1, 1] }
fn default() -> Self {
Self { dims: [1, 1, 1, 1] }
}
}

Expand Down Expand Up @@ -64,8 +64,8 @@ impl Dim4 {
/// use arrayfire::Dim4;
/// let dims = Dim4::new(&[4, 4, 2, 1]);
/// ```
pub fn new(dims: &[u64; 4]) -> Dim4 {
Dim4 { dims: dims.clone() }
pub fn new(dims: &[u64; 4]) -> Self {
Self { dims: dims.clone() }
}

/// Get the number of elements represented by Dim4 object
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Callback {
impl Callback {
/// Associated function to create a new Callback object
pub fn new(callback: ErrorCallback) -> Self {
Callback { cb: callback }
Self { cb: callback }
}

/// call invokes the error callback with `error_code`.
Expand Down
8 changes: 4 additions & 4 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub struct Window {

/// Used to create Window object from native(ArrayFire) resource handle
impl From<u64> for Window {
fn from(t: u64) -> Window {
Window {
fn from(t: u64) -> Self {
Self {
handle: t,
row: -1,
col: -1,
Expand Down Expand Up @@ -212,7 +212,7 @@ impl Window {
///
/// Window Object
#[allow(unused_mut)]
pub fn new(width: i32, height: i32, title: String) -> Window {
pub fn new(width: i32, height: i32, title: String) -> Self {
unsafe {
let mut temp: u64 = 0;
let cstr_ret = CString::new(title);
Expand All @@ -225,7 +225,7 @@ impl Window {
cstr.as_ptr(),
);
HANDLE_ERROR(AfError::from(err_val));
Window::from(temp)
Self::from(temp)
}
Err(_) => {
panic!("String creation failed while prepping params for window creation.")
Expand Down
6 changes: 3 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ where
impl<'object> Indexer<'object> {
#[allow(unused_mut)]
/// Create a new Indexer object and set the dimension specific index objects later
pub fn new() -> Indexer<'object> {
pub fn new() -> Self {
let mut temp: i64 = 0;
unsafe {
let err_val = af_create_indexers(&mut temp as MutAfIndex);
HANDLE_ERROR(AfError::from(err_val));
}
Indexer {
Self {
handle: temp,
count: 0,
marker: PhantomData,
Expand Down Expand Up @@ -596,7 +596,7 @@ impl SeqInternal {
where
c_double: From<T>,
{
SeqInternal {
Self {
begin: From::from(s.begin()),
end: From::from(s.end()),
step: From::from(s.step()),
Expand Down
4 changes: 2 additions & 2 deletions src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Seq<T> {
/// Default `Seq` spans all the elements along a dimension
impl<T: One + Zero> Default for Seq<T> {
fn default() -> Self {
Seq {
Self {
begin: One::one(),
end: One::one(),
step: Zero::zero(),
Expand All @@ -38,7 +38,7 @@ impl<T: fmt::Display> fmt::Display for Seq<T> {
impl<T: Copy> Seq<T> {
/// Create a `Seq` that goes from `begin` to `end` at a step size of `step`
pub fn new(begin: T, end: T, step: T) -> Self {
Seq {
Self {
begin: begin,
end: end,
step: step,
Expand Down
14 changes: 7 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,42 @@ pub fn free_host<T>(ptr: *mut T) {
}

impl From<i32> for AfError {
fn from(t: i32) -> AfError {
fn from(t: i32) -> Self {
assert!(AfError::SUCCESS as i32 <= t && t <= AfError::ERR_UNKNOWN as i32);
unsafe { mem::transmute(t) }
}
}

impl From<u32> for DType {
fn from(t: u32) -> DType {
fn from(t: u32) -> Self {
assert!(DType::F32 as u32 <= t && t <= DType::U64 as u32);
unsafe { mem::transmute(t) }
}
}

impl From<u32> for InterpType {
fn from(t: u32) -> InterpType {
fn from(t: u32) -> Self {
assert!(InterpType::NEAREST as u32 <= t && t <= InterpType::BICUBIC_SPLINE as u32);
unsafe { mem::transmute(t) }
}
}

impl From<u32> for ConvMode {
fn from(t: u32) -> ConvMode {
fn from(t: u32) -> Self {
assert!(ConvMode::DEFAULT as u32 <= t && t <= ConvMode::EXPAND as u32);
unsafe { mem::transmute(t) }
}
}

impl From<u32> for ConvDomain {
fn from(t: u32) -> ConvDomain {
fn from(t: u32) -> Self {
assert!(ConvDomain::AUTO as u32 <= t && t <= ConvDomain::FREQUENCY as u32);
unsafe { mem::transmute(t) }
}
}

impl From<u32> for MatchType {
fn from(t: u32) -> MatchType {
fn from(t: u32) -> Self {
assert!(MatchType::SAD as u32 <= t && t <= MatchType::SHD as u32);
unsafe { mem::transmute(t) }
}
Expand All @@ -129,7 +129,7 @@ pub fn to_u32(t: MatProp) -> u32 {
}

impl From<u32> for ColorMap {
fn from(t: u32) -> ColorMap {
fn from(t: u32) -> Self {
assert!(ColorMap::DEFAULT as u32 <= t && t <= ColorMap::BLUE as u32);
unsafe { mem::transmute(t) }
}
Expand Down
8 changes: 4 additions & 4 deletions src/vision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ impl Features {
///
/// This object is basically a bunch of Arrays.
#[allow(unused_mut)]
pub fn new(n: u64) -> Features {
pub fn new(n: u64) -> Self {
unsafe {
let mut temp: i64 = 0;
let err_val = af_create_features(&mut temp as *mut c_longlong as MutFeat, n as DimT);
HANDLE_ERROR(AfError::from(err_val));
Features { feat: temp }
Self { feat: temp }
}
}

Expand Down Expand Up @@ -197,15 +197,15 @@ impl Features {
}

impl Clone for Features {
fn clone(&self) -> Features {
fn clone(&self) -> Self {
unsafe {
let mut temp: i64 = 0;
let ret_val = af_retain_features(
&mut temp as *mut c_longlong as MutFeat,
self.feat as *const c_longlong as Feat,
);
HANDLE_ERROR(AfError::from(ret_val));
Features { feat: temp }
Self { feat: temp }
}
}
}
Expand Down