-
-
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
Fixed norm #30481
Fixed norm #30481
Conversation
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 isn’t correct, I think: the float
function isn’t defined for an arbitrary iterators, and in any case might make a copy of a whole array.
We need to call float
on the individual elements inside the loops of the norm functions.
stdlib/LinearAlgebra/src/generic.jl
Outdated
@@ -273,40 +273,40 @@ diag(A::AbstractVector) = throw(ArgumentError("use diagm instead of diag to cons | |||
# special cases of norm; note that they don't need to handle isempty(x) | |||
function generic_normMinusInf(x) | |||
(v, s) = iterate(x)::Tuple | |||
minabs = norm(v) | |||
minabs = norm(float(v)) |
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 isn't right either, since v
might not be a scalar.
We might need to call something like floatnorm(x) = norm(x) # fallback
floatnorm(x::Number) = norm(float(x)) # avoid wraparound for `typemin(Int)` values (There's also the question of what the performance hit for this is for the norm of integer arrays, and whether it is worth it.) |
@stevengj The failing Quaternion array test is due to absence of AbstractFloat(::Quaternion{Float64}) declaration which would again fall under |
Note that the quaternion type is also susceptible to wraparound problems for Two questions:
|
@stevengj |
Arguably, any serious quaternion type should have a |
@stevengj Maybe we can explicitly define AbstractFloat for Quaternion type just like other function are explicitly defined for it like abs, real or conj something like this
|
@raghav9-97, I don't think that's correct. Similarly, |
Given that we currently promote to floats in We thereby require that any number type used with A final comment, given our choice of integer arithmetic, I think JuliaLang/LinearAlgebra.jl#593 is actually only an issue because we convert to floats in |
@andreasnoack Is it correct definition of float(z::Quaternion) ? |
Yes. That definition for |
I have not yet checked for the tests which needs to be changed maybe there aren't any. In addition to the Quaternion float definition and converting input to float before |
I suspect that you can just remove all the |
Thanks for the help @andreasnoack. |
stdlib/LinearAlgebra/test/generic.jl
Outdated
@@ -225,6 +225,12 @@ end | |||
end | |||
end | |||
|
|||
@testset "Issue #30466" begin | |||
@test norm([typemin(Int), typemin(Int)], Inf) == 9.223372036854776e18 | |||
@test norm([typemin(Int), typemin(Int)], -Inf) == 9.223372036854776e18 |
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.
Did we discuss this anywhere? I'm not sure we should allow negative p
arguments so probably better to leave out this test.
Is it now good enough to be merged? |
Two issues:
|
Our general policy has been that this could be an acceptable "minor change" if it doesn't break any packages when we run PkgEval. |
I really doubt that it breaks anything so I'd rather not introduce a new function for this. We run the package evaluator before releases so if it breaks anything we should be able to detect it. It's also a bit odd that |
Do we need some other changes in PR or is it okay to merge? |
tests are failing? |
Also, what is the performance impact (if any) for |
stdlib/LinearAlgebra/test/generic.jl
Outdated
@@ -225,6 +225,11 @@ end | |||
end | |||
end | |||
|
|||
@testset "Issue #30466" begin | |||
@test norm([typemin(Int), typemin(Int)], Inf) == 9.223372036854776e18 |
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.
Int
is Int32
on 32 bit systems so make the rhs here float(typemax(Int))
and 2float(typemax(Int))
in the line below.
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.
You mean -float(typemin(Int))
, I guess (since typemin
and typemax
are not equal in magnitude).
Is this PR now ready to be merged? |
I believe we are still waiting for the benchmarks requested in |
Benchmarks for new norm function
Benchmarks for old norm function
|
Thanks for helping me out @andreasnoack @stevengj. |
Fixes JuliaLang/LinearAlgebra.jl#593.