Skip to content

Commit e96b4c3

Browse files
committed
fix offset parameter type for shift function
Added an example code to shift function as well Fixes #117
1 parent 38a004b commit e96b4c3

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/data/mod.rs

+37-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern {
3838

3939
fn af_tile(out: MutAfArray, arr: AfArray, x: c_uint, y: c_uint, z: c_uint, w: c_uint) -> c_int;
4040
fn af_reorder(o: MutAfArray, a: AfArray, x: c_uint, y: c_uint, z: c_uint, w: c_uint) -> c_int;
41-
fn af_shift(o: MutAfArray, a: AfArray, x: c_uint, y: c_uint, z: c_uint, w: c_uint) -> c_int;
41+
fn af_shift(o: MutAfArray, a: AfArray, x: c_int, y: c_int, z: c_int, w: c_int) -> c_int;
4242
fn af_moddims(out: MutAfArray, arr: AfArray, ndims: c_uint, dims: *const DimT) -> c_int;
4343

4444
fn af_flat(out: MutAfArray, arr: AfArray) -> c_int;
@@ -375,7 +375,42 @@ macro_rules! data_func_def {
375375

376376
data_func_def!("Tile the input array along specified dimension", tile, af_tile);
377377
data_func_def!("Reorder the array in specified order", reorder, af_reorder);
378-
data_func_def!("Circular shift of values along specified dimension", shift, af_shift);
378+
379+
380+
///"Circular shift of values along specified dimension
381+
///
382+
///# Parameters
383+
///
384+
/// - `input` is the input Array
385+
/// - `offsets` is 4-value tuple that specifies the shift along respective dimension
386+
///
387+
///# Return Values
388+
///
389+
/// An Array with shifted data.
390+
///
391+
///# Examples
392+
///
393+
/// ```rust
394+
/// use arrayfire::{Array, Dim4, print, randu, shift};
395+
/// let a = randu::<f32>(Dim4::new(&[5, 1, 1, 1]));
396+
/// let _a = shift(&a, &[-1i32, 1 , 1, 1]); //shift data one step backward
397+
/// let a_ = shift(&a, &[ 1i32, 1 , 1, 1]); //shift data one step forward
398+
/// print(& a);
399+
/// print(&_a);
400+
/// print(&a_);
401+
/// ```
402+
#[allow(unused_mut)]
403+
pub fn shift(input: &Array, offsets: &[i32; 4]) -> Array {
404+
unsafe {
405+
let mut temp: i64 = 0;
406+
let err_val = af_shift(&mut temp as MutAfArray, input.get() as AfArray,
407+
offsets[0] as c_int, offsets[1] as c_int,
408+
offsets[2] as c_int, offsets[3] as c_int);
409+
HANDLE_ERROR(AfError::from(err_val));
410+
Array::from(temp)
411+
}
412+
}
413+
379414

380415
/// Change the shape of the Array
381416
///

0 commit comments

Comments
 (0)