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

Method shape

imperative/python/megengine/tensor.py:92–108  ·  view source on GitHub ↗

r"""Returns a :class:`tuple` or a :class:`~.Tensor` represents tensor dimensions. Note: The shape of a tensor was usually represented by a :class:`tuple`. But if a tensor was treated as symbolic placeholder with tracing, it's shape could also be a :class:`~.

(self)

Source from the content-addressed store, hash-verified

90
91 @property
92 def shape(self) -> Union[tuple, "Tensor"]:
93 r"""Returns a :class:`tuple` or a :class:`~.Tensor` represents tensor dimensions.
94
95 Note:
96 The shape of a tensor was usually represented by a :class:`tuple`.
97 But if a tensor was treated as symbolic placeholder with tracing,
98 it's shape could also be a :class:`~.Tensor`. See :class:`~.trace` for more details.
99
100 The shape property is usually used to get the current shape of a tensor,
101 but may also be used to reshape the tensor in-place by assigning a tuple of tensor dimensions to it.
102 As with :func:`~.reshape`, one of the new shape dimensions can be -1,
103 in which case its value is inferred from the size of the tensor and the remaining dimensions.
104 """
105 shape = super().shape
106 if shape == () or not use_symbolic_shape():
107 return shape
108 return apply(GetVarShape(), self)[0]
109
110 @property
111 def _tuple_shape(self):

Callers

nothing calls this directly

Calls 3

use_symbolic_shapeFunction · 0.85
GetVarShapeClass · 0.85
applyFunction · 0.50

Tested by

no test coverage detected