-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
faster and simpler generic_norm2 #43256
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
Changes from 2 commits
3e696ed
604adc3
44509da
aedb519
b8c8b85
689032c
812bd57
4306643
3de392a
d9de30b
543f563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -449,7 +449,7 @@ diag(A::AbstractVector) = throw(ArgumentError("use diagm instead of diag to cons | |||||
| # Dot products and norms | ||||||
|
|
||||||
| # special cases of norm; note that they don't need to handle isempty(x) | ||||||
| generic_normMinusInf(x) = float(mapreduce(norm, min, x)) | ||||||
| 2MinusInf(x) = float(mapreduce(norm, min, x)) | ||||||
|
|
||||||
| generic_normInf(x) = float(mapreduce(norm, max, x)) | ||||||
|
|
||||||
|
|
@@ -462,61 +462,33 @@ norm_sqr(x::Union{T,Complex{T},Rational{T}}) where {T<:Integer} = abs2(float(x)) | |||||
|
|
||||||
| function generic_norm2(x) | ||||||
| maxabs = normInf(x) | ||||||
| (maxabs == 0 || isinf(maxabs)) && return maxabs | ||||||
| (v, s) = iterate(x)::Tuple | ||||||
| (ismissing(maxabs) || maxabs == 0 || isinf(maxabs)) && return maxabs | ||||||
|
||||||
| (ismissing(maxabs) || maxabs == 0 || isinf(maxabs)) && return maxabs | |
| (isinf(maxabs) !== false || maxabs == 0) && return maxabs |
be preferable? (Which I think should be equivalent, but please do double-check.)
EDIT by @dkarrasch : one needs to avoid performing maxabs == 0 because that throws a TypeError: non-boolean (Missing) used in boolean context. Otherwise that would work, because of short-circuiting.
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.
So that you get a notification: I modified @martinholters's suggestion, which I tested for maxabs = missing and it works.
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, and that same trick should make it possible to apply the same steps to generic_normp!
Uh oh!
There was an error while loading. Please reload this page.