From ef88b4548d06a77d2574b32e70d2fb9d680a697c Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 15 Jun 2018 10:48:02 -0400 Subject: [PATCH 1/2] new norm, dot, and opnorm --- README.md | 5 +++++ src/Compat.jl | 9 +++++++++ test/runtests.jl | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 5e498609c..db057eaea 100644 --- a/README.md +++ b/README.md @@ -416,6 +416,10 @@ Currently, the `@compat` macro supports the following syntaxes: * `Unicode.isnumeric` is now available as `isnumeric` ([#25479]). +* `vecnorm` and `vecdot` are now `Compat.norm` and `Compat.dot`, respectively, while the + old `norm(A::AbstractMatrix, p=2)` is now `Compat.opnorm` ([#27401]). `import Compat: ⋅` + to get `Compat.dot` as the binary operator `⋅`. + * `atan2` is now a 2-argument method of `atan` ([#27253]). ## New macros @@ -648,3 +652,4 @@ includes this fix. Find the minimum version from there. [#27258]: https://github.com/JuliaLang/julia/issues/27258 [#27298]: https://github.com/JuliaLang/julia/issues/27298 [#27253]: https://github.com/JuliaLang/julia/issues/27253 +[#27401]: https://github.com/JuliaLang/julia/issues/27401 diff --git a/src/Compat.jl b/src/Compat.jl index 915ff6ef4..7e1f597fe 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1933,6 +1933,15 @@ if VERSION < v"0.7.0-DEV.5278" export something end +if !isdefined(LinearAlgebra, :opnorm) # julia#27401 + opnorm(A::AbstractMatrix, p::Real=2) = LinearAlgebra.norm(A, p) + norm(x, p::Real=2) = LinearAlgebra.vecnorm(x, p) + dot(x, y) = LinearAlgebra.vecdot(x, y) + const ⋅ = dot +else + const opnorm = LinearAlgebra.opnorm +end + # https://github.com/JuliaLang/julia/pull/27253 @static if VERSION < v"0.7.0-alpha.44" Base.atan(x::Real, y::Real) = atan2(x, y) diff --git a/test/runtests.jl b/test/runtests.jl index 73963fa47..171086217 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1778,6 +1778,14 @@ let sep = Compat.Sys.iswindows() ? ';' : ':' end end +# julia#27401 +import Compat: ⋅ +@test Compat.opnorm([1 2;3 4]) ≈ 5.464985704219043 +@test Compat.opnorm([1 2;3 4], 1) ≈ 6 +@test Compat.norm([1 2;3 4]) ≈ 5.477225575051661 +@test Compat.norm([1 2;3 4], 1) ≈ 10 +@test Compat.dot([1 2;3 4], [5 6;7 8]) == [1 2;3 4] ⋅ [5 6;7 8] ≈ 70 + # 0.7.0-alpha.44 @test atan(1, 2) == atan(0.5) @test atan(1.0, 2.0) == atan(0.5) From 42bbf3c1eb5ac4e59ec682cd0f8f9d958365ece3 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 15 Jun 2018 14:29:50 -0400 Subject: [PATCH 2/2] make sure to define Compat.norm and Compat.dot --- src/Compat.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index 7e1f597fe..06b24b061 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1935,12 +1935,14 @@ end if !isdefined(LinearAlgebra, :opnorm) # julia#27401 opnorm(A::AbstractMatrix, p::Real=2) = LinearAlgebra.norm(A, p) - norm(x, p::Real=2) = LinearAlgebra.vecnorm(x, p) - dot(x, y) = LinearAlgebra.vecdot(x, y) - const ⋅ = dot + const norm = LinearAlgebra.vecnorm + const dot = LinearAlgebra.vecdot else const opnorm = LinearAlgebra.opnorm + const norm = LinearAlgebra.norm + const dot = LinearAlgebra.dot end +const ⋅ = dot # https://github.com/JuliaLang/julia/pull/27253 @static if VERSION < v"0.7.0-alpha.44"