|
1 | 1 | extern crate libc; |
2 | 2 |
|
3 | 3 | use array::Array; |
4 | | -use defines::AfError; |
| 4 | +use defines::{AfError, BinaryOp}; |
5 | 5 | use error::HANDLE_ERROR; |
6 | | -use self::libc::{c_int, c_uint, c_double}; |
| 6 | +use self::libc::{c_int, uint8_t, c_uint, c_double}; |
7 | 7 |
|
8 | 8 | type MutAfArray = *mut self::libc::c_longlong; |
9 | 9 | type MutDouble = *mut self::libc::c_double; |
@@ -46,6 +46,10 @@ extern { |
46 | 46 |
|
47 | 47 | fn af_sort_by_key(out_keys: MutAfArray, out_vals: MutAfArray, |
48 | 48 | in_keys: AfArray, in_vals: AfArray, dim: c_uint, ascend: c_int) -> c_int; |
| 49 | + |
| 50 | + fn af_scan(out: MutAfArray, inp: AfArray, dim: c_int, op: uint8_t, inclusive: c_int) -> c_int; |
| 51 | + fn af_scan_by_key(out: MutAfArray, key: AfArray, inp: AfArray, |
| 52 | + dim: c_int, op: uint8_t, inclusive: c_int) -> c_int; |
49 | 53 | } |
50 | 54 |
|
51 | 55 | macro_rules! dim_reduce_func_def { |
@@ -855,3 +859,51 @@ pub fn set_intersect(first: &Array, second: &Array, is_unique: bool) -> Array { |
855 | 859 | Array::from(temp) |
856 | 860 | } |
857 | 861 | } |
| 862 | + |
| 863 | +/// Generalized scan |
| 864 | +/// |
| 865 | +/// # Parameters |
| 866 | +/// |
| 867 | +/// - `input` is the data on which scan is to be performed |
| 868 | +/// - `dim` is the dimension along which scan operation is to be performed |
| 869 | +/// - `op` takes value of [BinaryOp](./enum.BinaryOp.html) enum indicating |
| 870 | +/// the type of scan operation |
| 871 | +/// - `inclusive` says if inclusive/exclusive scan is to be performed |
| 872 | +/// |
| 873 | +/// # Return Values |
| 874 | +/// |
| 875 | +/// Output Array of scanned input |
| 876 | +pub fn scan(input: &Array, dim: i32, op: BinaryOp, inclusive: bool) -> Array { |
| 877 | + unsafe { |
| 878 | + let mut temp : i64 = 0; |
| 879 | + let err_val = af_scan(&mut temp as MutAfArray, input.get() as AfArray, dim as c_int, |
| 880 | + op as uint8_t, inclusive as c_int); |
| 881 | + HANDLE_ERROR(AfError::from(err_val)); |
| 882 | + Array::from(temp) |
| 883 | + } |
| 884 | +} |
| 885 | + |
| 886 | +/// Generalized scan by key |
| 887 | +/// |
| 888 | +/// # Parameters |
| 889 | +/// |
| 890 | +/// - `key` is the key Array |
| 891 | +/// - `input` is the data on which scan is to be performed |
| 892 | +/// - `dim` is the dimension along which scan operation is to be performed |
| 893 | +/// - `op` takes value of [BinaryOp](./enum.BinaryOp.html) enum indicating |
| 894 | +/// the type of scan operation |
| 895 | +/// - `inclusive` says if inclusive/exclusive scan is to be performed |
| 896 | +/// |
| 897 | +/// # Return Values |
| 898 | +/// |
| 899 | +/// Output Array of scanned input |
| 900 | +pub fn scan_by_key(key: &Array, input: &Array, dim: i32, op: BinaryOp, inclusive: bool) -> Array { |
| 901 | + unsafe { |
| 902 | + let mut temp : i64 = 0; |
| 903 | + let err_val = af_scan_by_key(&mut temp as MutAfArray, |
| 904 | + key.get() as AfArray, input.get() as AfArray, dim as c_int, |
| 905 | + op as uint8_t, inclusive as c_int); |
| 906 | + HANDLE_ERROR(AfError::from(err_val)); |
| 907 | + Array::from(temp) |
| 908 | + } |
| 909 | +} |
0 commit comments