-
-
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 new compact parametric syntax where possible #20446
Conversation
This is great. The payoff is especially large when multiple parameters are involved. |
@@ -249,7 +249,7 @@ end | |||
|
|||
### Default to no pivoting (and storing of upper factor) when not explicit | |||
cholfact!(A::Hermitian) = cholfact!(A, Val{false}) | |||
cholfact!{T<:Real,S}(A::Symmetric{T,S}) = cholfact!(A, Val{false}) | |||
cholfact!(A::Symmetric{<:Real}) = cholfact!(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.
Can this really go from two parameters to one? I guess the 2nd isn't used at all?
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> Symmetric{<:Real}
Symmetric{#s1,S} where S<:(AbstractArray{T,2} where T) where #s1<:Real
And yes, the second isn't used.
786df30
to
ee778f5
Compare
base/abstractarray.jl
Outdated
@@ -89,7 +89,7 @@ julia> extrema(b) | |||
""" | |||
linearindices(A) = (@_inline_meta; OneTo(_length(A))) | |||
linearindices(A::AbstractVector) = (@_inline_meta; indices1(A)) | |||
eltype(::Type{A}) where A<:AbstractArray{E} where E = E | |||
eltype(::Type{<:AbstractArray{E}}) where E = E |
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.
parenthesize the where (E)
? would look a little more readable
fe86631
to
928c821
Compare
@@ -46,43 +46,43 @@ end | |||
read_tree!(idx::GitIndex, hash::AbstractGitHash) = | |||
read_tree!(idx, GitTree(repository(idx), hash)) | |||
|
|||
function add!{T<:AbstractString}(idx::GitIndex, files::T...; | |||
flags::Cuint = Consts.INDEX_ADD_DEFAULT) | |||
function add!(idx::GitIndex, files::AbstractString...; |
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 this should still work, but this change is slightly more permissive right? In the old version wouldn't each of files
have to be the same type, but now they can individually be different AbstractString
subtypes?
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.
Sounds like an improvement.
base/linalg/cholesky.jl
Outdated
@@ -445,13 +445,13 @@ function getindex{T<:BlasFloat}(C::CholeskyPivoted{T}, d::Symbol) | |||
throw(KeyError(d)) | |||
end | |||
|
|||
show{T,S<:AbstractMatrix}(io::IO, C::Cholesky{T,S}) = | |||
show{T}(io::IO, C::Cholesky{T,<:AbstractMatrix}) = |
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.
could the T
be <:Any
here? (also L454)
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.
Might be nice to support Foo{_,<:Bar}
for this sort of thing eventually.
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.
<:Any
is perfectly clear to me, I don't think it needs an abbreviation
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.
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.
Giving a special meaning to underscore like that is not at all intuitive. Saving 4 characters isn't worth ending up with code that requires finding an obscure manual section to understand.
base/linalg/lu.jl
Outdated
A_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, B::StridedMatrix) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), B[ipiv2perm(A.ipiv, size(B, 1)),:])) | ||
A_ldiv_B!{T<:BlasFloat}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('N', A.factors, A.ipiv, B) A.info | ||
A_ldiv_B!{T}(A::LU{T,<:StridedMatrix}, b::StridedVector) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), b[ipiv2perm(A.ipiv, length(b))])) | ||
A_ldiv_B!{T}(A::LU{T,<:StridedMatrix}, B::StridedMatrix) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), B[ipiv2perm(A.ipiv, size(B, 1)),:])) |
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.
looks like T
could be <:Any
for the latter two
base/linalg/lu.jl
Outdated
|
||
cond{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}, p::Number) = inv(LAPACK.gecon!(p == 1 ? '1' : 'I', A.factors, norm((A[:L]*A[:U])[A[:p],:], p))) | ||
cond{T<:BlasFloat}(A::LU{T,<:StridedMatrix}, p::Number) = inv(LAPACK.gecon!(p == 1 ? '1' : 'I', A.factors, norm((A[:L]*A[:U])[A[:p],:], p))) |
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.
LU{<:BlasFloat,<:StridedMatrix}
should work for these 3?
base/linalg/symmetric.jl
Outdated
det(A::Symmetric) = det(bkfact(A)) | ||
|
||
\{T,S<:StridedMatrix}(A::HermOrSym{T,S}, B::StridedVecOrMat) = \(bkfact(A.data, Symbol(A.uplo), issymmetric(A)), B) | ||
\{T}(A::HermOrSym{T,<:StridedMatrix}, B::StridedVecOrMat) = \(bkfact(A.data, Symbol(A.uplo), issymmetric(A)), B) |
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.
could T
be replaced by <:Any
here?
base/linalg/triangular.jl
Outdated
LAPACK.trrfs!($uploc, 'N', $isunitc, A.data, B, X) | ||
|
||
# Condition numbers | ||
function cond{T<:BlasFloat,S}(A::$t{T,S}, p::Real=2) | ||
function cond{T<:BlasFloat}(A::$t{T}, p::Real=2) |
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.
A::$t{<:BlasFloat}
?
base/linalg/triangular.jl
Outdated
LAPACK.trevc!('L', 'A', BlasInt[], tril!(A.data)') | ||
end | ||
function eigvecs{T<:BlasFloat,S<:StridedMatrix}(A::UnitLowerTriangular{T,S}) | ||
function eigvecs{T<:BlasFloat}(A::UnitLowerTriangular{T,<:StridedMatrix}) |
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.
A::XTriangular{<:BlasFloat,<:StridedMatrix}
for these 4?
base/sparse/abstractsparse.jl
Outdated
issparse{T}(S::LowerTriangular{T, <:AbstractSparseMatrix}) = true | ||
issparse{T}(S::LinAlg.UnitLowerTriangular{T, <:AbstractSparseMatrix}) = true | ||
issparse{T}(S::UpperTriangular{T, <:AbstractSparseMatrix}) = true | ||
issparse{T}(S::LinAlg.UnitUpperTriangular{T, <:AbstractSparseMatrix}) = true |
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.
{<:Any, <:AbstractSparseMatrix}
for these?
base/sparse/sparsematrix.jl
Outdated
@@ -222,7 +222,7 @@ function reinterpret{T,Tv,Ti,N}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}, dims::NTup | |||
return SparseMatrixCSC(mS, nS, colptr, rowval, nzval) | |||
end | |||
|
|||
function copy{T,P<:SparseMatrixCSC}(ra::ReshapedArray{T,2,P}) | |||
function copy{T}(ra::ReshapedArray{T,2,<:SparseMatrixCSC}) |
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.
T
can be <:Any
(unless ReshapedArray has constraints I guess)
base/sparse/sparsevector.jl
Outdated
hcat{Tv,Ti<:Integer}(X::SparseVector{Tv,Ti}...) = _absspvec_hcat(X...) | ||
hcat{Tv,Ti<:Integer}(X::AbstractSparseVector{Tv,Ti}...) = _absspvec_hcat(X...) | ||
hcat{Tv}(X::SparseVector{Tv,<:Integer}...) = _absspvec_hcat(X...) | ||
hcat{Tv}(X::AbstractSparseVector{Tv,<:Integer}...) = _absspvec_hcat(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.
would this allow each argument to have a different index type?
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:
julia> f(::(Vector{T} where T<:Real)...) = 1
f (generic function with 1 method)
julia> f([1,2,3], [4.0])
1
928c821
to
7195193
Compare
These lines can now probably be improved to:
|
7195193
to
3d7d4bf
Compare
Done |
@deprecate big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) big.(A) | ||
@deprecate big(A::AbstractArray{<:Complex{<:Integer}}) big.(A) | ||
@deprecate big(A::AbstractArray{<:Complex{<:AbstractFloat}}) big.(A) | ||
@deprecate big(x::AbstractArray{<:Complex{<:Rational{<:Integer}}}) big.(A) |
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 do these end up needing multiple levels of <:
?
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.
An AbstractArray{Complex{<:Integer}}
would be an array of elements that can hold any integer complex type (e.g. the elements can be Complex{Int}
, Complex{Int8}
, etcetera in the same array).
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.
AbstractArray{Complex{<:Integer}}
is equivalent to AbstractArray{Complex{T} where T<:Integer}
so it matches AbstratctArray
s with a UnionAll
element type (Complex{T} where T<:Integer
).
foo(::AbstractArray{Complex{<:Integer}}) = 1
bar(::AbstractArray{<:Complex{<:Integer}}) = 2
foo([1im]) #MethodError
bar([1im]) == 2
foo((Complex{T} where T<:Integer)[1im]) == 1
bar((Complex{T} where T<:Integer)[1im]) == 2
# since AbstractArray{Complex{T} where T<:Integer} <: (AbstractArray{T} where T<:(Complex{I} where I))
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.
UnionAll element types don't seem like they're going to occur in practice
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.
Yeah, but AbstractArray{<:Complex{<:Integer}}
will handle the cases we care about.
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.
isn't the problem not the number of where
s we need, but the placement? so AbstractArray{Complex{<:Integer}}
is AbstractArray{Complex{T} where T<:Integer}
but we actually want AbstractArray{Complex{T}} where T<:Integer
?
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.
We had R = AbstractArray{Complex{I},N} where N where I<:Integer
and with this we have S = AbstractArray{C,N} where N where C<:(Complex{I} where I<:Integer)
, but R <: S
. This will handle a little more cases (which we almost surely won't be seeing), but I don't see the harm in doing so.
3d7d4bf
to
2965a38
Compare
f = deserialize_rr(s,t) | ||
Future(f.where, RRID(f.whence, f.id), f.v) # ctor adds to client_refs table | ||
end | ||
|
||
function deserialize{T<:RemoteChannel}(s::AbstractSerializer, t::Type{T}) | ||
function deserialize(s::AbstractSerializer, t::Type{<:RemoteChannel}) |
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 had also converted function deserialize(s::ClusterSerializer, t::Type{T}) where T <: CapturedException
in an earlier version, which is now in clusterserialize.jl
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.
Missed it with all the moving from that PR. Will change it again.
66a7209
to
6a7b225
Compare
886da54
to
82a63fd
Compare
x-ref: #20414 (comment)