Backends are used by objects that implement the Parallel interface to carry out their deferred computations. They are usually used to execute batches of computation in parallel as a way of increasing performance.

Enqueue Computation#

To enqueue a Deferred computation for backend processing:

public enqueue(Deferred $deferred, ?Closure $after = null) : void


use Rubix\ML\Deferred;
use Rubix\ML\Backends\Amp;

$backend = new Amp(4);

$deferred = new Deferred(function ($input) {
    return $input ** 2;
}, [2.5]);

$after = function ($result) {
    echo 'done';

$backend->enqueue($deferred, $after);

Process Queue#

Process the queue of deferred computations:

public process() : array


$results = $backend->process();

array(1) {
    [0]=> float(6.25)

Flush Queue#

Sometimes it might be necessary to remove leftover items from the queue before proceeding. In such a case the flush() method will clear the queue of Deferred computations.

public flush(): void