MCPcopy Create free account
hub / github.com/BabitMF/bmf / parse_tensor_options

Function parse_tensor_options

bmf/python/py_module_sdk.cpp:166–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 PACKET_REGISTER_TYPE("bmf.lib._bmf.sdk." #T, T)
165
166hmp::TensorOptions parse_tensor_options(const py::kwargs &kwargs,
167 const hmp::TensorOptions &ref) {
168 using namespace hmp;
169
170 TensorOptions opts(ref);
171
172 if (kwargs.contains("pinned_memory")) {
173 opts = opts.pinned_memory(py::cast<bool>(kwargs["pinned_memory"]));
174 }
175
176 if (kwargs.contains("device")) {
177 auto device = kwargs["device"];
178 if (PyUnicode_Check(device.ptr()))
179 opts = opts.device(py::cast<std::string>(kwargs["device"]));
180 else if (py::isinstance<Device>(kwargs["device"]))
181 opts = opts.device(py::cast<Device>(kwargs["device"]));
182 else
183 opts = opts.device(py::cast<DeviceType>(kwargs["device"]));
184 }
185
186 if (kwargs.contains("dtype")) {
187 opts = opts.dtype(py::cast<ScalarType>(kwargs["dtype"]));
188 }
189
190 return opts;
191}
192
193struct PyPacketQueue {
194 PyPacketQueue(const std::shared_ptr<std::queue<bmf_sdk::Packet>> &queue)

Callers 1

module_sdk_bindFunction · 0.70

Calls 2

deviceMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected