18 @brief Represents a future for retrieving the result of asynchronous inference.
20 This class provides a mechanism similar to C++11 std::future, allowing access to
21 the result of an asynchronous inference operation initiated via `Model.infer_async()`.
22 For details on C++11 std::future, refer to https://en.cppreference.com/w/cpp/thread/future.html .
24 The Future object enables the caller to:
25 - Wait for the inference to complete (`wait_for`)
26 - Block until completion and retrieve the output (`get`)
32 Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8]
34 _inputs: Optional[List[np.ndarray]] =
None,
38 self.
_future = _future
if _future
is not None else _cQbRuntime.FutureFloat()
46 _future: Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8],
47 _inputs: List[np.ndarray],
49 return cls(_future, _inputs)
53 @brief Waits for asynchronous inference to complete or until the timeout elapses.
55 @note This method is safe to call multiple times. Calling it with
56 a timeout of zero (i.e., `wait_for(0)`) performs a non-blocking
57 check to see whether asynchronous inference has already completed.
59 @param[in] timeout_ms Maximum duration to wait, in milliseconds.
61 @return True if inference completed before the timeout, false otherwise.
65 def get(self) -> List[np.ndarray]:
67 @brief Blocks until asynchronous inference completes and retrieves the output.
69 @note This method should be called only once per Future. If called again,
70 the return value will be invalid, and it will raise qbruntime.QbRuntimeError
73 @return A list of numpy ndarray containing the inference output.
77 return [np.asarray(o)
for o
in outputs]