From 766c37969d4356a88e52768aa83d6743e5f30d4b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 18 Jul 2017 17:39:58 -0700 Subject: [PATCH] Add Val(x) Introduced in https://github.com/JuliaLang/julia/pull/22475 --- src/Compat.jl | 6 ++++++ test/runtests.jl | 29 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index c65f49e4f..5f0363316 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -607,6 +607,12 @@ if VERSION < v"0.6.0-pre.beta.455" isless(x::Dates.OtherPeriod, y::Dates.FixedPeriod) = throw(MethodError(isless, (x, y))) end +# https://github.com/JuliaLang/julia/pull/22475 +if VERSION < v"0.7.0-DEV.843" + import Base: Val + (::Type{Val})(x) = (Base.@_pure_meta; Val{x}()) +end + include("deprecated.jl") # https://github.com/JuliaLang/julia/pull/21746 diff --git a/test/runtests.jl b/test/runtests.jl index 5b86d7e2e..2aacb0a1e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -338,28 +338,33 @@ end # Val begin local firstlast - firstlast(::Type{Val{true}}) = "First" - firstlast(::Type{Val{false}}) = "Last" + firstlast(::Val{true}) = "First" + firstlast(::Val{false}) = "Last" - @test firstlast(Val{true}) == "First" - @test firstlast(Val{false}) == "Last" + @test firstlast(Val(true)) == "First" + @test firstlast(Val(false)) == "Last" end +# The constructors for some linear algebra stuff changed to take Val{x} +# instead of Type{Val{x}} +const valtrue = VERSION < v"0.7.0-DEV.843" ? Val{true} : Val(true) +const valfalse = VERSION < v"0.7.0-DEV.843" ? Val{false} : Val(false) + # qr, qrfact, qrfact! let A = [1.0 2.0; 3.0 4.0] - Q, R = qr(A, Val{false}) + Q, R = qr(A, valfalse) @test Q*R ≈ A - Q, R, p = qr(A, Val{true}) + Q, R, p = qr(A, valtrue) @test Q*R ≈ A[:,p] - F = qrfact(A, Val{false}) + F = qrfact(A, valfalse) @test F[:Q]*F[:R] ≈ A - F = qrfact(A, Val{true}) + F = qrfact(A, valtrue) @test F[:Q]*F[:R] ≈ A[:,F[:p]] A_copy = copy(A) - F = qrfact!(A_copy, Val{false}) + F = qrfact!(A_copy, valfalse) @test F[:Q]*F[:R] ≈ A A_copy = copy(A) - F = qrfact!(A_copy, Val{true}) + F = qrfact!(A_copy, valtrue) @test F[:Q]*F[:R] ≈ A[:,F[:p]] end @@ -1397,11 +1402,11 @@ for A in (Hermitian(randn(5,5) + 10I), @test istriu(chol(A)) @test chol(A) ≈ F[:U] - F = cholfact(A, Val{true}) + F = cholfact(A, valtrue) @test F[:U]'F[:U] ≈ A[F[:p], F[:p]] @test F[:L]*F[:L]' ≈ A[F[:p], F[:p]] Ac = copy(A) - F = cholfact!(Ac, Val{true}) + F = cholfact!(Ac, valfalse) @test F[:U]'F[:U] ≈ A[F[:p], F[:p]] @test F[:L]*F[:L]' ≈ A[F[:p], F[:p]] end