In Julia, we can use -I
:
julia> -I
UniformScaling{Int64}
-1*I
which is exactly the same as -1*I
. However, +I
is not defined:
julia> +I
ERROR: MethodError: no method matching +(::UniformScaling{Bool})
Closest candidates are:
+(::UniformScaling, ::Number) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/uniformscaling.jl:109
+(::UniformScaling, ::UniformScaling) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/uniformscaling.jl:114
+(::UniformScaling, ::BitArray{2}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/uniformscaling.jl:116
...
Stacktrace:
[1] top-level scope at REPL[136]:1
This seems confusing at first glance. Hence, I propose that we define +I
as +1*I
to keep consistency.
If this is approved, then I can do a PR.
Why not have
(+)(J::UniformScaling) = J
to avoid unnecessary promotion of J.位
?
I think I'd do:
(+)(J::UniformScaling) = UniformScaling(+J.位)
Why not have
(+)(J::UniformScaling) = J
to avoid unnecessary promotion of
J.位
?
The only problem here is that we will have a different behavior between -
and +
:
julia> import Base: +
julia> (+)(J::UniformScaling) = J
+ (generic function with 290 methods)
julia> -I
UniformScaling{Int64}
-1*I
julia> +I
UniformScaling{Bool}
true*I
I think I'd do:
(+)(J::UniformScaling) = UniformScaling(+J.位)
This seems to be fine since it replicates that same behavior of -
:
julia> import Base: +
julia> (+)(J::UniformScaling) = UniformScaling(+J.位)
+ (generic function with 167 methods)
julia> -I
UniformScaling{Int64}
-1*I
julia> +I
UniformScaling{Int64}
1*I
I will wait a couple of days for any new ideas and then I submit the PR.
Done! In Brazil, couple of days === 8 days 馃槄 (sorry for the delay, completely forgot about this...)
Most helpful comment
The only problem here is that we will have a different behavior between
-
and+
:This seems to be fine since it replicates that same behavior of
-
:I will wait a couple of days for any new ideas and then I submit the PR.