future.py Source File

future.py Source File#

SDK qb Runtime Library: future.py Source File
SDK qb Runtime Library v0.29
MCS001-EN
future.py
Go to the documentation of this file.
1
4
5from typing import List, Optional
6
7import numpy as np
8
9import maccel.maccel as _cMaccel
10
11
14
15class Future:
16 def __init__(
17 self,
18 _future: _cMaccel.Future = None,
19 _inputs: Optional[List[np.ndarray]] = None,
20 ):
21 self._future = _future if _future is not None else _cMaccel.Future()
22 # self._inputs holds user inputs to prevent them from being garbage collected
23 # before asynchronous inference is completed.
24 self._inputs = _inputs
25
26 @classmethod
27 def from_cpp(cls, _future: _cMaccel.Future, _inputs: List[np.ndarray]):
28 return cls(_future, _inputs)
29
30 def wait_for(self, timeout_ms: int) -> bool:
31 return self._future.wait_for(timeout_ms)
32
33 def get(self) -> List[np.ndarray]:
34 outputs = self._future.get()
35 self._inputs = None
36 return [np.asarray(o) for o in outputs]
37
38