-
-
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
det(I) #23364
det(I) #23364
Conversation
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,7 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling) = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't think this handles correctly when \lambda
is not 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's better.
Could also add |
I made it |
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,8 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling{T}) where {T} = one(T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but det (10*eye(n,n)) == 10^n
not 1.0, so I don't think this will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, forgot about the lambda. My bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you could check if \lambda == 1
or else throw, but doesn't seem very useful ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it is useful if you don't want to special case it. I opened this PR because I ran into that exact issue:
https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/problems/dde_problems.jl#L36
|
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,8 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling{T}) where {T} = J.λ==one(T) ? one(T) : error("Determinant of UniformScaling is only well-defined when λ=1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArgumentError
would be better than error
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,8 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling{T}) where {T} = J.λ==one(T) ? one(T) : ArgumentError("Determinant of UniformScaling is only well-defined when λ=1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isone(J.λ) ? one(T) : throw(ArgumentError("Determinant of UniformScaling is only well-defined when λ = 1."))
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,8 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling{T}) where {T} = isone(J.λ) ? one(T) : throw(ArgumentError("Determinant of UniformScaling is only well-defined when λ=1.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually one
is wrong as well. det(eye(Int, 3, 3))
is Float64
, whereas det(I)
will be Int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
det(eye(Int, 3, 3))
is a Float64
only because it is promoted to perform an LU factorization. In this case we don't need that so I think one(T)
is perfectly fine. We have for example:
julia> det(Diagonal([1,2,3]))
6
for the same reason; no need to promote for LU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0I
should also be fine?
base/linalg/uniformscaling.jl
Outdated
@@ -167,6 +167,8 @@ end | |||
|
|||
inv(J::UniformScaling) = UniformScaling(inv(J.λ)) | |||
norm(J::UniformScaling, p::Real=2) = abs(J.λ) | |||
det(J::UniformScaling{T}) where {T} = isone(J.λ) ? one(T) : throw(ArgumentError("Determinant of UniformScaling is only well-defined when λ=1.")) | |||
logdet(::UniformScaling{T}) where {T} = isone(J.λ) ? log(one(T)) : throw(ArgumentError("Determinant of UniformScaling is only well-defined when λ=1.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing J
for the argument. But we actually do not need this since we have
Line 1267 in e701561
logdet(A) = log(det(A)) |
Codecov Report
@@ Coverage Diff @@
## master #23364 +/- ##
==========================================
- Coverage 54.98% 54.98% -0.01%
==========================================
Files 275 275
Lines 51130 51132 +2
==========================================
- Hits 28115 28114 -1
- Misses 23015 23018 +3
Continue to review full report at Codecov.
|
What about |
Why should it match |
I think the current implementation is OK. There is a trailing whitespace (which fails CI) and would be great with some testcases :) |
test/linalg/uniformscaling.jl
Outdated
@test typeof(det(I)) == Int | ||
@test typeof(det(1.0I)) == Float64 | ||
@test iszero(det(0I)) | ||
@test isone(logdet(I)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be iszero
, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🇸🇪
test/linalg/uniformscaling.jl
Outdated
@@ -43,6 +43,15 @@ end | |||
@test UniformScaling(α)./α == UniformScaling(1.0) | |||
end | |||
|
|||
@testset "det and logdet" begin | |||
@test isone(det(I)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should actually change this to @test det(I) === 1
instead. Since isone(I)
is true, this will still succeed if det(::UniformScaling)
becomes a no-op :)
When an input line like `[import|using] AAA: xxx` is entered, if `AAA` is already loaded in the REPL session, it will now autocomplete to the names available in `AAA` that start with `xxx`. For example, it will autocomplete `using Base.Experimental: @ov|` to `using Base.Experimental: @overlay`. - fixes #23364
When an input line like `[import|using] AAA: xxx` is entered, if `AAA` is already loaded in the REPL session, it will now autocomplete to the names available in `AAA` that start with `xxx`. For example, it will autocomplete `using Base.Experimental: @ov|` to `using Base.Experimental: @overlay`. - fixes #23364
When an input line like `[import|using] AAA: xxx` is entered, if `AAA` is already loaded in the REPL session, it will now autocomplete to the names available in `AAA` that start with `xxx`. For example, it will autocomplete `using Base.Experimental: @ov|` to `using Base.Experimental: @overlay`. - fixes #23364
When an input line like `[import|using] AAA: xxx` is entered, if `AAA` is already loaded in the REPL session, it will now autocomplete to the names available in `AAA` that start with `xxx`. For example, it will autocomplete `using Base.Experimental: @ov|` to `using Base.Experimental: @overlay`. - fixes #23364
When an input line like `[import|using] AAA: xxx` is entered, if `AAA` is already loaded in the REPL session, it will now autocomplete to the names available in `AAA` that start with `xxx`. For example, it will autocomplete `using Base.Experimental: @ov|` to `using Base.Experimental: @overlay`. - fixes #23364
The determinant for the UniformScaling operator was missing.