Skip to content
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

Add Val(x) #381

Merged
merged 2 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064])

* `Val(x)` constructs `Val{x}()`. ([#22475])

## Renamed functions


Expand Down Expand Up @@ -283,3 +285,4 @@ includes this fix. Find the minimum version from there.
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22475]: https://github.com/JuliaLang/julia/issues/22475
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
29 changes: 17 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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, valtrue)
@test F[:U]'F[:U] ≈ A[F[:p], F[:p]]
@test F[:L]*F[:L]' ≈ A[F[:p], F[:p]]
end
Expand Down