Skip to content
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

Support more general tensor comparisons #159

Open
gbaydin opened this issue Sep 4, 2020 · 4 comments
Open

Support more general tensor comparisons #159

gbaydin opened this issue Sep 4, 2020 · 4 comments
Labels

Comments

@gbaydin
Copy link
Member

gbaydin commented Sep 4, 2020

Currently we have the behavior

let t = dsharp.tensor([1.;2.;3.])
t.lt(dsharp.tensor(3.))
System.ArgumentException: The arrays have different lengths.
array1.Length = 3, array2.Length = 1 (Parameter 'array1')

We can generalize these comparisons to support cases like the following in PyTorch

t = torch.tensor([1,2,3])
t.lt(torch.tensor(3))
tensor([ True,  True, False])
@gbaydin
Copy link
Member Author

gbaydin commented Sep 4, 2020

Another behavior that can be updated in this is

dsharp.tensor([1.;2.;3.]) < 3.
This expression was expected to have type
    'Tensor'    
but here has type
    'float'    
dsharp.tensor([1.;2.;3.]) < dsharp.tensor(3.)
System.Exception: Cannot compare non-scalar Tensors

instead of which we can again support more general comparisons like PyTorch

torch.tensor([1,2,3]) < 3
tensor([ True,  True, False])

I think this can be accomplished by overloading the relevant operators (op_LessThan etc.).

@gbaydin gbaydin added the feature label Sep 4, 2020
@dsyme
Copy link
Collaborator

dsyme commented Sep 4, 2020

instead of which we can again support more general comparisons like PyTorch

Annoyingly the < and other comparison operators are tied to a return type of bool in F#. It's something we should address. Instead one has to make a <. or other operator specifically for tensors I think. Though that's not such a bad thing.

@gbaydin
Copy link
Member Author

gbaydin commented Sep 4, 2020

Annoyingly the < and other comparison operators are tied to a return type of bool in F#.

Oh good point, I remember now that this was the main reason behind this choice.

I think then just supporting the lt, le etc. with multi-dimensional bool tensor results is good enough.

@kevmal
Copy link
Contributor

kevmal commented Sep 4, 2020

I think there's no harm in adding the .< style ops to the type. It would actually feel natural to have A = B be bool and A .= B to be a bool Tensor. In general it greatly improves readability over lt, lte style methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants