Skip to content

Commit

Permalink
more general indexing [4]
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zhabinski committed May 6, 2016
1 parent 9caa28d commit ba52671
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ function writedlm(io::IO, a::AbstractMatrix, dlm; opts...)
pb = PipeBuffer()
nr = size(a, 1)
nc = size(a, 2)
for i = 1:nr
for i = 1:nr # fixme (iter): improve if timholy/ArrayIteration.jl is merged into Base
for j = 1:nc
writedlm_cell(pb, a[i, j], dlm, quotes)
j == nc ? write(pb,'\n') : print(pb,dlm)
Expand Down
22 changes: 11 additions & 11 deletions base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,19 @@ Date(dt::AbstractString,df::DateFormat=ISODateFormat) = Date(parse(dt,df)...)
format(dt::TimeType,f::AbstractString;locale::AbstractString="english") = format(dt,DateFormat(f,locale))

# vectorized
DateTime{T<:AbstractString}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = DateTime(y,DateFormat(format,locale))
function DateTime{T<:AbstractString}(y::AbstractArray{T},df::DateFormat=ISODateTimeFormat)
return reshape(DateTime[DateTime(parse(y[i],df)...) for i in 1:length(y)], size(y))
DateTime{T<:AbstractString}(Y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = DateTime(Y,DateFormat(format,locale))
function DateTime{T<:AbstractString}(Y::AbstractArray{T},df::DateFormat=ISODateTimeFormat)
return reshape(DateTime[DateTime(parse(y,df)...) for y in Y], size(Y))
end
Date{T<:AbstractString}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Date(y,DateFormat(format,locale))
function Date{T<:AbstractString}(y::AbstractArray{T},df::DateFormat=ISODateFormat)
return reshape(Date[Date(parse(y[i],df)...) for i in 1:length(y)], size(y))
Date{T<:AbstractString}(Y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Date(Y,DateFormat(format,locale))
function Date{T<:AbstractString}(Y::AbstractArray{T},df::DateFormat=ISODateFormat)
return reshape(Date[Date(parse(y,df)...) for y in Y], size(Y))
end

format{T<:TimeType}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Dates.format(y,DateFormat(format,locale))
function format(y::AbstractArray{Date},df::DateFormat=ISODateFormat)
return reshape([Dates.format(y[i],df) for i in 1:length(y)], size(y))
format{T<:TimeType}(Y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Dates.format(Y,DateFormat(format,locale))
function format(Y::AbstractArray{Date},df::DateFormat=ISODateFormat)
return reshape([Dates.format(y,df) for y in Y], size(Y))
end
function format(y::AbstractArray{DateTime},df::DateFormat=ISODateTimeFormat)
return reshape([Dates.format(y[i],df) for i in 1:length(y)], size(y))
function format(Y::AbstractArray{DateTime},df::DateFormat=ISODateTimeFormat)
return reshape([Dates.format(y,df) for y in Y], size(Y))
end
8 changes: 4 additions & 4 deletions base/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ for (op,Ty,Tz) in ((:.*,Real,:P),
@eval begin
function ($op){P<:Period}(X::StridedArray{P},y::$Ty)
Z = similar(X, $Tz)
for i = 1:length(X)
@inbounds Z[i] = ($op_)(X[i],y)
for (Idst, Isrc) in zip(eachindex(Z), eachindex(X))
@inbounds Z[Idst] = ($op_)(X[Isrc],y)
end
return Z
end
Expand Down Expand Up @@ -238,8 +238,8 @@ for op in (:.+, :.-)
@eval begin
function ($op){P<:GeneralPeriod}(X::StridedArray{P},y::GeneralPeriod)
Z = similar(X, CompoundPeriod)
for i = 1:length(X)
@inbounds Z[i] = ($op_)(X[i],y)
for (Idst, Isrc) in zip(eachindex(Z), eachindex(X))
@inbounds Z[Idst] = ($op_)(X[Isrc],y)
end
return Z
end
Expand Down
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ end
function digits!{T<:Integer}(a::AbstractArray{T,1}, n::Integer, base::Integer=10)
2 <= base || throw(ArgumentError("base must be ≥ 2, got $base"))
base - 1 <= typemax(T) || throw(ArgumentError("type $T too small for base $base"))
for i = 1:length(a)
for i in eachindex(a)
a[i] = rem(n, base)
n = div(n, base)
end
Expand Down

0 comments on commit ba52671

Please sign in to comment.