MCPcopy
hub / github.com/tinygrad/tinygrad / float

Method float

tinygrad/mixin/dtype.py:35–48  ·  view source on GitHub ↗

Convenience method to cast `self` to a `float32` Tensor. ```python exec="true" source="above" session="tensor" result="python" t = Tensor([-1, 2, 3], dtype=dtypes.int32) print(t.dtype, t.numpy()) ``` ```python exec="true" source="above" session="tensor" result="python"

(self)

Source from the content-addressed store, hash-verified

33 return dtypes.is_float(self.dtype.base)
34
35 def float(self) -> Self:
36 """
37 Convenience method to cast `self` to a `float32` Tensor.
38
39 ```python exec="true" source="above" session="tensor" result="python"
40 t = Tensor([-1, 2, 3], dtype=dtypes.int32)
41 print(t.dtype, t.numpy())
42 ```
43 ```python exec="true" source="above" session="tensor" result="python"
44 t = t.float()
45 print(t.dtype, t.numpy())
46 ```
47 """
48 return self.cast(dtypes.float32)
49
50 def half(self) -> Self:
51 """

Callers 15

numpyMethod · 0.80
multinomialMethod · 0.80
_attentionMethod · 0.80
forwardMethod · 0.80
BinarizerFunction · 0.80
__call__Method · 0.80
u16_to_f16Function · 0.80
eval_custom_matmulFunction · 0.80
test_matmulFunction · 0.80
test_copy_castMethod · 0.80
test_mnist_indexMethod · 0.80

Calls 1

castMethod · 0.95

Tested by 15

test_matmulFunction · 0.64
test_copy_castMethod · 0.64
test_mnist_indexMethod · 0.64
test_methodMethod · 0.64
test_mul_float_intMethod · 0.64
test_div_sum_by_sumMethod · 0.64
test_iscloseMethod · 0.64
test_floordiv_floatMethod · 0.64
test_mod_floatMethod · 0.64
test_div_trunc_floatMethod · 0.64