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

Function reshape_rule

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

Source from the content-addressed store, hash-verified

234}
235
236ValueRefList reshape_rule(
237 const Reshape& reshape, Span<ValueRef> inputs, Span<bool> inputs_mask,
238 const Type<ScalarValue>& scalar_type) {
239 mgb_assert(inputs.size() == 1 || inputs.size() == 2);
240 size_t nr_inp = inputs.size();
241 bool is_scalar = (nr_inp == 2 && is_scalar_shape(inputs[1])) ||
242 (nr_inp == 1 && reshape.shape.size() == 0);
243 if (is_scalar) {
244 return {scalar_type.make(imperative::apply(
245 reshape, inputs[0], make_scalar_shape(*inputs[0].device()))[0])};
246 } else {
247 return imperative::apply(reshape, inputs);
248 }
249}
250
251ValueRefList broadcast_rule(
252 const Broadcast& broadcast, Span<ValueRef> inputs, Span<bool> inputs_mask,

Callers

nothing calls this directly

Calls 6

is_scalar_shapeFunction · 0.85
make_scalar_shapeFunction · 0.85
applyFunction · 0.50
sizeMethod · 0.45
makeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected