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

Method numpy

imperative/python/src/tensor.cpp:696–719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694}
695
696PyObject* TensorWrapper::numpy() {
697 auto hv = m_tensor->numpy();
698 if (!hv) {
699 if (TransformationManager::get_instance()
700 .segments[TransformationManager::Segment::Eval]
701 .size() > 1) {
702 PyErr_SetString(
703 PyExc_ValueError,
704 "tensor invalid, can not infer value of this tensor under "
705 "trace(symbolic=True). You can try to use trace(symbolic=False) to "
706 "avoid this issue.");
707 } else {
708 PyErr_SetString(PyExc_ValueError, "tensor invalid");
709 }
710 return nullptr;
711 }
712 auto arr = py::reinterpret_steal<py::array>(
713 npy::ndarray_from_tensor(hv->as_nd(true), npy::ShareType::TRY_SHARE));
714 if (hv->shape().is_scalar()) {
715 mgb_assert(PyArray_Check(arr.ptr()));
716 return PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(arr.ptr()));
717 }
718 return arr.release().ptr();
719}
720
721void TensorWrapper::reset(PyObject* tensor) {
722 TensorWrapper* t = TensorWrapper::try_cast(tensor);

Callers 15

test_advance_indexingFunction · 0.45
update_modelFunction · 0.45
workerFunction · 0.45
run_dtr_resnet1202Function · 0.45
workerFunction · 0.45
test_xornet_trace_dumpFunction · 0.45
runnerFunction · 0.45
test_detachFunction · 0.45
_test_optimizerFunction · 0.45
__call__Method · 0.45

Calls 7

ndarray_from_tensorFunction · 0.85
as_ndMethod · 0.80
sizeMethod · 0.45
is_scalarMethod · 0.45
shapeMethod · 0.45
ptrMethod · 0.45
releaseMethod · 0.45

Tested by 15

test_advance_indexingFunction · 0.36
update_modelFunction · 0.36
workerFunction · 0.36
run_dtr_resnet1202Function · 0.36
workerFunction · 0.36
test_xornet_trace_dumpFunction · 0.36
runnerFunction · 0.36
test_detachFunction · 0.36
_test_optimizerFunction · 0.36
__call__Method · 0.36