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

Change some arguments from T::Type::Type{T} #10989

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function cat(catdims, X...)
cat_t(catdims, T, X...)
end

function cat_t(catdims, typeC::Type, X...)
function cat_t{typeC}(catdims, ::Type{typeC}, X...)
catdims = collect(catdims)
nargs = length(X)
ndimsX = Int[isa(a,AbstractArray) ? ndims(a) : 0 for a in X]
Expand Down Expand Up @@ -711,8 +711,8 @@ end
vcat(X...) = cat(1, X...)
hcat(X...) = cat(2, X...)

typed_vcat(T::Type, X...) = cat_t(1, T, X...)
typed_hcat(T::Type, X...) = cat_t(2, T, X...)
typed_vcat{T}(::Type{T}, X...) = cat_t(1, T, X...)
typed_hcat{T}(::Type{T}, X...) = cat_t(2, T, X...)

cat{T}(catdims, A::AbstractArray{T}...) = cat_t(catdims, T, A...)

Expand All @@ -721,8 +721,8 @@ cat(catdims, A::AbstractArray...) = cat_t(catdims, promote_eltype(A...), A...)
vcat(A::AbstractArray...) = cat(1, A...)
hcat(A::AbstractArray...) = cat(2, A...)

typed_vcat(T::Type, A::AbstractArray...) = cat_t(1, T, A...)
typed_hcat(T::Type, A::AbstractArray...) = cat_t(2, T, A...)
typed_vcat{T}(::Type{T}, A::AbstractArray...) = cat_t(1, T, A...)
typed_hcat{T}(::Type{T}, A::AbstractArray...) = cat_t(2, T, A...)

# 2d horizontal and vertical concatenation

Expand Down Expand Up @@ -814,7 +814,7 @@ function hvcat_fill(a, xs)
a
end

function typed_hvcat(T::Type, rows::Tuple{Vararg{Int}}, xs::Number...)
function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...)
nr = length(rows)
nc = rows[1]
for i = 2:nr
Expand Down Expand Up @@ -846,7 +846,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, as...)
vcat(rs...)
end

function typed_hvcat(T::Type, rows::Tuple{Vararg{Int}}, as...)
function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, as...)
nbr = length(rows) # number of block rows
rs = cell(nbr)
a = 1
Expand Down
14 changes: 7 additions & 7 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ function countlines(io::IO, eol::Char)
nl
end

readdlm(input, T::Type; opts...) = readdlm(input, invalid_dlm, T, '\n'; opts...)
readdlm(input, dlm::Char, T::Type; opts...) = readdlm(input, dlm, T, '\n'; opts...)
readdlm{T}(input, ::Type{T}; opts...) = readdlm(input, invalid_dlm, T, '\n'; opts...)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 1-line function like this that just passes its arguments through is a perfect example of a case where you don't need to specialize on every value of T.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it treated differently upon inlining? I was under the (perhaps misguided) impression that this was also the better style in general. I'll re-examine this PR with more consideration.

readdlm{T}(input, dlm::Char, ::Type{T}; opts...) = readdlm(input, dlm, T, '\n'; opts...)

readdlm(input; opts...) = readdlm(input, invalid_dlm, '\n'; opts...)
readdlm(input, dlm::Char; opts...) = readdlm(input, dlm, '\n'; opts...)

readdlm(input, dlm::Char, eol::Char; opts...) = readdlm_auto(input, dlm, Float64, eol, true; opts...)
readdlm(input, dlm::Char, T::Type, eol::Char; opts...) = readdlm_auto(input, dlm, T, eol, false; opts...)
readdlm{T}(input, dlm::Char, ::Type{T}, eol::Char; opts...) = readdlm_auto(input, dlm, T, eol, false; opts...)

function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
function readdlm_auto{T}(input, dlm::Char, ::Type{T}, eol::Char, auto::Bool; opts...)
optsd = val_opts(opts)
use_mmap = get(optsd, :use_mmap, @windows ? false : true)
isa(input, AbstractString) && (fsz = filesize(input); input = use_mmap && (fsz > 0) && fsz < typemax(Int) ? as_mmap(input,fsz) : readall(input))
Expand Down Expand Up @@ -241,7 +241,7 @@ function result{T}(dlmstore::DLMStore{T})
end


function readdlm_string(sbuff::ByteString, dlm::Char, T::Type, eol::Char, auto::Bool, optsd::Dict)
function readdlm_string{T}(sbuff::ByteString, dlm::Char, ::Type{T}, eol::Char, auto::Bool, optsd::Dict)
ign_empty = (dlm == invalid_dlm)
quotes = get(optsd, :quotes, true)
comments = get(optsd, :comments, true)
Expand Down Expand Up @@ -298,7 +298,7 @@ function val_opts(opts)
d
end

function dlm_fill(T::DataType, offarr::Vector{Vector{Int}}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::ByteString, auto::Bool, eol::Char)
function dlm_fill{T}(::Type{T}, offarr::Vector{Vector{Int}}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::ByteString, auto::Bool, eol::Char)
idx = 1
offidx = 1
offsets = offarr[1]
Expand Down Expand Up @@ -530,7 +530,7 @@ function dlm_parse{T,D}(dbuff::T, eol::D, dlm::D, qchar::D, cchar::D, ign_adj_dl
end

readcsv(io; opts...) = readdlm(io, ','; opts...)
readcsv(io, T::Type; opts...) = readdlm(io, ',', T; opts...)
readcsv{T}(io, ::Type{T}; opts...) = readdlm(io, ',', T; opts...)

# todo: keyword argument for # of digits to print
writedlm_cell(io::IO, elt::FloatingPoint, dlm, quotes) = print_shortest(io, elt)
Expand Down