MCPcopy
hub / github.com/tinygrad/tinygrad / from_blob

Method from_blob

tinygrad/tensor.py:505–516  ·  view source on GitHub ↗

Exposes the pointer as a Tensor without taking ownership of the original data. The pointer must remain valid for the entire lifetime of the created Tensor. You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. Additionally, all ot

(ptr:int, shape:tuple[int, ...], **kwargs)

Source from the content-addressed store, hash-verified

503
504 @staticmethod
505 def from_blob(ptr:int, shape:tuple[int, ...], **kwargs) -> Tensor:
506 """
507 Exposes the pointer as a Tensor without taking ownership of the original data.
508 The pointer must remain valid for the entire lifetime of the created Tensor.
509
510 You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor.
511 Additionally, all other keyword arguments are passed to the constructor of the tensor.
512 """
513 r = Tensor.empty(*shape, **kwargs)
514 assert isinstance(r.device, str)
515 cast(Buffer, r.uop.buffer).allocate(external_ptr=ptr)
516 return r
517
518 @staticmethod
519 def from_url(url:str, gunzip:bool=False, **kwargs) -> Tensor:

Callers 7

create_tiny_mappingMethod · 0.80
test_tensor_from_blobMethod · 0.80
test_torch_interopMethod · 0.80
custom_kernelFunction · 0.80

Calls 3

castFunction · 0.85
allocateMethod · 0.80
emptyMethod · 0.45

Tested by 3

test_tensor_from_blobMethod · 0.64
test_torch_interopMethod · 0.64