-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use Val(x) and f(::Val{x}) #22475
Use Val(x) and f(::Val{x}) #22475
Conversation
You are replacing the current docstring here with your new one. You can probably merge them into the same docstring and delete the one in |
Are there any tangible benefits, e.g. in terms of inferability or time needed for inference? (Just curious, not that I'm against this PR if there aren't.) |
While I feel it's primarily aesthetic, you can also infer multiple return |
base/deprecated.jl
Outdated
@deprecate literal_pow{N}(a,b , ::Type{Val{N}}) literal_pow(f, Val(N)) | ||
#@deprecate IteratorsMD.split(t, V::Type{Val{n}}) IteratorsMD.split(t, Val(n)) | ||
@deprecate sqrtm{T,realmatrix}(A::UpperTriangular{T},::Type{Val{realmatrix}}) sqrtm(A, Val(realmatrix)) | ||
@deprecate lufact(A, pivot::Union{Type{Val{false}}, Type{Val{true}}}) lufact(A, pivot) |
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.
The replacement syntax is the same!? Wont this create an infinite loop?
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.
Yes - yes it would :) Thanks @fredrikekre
See also earlier discussion in #9452 |
I wasn't expected to change |
base/deprecated.jl
Outdated
@deprecate ntuple{N}(f, ::Type{Val{N}}) ntuple(f, Val(N)) | ||
@deprecate fill_to_length{N}(t, val, ::Type{Val{N}}) fill_to_length(t, val, Val(N)) | ||
@deprecate literal_pow{N}(a,b , ::Type{Val{N}}) literal_pow(f, Val(N)) | ||
#@deprecate IteratorsMD.split(t, V::Type{Val{n}}) IteratorsMD.split(t, Val(n)) |
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.
the @deprecate
macro was not happy with this. Probably unnecessary.
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.
You can @eval
the deprecation into the IteratorsMS
module.
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.
IIRC, happily @deprecate
now accepts a module as well? :)
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.
Nope
julia> @deprecate Base.foo Base.bar
ERROR: invalid usage of @deprecate
Could be fixed though.
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.
@eval
accepts a module, and you can put the @deprecate
in an @eval
block
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.
Ah yes, it's @eval module @dep...
that I was remembering :).
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.
Thats what I suggested 😄
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.
Indeed :)
@@ -134,7 +134,7 @@ Base.@propagate_inbounds _broadcast_getindex(::Any, A, I) = A[I] | |||
## Broadcasting core | |||
# nargs encodes the number of As arguments (which matches the number | |||
# of keeps). The first two type parameters are to ensure specialization. | |||
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Type{Val{N}}, iter) where {K,ID,AT,BT,N} | |||
@generated function _broadcast!(f, B::AbstractArray, keeps::K, Idefaults::ID, A::AT, Bs::BT, ::Val{N}, iter) where {K,ID,AT,BT,N} |
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.
Is this public interface (meaning - does this require a @deprecate
)?
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.
Should be fine without :).
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.
unless packages have been extending it...
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.
DataArrays, StaticArrays, and IndexedTables define methods for something called _broadcast!
but I don't think they're importing the Base one
There is an export true/false option for |
|
base/deprecated.jl
Outdated
@@ -1485,6 +1485,23 @@ end | |||
using .DSP | |||
export conv, conv2, deconv, filt, filt!, xcorr | |||
|
|||
# PR #22475 | |||
@deprecate ntuple{N}(f, ::Type{Val{N}}) ntuple(f, Val(N)) |
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.
use new where
syntax here and below?
@deprecate ntuple(f, ::Type{Val{N}}) where {N} ntuple(f, Val(N))
base/essentials.jl
Outdated
""" | ||
Val(c) | ||
|
||
Constructs a `Val{c}()`, which contains no run-time data. Types like this can be used to |
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.
"Construct" instead of "Constructs" to comply with the usual phrasing of docstrings?
end | ||
|
||
Val(x) = (@_pure_meta; Val{x}()) | ||
|
||
show(io::IO, ::Val{x}) where {x} = print(io, "Val($x)") |
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.
Why this? Shouldn't we show the object for what it is, i.e. Val{T}()
(as it does by default already)
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.
The cool kids like "print it like you write it" these days.
I personally feel this much more aesthetic. There is a doc string for Val
which explains the representation.
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.
julia> dot([1, 2], [3, 4])
dot([1, 2], [3, 4])
? 😄
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.
It does kind of make sense to show it the way it's expected to be written, but we don't generally do this in other cases, e.g.
julia> Ref(0)
Base.RefValue{Int64}(0)
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.
And also, Val(x)
is just for convenience; Val{x}()
is the "real" constructor, right? :)
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.
The RefValue
example exposes larger differences, e.g. a concrete type, and we allow RefValue{Any}(0)
also. In the case of Val
the relation is (more-or-less) one-to-one; I wouldn't have done it otherwise and in my opinion the printing of RefValue
is 100% correct.
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.
I think I'm ok with either printing in this case.
30463e4
to
51998dc
Compare
There is a single spawn test failure on OSX throwing an InterruptException on travis. I'm guessing this is unrelated. Other than that - is this good to go? |
base/deprecated.jl
Outdated
@deprecate literal_pow{N}(a,b , ::Type{Val{N}}) literal_pow(f, Val(N)) false | ||
@eval IteratorsMD @deprecate split{n}(t, V::Type{Val{n}}) split(t, Val(n)) false | ||
@deprecate sqrtm{T,realmatrix}(A::UpperTriangular{T},::Type{Val{realmatrix}}) sqrtm(A, Val(realmatrix)) | ||
@deprecate lufact(::AbstractMatrix, ::Type{Val{false}}) lufact(A, Val(false)) |
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.
missing A on the input ?
base/deprecated.jl
Outdated
# PR #22475 | ||
@deprecate ntuple{N}(f, ::Type{Val{N}}) ntuple(f, Val(N)) | ||
@deprecate fill_to_length{N}(t, val, ::Type{Val{N}}) fill_to_length(t, val, Val(N)) false | ||
@deprecate literal_pow{N}(a,b , ::Type{Val{N}}) literal_pow(f, Val(N)) false |
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.
strange spacing on the inputs, f not defined?
base/deprecated.jl
Outdated
@deprecate cat{N}(::Type{Val{N}}, A::AbstractArray...) cat(Val(N), A...) | ||
@deprecate cat{N}(::Type{Val{N}}, A::SparseArrays._SparseConcatGroup...) cat(Val(N), A...) | ||
@deprecate cat{N}(::Type{Val{N}}, A::SparseArrays._DenseConcatGroup...) cat(Val(N), A...) | ||
@deprecate cat_t{N,T}(::Type{Val{N}}, ::Type{T}, A, B) cat(Val(N), T, A, B) false |
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.
should this call cat_t
?
base/essentials.jl
Outdated
Return `Val{c}()`, which contains no run-time data. Types like this can be used to | ||
pass the information between functions through the value `c`, which must be an `isbits` | ||
value. The intent of this construct is to be able to dispatch on constants directly (at | ||
compile time) without having test the value of the constant at run time. |
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.
having to test
base/essentials.jl
Outdated
compile time) without having test the value of the constant at run time. | ||
|
||
### Example | ||
|
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.
use
# Examples
```jldoctest
single #, plural Examples, no blank
@@ -208,7 +208,7 @@ chol(x::Number, args...) = ((C, info) = _chol!(x, nothing); @assertposdef C info | |||
# cholfact!. Destructive methods for computing Cholesky factorization of real symmetric | |||
# or Hermitian matrix | |||
## No pivoting (default) | |||
function cholfact!(A::RealHermSymComplexHerm, ::Type{Val{false}}=Val{false}) | |||
function cholfact!(A::RealHermSymComplexHerm, ::Val{false}=Val(false)) |
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.
cholfact!
and cholfact
are missing from news and deprecations
function reshape(parent::AbstractArray, ndims::Type{Val{N}}) where N | ||
reshape(parent, rdims(Val{N}, indices(parent))) | ||
reshape(parent::AbstractArray{T,N}, ndims::Val{N}) where {T,N} = parent | ||
function reshape(parent::AbstractArray, ndims::Val{N}) where N |
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.
mention in news
Should do something with these too I think Lines 1356 to 1362 in 71d7c16
Val usage in the 0.6 section of deprecated.jl but should not matter.
|
2bdbb63
to
76c4a2b
Compare
👍 |
The timeout on 64 bit Linux Travis is a bit unexpected. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
Replaces `f(Val{x})` on call sites with `f(Val(x))`, using a new `@pure` function `Val(x) = Val{x}()`. This simplifies the method definitions from `f(::Type{Val{x}}) where x` to `f(::Val{x}) where x`. This form also has the advantage that multiple singleton instances can be put in a tuple and inference will work (similarly with multiple-return functions).
Thanks everyone for reviewing! I have rebased, and updated the manual to reflect this change. |
Appveyor error is something about pkg and libgit2 on Windows... |
Merge? |
Yes, please (I can't do it). |
Introduced in JuliaLang/julia#22475
Introduced in JuliaLang/julia#22475
Introduced in JuliaLang/julia#22475
@JeffBezanson as discussed. Instead of calling
f(Val{x})
and method definitionsf(::Type{Val{x}}) where x = ...
, we usef(Val(x))
andf(::Val{x}) where x = ...
. There is a new@pure
function forVal(x) -> Val{x}()
, ashow
override, and a docstring/doctest.This is WIP and so far only "upgrades" two functions (I have replaced all uses ofntuple
andfill_to_length
). I am currently intending to replaceVal{x}
inBase
with the new constructor (except for specific inference tests targeting type parameters).Also, what does this mean when building? I'm kind-of lost with the documentation system.