tinygrad icon indicating copy to clipboard operation
tinygrad copied to clipboard

replace Tensor.eq with __eq__

Open dc-dc-dc opened this issue 1 year ago • 2 comments

currently to compare tensors we use the eq function inside Tensor but ideally should use __eq__ to support (t1 == t2)

keep an eye out as when I attempted this, it made the Tensor class un-hashable and broke use cases where Tensor was used in sets

dc-dc-dc avatar Mar 02 '23 16:03 dc-dc-dc

still seems hashable, to me. Don't know about sets though.

catasaurus avatar Mar 03 '23 22:03 catasaurus

If you define __eq__ without defining __hash__ the object becomes unhashable. Sets and dictionaries rely on an immutable hash for an object. Not sure if it's worth the extra lines. Torch also uses .eq and .eq_ methods: https://pytorch.org/docs/stable/generated/torch.eq.html#torch.eq

jarkenau avatar Mar 06 '23 07:03 jarkenau