Skip to content

Commit 592b9c1

Browse files
committed
Update crate with new APIs added for upstream 3.8 release
- max ragged API, docs and example - API for cov, var & stdev fns that accept bias enum - bitwise complement - Bump up Crate version to 3.8.0 - Update GitHub Action CI to use version 3.8.0 Linux installer - Update README to reflect package manager packages newly being shipped starting 3.8.0 release of ArrayFire upstream
1 parent 8a05b28 commit 592b9c1

File tree

7 files changed

+311
-32
lines changed

7 files changed

+311
-32
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Build and Test Wrapper
1414
runs-on: ubuntu-18.04
1515
env:
16-
AF_VER: 3.7.2
16+
AF_VER: 3.8.0
1717
steps:
1818
- name: Checkout Repository
1919
uses: actions/checkout@master

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
edition = "2018"
33
name = "arrayfire"
44
description = "ArrayFire is a high performance software library for parallel computing with an easy-to-use API. Its array based function set makes parallel programming simple. ArrayFire's multiple backends (CUDA, OpenCL and native CPU) make it platform independent and highly portable. A few lines of code in ArrayFire can replace dozens of lines of parallel computing code, saving you valuable time and lowering development costs. This crate provides Rust bindings for ArrayFire library."
5-
version = "3.7.2"
5+
version = "3.8.0"
66
documentation = "http://arrayfire.github.io/arrayfire-rust/arrayfire/index.html"
77
homepage = "https://github.com/arrayfire/arrayfire"
88
repository = "https://github.com/arrayfire/arrayfire-rust"

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Linux, Windows and OSX. Rust 1.31 or newer is required.
2222

2323
To use the rust bindings for ArrayFire from crates.io, the following requirements are to be met first.
2424

25-
1. [Download and install ArrayFire binaries][10] based on your operating system.
25+
1. [Download and install ArrayFire binaries][10] based on your operating system. Depending on the
26+
method of your installation for Linux, steps (2) & (3) may not be required. If that is the case,
27+
proceed to step (4) directly.
2628
2. Set the evironment variable `AF_PATH` to point to ArrayFire installation root folder.
2729
3. Make sure to add the path to lib files to your path environment variables.
2830
- On Linux: do `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$AF_PATH/lib64`
@@ -44,7 +46,7 @@ one of the following two ways.
4446
- [Download and install binaries][10]
4547
- [Build and install from source][1]
4648

47-
To build arrayfire submodule available in the rust wrapper, you have to do the following.
49+
To build arrayfire submodule available in the rust wrapper repository, you have to do the following.
4850

4951
```bash
5052
git submodule update --init --recursive

src/algorithm/mod.rs

+67
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ extern "C" {
133133
dim: c_int,
134134
nan_val: c_double,
135135
) -> c_int;
136+
fn af_max_ragged(
137+
val_out: *mut af_array,
138+
idx_out: *mut af_array,
139+
input: af_array,
140+
ragged_len: af_array,
141+
dim: c_int,
142+
) -> c_int;
136143
}
137144

138145
macro_rules! dim_reduce_func_def {
@@ -1440,6 +1447,66 @@ dim_reduce_by_key_nan_func_def!(
14401447
ValueType::ProductOutType
14411448
);
14421449

1450+
/// Max reduction along given axis as per ragged lengths provided
1451+
///
1452+
/// # Parameters
1453+
///
1454+
/// - `input` contains the input values to be reduced
1455+
/// - `ragged_len` array containing number of elements to use when reducing along `dim`
1456+
/// - `dim` is the dimension along which the max operation occurs
1457+
///
1458+
/// # Return Values
1459+
///
1460+
/// Tuple of Arrays:
1461+
/// - First element: An Array containing the maximum ragged values in `input` along `dim`
1462+
/// according to `ragged_len`
1463+
/// - Second Element: An Array containing the locations of the maximum ragged values in
1464+
/// `input` along `dim` according to `ragged_len`
1465+
///
1466+
/// # Examples
1467+
/// ```rust
1468+
/// use arrayfire::{Array, dim4, print, randu, max_ragged};
1469+
/// let vals: [f32; 6] = [1.0f32, 2.0, 3.0, 4.0, 5.0, 6.0];
1470+
/// let rlens: [u32; 2] = [9, 2];
1471+
/// let varr = Array::new(&vals, dim4![3, 2]);
1472+
/// let rarr = Array::new(&rlens, dim4![1, 2]);
1473+
/// print(&varr);
1474+
/// // 1 4
1475+
/// // 2 5
1476+
/// // 3 6
1477+
/// print(&rarr); // numbers of elements to participate in reduction along given axis
1478+
/// // 9 2
1479+
/// let (out, idx) = max_ragged(&varr, &rarr, 0);
1480+
/// print(&out);
1481+
/// // 3 5
1482+
/// print(&idx);
1483+
/// // 2 1 //Since 3 is max element for given length 9 along first column
1484+
/// //Since 5 is max element for given length 2 along second column
1485+
/// ```
1486+
pub fn max_ragged<T>(
1487+
input: &Array<T>,
1488+
ragged_len: &Array<u32>,
1489+
dim: i32,
1490+
) -> (Array<T::InType>, Array<u32>)
1491+
where
1492+
T: HasAfEnum,
1493+
T::InType: HasAfEnum,
1494+
{
1495+
unsafe {
1496+
let mut out_vals: af_array = std::ptr::null_mut();
1497+
let mut out_idxs: af_array = std::ptr::null_mut();
1498+
let err_val = af_max_ragged(
1499+
&mut out_vals as *mut af_array,
1500+
&mut out_idxs as *mut af_array,
1501+
input.get(),
1502+
ragged_len.get(),
1503+
dim,
1504+
);
1505+
HANDLE_ERROR(AfError::from(err_val));
1506+
(out_vals.into(), out_idxs.into())
1507+
}
1508+
}
1509+
14431510
#[cfg(test)]
14441511
mod tests {
14451512
use super::super::core::c32;

src/core/arith.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::data::{constant, tile, ConstGenerator};
33
use super::defines::AfError;
44
use super::dim4::Dim4;
55
use super::error::HANDLE_ERROR;
6-
use super::util::{af_array, HasAfEnum, ImplicitPromote};
6+
use super::util::{af_array, HasAfEnum, ImplicitPromote, IntegralType};
77
use num::Zero;
88

99
use libc::c_int;
@@ -97,6 +97,7 @@ extern "C" {
9797
fn af_iszero(out: *mut af_array, arr: af_array) -> c_int;
9898
fn af_isinf(out: *mut af_array, arr: af_array) -> c_int;
9999
fn af_isnan(out: *mut af_array, arr: af_array) -> c_int;
100+
fn af_bitnot(out: *mut af_array, arr: af_array) -> c_int;
100101
}
101102

102103
/// Enables use of `!` on objects of type [Array](./struct.Array.html)
@@ -975,3 +976,16 @@ where
975976
sub(&cnst, &self, true)
976977
}
977978
}
979+
980+
/// Perform bitwise complement on all values of Array
981+
pub fn bitnot<T: HasAfEnum>(input: &Array<T>) -> Array<T>
982+
where
983+
T: HasAfEnum + IntegralType,
984+
{
985+
unsafe {
986+
let mut temp: af_array = std::ptr::null_mut();
987+
let err_val = af_bitnot(&mut temp as *mut af_array, input.get());
988+
HANDLE_ERROR(AfError::from(err_val));
989+
temp.into()
990+
}
991+
}

src/core/util.rs

+12
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,15 @@ impl IndexableType for u32 {}
835835
impl IndexableType for i16 {}
836836
impl IndexableType for u16 {}
837837
impl IndexableType for u8 {}
838+
839+
/// Trait qualifier for given type indicating computability of covariance
840+
pub trait IntegralType {}
841+
842+
impl IntegralType for i64 {}
843+
impl IntegralType for u64 {}
844+
impl IntegralType for i32 {}
845+
impl IntegralType for u32 {}
846+
impl IntegralType for i16 {}
847+
impl IntegralType for u16 {}
848+
impl IntegralType for u8 {}
849+
impl IntegralType for bool {}

0 commit comments

Comments
 (0)