MCPcopy
hub / github.com/tinygrad/tinygrad / tolist

Method tolist

tinygrad/tensor.py:323–339  ·  view source on GitHub ↗

Returns the value of this tensor as a nested list. Returns single value for const tensor. ```python exec="true" source="above" session="tensor" result="python" t = Tensor([1, 2, 3, 4]) print(t.tolist()) ``` ```python exec="true" source="above" session="tensor" result="p

(self)

Source from the content-addressed store, hash-verified

321
322 # NOTE: list[Any] because return type is recursive (list[list[...]] for higher dimensions)
323 def tolist(self) -> PyConst|list[Any]:
324 """
325 Returns the value of this tensor as a nested list.
326 Returns single value for const tensor.
327
328 ```python exec="true" source="above" session="tensor" result="python"
329 t = Tensor([1, 2, 3, 4])
330 print(t.tolist())
331 ```
332 ```python exec="true" source="above" session="tensor" result="python"
333 t = Tensor(5)
334 print(t.tolist())
335 ```
336 """
337 # TODO: remove half once minimum python supports it
338 if self.dtype in (dtypes.half, dtypes.bfloat16, *dtypes.fp8s): return self.cast(dtypes.float32).tolist()
339 return self.data().tolist()
340
341 def numpy(self) -> 'numpy.ndarray':
342 """

Callers 15

test_copyMethod · 0.95
test_bytesMethod · 0.95
test_float_bytesMethod · 0.95
enumerate_devices_strFunction · 0.45
supported_dtypesMethod · 0.45
zip_extractFunction · 0.45
_to_python_constFunction · 0.45
_should_emulateFunction · 0.45
__call__Method · 0.45

Calls 2

castMethod · 0.95
dataMethod · 0.95

Tested by 15

test_copyMethod · 0.76
test_bytesMethod · 0.76
test_float_bytesMethod · 0.76
test_eluMethod · 0.36
test_plusMethod · 0.36
test_plus_intMethod · 0.36
test_plus_bigMethod · 0.36
test_catMethod · 0.36
test_gemmMethod · 0.36