MCPcopy Create free account
hub / github.com/ml-explore/mlx / PyStreamContext

Class PyStreamContext

python/src/stream.cpp:18–42  ·  view source on GitHub ↗

Create the StreamContext on enter and delete on exit.

Source from the content-addressed store, hash-verified

16
17// Create the StreamContext on enter and delete on exit.
18class PyStreamContext {
19 public:
20 PyStreamContext(mx::StreamOrDevice s) : _inner(nullptr) {
21 if (std::holds_alternative<std::monostate>(s)) {
22 throw std::runtime_error(
23 "[StreamContext] Invalid argument, please specify a stream or device.");
24 }
25 _s = s;
26 }
27
28 void enter() {
29 _inner = new mx::StreamContext(_s);
30 }
31
32 void exit() {
33 if (_inner != nullptr) {
34 delete _inner;
35 _inner = nullptr;
36 }
37 }
38
39 private:
40 mx::StreamOrDevice _s;
41 mx::StreamContext* _inner;
42};
43
44void init_stream(nb::module_& m) {
45 nb::class_<mx::Stream>(

Callers 1

init_streamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected