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

Function get_ndim_safe

imperative/python/src/tensor_utils.cpp:778–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778std::pair<size_t, bool> get_ndim_safe(py::handle tensor) {
779 if (auto p = TensorWrapper::try_cast(tensor.ptr())) {
780 return {p->m_tensor->shape()->ndim, true};
781 }
782
783 try {
784 return {getattr(tensor, "ndim").cast<size_t>(), true};
785 } catch (py::error_already_set& err) {
786 return {0, false};
787 }
788}
789
790py::tuple _unpack_indexes(py::handle inp_hdl, py::tuple tuple_val) {
791 py::object inp = py::reinterpret_borrow<py::object>(inp_hdl);

Callers 3

_unpack_indexesFunction · 0.85
_expand_dims_cppFunction · 0.85
_transpose_cppFunction · 0.85

Calls 3

try_castFunction · 0.85
ptrMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected