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

Method apply_get_attr

imperative/src/impl/transformations/scalar.cpp:312–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310} // namespace
311
312ValueRefList ScalarTransformation::apply_get_attr(
313 const GetAttr& get_attr, Span<ValueRef> inputs) {
314 auto&& input = inputs.item();
315 bool is_scalar = input.is(m_value_type);
316 if (!is_scalar) {
317 return imperative::apply(get_attr, input);
318 }
319 auto unwrapped_input = input.cast(m_value_type).value();
320 if (get_attr.attr() == GetAttr::Shape) {
321 if (!m_empty_shape) {
322 m_empty_shape = ShapeValue::make();
323 }
324 return {m_empty_shape};
325 } else {
326 auto outputs = imperative::apply(get_attr, unwrapped_input);
327 auto& output = outputs[0];
328 switch (get_attr.attr()) {
329 case GetAttr::Value: {
330 auto& hv = output.cast<HostValue>();
331 mgb_assert(
332 hv.shape() == ValueShape({1}),
333 "underlying value should has shape {1}, got %s",
334 hv.shape().to_string().c_str());
335 output = HostValue::make(hv.dtype(), ValueShape(), hv.storage());
336 break;
337 }
338 case GetAttr::Data: {
339 auto& dv = output.cast<DeviceValue>();
340 mgb_assert(
341 dv.shape() == ValueShape({1}),
342 "underlying value should has shape {1}, got %s",
343 dv.shape().to_string().c_str());
344 output = DeviceValue::make(dv.dtype(), ValueShape(), dv.storage());
345 break;
346 }
347 default:
348 break;
349 }
350 return outputs;
351 }
352}
353
354ValueRefList ScalarTransformation::apply_transformation(
355 const Operator& op, Span<ValueRef> inputs) {

Callers

nothing calls this directly

Calls 12

ValueShapeClass · 0.85
attrMethod · 0.80
storageMethod · 0.80
applyFunction · 0.50
makeFunction · 0.50
itemMethod · 0.45
isMethod · 0.45
valueMethod · 0.45
castMethod · 0.45
shapeMethod · 0.45
to_stringMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected