-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Unary minus precedence? #565
Comments
Good catch. I'd say this is a bug, because:
The first one is the one we intended, and these clearly shouldn't be different. |
Oh, I know why this happened. We made
Otherwise it would have to be written as
But I think this was the wrong tradeoff, since you hardly ever want to call or define |
I guess if we switch this back then methods for |
We might be able to have both, if we're willing to assume you never want to negate a tuple. |
Seems reasonable enough to me. There will inevitably be people who try |
This comment has been minimized.
This comment has been minimized.
Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: main Julia branch: master Old commit: 0dd8d45 New commit: 14333ea Julia version: 1.12.0-DEV SparseArrays version: 1.12.0 Bump invoked by: @ViralBShah Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@0dd8d45...14333ea ``` $ git log --oneline 0dd8d45..14333ea 14333ea Break recursion (#579) 07cf4a6 Update ci.yml (#578) 33491e0 added diagonal-sparse multiplication (#564) 8f02b7f doc: move solvers doc to `src\solvers.md` (#576) 485fd4b Inline sparse-times-dense in-place multiplication (#567) f10d4da added specialized method for 3-argument dot with diagonal matrix (#565) 70c06b1 Diagonal-sandwiched triple product for SparseMatrixCSC (#562) 313a04f Change default QR tolerance to match SPQR (#557) 81d49e9 Update ci.yml (#558) ``` Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Not sure if this is intentional or not, but it caused me some confusion. If it's intentional, I'd be interested to hear the rationale.
The precedence of the unary minus seems to be over exponentiation such that
-(x-y)^2
equals(-(x-y))^2
, so for example-(1-3)^2 == 4
. This differs from at least Python, where-(x-y)**2
equals-((x-y)**2)
.Might be a matter of taste (as Python is my major language), but for me this latter way is more intuitive, and makes for prettier expressions. I was writing something with a gaussian function
exp(-(x-a)^2)
and got quite unexpected numbers out at first. Had to write itexp(-((x-a)^2))
which looks a bit cluttered.I think this should at least be mentioned in the manual somewhere (at least I couldn't find much about operator precedence).
The text was updated successfully, but these errors were encountered: