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

Method parse

imperative/src/impl/basic_operators.cpp:55–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55auto CreateTensor::parse(Span<ValueRef> inputs) const -> Args {
56 Args result;
57 for (auto&& input : inputs) {
58 if (auto host_storage = input.as_ref<HostStorage>()) {
59 mgb_assert(!result.host, "duplicated host value");
60 result.host.emplace();
61 result.host->reset(*host_storage, {shape().as_tensor_shape(), dtype()});
62 mgb_assert(result.host->layout().ndim, "invalid shape");
63 } else if (auto device_storage = input.as_ref<DeviceStorage>()) {
64 mgb_assert(!result.device, "duplicated device value");
65 result.device.emplace(device(), shape().as_tensor_shape(), dtype());
66 result.device->reset(*device_storage, {shape().as_tensor_shape(), dtype()});
67 mgb_assert(result.device->layout().ndim, "invalid shape");
68 } else {
69 mgb_throw(
70 MegBrainError,
71 "unknown input type, expects HostStorage or DeviceStorage, got "
72 "%s",
73 input.to_string().c_str());
74 }
75 }
76 mgb_assert(
77 result.host || result.device, "require at least one of host/device value");
78 result.kind = kind();
79 return result;
80}
81
82std::string CreateTensor::to_string() const {
83 return ssprintf(

Callers 6

__getitem__Method · 0.45
mhloMethod · 0.45
apply_create_tensorMethod · 0.45
apply_create_tensorMethod · 0.45
apply_transformationMethod · 0.45
apply_transformationMethod · 0.45

Calls 6

deviceFunction · 0.85
shapeFunction · 0.50
emplaceMethod · 0.45
resetMethod · 0.45
layoutMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected