-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
make .+= et al. mutating #119
Comments
Would this mean you could write a |
So that would mean that |
I guess this implies Then what about when |
Yes, that's what it would mean. |
Can we get that for |
I don't like the kind of behavior where see also JuliaLang/julia#249, JuliaLang/julia#1115 |
Yes, this kind of inconsistency would be a problem. What about something like: .+!(x, y) Or, perhaps let's just do it using named functions: add!(x, y) |
what about just not defining |
I'm not sure I see the rationale for this. The main reason for doing element-wise operations in-place is for performance and to avoid memory allocation. However, I would think that in most performance-critical real applications you aren't doing something as simple as performing a single binary operation on two arrays, and so these semantics won't solve the problem. For example, in ODE solvers you often do things like Who is helped by |
I'd rather have something like @lindahua's Devectorize package, but one in which I can write:
and have it work in-place on |
I really like the simplicity of having |
Ok, it's good to get feedback on this. There's been a lot of pushback about this not being in-place so I thought maybe we could have it both ways with this. Complaints tend to be louder than affirmations of the status quo. |
For me it's always seemed like there's a tension here between simplicity (as John says, knowing that |
Could someone give me an example where one can determine from outside whether While it would be really cool to have something like |
For me (and my scope of writing programs) it's pretty clear: a = a + b and a+= b is the same operation: you update (if inplace or by a temporary) a by adding b. If a and b qualify for multiple elements, then the respective + is used - which is in most cases elementwise. What do we loose here, if a = a + b and a+=b is not the same operation? |
I agree with @stevengj. While the fact that What do other languages do in that regard (though most do not have the notion of element-wise operations)? |
Your example there @nalimilan, of
|
|
Note for example that |
@JeffBezanson I'm curious why you like |
I don't know, but that's not what I was referring to. The only point of my comment is that broadcasting is not a special feature of a few dot operators, but has a general version via the |
It seems there are three related issues here:
The two latter are logically strongly related, and could maybe be merged together (this is what So maybe using |
This is a very good observation of @nalimilan. Athough element-wise /devectorized operation will likely be implemented in a mutating manner it is less clear that To the point of @JeffBezanson of mutating behavior of |
Mutating means the following:
|
Ok, but sorry that I still not get it. I thought that |
Yes, |
Thanks for the clarification. So making One could think about deprecating |
-1 I've grown to like that x+=1 can't modify the callee's environment. I would rather get the speedup from optimizing the GC, rather than changing the semantics of this operation. |
I think this is covered by JuliaLang/julia#249 and JuliaLang/julia#1115. Probably will not do something special for dot operators. |
Fair enough. Good to have the discussion in any case. |
Hi, I realize this issue is closed, but I ran into this just now. I was suprised this didn't mutate the vector i passed in:
I'm not sure whether my expectations are somehow justified, or if it's just because I'm used to how numpy does it. If it's policy that in-place doesn't mutate, it might be nice to document somewhere (unless I missed it!). |
http://docs.julialang.org/en/latest/manual/mathematical-operations/#updating-operators Also please read the above discussion; it should explain our reasoning pretty well. |
Thanks! Sorry, I was just trying to contribute a data point. Maybe github issue comments are not a good way to do this. |
Fixed by JuliaLang/julia#17510, although we won't get the full power of fusing in-place assignment until |
We're now quite consistent about
+
being "mathematical" addition while.+
is "container" addition. In a sense+
treats its arguments as conceptually immutable mathematical objects – numbers, vectors;.+
treats its arguments as containers of values. In that view, it would make sense forx += y
to meanx = x + y
as it does now, whilex .+= y
could modifyx
in-place.The text was updated successfully, but these errors were encountered: