| 94 | |
| 95 | @dataclass |
| 96 | class FloatingType(DType): |
| 97 | sign_bits: int = 0 |
| 98 | exp_bits: int = 0 |
| 99 | mantissa_bits: int = 0 |
| 100 | |
| 101 | @property |
| 102 | def bits(self): |
| 103 | return self.sign_bits + self.exp_bits + self.mantissa_bits |
| 104 | |
| 105 | def _is(self, sign: int, exp: int, mantissa: int): |
| 106 | return ( |
| 107 | self.sign_bits == sign |
| 108 | and self.exp_bits == exp |
| 109 | and self.mantissa_bits == mantissa |
| 110 | ) |
| 111 | |
| 112 | def is_e3m4_t(self): |
| 113 | return self._is(1, 3, 4) |
| 114 | |
| 115 | def is_e4m3_t(self): |
| 116 | return self._is(1, 4, 3) |
| 117 | |
| 118 | def is_fp8_t(self): |
| 119 | return self.is_e3m4_t() or self.is_e4m3_t() |
| 120 | |
| 121 | def is_half_t(self): |
| 122 | return self._is(1, 5, 10) |
| 123 | |
| 124 | def is_float_t(self): |
| 125 | return self._is(1, 8, 23) |
| 126 | |
| 127 | def is_double_t(self): |
| 128 | return self._is(1, 11, 52) |
| 129 | |
| 130 | @classmethod |
| 131 | def e3m4_t(cls): |
| 132 | return cls(1, 3, 4) |
| 133 | |
| 134 | @classmethod |
| 135 | def e4m3_t(cls): |
| 136 | return cls(1, 4, 3) |
| 137 | |
| 138 | @classmethod |
| 139 | def half_t(cls): |
| 140 | return cls(1, 5, 10) |
| 141 | |
| 142 | @classmethod |
| 143 | def float_t(cls): |
| 144 | return cls(1, 8, 23) |
| 145 | |
| 146 | @classmethod |
| 147 | def double_t(cls): |
| 148 | return cls(1, 11, 52) |
| 149 | |
| 150 | def is_same(self, another_type: "FloatingType"): |
| 151 | return ( |
| 152 | isinstance(another_type, FloatingType) |
| 153 | and (self.sign_bits == another_type.sign_bits) |
nothing calls this directly
no outgoing calls
no test coverage detected