@@ -2,7 +2,7 @@ extern crate libc;
22
33use array:: Array ;
44use defines:: AfError ;
5- use self :: libc:: { c_int, c_uint} ;
5+ use self :: libc:: { c_int, c_uint, c_double } ;
66
77type MutAfArray = * mut self :: libc:: c_longlong ;
88type MutDouble = * mut self :: libc:: c_double ;
@@ -12,18 +12,18 @@ type AfArray = self::libc::c_longlong;
1212#[ allow( dead_code) ]
1313extern {
1414 fn af_sum ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
15- // fn af_sum_nan(out: MutAfArray, input: AfArray, dim: c_int, nanval: c_double) -> c_int;
15+ fn af_sum_nan ( out : MutAfArray , input : AfArray , dim : c_int , nanval : c_double ) -> c_int ;
1616 fn af_product ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
17- // fn af_product_nan(out: MutAfArray, input: AfArray, dim: c_int, val: c_double) -> c_int;
17+ fn af_product_nan ( out : MutAfArray , input : AfArray , dim : c_int , val : c_double ) -> c_int ;
1818 fn af_min ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
1919 fn af_max ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
2020 fn af_all_true ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
2121 fn af_any_true ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
2222 fn af_count ( out : MutAfArray , input : AfArray , dim : c_int ) -> c_int ;
2323 fn af_sum_all ( r : MutDouble , i : MutDouble , input : AfArray ) -> c_int ;
24- // fn af_sum_nan_all(r: MutDouble, i: MutDouble, input: AfArray, val: c_double) -> c_int;
24+ fn af_sum_nan_all ( r : MutDouble , i : MutDouble , input : AfArray , val : c_double ) -> c_int ;
2525 fn af_product_all ( r : MutDouble , i : MutDouble , input : AfArray ) -> c_int ;
26- // fn af_product_nan_all(r: MutDouble, i: MutDouble, input: AfArray, val: c_double) -> c_int;
26+ fn af_product_nan_all ( r : MutDouble , i : MutDouble , input : AfArray , val : c_double ) -> c_int ;
2727 fn af_min_all ( r : MutDouble , i : MutDouble , input : AfArray ) -> c_int ;
2828 fn af_max_all ( r : MutDouble , i : MutDouble , input : AfArray ) -> c_int ;
2929 fn af_all_true_all ( r : MutDouble , i : MutDouble , input : AfArray ) -> c_int ;
@@ -85,31 +85,64 @@ dim_reduce_func_def!(accum, af_accum);
8585dim_reduce_func_def ! ( diff1, af_diff1) ;
8686dim_reduce_func_def ! ( diff2, af_diff2) ;
8787
88- //pub fn sum_nan(input: &Array, dim: i32, nanval: f64) -> Array {
89- // unsafe {
90- // let mut temp: i64 = 0;
91- // af_sum_nan(&mut temp as MutAfArray, input.get() as AfArray,
92- // dim as c_int, nanval as c_double);
93- // Array {handle: temp}
94- // }
95- //}
88+ /// Reduction operation along specific dimension
89+ ///
90+ /// Sum values of the `input` Array along `dim` dimension after replacing any `NAN` values in the
91+ /// Array with `nanval` value.
92+ ///
93+ /// # Parameters
94+ ///
95+ /// - `input` is the input Array
96+ /// - `dim` is reduction dimension
97+ /// - `nanval` is value with which all the `NAN` values of Array are replaced with
98+ ///
99+ /// # Return Values
100+ ///
101+ /// Reduced Array
102+ pub fn sum_nan ( input : & Array , dim : i32 , nanval : f64 ) -> Result < Array , AfError > {
103+ unsafe {
104+ let mut temp: i64 = 0 ;
105+ let err_val = af_sum_nan ( & mut temp as MutAfArray , input. get ( ) as AfArray ,
106+ dim as c_int , nanval as c_double ) ;
107+ match err_val {
108+ 0 => Ok ( Array :: from ( temp) ) ,
109+ _ => Err ( AfError :: from ( err_val) ) ,
110+ }
111+ }
112+ }
96113
97- //pub fn product_nan(input: &Array, dim: i32, nanval: f64) -> Array {
98- // unsafe {
99- // let mut temp: i64 = 0;
100- // af_product_nan(&mut temp as MutAfArray, input.get() as AfArray,
101- // dim as c_int, nanval as c_double);
102- // Array {handle: temp}
103- // }
104- //}
114+ /// Reduction operation along specific dimension
115+ ///
116+ /// Compute product of the values of the `input` Array along `dim` dimension after replacing any `NAN` values in the Array with `nanval` value.
117+ ///
118+ /// # Parameters
119+ ///
120+ /// - `input` is the input Array
121+ /// - `dim` is reduction dimension
122+ /// - `nanval` is value with which all the `NAN` values of Array are replaced with
123+ ///
124+ /// # Return Values
125+ ///
126+ /// Reduced Array
127+ pub fn product_nan ( input : & Array , dim : i32 , nanval : f64 ) -> Result < Array , AfError > {
128+ unsafe {
129+ let mut temp: i64 = 0 ;
130+ let err_val = af_product_nan ( & mut temp as MutAfArray , input. get ( ) as AfArray ,
131+ dim as c_int , nanval as c_double ) ;
132+ match err_val {
133+ 0 => Ok ( Array :: from ( temp) ) ,
134+ _ => Err ( AfError :: from ( err_val) ) ,
135+ }
136+ }
137+ }
105138
106139macro_rules! all_reduce_func_def {
107140 ( $fn_name: ident, $ffi_name: ident) => (
108141 /// Reduction operation of all values
109142 ///
110143 /// # Parameters
111144 ///
112- /// `input` - Input Array
145+ /// - `input` is the input Array
113146 ///
114147 /// # Return Values
115148 ///
@@ -139,25 +172,59 @@ all_reduce_func_def!(all_true_all, af_all_true_all);
139172all_reduce_func_def ! ( any_true_all, af_any_true_all) ;
140173all_reduce_func_def ! ( count_all, af_count_all) ;
141174
142- //pub fn sum_nan_all(input: &Array, val: f64) -> (f64, f64) {
143- // unsafe {
144- // let mut real: f64 = 0.0;
145- // let mut imag: f64 = 0.0;
146- // af_sum_nan_all(&mut real as MutDouble, &mut imag as MutDouble,
147- // input.get() as AfArray, val as c_double);
148- // (real, imag)
149- // }
150- //}
175+ /// Reduction operation of all values
176+ ///
177+ /// Sum all the values of the `input` Array after replacing any `NAN` values with `val`.
178+ ///
179+ /// # Parameters
180+ ///
181+ /// - `input` is the input Array
182+ /// - `val` is the val that replaces all `NAN` values of the Array before reduction operation is
183+ /// performed.
184+ ///
185+ /// # Return Values
186+ ///
187+ /// A tuple of reduction result. For non-complex data type Arrays, second value of tuple is
188+ /// zero.
189+ pub fn sum_nan_all ( input : & Array , val : f64 ) -> Result < ( f64 , f64 ) , AfError > {
190+ unsafe {
191+ let mut real: f64 = 0.0 ;
192+ let mut imag: f64 = 0.0 ;
193+ let err_val = af_sum_nan_all ( & mut real as MutDouble , & mut imag as MutDouble ,
194+ input. get ( ) as AfArray , val as c_double ) ;
195+ match err_val {
196+ 0 => Ok ( ( real, imag) ) ,
197+ _ => Err ( AfError :: from ( err_val) ) ,
198+ }
199+ }
200+ }
151201
152- //pub fn product_nan_all(input: &Array, val: f64) -> (f64, f64) {
153- // unsafe {
154- // let mut real: f64 = 0.0;
155- // let mut imag: f64 = 0.0;
156- // af_product_nan_all(&mut real as MutDouble, &mut imag as MutDouble,
157- // input.get() as AfArray, val as c_double);
158- // (real, imag)
159- // }
160- //}
202+ /// Reduction operation of all values
203+ ///
204+ /// Compute the product of all the values of the `input` Array after replacing any `NAN` values with `val`.
205+ ///
206+ /// # Parameters
207+ ///
208+ /// - `input` is the input Array
209+ /// - `val` is the val that replaces all `NAN` values of the Array before reduction operation is
210+ /// performed.
211+ ///
212+ /// # Return Values
213+ ///
214+ /// A tuple of reduction result. For non-complex data type Arrays, second value of tuple is
215+ /// zero.
216+ pub fn product_nan_all ( input : & Array , val : f64 ) -> Result < ( f64 , f64 ) , AfError > {
217+ unsafe {
218+ let mut real: f64 = 0.0 ;
219+ let mut imag: f64 = 0.0 ;
220+ let err_val = af_product_nan_all ( & mut real as MutDouble , & mut imag as MutDouble ,
221+ input. get ( ) as AfArray , val as c_double ) ;
222+ match err_val {
223+ 0 => Ok ( ( real, imag) ) ,
224+ _ => Err ( AfError :: from ( err_val) ) ,
225+ }
226+ }
227+ }
161228
162229macro_rules! dim_ireduce_func_def {
163230 ( $fn_name: ident, $ffi_name: ident) => (
0 commit comments