Skip to content

Commit

Permalink
Merge pull request #16980 from JuliaLang/tk/backports-0.4.6
Browse files Browse the repository at this point in the history
[release-0.4, RFC] backports for 0.4.6
  • Loading branch information
tkelman authored Jun 19, 2016
2 parents 4bca2df + ef7b1dd commit 0e2919f
Show file tree
Hide file tree
Showing 63 changed files with 892 additions and 413 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ before_install:
- make check-whitespace
- if [ `uname` = "Linux" ]; then
contrib/travis_fastfail.sh || exit 1;
BUILDOPTS="-j3 VERBOSE=1 FORCE_ASSERTIONS=1";
BUILDOPTS="-j3 VERBOSE=1 FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1";
if [ "$ARCH" = "i686" ]; then
export BUILDOPTS="$BUILDOPTS MARCH=pentium4";
else
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ There are never enough tests. Track [code coverage at Coveralls](https://coveral
5. Submit the test as a pull request.

* Code for the buildbot configuration is maintained at: https://github.com/staticfloat/julia-buildbot
* You can see the current buildbot setup at: http://buildbot.e.ip.saba.us:8010/builders
* You can see the current buildbot setup at: https://build.julialang.org/builders
* [Issue 9493](https://github.com/JuliaLang/julia/issues/9493) and [issue 11885](https://github.com/JuliaLang/julia/issues/11885) have more detailed discussion on code coverage.

Coveralls shows functionality that still needs "proof of concept" tests. These are important, as are tests for tricky edge cases, such as converting between integer types when the number to convert is near the maximum of the range of one of the integer types. Even if a function already has some coverage on Coveralls, it may still benefit from tests for edge cases.
Expand Down
31 changes: 28 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type BitArray{N} <: DenseArray{Bool, N}
end

BitArray{N}(dims::NTuple{N,Int}) = BitArray{N}(dims...)
BitArray(dims::Int...) = BitArray(dims)
BitArray(dims::Integer...) = BitArray(map(Int,dims))

typealias BitVector BitArray{1}
typealias BitMatrix BitArray{2}
Expand Down Expand Up @@ -235,8 +235,33 @@ function fill!(B::BitArray, x)
return B
end

falses(args...) = fill!(BitArray(args...), false)
trues(args...) = fill!(BitArray(args...), true)
"""
falses(dims)
Create a `BitArray` with all values set to `false`.
"""
falses(dims::Dims) = fill!(BitArray(dims), false)
falses(dims::Integer...) = falses(map(Int,dims))
"""
falses(A)
Create a `BitArray` with all values set to `false` of the same shape as `A`.
"""
falses(A::AbstractArray) = falses(size(A))

"""
trues(dims)
Create a `BitArray` with all values set to `true`.
"""
trues(dims::Dims) = fill!(BitArray(dims), true)
trues(dims::Integer...) = trues(map(Int,dims))
"""
trues(A)
Create a `BitArray` with all values set to `true` of the same shape as `A`.
"""
trues(A::AbstractArray) = trues(size(A))

function one(x::BitMatrix)
m, n = size(x)
Expand Down
5 changes: 4 additions & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ macro nloops(N, itersym, rangeexpr, args...)
_nloops(N, itersym, rangeexpr, args...)
end

_nloops(N::Int, itersym::Symbol, arraysym::Symbol, args::Expr...) = _nloops(N, itersym, :(d->1:size($arraysym,d)), args...)
function _nloops(N::Int, itersym::Symbol, arraysym::Symbol, args::Expr...)
@gensym d
_nloops(N, itersym, :($d->1:size($arraysym, $d)), args...)
end

function _nloops(N::Int, itersym::Symbol, rangeexpr::Expr, args::Expr...)
if rangeexpr.head != :->
Expand Down
65 changes: 65 additions & 0 deletions base/dates/accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,68 @@ yearmonthday(dt::TimeType) = yearmonthday(days(dt))
@vectorize_1arg TimeType yearmonth
@vectorize_1arg TimeType monthday
@vectorize_1arg TimeType yearmonthday


# Documentation for exported accessors
for func in (:year, :month)
name = string(func)
@eval begin
@doc """
$($name)(dt::TimeType) -> Int64
The $($name) of a `Date` or `DateTime` as an `Int64`.
""" $func(dt::TimeType)
end
end

"""
week(dt::TimeType) -> Int64
Return the [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date) of a `Date` or
`DateTime` as an `Int64`. Note that the first week of a year is the week that contains the
first Thursday of the year which can result in dates prior to January 4th being in the last
week of the previous year. For example `week(Date(2005,1,1))` is the 53rd week of 2004.
"""
week(dt::TimeType)

for func in (:day, :dayofmonth)
name = string(func)
@eval begin
@doc """
$($name)(dt::TimeType) -> Int64
The day of month of a `Date` or `DateTime` as an `Int64`.
""" $func(dt::TimeType)
end
end

"""
hour(dt::DateTime) -> Int64
The hour of day of a `DateTime` as an `Int64`.
"""
hour(dt::DateTime)

for func in (:minute, :second, :millisecond)
name = string(func)
@eval begin
@doc """
$($name)(dt::DateTime) -> Int64
The $($name) of a `DateTime` as an `Int64`.
""" $func(dt::DateTime)
end
end

for parts in (["year", "month"], ["month", "day"], ["year", "month", "day"])
name = join(parts)
func = symbol(name)
@eval begin
@doc """
$($name)(dt::TimeType) -> ($(join(repeated(Int64, length($parts)), ", ")))
Simultaneously return the $(join($parts, ", ", " and ")) parts of a `Date` or
`DateTime`.
""" $func(dt::TimeType)
end
end
2 changes: 1 addition & 1 deletion base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SLOT_RULE['s'] = Millisecond

duplicates(slots) = any(map(x->count(y->x.parser==y.parser,slots),slots) .> 1)

function DateFormat(f::AbstractString,locale::AbstractString="english")
function DateFormat(f::AbstractString, locale::AbstractString="english")
slots = Slot[]
prefix = ""
params = ()
Expand Down
29 changes: 24 additions & 5 deletions base/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@ value(x::Period) = x.value
# The default constructors for Periods work well in almost all cases
# P(x) = new((convert(Int64,x))
# The following definitions are for Period-specific safety
for p in (:Year,:Month,:Week,:Day,:Hour,:Minute,:Second,:Millisecond)
for period in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond)
period_str = string(period)
accessor_str = lowercase(period_str)
# Convenience method for show()
@eval _units(x::$p) = $(" " * lowercase(string(p))) * (abs(value(x)) == 1 ? "" : "s")
@eval _units(x::$period) = " " * $accessor_str * (abs(value(x)) == 1 ? "" : "s")
# periodisless
@eval periodisless(x::$p,y::$p) = value(x) < value(y)
@eval periodisless(x::$period,y::$period) = value(x) < value(y)
# AbstractString parsing (mainly for IO code)
@eval $p(x::AbstractString) = $p(Base.parse(Int64,x))
@eval $period(x::AbstractString) = $period(Base.parse(Int64,x))
# Period accessors
@eval $p(x::TimeType) = $p($(symbol(lowercase(string(p))))(x))
typ_str = period in (:Hour, :Minute, :Second, :Millisecond) ? "DateTime" : "TimeType"
description = typ_str == "TimeType" ? "`Date` or `DateTime`" : "`$typ_str`"
reference = period == :Week ? " For details see [`$accessor_str(::$typ_str)`](:func:`$accessor_str`)." : ""
@eval begin
@doc """
$($period_str)(dt::$($typ_str)) -> $($period_str)
The $($accessor_str) part of a $($description) as a `$($period_str)`.$($reference)
""" ->
$period(dt::$(symbol(typ_str))) = $period($(symbol(accessor_str))(dt))

@doc """
$($period_str)(v)
Construct a `$($period_str)` object with the given `v` value. Input must be
losslessly convertible to an `Int64`.
""" $period(v)
end
end
# Now we're safe to define Period-Number conversions
# Anything an Int64 can convert to, a Period can convert to
Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ end
function depwarn(msg, funcsym)
opts = JLOptions()
if opts.depwarn > 0
ln = unsafe_load(cglobal(:jl_lineno, Int))
ln = Int(unsafe_load(cglobal(:jl_lineno, Cint)))
fn = bytestring(unsafe_load(cglobal(:jl_filename, Ptr{Cchar})))
bt = backtrace()
caller = firstcaller(bt, funcsym)
Expand Down
40 changes: 27 additions & 13 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ SerializationState(io::IO) = SerializationState{typeof(io)}(io)

# dict

# These can be changed, to trade off better performance for space
const global maxallowedprobe = 16
const global maxprobeshift = 6

type Dict{K,V} <: Associative{K,V}
slots::Array{UInt8,1}
keys::Array{K,1}
Expand All @@ -380,10 +384,11 @@ type Dict{K,V} <: Associative{K,V}
count::Int
dirty::Bool
idxfloor::Int # an index <= the indexes of all used slots
maxprobe::Int

function Dict()
n = 16
new(zeros(UInt8,n), Array(K,n), Array(V,n), 0, 0, false, 1)
new(zeros(UInt8,n), Array(K,n), Array(V,n), 0, 0, false, 1, 0)
end
function Dict(kv)
h = Dict{K,V}()
Expand All @@ -406,7 +411,8 @@ type Dict{K,V} <: Associative{K,V}
rehash!(d)
end
@assert d.ndel == 0
new(copy(d.slots), copy(d.keys), copy(d.vals), 0, d.count, d.dirty, d.idxfloor)
new(copy(d.slots), copy(d.keys), copy(d.vals), 0, d.count, d.dirty, d.idxfloor,
d.maxprobe)
end
end
Dict() = Dict{Any,Any}()
Expand Down Expand Up @@ -495,7 +501,7 @@ function rehash!{K,V}(h::Dict{K,V}, newsz = length(h.keys))
vals = Array(V, newsz)
count0 = h.count
count = 0
maxprobe = max(16, newsz>>6)
maxprobe = h.maxprobe

for i = 1:sz
if olds[i] == 0x1
Expand All @@ -505,11 +511,8 @@ function rehash!{K,V}(h::Dict{K,V}, newsz = length(h.keys))
while slots[index] != 0
index = (index & (newsz-1)) + 1
end
if index - index0 > maxprobe
# rare condition: new table size causes more grouping of keys than before
# see issue #15077
return rehash!(h, newsz*2)
end
probe = (index - index0) & (newsz-1)
probe > maxprobe && (maxprobe = probe)
slots[index] = 0x1
keys[index] = k
vals[index] = v
Expand All @@ -527,6 +530,7 @@ function rehash!{K,V}(h::Dict{K,V}, newsz = length(h.keys))
h.vals = vals
h.count = count
h.ndel = 0
h.maxprobe = maxprobe

return h
end
Expand Down Expand Up @@ -562,7 +566,7 @@ end
function ht_keyindex{K,V}(h::Dict{K,V}, key)
sz = length(h.keys)
iter = 0
maxprobe = max(16, sz>>6)
maxprobe = h.maxprobe
index = hashindex(key, sz)
keys = h.keys

Expand All @@ -575,10 +579,9 @@ function ht_keyindex{K,V}(h::Dict{K,V}, key)
end

index = (index & (sz-1)) + 1
iter+=1
iter += 1
iter > maxprobe && break
end

return -1
end

Expand All @@ -588,7 +591,7 @@ end
function ht_keyindex2{K,V}(h::Dict{K,V}, key)
sz = length(h.keys)
iter = 0
maxprobe = max(16, sz>>6)
maxprobe = h.maxprobe
index = hashindex(key, sz)
avail = 0
keys = h.keys
Expand All @@ -610,12 +613,23 @@ function ht_keyindex2{K,V}(h::Dict{K,V}, key)
end

index = (index & (sz-1)) + 1
iter+=1
iter += 1
iter > maxprobe && break
end

avail < 0 && return avail

maxallowed = max(maxallowedprobe, sz>>maxprobeshift)
# Check if key is not present, may need to keep searching to find slot
while iter < maxallowed
if !isslotfilled(h,index)
h.maxprobe = iter
return -index
end
index = (index & (sz-1)) + 1
iter += 1
end

rehash!(h, h.count > 64000 ? sz*2 : sz*4)

return ht_keyindex2(h, key)
Expand Down
Loading

0 comments on commit 0e2919f

Please sign in to comment.