Skip to content

Commit

Permalink
Add Val(x)
Browse files Browse the repository at this point in the history
Introduced in JuliaLang/julia#22475
  • Loading branch information
ararslan committed Jul 19, 2017
1 parent bdf61d8 commit 280c2fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,28 +338,28 @@ 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

# qr, qrfact, qrfact!
let A = [1.0 2.0; 3.0 4.0]
Q, R = qr(A, Val{false})
Q, R = qr(A, Val(false))
@test Q*R A
Q, R, p = qr(A, Val{true})
Q, R, p = qr(A, Val(true))
@test Q*R A[:,p]
F = qrfact(A, Val{false})
F = qrfact(A, Val(false))
@test F[:Q]*F[:R] A
F = qrfact(A, Val{true})
F = qrfact(A, Val(true))
@test F[:Q]*F[:R] A[:,F[:p]]
A_copy = copy(A)
F = qrfact!(A_copy, Val{false})
F = qrfact!(A_copy, Val(false))
@test F[:Q]*F[:R] A
A_copy = copy(A)
F = qrfact!(A_copy, Val{true})
F = qrfact!(A_copy, Val(true))
@test F[:Q]*F[:R] A[:,F[:p]]
end

Expand Down Expand Up @@ -1397,11 +1397,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, Val(true))
@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, Val(true))
@test F[:U]'F[:U] A[F[:p], F[:p]]
@test F[:L]*F[:L]' A[F[:p], F[:p]]
end
Expand Down

0 comments on commit 280c2fc

Please sign in to comment.