Skip to content

Commit dbac16c

Browse files
authored
Merge pull request #142 from 9prady9/fixes
Bug Fixes
2 parents ce74da0 + 33f9175 commit dbac16c

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ You can find the most recent updated documentation [here](http://arrayfire.githu
1818

1919
## Supported platforms
2020

21-
- Linux and OSX: The bindings have been tested with Rust 1.x.
22-
- Windows: Rust 1.5 (MSVC ABI) is the first version that works with our bindings and ArrayFire library(built using MSVC compiler).
23-
24-
We recommend using Rust 1.5 and higher.
25-
26-
Rust 1.8 stabilized the traits for compound assignment operations. These are automatically enabled
27-
based on the rust version you are using.
21+
Linux, Windows and OSX. We recommend using Rust 1.15.1 or higher.
2822

2923
## Use from Crates.io [![](http://meritbadge.herokuapp.com/arrayfire)](https://crates.io/crates/arrayfire)
3024

src/arith/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ macro_rules! overloaded_binary_func {
255255
///
256256
/// An Array with results of the binary operation.
257257
///
258+
/// In the case of comparison operations such as the following, the type of output
259+
/// Array is [DType::B8](./enum.DType.html). To retrieve the results of such boolean output
260+
/// to host, an array of 8-bit wide types(eg. u8, i8) should be used since ArrayFire's internal
261+
/// implementation uses char for boolean.
262+
///
263+
/// * [gt](./fn.gt.html)
264+
/// * [lt](./fn.lt.html)
265+
/// * [ge](./fn.ge.html)
266+
/// * [le](./fn.le.html)
267+
/// * [eq](./fn.eq.html)
268+
///
258269
///# Note
259270
///
260271
/// The trait `Convertable` essentially translates to a scalar native type on rust or Array.

src/array.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ impl Array {
233233
}
234234

235235
/// Returns the number of elements in the Array
236-
pub fn elements(&self) -> i64 {
236+
pub fn elements(&self) -> usize {
237237
unsafe {
238238
let mut ret_val: i64 = 0;
239239
let err_val = af_get_elements(&mut ret_val as MutAfArray, self.handle as AfArray);
240240
HANDLE_ERROR(AfError::from(err_val));
241-
ret_val
241+
ret_val as usize
242242
}
243243
}
244244

@@ -308,7 +308,10 @@ impl Array {
308308
}
309309

310310
/// Copies the data from the Array to the mutable slice `data`
311-
pub fn host<T>(&self, data: &mut [T]) {
311+
pub fn host<T: HasAfEnum>(&self, data: &mut [T]) {
312+
if data.len() != self.elements() {
313+
HANDLE_ERROR(AfError::ERR_SIZE);
314+
}
312315
unsafe {
313316
let err_val = af_get_data_ptr(data.as_mut_ptr() as *mut c_void, self.handle as AfArray);
314317
HANDLE_ERROR(AfError::from(err_val));

src/image/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ pub fn gradient(input: &Array) -> (Array, Array) {
126126

127127
/// Load Image into Array
128128
///
129+
/// Only, Images with 8/16/32 bits per channel can be loaded using this function.
130+
///
129131
/// # Parameters
130132
///
131133
/// - `filename` is aboslute path of the image to be loaded.

src/index.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,33 @@ use defines::AfError;
55
use error::HANDLE_ERROR;
66
use seq::Seq;
77
use self::libc::{c_double, c_int, c_uint};
8-
use util::{AfArray, DimT, IndexT, MutAfArray, MutAfIndex};
8+
use util::{AfArray, AfIndex, DimT, MutAfArray, MutAfIndex};
99

1010
#[allow(dead_code)]
1111
extern {
1212
fn af_create_indexers(indexers: MutAfIndex) -> c_int;
13-
fn af_set_array_indexer(indexer: MutAfIndex, idx: AfArray, dim: DimT) -> c_int;
14-
fn af_set_seq_indexer(indexer: MutAfIndex, idx: *const SeqInternal, dim: DimT, is_batch: c_int) -> c_int;
15-
fn af_release_indexers(indexers: MutAfIndex) -> c_int;
13+
fn af_set_array_indexer(indexer: AfIndex, idx: AfArray, dim: DimT) -> c_int;
14+
fn af_set_seq_indexer(indexer: AfIndex, idx: *const SeqInternal, dim: DimT, is_batch: c_int) -> c_int;
15+
fn af_release_indexers(indexers: AfIndex) -> c_int;
1616

1717
fn af_index(out: MutAfArray, input: AfArray, ndims: c_uint, index: *const SeqInternal) -> c_int;
1818
fn af_lookup(out: MutAfArray, arr: AfArray, indices: AfArray, dim: c_uint) -> c_int;
1919
fn af_assign_seq(out: MutAfArray, lhs: AfArray, ndims: c_uint, indices: *const SeqInternal, rhs: AfArray) -> c_int;
20-
fn af_index_gen(out: MutAfArray, input: AfArray, ndims: DimT, indices: *const IndexT) -> c_int;
21-
fn af_assign_gen(out: MutAfArray, lhs: AfArray, ndims: DimT, indices: *const IndexT, rhs: AfArray) -> c_int;
20+
fn af_index_gen(out: MutAfArray, input: AfArray, ndims: DimT, indices: AfIndex) -> c_int;
21+
fn af_assign_gen(out: MutAfArray, lhs: AfArray, ndims: DimT, indices: AfIndex, rhs: AfArray) -> c_int;
2222
}
2323

2424
/// Struct to manage an array of resources of type `af_indexer_t`(ArrayFire C struct)
2525
pub struct Indexer {
2626
handle: i64,
27-
count: u32,
2827
}
2928

3029
// Trait that indicates that object can be used for indexing
3130
//
3231
// Any object to be able to be passed on to [./struct.Indexer.html#method.set_index] method
3332
// should implement this trait with appropriate implementation
3433
pub trait Indexable {
35-
fn set(&self, idxr: &Indexer, dim: u32, is_batch: Option<bool>);
34+
fn set(&self, idxr: &mut Indexer, dim: u32, is_batch: Option<bool>);
3635
}
3736

3837
/// Enables [Array](./struct.Array.html) to be used to index another Array
@@ -41,11 +40,10 @@ pub trait Indexable {
4140
/// [assign_gen](./fn.assign_gen.html)
4241
impl Indexable for Array {
4342
#[allow(unused_variables)]
44-
fn set(&self, idxr: &Indexer, dim: u32, is_batch: Option<bool>) {
43+
fn set(&self, idxr: &mut Indexer, dim: u32, is_batch: Option<bool>) {
4544
unsafe {
46-
let err_val = af_set_array_indexer(idxr.clone().get() as MutAfIndex,
47-
self.get() as AfArray,
48-
dim as DimT);
45+
let err_val = af_set_array_indexer(idxr.get() as AfIndex, self.clone().get() as AfArray,
46+
dim as DimT);
4947
HANDLE_ERROR(AfError::from(err_val));
5048
}
5149
}
@@ -56,9 +54,9 @@ impl Indexable for Array {
5654
/// This is used in functions [index_gen](./fn.index_gen.html) and
5755
/// [assign_gen](./fn.assign_gen.html)
5856
impl<T: Copy> Indexable for Seq<T> where c_double: From<T> {
59-
fn set(&self, idxr: &Indexer, dim: u32, is_batch: Option<bool>) {
57+
fn set(&self, idxr: &mut Indexer, dim: u32, is_batch: Option<bool>) {
6058
unsafe {
61-
let err_val = af_set_seq_indexer(idxr.clone().get() as MutAfIndex,
59+
let err_val = af_set_seq_indexer(idxr.get() as AfIndex,
6260
&SeqInternal::from_seq(self) as *const SeqInternal,
6361
dim as DimT, is_batch.unwrap() as c_int);
6462
HANDLE_ERROR(AfError::from(err_val));
@@ -74,33 +72,25 @@ impl Indexer {
7472
let mut temp: i64 = 0;
7573
let err_val = af_create_indexers(&mut temp as MutAfIndex);
7674
HANDLE_ERROR(AfError::from(err_val));
77-
Indexer{handle: temp, count: 0}
75+
Indexer{handle: temp}
7876
}
7977
}
8078

8179
/// Set either [Array](./struct.Array.html) or [Seq](./struct.Seq.html) to index an Array along `idx` dimension
8280
pub fn set_index<T: Indexable>(&mut self, idx: &T, dim: u32, is_batch: Option<bool>) {
83-
self.count = self.count + 1;
8481
idx.set(self, dim, is_batch)
8582
}
8683

8784
/// Get native(ArrayFire) resource handle
8885
pub fn get(&self) -> i64 {
8986
self.handle
9087
}
91-
92-
/// Get number of indexers
93-
///
94-
/// This can be a maximum of four since currently ArrayFire supports maximum of four dimensions
95-
pub fn len(&self) -> u32 {
96-
self.count
97-
}
9888
}
9989

10090
impl Drop for Indexer {
10191
fn drop(&mut self) {
10292
unsafe {
103-
let ret_val = af_release_indexers(self.handle as MutAfIndex);
93+
let ret_val = af_release_indexers(self.handle as AfIndex);
10494
match ret_val {
10595
0 => (),
10696
_ => panic!("Failed to release indexers resource: {}", ret_val),
@@ -338,7 +328,7 @@ pub fn index_gen(input: &Array, indices: Indexer) -> Array {
338328
unsafe{
339329
let mut temp: i64 = 0;
340330
let err_val = af_index_gen(&mut temp as MutAfArray, input.get() as AfArray,
341-
indices.len() as DimT, indices.get() as *const IndexT);
331+
4, indices.get() as AfIndex);
342332
HANDLE_ERROR(AfError::from(err_val));
343333
Array::from(temp)
344334
}
@@ -380,7 +370,7 @@ pub fn assign_gen(lhs: &Array, indices: &Indexer, rhs: &Array) -> Array {
380370
unsafe{
381371
let mut temp: i64 = 0;
382372
let err_val = af_assign_gen(&mut temp as MutAfArray, lhs.get() as AfArray,
383-
indices.len() as DimT, indices.get() as *const IndexT,
373+
4, indices.get() as AfIndex,
384374
rhs.get() as AfArray);
385375
HANDLE_ERROR(AfError::from(err_val));
386376
Array::from(temp)

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3030
html_root_url = "http://arrayfire.com/docs/rust")]
3131
#![warn(missing_docs)]
32+
#![allow(non_camel_case_types)]
3233

3334
#[macro_use]
3435
extern crate lazy_static;

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use self::num::Complex;
99
use self::libc::{uint8_t, c_int, size_t, c_void};
1010

1111
pub type AfArray = self::libc::c_longlong;
12+
pub type AfIndex = self::libc::c_longlong;
1213
pub type CellPtr = *const self::libc::c_void;
1314
pub type Complex32 = Complex<f32>;
1415
pub type Complex64 = Complex<f64>;
1516
pub type DimT = self::libc::c_longlong;
1617
pub type Feat = *const self::libc::c_void;
17-
pub type IndexT = self::libc::c_longlong;
1818
pub type Intl = self::libc::c_longlong;
1919
pub type MutAfArray = *mut self::libc::c_longlong;
2020
pub type MutAfIndex = *mut self::libc::c_longlong;

0 commit comments

Comments
 (0)