-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
operator overload doesn't work on Tensors #6
Comments
Hey, I would like to deal with this issue but I am confused about how to do it. TL;DR : how to implement an operator overload between I naively tried to implement the + overload like this : //+ operator overload
[inline]
pub fn (a &Tensor<f64>) + (b &Tensor<f64>) &Tensor<f64>{
return add(a, b)
} getting this error on my test : fn test_plus_operator(){
a := ones<int>([2,2])
b := ones<int>([2,2])
assert a + b == add(a, b) ---- Testing... ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
FAIL 327.520 ms /home/cmnemoi/Documents/Code/V/vtl/math_op_test.v
math_op_test.v:7:9: error: invalid operator `+` to `&.Tensor<int>` and `&.Tensor<int>`
5 | b := ones<int>([2,2])
6 |
7 | assert a + b == add(a, b)
| ~~~~~
8 | } After some experimentation with the V doc example on operator overloading, I guessed overloading is not supported between object references (is it ?). Then I implemented the overload on Tensors copies : [inline]
pub fn (a Tensor<f64>) + (b Tensor<f64>) &Tensor<f64>{
return add(a, b)
} and get the following error : fn test_plus_operator(){
a := ones<int>([2,2])
b := ones<int>([2,2])
assert *a + *b == add(a, b) //dereferencing vtl.Tensors ---- Testing... ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
FAIL 327.520 ms /home/cmnemoi/Documents/Code/V/vtl/math_op_test.v
math_op_test.v:7:9: error: invalid operator `+` to `.Tensor<int>` and `.Tensor<int>`
5 | b := ones<int>([2,2])
6 |
7 | assert *a + *b == add(a, b) //dereferencing vtl.Tensors
| ~~~~~
8 | } What is a .Tensor ? I couldn't find any reference in V ecosystem. On another side, when I try to use the + operator outside I am very confused. |
@cmnemoi hey! thanks for your contributions! unfortunately I think V is not capable to overload operators on structs that use generics for now :/
|
That makes sense, thanks for the answer. |
(I guess V's op overload is now stable enough so...)
VTL version:
master
OS:
win10
What did you do?
(Just take plus op as an example)
What did you expect to see?
a 2*2 matrix with elements 2.0
What did you see instead?
The text was updated successfully, but these errors were encountered: