@@ -317,6 +317,38 @@ macro_rules! constant {
317
317
} ;
318
318
}
319
319
320
+ /// Create an array of given shape sampled from uniform distribution
321
+ ///
322
+ /// If no type argument is specified, the data type defaults to 32 bit floats.
323
+ ///
324
+ /// # Examples
325
+ ///
326
+ /// ```rust
327
+ /// # use arrayfire::{randu};
328
+ /// let mat10x10 = randu!(10, 10);
329
+ /// ```
330
+ #[ macro_export]
331
+ macro_rules! randu {
332
+ ( $( $dim: expr) ,+) => { $crate:: randu:: <f32 >( $crate:: dim4!( $( $dim) ,* ) ) } ;
333
+ ( $type: ty; $( $dim: expr) ,+) => { $crate:: randu:: <$type>( $crate:: dim4!( $( $dim) ,* ) ) } ;
334
+ }
335
+
336
+ /// Create an array of given shape sampled from normal distribution
337
+ ///
338
+ /// If no type argument is specified, the data type defaults to 32 bit floats.
339
+ ///
340
+ /// # Examples
341
+ ///
342
+ /// ```rust
343
+ /// # use arrayfire::{randn};
344
+ /// let mat10x10 = randn!(10, 10);
345
+ /// ```
346
+ #[ macro_export]
347
+ macro_rules! randn {
348
+ ( $( $dim: expr) ,+) => { $crate:: randn:: <f32 >( $crate:: dim4!( $( $dim) ,* ) ) } ;
349
+ ( $type: ty; $( $dim: expr) ,+) => { $crate:: randn:: <$type>( $crate:: dim4!( $( $dim) ,* ) ) } ;
350
+ }
351
+
320
352
#[ cfg( test) ]
321
353
mod tests {
322
354
use super :: super :: array:: Array ;
@@ -455,4 +487,12 @@ mod tests {
455
487
let dim = 10 ;
456
488
let _mix_shape = constant ! ( 42.0f32 ; dim, 10 ) ;
457
489
}
490
+
491
+ #[ test]
492
+ fn rand_macro ( ) {
493
+ let _ru5x5 = randu ! ( 5 , 5 ) ;
494
+ let _rn5x5 = randn ! ( 5 , 5 ) ;
495
+ let _ruu32_5x5 = randu ! ( u32 ; 5 , 5 ) ;
496
+ let _ruu8_5x5 = randu ! ( u8 ; 5 , 5 ) ;
497
+ }
458
498
}
0 commit comments