maccel.future.Future Class Reference

maccel.future.Future Class Reference#

Runtime Library: maccel.future.Future Class Reference
Runtime Library v0.30
Mobilint SDK qb

Represents a future for retrieving the result of asynchronous inference. More...

Public Member Functions

 __init__ (self, Optional[Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8]] _future=None, Optional[List[np.ndarray]] _inputs=None)
 from_cpp (cls, Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8] _future, List[np.ndarray] _inputs)
bool wait_for (self, int timeout_ms)
 Waits for asynchronous inference to complete or until the timeout elapses.
List[np.ndarray] get (self)
 Blocks until asynchronous inference completes and retrieves the output.

Protected Attributes

 _future = _future if _future is not None else _cMaccel.FutureFloat()
 _inputs = _inputs

Detailed Description

Represents a future for retrieving the result of asynchronous inference.

This class provides a mechanism similar to C++11 std::future, allowing access to the result of an asynchronous inference operation initiated via Model.infer_async(). For details on C++11 std::future, refer to https://en.cppreference.com/w/cpp/thread/future.html .

The Future object enables the caller to:

  • Wait for the inference to complete (wait_for)
  • Block until completion and retrieve the output (get)

Definition at line 16 of file future.py.

Constructor & Destructor Documentation

◆ __init__()

maccel.future.Future.__init__ ( self,
Optional[Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8]] _future = None,
Optional[List[np.ndarray]] _inputs = None )

Definition at line 29 of file future.py.

Member Function Documentation

◆ from_cpp()

maccel.future.Future.from_cpp ( cls,
Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8] _future,
List[np.ndarray] _inputs )

Definition at line 42 of file future.py.

◆ wait_for()

bool maccel.future.Future.wait_for ( self,
int timeout_ms )

Waits for asynchronous inference to complete or until the timeout elapses.

Note
This method is safe to call multiple times. Calling it with a timeout of zero (i.e., wait_for(0)) performs a non-blocking check to see whether asynchronous inference has already completed.
Parameters
[in]timeout_msMaximum duration to wait, in milliseconds.
Returns
True if inference completed before the timeout, false otherwise.

Definition at line 49 of file future.py.

◆ get()

List[np.ndarray] maccel.future.Future.get ( self)

Blocks until asynchronous inference completes and retrieves the output.

Note
This method should be called only once per Future. If called again, the return value will be invalid, and it will raise maccel.MAccelError "Future_NotValid".
Returns
A list of numpy ndarray containing the inference output.

Definition at line 63 of file future.py.

Member Data Documentation

◆ _future

maccel.future.Future._future = _future if _future is not None else _cMaccel.FutureFloat()
protected

Definition at line 36 of file future.py.

◆ _inputs

maccel.future.Future._inputs = _inputs
protected

Definition at line 39 of file future.py.


The documentation for this class was generated from the following file: