-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Deprecate broadcast behaviour of +
in favour of adding identity matrices
#449
Comments
So I'm not clear what problem we are solving with f(x,y) = x*y + x + y + 1 with the current behavior I would call Basically I feel that allowing |
Half of this issue is already fixed with JuliaLang/julia#22932. With JuliaLang/julia#23923, it would again be possible to use |
I feel we should aim to support the distributive law |
While I agree with that in principle, I fear that the behavior of other systems (Python, R, Matlab) here will make this quite dangerous. People will write |
I'm sorry if I'm being too greedy, but I'm not really sure that it is solved by the reintroduction of This gets even trickier when you have a function such as Note also that distributivity does not hold for Finally, if |
Edit: Rereading the issue I now see with @andreasnoack that UniformScalings have the right properties except |
@eveydee, The direction you're moving this is very much towards scalars simply being what UniformScaling was introduced as. We should stop and consider if that's where we want to go. I'm not saying it's not, but we should certainly consider it. And if we do that, it should be one of the first warnings we give to people coming from other systems: in Julia, |
@StefanKarpinski You are right, and I am not sure it is the right way to go. The problem for me is: how to write code that works for generic linear algebra objects. That is, how do you translate from equations that you derive on a whiteboard to code implemented in Julia. As I see it, there are two possible routes to being able to write fully generic code, which has simple-to-follow rules, none of which are currently satisfied:
The first one is annoying for people like me, who primarily use Julia to do linear algebra (arguably a minority in the Julia community), but the inconvenience of suffixing every scalar literal constant by The second one has the potential to be a source of confusion and bugs for people with Matlab or Python muscle-memory who use arrays for non-linear algebra applications. However, all it requires is defining |
What about having |
This is not entirely true since one can also do neat things like this with julia> A = rand(3, 2)
3×2 Array{Float64,2}:
0.777236 0.80784
0.46201 0.548122
0.447051 0.407108
julia> [A I; I A]
6×5 Array{Float64,2}:
0.777236 0.80784 1.0 0.0 0.0
0.46201 0.548122 0.0 1.0 0.0
0.447051 0.407108 0.0 0.0 1.0
1.0 0.0 0.0 0.777236 0.80784
0.0 1.0 0.0 0.46201 0.548122
0.0 0.0 1.0 0.447051 0.407108
julia> [A I; I A']
5×5 Array{Float64,2}:
0.777236 0.80784 1.0 0.0 0.0
0.46201 0.548122 0.0 1.0 0.0
0.447051 0.407108 0.0 0.0 1.0
1.0 0.0 0.777236 0.46201 0.447051
0.0 1.0 0.80784 0.548122 0.407108
julia> [A 0I; 0I A]
6×5 Array{Float64,2}:
0.777236 0.80784 0.0 0.0 0.0
0.46201 0.548122 0.0 0.0 0.0
0.447051 0.407108 0.0 0.0 0.0
0.0 0.0 0.0 0.777236 0.80784
0.0 0.0 0.0 0.46201 0.548122
0.0 0.0 0.0 0.447051 0.407108 If we deprecated |
I'm having trouble distilling what exactly this issue is about. Is it to define |
My take is that it is to allow things like Taylor expansions, e.g. We've already deprecated There's also the issue of the distributive law which should read |
It seems that the breaking part of this change has already happened. Whether to allow |
Hmm? I plan to make a v1.0 PR as soon as a v1.0 branch opens and the v0.7 deprecations are removed. (Probably not a change that would block releasing v1.0, so perhaps this makes sense). |
Honestly, I would let things settle for a while before introducing |
I suppose the same argument could be said to apply to v1.1... But at what point to you draw the line? |
As @andreasnoack mentioned, with JuliaLang/julia#23923 merged, this seems to work pretty well now. We might add JuliaLang/julia#29951, but there seemed to be a consensus against taking that step. |
I understand this has been discussed and experimented with before and people found that it was really annoying when
+
didn't automatically broadcast. But @StefanKarpinski suggested I opened an issue for this to describe the rationale for bringing it up again.Currently, you can write a generic polynomial function that "almost just works" by using
I
in the following pattern:The almost here refers to the fact that this will return a UniformScaling if all of the inputs are scalar. With the deprecation of
+(::UniformScalar, ::Number)
this pattern is broken. After the deprecation, you must now explicitly useone
in defining the polynomial to ensure thatx
andy
have similar dimensionality:But this becomes really messy as soon as you have more than two variables in an expression:
which explodes as you go to higher order. The solution for this is to drop the broadcasting behaviour and define:
or possibly even:
I think the argument that automatic broadcasting happens in other languages is a really good argument for keeping it as it is. But I feel that with dot-notation, we can have the best of both worlds now, since you can define a polynomial like:
where you get the standard or broadcast behaviour by calling either
f(A, B)
orf.(A, B)
.And if you are interested in a personal anecdote, then I spent a whole day (possibly two) debugging my code two months ago in frustration because I was inverting an array of the form:
(H - E)^-1
and couldn't figure out why I got unphysical results. Spoiler:E
was a scalar and I was expecting it to subtract from the diagonal.The text was updated successfully, but these errors were encountered: