@@ -174,10 +174,33 @@ cnst!(u32 , 6);
174174cnst ! ( u8 , 7 ) ;
175175
176176
177+ /// Create an Array with constant value
178+ ///
179+ /// # Parameters
180+ ///
181+ /// - `cnst` is the constant value to be filled in the Array
182+ /// - `dims` is the size of the constant Array
183+ ///
184+ /// # Return Values
185+ ///
186+ /// An Array of given dimensions with constant value
177187pub fn constant < T : ConstGenerator > ( cnst : T , dims : Dim4 ) -> Result < Array , AfError > {
178188 cnst. generate ( dims)
179189}
180190
191+ /// Create a Range of values
192+ ///
193+ /// Creates an array with [0, n] values along the `seq_dim` which is tiled across other dimensions.
194+ ///
195+ /// # Parameters
196+ ///
197+ /// - `dims` is the size of Array
198+ /// - `seq_dim` is the dimension along which range values are populated, all values along other
199+ /// dimensions are just repeated
200+ /// - `aftype` is the type of the Array.
201+ ///
202+ /// # Return Values
203+ /// Array
181204#[ allow( unused_mut) ]
182205pub fn range ( dims : Dim4 , seq_dim : i32 , aftype : Aftype ) -> Result < Array , AfError > {
183206 unsafe {
@@ -192,6 +215,19 @@ pub fn range(dims: Dim4, seq_dim: i32, aftype: Aftype) -> Result<Array, AfError>
192215 }
193216}
194217
218+ /// Create a range of values
219+ ///
220+ /// Create an sequence [0, dims.elements() - 1] and modify to specified dimensions dims and then tile it according to tile_dims.
221+ ///
222+ /// # Parameters
223+ ///
224+ /// - `dims` is the dimensions of the sequence to be generated
225+ /// - `tdims` is the number of repitions of the unit dimensions
226+ /// - `aftype` is the type of Array to generate
227+ ///
228+ /// # Return Values
229+ ///
230+ /// Array
195231#[ allow( unused_mut) ]
196232pub fn iota ( dims : Dim4 , tdims : Dim4 , aftype : Aftype ) -> Result < Array , AfError > {
197233 unsafe {
@@ -207,6 +243,7 @@ pub fn iota(dims: Dim4, tdims: Dim4, aftype: Aftype) -> Result<Array, AfError> {
207243 }
208244}
209245
246+ /// Set seed for random number generation
210247pub fn set_seed ( seed : u64 ) -> Result < ( ) , AfError > {
211248 unsafe {
212249 let err_val = af_set_seed ( seed as Uintl ) ;
@@ -217,6 +254,7 @@ pub fn set_seed(seed: u64) -> Result<(), AfError> {
217254 }
218255}
219256
257+ /// Get the seed of random number generator
220258#[ allow( unused_mut) ]
221259pub fn get_seed ( ) -> Result < u64 , AfError > {
222260 unsafe {
@@ -251,6 +289,17 @@ data_gen_def!(randu, af_randu);
251289data_gen_def ! ( randn, af_randn) ;
252290data_gen_def ! ( identity, af_identity) ;
253291
292+ /// Create a diagonal matrix
293+ ///
294+ /// # Parameters
295+ ///
296+ /// - `input` is the input Array
297+ /// - `dim` is the diagonal index relative to principal diagonal where values from input Array are
298+ /// to be placed
299+ ///
300+ /// # Return Values
301+ ///
302+ /// An Array with values as a diagonal Matrix
254303#[ allow( unused_mut) ]
255304pub fn diag_create ( input : & Array , dim : i32 ) -> Result < Array , AfError > {
256305 unsafe {
@@ -263,6 +312,16 @@ pub fn diag_create(input: &Array, dim: i32) -> Result<Array, AfError> {
263312 }
264313}
265314
315+ /// Extract diagonal from a given Matrix
316+ ///
317+ /// # Parameters
318+ ///
319+ /// - `input` is the input Matrix
320+ /// - `dim` is the index of the diagonal that has to be extracted from the input Matrix
321+ ///
322+ /// # Return Values
323+ ///
324+ /// An Array with values of the diagonal from input Array
266325#[ allow( unused_mut) ]
267326pub fn diag_extract ( input : & Array , dim : i32 ) -> Result < Array , AfError > {
268327 unsafe {
@@ -276,6 +335,17 @@ pub fn diag_extract(input: &Array, dim: i32) -> Result<Array, AfError> {
276335 }
277336}
278337
338+ /// Join two arrays
339+ ///
340+ /// # Parameters
341+ ///
342+ /// - `dim` is the dimension along which the concatenation has to be done
343+ /// - `first` is the Array that comes first in the concatenation
344+ /// - `second` is the Array that comes last in the concatenation
345+ ///
346+ /// # Return Values
347+ ///
348+ /// Concatenated Array
279349#[ allow( unused_mut) ]
280350pub fn join ( dim : i32 , first : & Array , second : & Array ) -> Result < Array , AfError > {
281351 unsafe {
@@ -289,6 +359,16 @@ pub fn join(dim: i32, first: &Array, second: &Array) -> Result<Array, AfError> {
289359 }
290360}
291361
362+ /// Join multiple arrays
363+ ///
364+ /// # Parameters
365+ ///
366+ /// - `dim` is the dimension along which the concatenation has to be done
367+ /// - `inputs` is the vector of Arrays that has to be concatenated
368+ ///
369+ /// # Return Values
370+ ///
371+ /// Concatenated Array
292372#[ allow( unused_mut) ]
293373pub fn join_many ( dim : i32 , inputs : Vec < & Array > ) -> Result < Array , AfError > {
294374 unsafe {
@@ -302,6 +382,25 @@ pub fn join_many(dim: i32, inputs: Vec<&Array>) -> Result<Array, AfError> {
302382 }
303383}
304384
385+ /// Join multiple Arrays along a given dimension
386+ ///
387+ /// # Examples
388+ ///
389+ /// ```
390+ /// # #[macro_use] extern crate arrayfire;
391+ /// # fn main() {
392+ /// let a = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
393+ /// let b = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
394+ /// let c = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
395+ /// let d = join_many![2, a, b, c];
396+ /// # }
397+ /// ```
398+ ///
399+ /// # Panics
400+ ///
401+ /// Using this macro to create an Array from multiple Arrays doesn't implicitly check for errors
402+ /// during FFI calls. Therefore, make sure your inputs are correct. In case, you do need proper
403+ /// error checking, use the [function version](./fn.join_many.html) of this macro.
305404// Using macro to implement join many wrapper
306405#[ macro_export]
307406macro_rules! join_many {
@@ -344,6 +443,15 @@ data_func_def!(tile, af_tile);
344443data_func_def ! ( reorder, af_reorder) ;
345444data_func_def ! ( shift, af_shift) ;
346445
446+ /// Change the shape of the Array
447+ ///
448+ /// # Parameters
449+ ///
450+ /// - `input` is the input Array
451+ /// - `dims` is the new dimensions to which the input Array is reshaped to
452+ ///
453+ /// # Return Values
454+ /// Reshaped Array
347455#[ allow( unused_mut) ]
348456pub fn moddims ( input : & Array , dims : Dim4 ) -> Result < Array , AfError > {
349457 unsafe {
@@ -357,6 +465,7 @@ pub fn moddims(input: &Array, dims: Dim4) -> Result<Array, AfError> {
357465 }
358466}
359467
468+ /// Flatten the multidimensional Array to an 1D Array
360469#[ allow( unused_mut) ]
361470pub fn flat ( input : & Array ) -> Result < Array , AfError > {
362471 unsafe {
@@ -369,6 +478,16 @@ pub fn flat(input: &Array) -> Result<Array, AfError> {
369478 }
370479}
371480
481+ /// Flip the Array
482+ ///
483+ /// # Parameters
484+ ///
485+ /// - `input` is the Array to be flipped
486+ /// - `dim` is the dimension along which the flip has to happen
487+ ///
488+ /// # Return Values
489+ ///
490+ /// Flipped Array
372491#[ allow( unused_mut) ]
373492pub fn flip ( input : & Array , dim : u32 ) -> Result < Array , AfError > {
374493 unsafe {
@@ -381,6 +500,15 @@ pub fn flip(input: &Array, dim: u32) -> Result<Array, AfError> {
381500 }
382501}
383502
503+ /// Create lower triangular matrix
504+ ///
505+ /// # Parameters
506+ ///
507+ /// - `input` is the input Array
508+ /// - `is_unit_diag` dictates if the output Array should have 1's along diagonal
509+ ///
510+ /// # Return Values
511+ /// Array
384512#[ allow( unused_mut) ]
385513pub fn lower ( input : & Array , is_unit_diag : bool ) -> Result < Array , AfError > {
386514 unsafe {
@@ -394,6 +522,15 @@ pub fn lower(input: &Array, is_unit_diag: bool) -> Result<Array, AfError> {
394522 }
395523}
396524
525+ /// Create upper triangular matrix
526+ ///
527+ /// # Parameters
528+ ///
529+ /// - `input` is the input Array
530+ /// - `is_unit_diag` dictates if the output Array should have 1's along diagonal
531+ ///
532+ /// # Return Values
533+ /// Array
397534#[ allow( unused_mut) ]
398535pub fn upper ( input : & Array , is_unit_diag : bool ) -> Result < Array , AfError > {
399536 unsafe {
0 commit comments