eval

arrayfire.eval(*arrays: Array) None

Forces the evaluation of one or more ArrayFire arrays.

In ArrayFire, operations are typically executed lazily, meaning that computations are not actually performed until the results are needed. This function forces the evaluation of its input arrays, potentially optimizing the execution by combining multiple operations into a single kernel launch.

Parameters

*arraysArray

Variable number of ArrayFire arrays to be evaluated. All input arrays should be of the same size.

Note

It’s important to ensure that all input arrays are of the same size to avoid runtime errors. This function facilitates performing multiple array operations in a single step, improving performance by reducing the number of kernel launches.

Examples

>>> import arrayfire as af
>>> a = af.constant(1, (3, 3))
>>> b = af.constant(2, (3, 3))
>>> c = a + b
>>> d = a - b
>>> af.eval(c, d)  # Forces evaluation, optimizing the execution
>>> c
[3 3 1 1]
    3.0000     3.0000     3.0000
    3.0000     3.0000     3.0000
    3.0000     3.0000     3.0000
>>> d
[3 3 1 1]
    -1.0000    -1.0000    -1.0000
    -1.0000    -1.0000    -1.0000
    -1.0000    -1.0000    -1.0000

In this example, eval is used to force the evaluation of c and d. Instead of executing two separate operations (addition and subtraction), ArrayFire optimizes the process into a single kernel execution, thus enhancing performance.