MCPcopy
hub / github.com/tinygrad/tinygrad / get_shape

Function get_shape

tinygrad/tensor.py:47–51  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

45 return ret.reshape(x.shape)
46
47def get_shape(x) -> tuple[int, ...]:
48 # NOTE: str is special because iterating it still yields strs
49 if not hasattr(x, "__len__") or isinstance(x, str) or getattr(x, "shape", None) == (): return ()
50 if not all_same(subs:=[get_shape(xi) for xi in x]): raise ValueError(f"inhomogeneous shape from {x}")
51 return (len(subs),) + (subs[0] if subs else ())
52
53def _frompy(x:list|tuple|bytes, dtype:DType, device:str|tuple[str,...]) -> UOp:
54 if isinstance(x, bytes): ret, data = UOp.new_buffer("PYTHON", len(x)//dtype.itemsize, dtype), x

Callers 3

test_get_shapeMethod · 0.90
_frompyFunction · 0.85

Calls 1

all_sameFunction · 0.90

Tested by 2

test_get_shapeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…