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

Function ptr2shape

imperative/python/src/dlpack_convertor.cpp:224–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224TensorShape ptr2shape(const int64_t* ptr, size_t ndim) {
225 TensorShape shape;
226 mgb_assert(
227 ndim <= TensorShape::MAX_NDIM, "dim too large: %zd (max %zd)", ndim,
228 TensorShape::MAX_NDIM);
229 shape.ndim = ndim;
230 for (size_t i = 0; i < ndim; i++) {
231 if (ptr[i] < 0 || ptr[i] > std::numeric_limits<size_t>::max()) {
232 std::string error_msg = "";
233 for (size_t idx = 0; idx < ndim; idx++) {
234 auto shape_i = " " + std::to_string(ptr[i]);
235 error_msg += shape_i;
236 }
237 mgb_throw(
238 MegBrainError, "unsupported dlpack input shape: %s",
239 error_msg.c_str());
240 }
241 shape[i] = ptr[i];
242 }
243 return shape;
244}
245
246ValueRef mgb::imperative::from_dlpack(DLManagedTensor* dlMTensor, int stream = 0) {
247 std::function<void(void*)> deleter_dispatch = [dlMTensor](void*) {

Callers 1

from_dlpackMethod · 0.85

Calls 2

maxFunction · 0.85
to_stringFunction · 0.85

Tested by

no test coverage detected