Calculates a 16-byte hash of the tensor. ```python exec="false source="above" session="tensor" result="python" t = Tensor(b"Hello World!").hash() print(t.data().hex()) ```
(self)
| 1165 | return self.reshape(-1, 4096).keccak("shake_128").reshape(self.shape[0], -1).keccak("shake_128") |
| 1166 | |
| 1167 | def hash(self) -> Tensor: |
| 1168 | """ |
| 1169 | Calculates a 16-byte hash of the tensor. |
| 1170 | ```python exec="false source="above" session="tensor" result="python" |
| 1171 | t = Tensor(b"Hello World!").hash() |
| 1172 | print(t.data().hex()) |
| 1173 | ``` |
| 1174 | """ |
| 1175 | data = self.flatten().bitcast(dtypes.uint8) |
| 1176 | n = data.shape[0] |
| 1177 | assert isinstance(n, int), "hash requires concrete shape" |
| 1178 | chunks = ceildiv(n, 2**20) |
| 1179 | while chunks > 1: |
| 1180 | data = data.pad_to(chunks * 2**20).reshape(chunks, 2**20)._hash_1mb().flatten() |
| 1181 | chunks = ceildiv(chunks, 65536) |
| 1182 | return data.pad_to(2**20).unsqueeze(0)._hash_1mb().flatten()[:16] |
| 1183 | |
| 1184 | # ***** processing ops ***** |
| 1185 |