MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _Const

Function _Const

imperative/python/src/tensor_utils.cpp:307–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307py::object _Const(py::handle value, py::handle dtype, py::handle device) {
308 py::object val = py::reinterpret_borrow<py::object>(value);
309 if (PyArray_Check(value.ptr())) {
310 py::tuple strides =
311 py::reinterpret_borrow<py::tuple>(getattr(value, "strides"));
312 bool need_squeeze = false;
313 for (size_t i = 0; i < strides.size(); ++i) {
314 if (strides[i].cast<ptrdiff_t>() == 0) {
315 need_squeeze = true;
316 }
317 }
318 if (need_squeeze) {
319 val = py::reinterpret_borrow<py::array>(value);
320 py::object orig_shp = val.attr("shape");
321 val = val.attr("squeeze")();
322 val = val.attr("reshape")(orig_shp);
323 }
324 }
325 py::object device_obj = device2obj(device, true);
326 py::tuple tup =
327 py::make_tuple(val, dtype, device_obj, true, false, py::none(), py::none());
328 return TensorWrapper::make(py_tensor_type, tup.ptr(), nullptr);
329}
330
331py::tuple _make_shape_tuple(py::handle shape) {
332 py::list orig;

Callers 7

get_res_by_refhdlFunction · 0.85
_get_indexFunction · 0.85
_try_cond_takeFunction · 0.85
_setitem_cppFunction · 0.85
_split_cppFunction · 0.85
tensor_utils.cppFile · 0.85

Calls 5

device2objFunction · 0.85
attrMethod · 0.80
makeFunction · 0.50
ptrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected