@@ -117,20 +117,6 @@ macro_rules! af_print {
117
117
} ;
118
118
}
119
119
120
- /// Evaluate arbitrary number of arrays
121
- #[ macro_export]
122
- macro_rules! eval {
123
- [ $( $x: expr) ,+] => {
124
- {
125
- let mut temp_vec = Vec :: new( ) ;
126
- $(
127
- temp_vec. push( $x) ;
128
- ) *
129
- eval_multiple( temp_vec)
130
- }
131
- } ;
132
- }
133
-
134
120
/// Create a dim4 object from provided dimensions
135
121
///
136
122
/// The user can pass 1 or more sizes and the left over values will default to 1.
@@ -227,16 +213,33 @@ macro_rules! view {
227
213
} ;
228
214
}
229
215
230
- /// This macro is syntactic sugar for modifying portions of Array with another Array using a
231
- /// combination of [Sequences][1] and/or [Array][2] objects.
216
+ /// Macro to evaluate individual Arrays or assignment operations
232
217
///
233
- /// Examples on how to use this macro are provided in the [tutorials book][3]
218
+ /// - Evaluate on one or more Array identifiers: essentially calls [Array::eval][4] on each of those
219
+ /// Array objects individually.
220
+ ///
221
+ /// ```rust
222
+ /// use arrayfire::{dim4, eval, randu};
223
+ /// let dims = dim4!(5, 5);
224
+ /// let a = randu::<f32>(dims);
225
+ /// let b = a.clone();
226
+ /// let c = a.clone();
227
+ /// let d = a.clone();
228
+ /// let x = a - b;
229
+ /// let y = c * d;
230
+ /// eval!(&x, &y);
231
+ /// ```
232
+ ///
233
+ /// - Evaluate assignment operations: This is essentially syntactic sugar for modifying portions of
234
+ /// Array with another Array using a combination of [Sequences][1] and/or [Array][2] objects.
235
+ /// Full examples for this use case are provided in the [tutorials book][3]
234
236
///
235
237
/// [1]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Seq.html
236
238
/// [2]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Array.html
237
239
/// [3]: http://arrayfire.org/arrayfire-rust/book/indexing.html
240
+ /// [4]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Array.html#method.eval
238
241
#[ macro_export]
239
- macro_rules! equation {
242
+ macro_rules! eval {
240
243
( $l: ident [ $( $lb: literal : $le: literal : $ls: literal) ,+ ] =
241
244
$r: ident [ $( $rb: literal : $re: literal : $rs: literal) ,+ ] ) => {
242
245
{
@@ -284,6 +287,15 @@ macro_rules! equation {
284
287
$crate:: assign_gen( & mut $lhs, & idxrs, & $rhs) ;
285
288
}
286
289
} ;
290
+ [ $( $x: expr) ,+] => {
291
+ {
292
+ let mut temp_vec = Vec :: new( ) ;
293
+ $(
294
+ temp_vec. push( $x) ;
295
+ ) *
296
+ $crate:: eval_multiple( temp_vec)
297
+ }
298
+ } ;
287
299
}
288
300
289
301
#[ cfg( test) ]
@@ -357,7 +369,7 @@ mod tests {
357
369
}
358
370
359
371
#[ test]
360
- fn equation_macro1 ( ) {
372
+ fn eval_assign_seq_indexed_array ( ) {
361
373
let dims = dim4 ! ( 5 , 5 ) ;
362
374
let mut a = randu :: < f32 > ( dims) ;
363
375
//print(&a);
@@ -381,7 +393,7 @@ mod tests {
381
393
let d1 = seq ! ( 1 : 2 : 1 ) ;
382
394
let s0 = seq ! ( 1 : 2 : 1 ) ;
383
395
let s1 = seq ! ( 1 : 2 : 1 ) ;
384
- equation ! ( a[ d0, d1] = b[ s0, s1] ) ;
396
+ eval ! ( a[ d0, d1] = b[ s0, s1] ) ;
385
397
//print(&a);
386
398
//[5 5 1 1]
387
399
// 0.6010 0.5497 0.1583 0.3636 0.6755
@@ -392,19 +404,11 @@ mod tests {
392
404
}
393
405
394
406
#[ test]
395
- fn equation_macro2 ( ) {
396
- let dims = dim4 ! ( 5 , 5 ) ;
397
- let mut a = randu :: < f32 > ( dims) ;
398
- let b = randu :: < f32 > ( dims) ;
399
- equation ! ( a[ 1 : 2 : 1 , 1 : 2 : 1 ] = b[ 1 : 2 : 1 , 1 : 2 : 1 ] ) ;
400
- }
401
-
402
- #[ test]
403
- fn equation_macro3 ( ) {
407
+ fn eval_assign_array_to_seqd_array ( ) {
404
408
// ANCHOR: macro_seq_assign
405
409
let mut a = randu :: < f32 > ( dim4 ! ( 5 , 5 ) ) ;
406
410
let b = randu :: < f32 > ( dim4 ! ( 2 , 2 ) ) ;
407
- equation ! ( a[ 1 : 2 : 1 , 1 : 2 : 1 ] = b) ;
411
+ eval ! ( a[ 1 : 2 : 1 , 1 : 2 : 1 ] = b) ;
408
412
// ANCHOR_END: macro_seq_assign
409
413
}
410
414
@@ -418,7 +422,7 @@ mod tests {
418
422
419
423
let b = constant ( 2.0 as f32 , dim4 ! ( 3 , 3 ) ) ;
420
424
421
- equation ! ( a[ indices, seq4gen] = b) ;
425
+ eval ! ( a[ indices, seq4gen] = b) ;
422
426
// ANCHOR_END: macro_seq_array_assign
423
427
}
424
428
}
0 commit comments