MCPcopy
hub / github.com/tinygrad/tinygrad / numel

Method numel

tinygrad/mixin/movement.py:38–47  ·  view source on GitHub ↗

Returns the total number of elements in the tensor. ```python exec="true" source="above" session="tensor" result="python" t = Tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(t.numel()) ```

(self)

Source from the content-addressed store, hash-verified

36 return len(self.shape)
37
38 def numel(self) -> sint:
39 """
40 Returns the total number of elements in the tensor.
41
42 ```python exec="true" source="above" session="tensor" result="python"
43 t = Tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
44 print(t.numel())
45 ```
46 """
47 return prod(self.shape)
48
49 def size(self, dim:int|None=None) -> sint|tuple[sint, ...]:
50 """

Callers 15

_make_buffer_viewFunction · 0.80
itemMethod · 0.80
masked_selectMethod · 0.80
mainFunction · 0.80
__init__Method · 0.80
reshapeFunction · 0.80
OptionalHasElementFunction · 0.80
SizeFunction · 0.80
NonZeroFunction · 0.80
__call__Method · 0.80
_zero_kernelFunction · 0.80
_embedding_bwd_kernelFunction · 0.80

Calls 1

prodFunction · 0.90

Tested by 15

test_simple_addMethod · 0.64
test_simple_add_sqMethod · 0.64
test_simple_matmulMethod · 0.64
test_new_bufferMethod · 0.64
test_numelMethod · 0.64
custom_eye_kernelFunction · 0.64
custom_add_one_kernelFunction · 0.64
flip_contract_kernelFunction · 0.64
custom_add_with_tmpMethod · 0.64