Skip to content

Commit 8076658

Browse files
committed
Refactor eval to handle patterns handled by equation macro(removed now)
1 parent 7d75e62 commit 8076658

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

src/core/macros.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,6 @@ macro_rules! af_print {
117117
};
118118
}
119119

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-
134120
/// Create a dim4 object from provided dimensions
135121
///
136122
/// The user can pass 1 or more sizes and the left over values will default to 1.
@@ -227,16 +213,33 @@ macro_rules! view {
227213
};
228214
}
229215

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
232217
///
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]
234236
///
235237
/// [1]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Seq.html
236238
/// [2]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Array.html
237239
/// [3]: http://arrayfire.org/arrayfire-rust/book/indexing.html
240+
/// [4]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Array.html#method.eval
238241
#[macro_export]
239-
macro_rules! equation {
242+
macro_rules! eval {
240243
( $l:ident [ $($lb:literal : $le:literal : $ls:literal),+ ] =
241244
$r:ident [ $($rb:literal : $re:literal : $rs:literal),+ ]) => {
242245
{
@@ -284,6 +287,15 @@ macro_rules! equation {
284287
$crate::assign_gen(&mut $lhs, &idxrs, &$rhs);
285288
}
286289
};
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+
};
287299
}
288300

289301
#[cfg(test)]
@@ -357,7 +369,7 @@ mod tests {
357369
}
358370

359371
#[test]
360-
fn equation_macro1() {
372+
fn eval_assign_seq_indexed_array() {
361373
let dims = dim4!(5, 5);
362374
let mut a = randu::<f32>(dims);
363375
//print(&a);
@@ -381,7 +393,7 @@ mod tests {
381393
let d1 = seq!(1:2:1);
382394
let s0 = seq!(1:2:1);
383395
let s1 = seq!(1:2:1);
384-
equation!(a[d0, d1] = b[s0, s1]);
396+
eval!(a[d0, d1] = b[s0, s1]);
385397
//print(&a);
386398
//[5 5 1 1]
387399
// 0.6010 0.5497 0.1583 0.3636 0.6755
@@ -392,19 +404,11 @@ mod tests {
392404
}
393405

394406
#[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() {
404408
// ANCHOR: macro_seq_assign
405409
let mut a = randu::<f32>(dim4!(5, 5));
406410
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);
408412
// ANCHOR_END: macro_seq_assign
409413
}
410414

@@ -418,7 +422,7 @@ mod tests {
418422

419423
let b = constant(2.0 as f32, dim4!(3, 3));
420424

421-
equation!(a[indices, seq4gen] = b);
425+
eval!(a[indices, seq4gen] = b);
422426
// ANCHOR_END: macro_seq_array_assign
423427
}
424428
}

0 commit comments

Comments
 (0)