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

Function expand_dims

imperative/python/megengine/xla/rules/tensor.py:81–91  ·  view source on GitHub ↗
(inp, axis)

Source from the content-addressed store, hash-verified

79
80
81def expand_dims(inp, axis):
82 assert isinstance(axis, int), f"only int axis supported, get {axis}"
83 assert (
84 axis >= -inp.ndim - 1 and axis <= inp.ndim
85 ), f"invalid axis {axis} for {inp.shape}"
86
87 dst_shape = list(inp.shape)
88 insert_pos = axis if axis >= 0 else (axis + inp.ndim + 1)
89 dst_shape.insert(insert_pos, 1)
90
91 return inp.reshape(tuple(dst_shape))
92
93
94@register_lower_rule(mops.Dimshuffle)

Callers 6

argsort_backward_lowerFunction · 0.70
checknonfinite_lowerFunction · 0.70
stackFunction · 0.70
calc_bmm_quantizedMethod · 0.50
from_qat_moduleMethod · 0.50

Calls 3

listFunction · 0.85
insertMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected