MCPcopy
hub / github.com/tinygrad/tinygrad / numpy

Method numpy

tinygrad/device.py:201–204  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

199 assert not force_zero_copy, "force zero copy was passed, but copy is required"
200 return self.copyout(memoryview(bytearray(self.nbytes)))
201 def numpy(self) -> 'np.ndarray': # type: ignore [name-defined] # noqa: F821
202 import numpy as np
203 assert _to_np_dtype(self.dtype.base) is not None, f"no np dtype for {self.dtype.base}"
204 return np.frombuffer(self.as_memoryview(), dtype=_to_np_dtype(self.dtype.base))
205 def copyin(self, mv:memoryview):
206 mv = flat_mv(mv)
207 assert len(mv) == self.nbytes, f"size mismatch, {len(mv)=} != {self.dtype=} {self.size=}"

Callers 15

exec_validateFunction · 0.45
multitensor.pyFile · 0.45
jacobianFunction · 0.45
numerical_jacobianFunction · 0.45
get_lrMethod · 0.45
__init__Method · 0.45
get_lrMethod · 0.45
trainFunction · 0.45
numpy_evalFunction · 0.45
hook_cuda.pyFile · 0.45
fuzz_matmul.pyFile · 0.45

Calls 2

as_memoryviewMethod · 0.95
_to_np_dtypeFunction · 0.90

Tested by 15

test_matmulFunction · 0.36
test_matmulFunction · 0.36
test_big_prime_numberMethod · 0.36
_realizeMethod · 0.36
_check_kernel_countMethod · 0.36
test_numpy_onesMethod · 0.36