-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyO3: Add equal
and __richcmp__
to candle.Tensor
#1099
PyO3: Add equal
and __richcmp__
to candle.Tensor
#1099
Conversation
…-equality-operations
…-equality-operations
Thanks, I have mixed feelings about this one. Providing an equality comparison is really tricky, e.g. what should it do for tensors located on different devices, for tensor with the same values but different types, ...? I don't think there are good answers to these. Do you know of specific use cases where these would be useful? |
I based the |
Yeah I think it indeed makes sense for test but instead I would rather have some function that are just on the test side and can be pure python, e.g. |
Alright i will create a |
I think that we could go for something simpler than |
You are probably right about this. Just so we don't mix things up here, i first added So i guess what we want to do is implement some simple |
Oh I think we just want |
I mainly added
They basically create their causal mask via a rich compare and i agree it's not what i would call "easily readable code" but i added the |
Ah yeah that looks like a potential use case that people coming from PyTorch may want to replicate. Maybe it's good to have in that case - I'm a bit on the fence. How do you feel about it? Actually I'm happy either way the added code is not too large neither and could easily be tested. |
Alright, here is what i would do:
I see no reason to remove |
Yeah that sounds reasonable then. Do you want to make a new PR for |
Im gonna use this one for |
Great, let me know when it's good to look at. |
Alright, should be ready, but I'm not happy how |
On a second thought, |
A bit hacky but you can take the difference of |
I tried to implement it by casting my unsigned types to |
The pyo3 CI seems to fail, mind taking a look? |
Yeah it currently fails because |
Ah right, just merged #1216 that adds the abs function for integer types, let me know if this doesn't work on your side. |
Ah, nice. Yeah that should fix the problem. I'm gonna finish this PR tomorrow at work 👍 |
…-equality-operations
Alright, should be good to go 👍 |
Great, thanks! |
This PR adds support for all equality operations between tensors and scalars/tensors. This also has the same broadcasting behavior as pytorch/numpy meaning the
rhs
andlhs
will be automatically broadcasted into the right shapes for the comparison.