Skip to content

Commit

Permalink
Fix some Julia v0.6 / v0.7 combatiblity bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Ferris committed Jul 10, 2018
1 parent 1bbccc5 commit 55287b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/group.jl
Expand Up @@ -148,7 +148,6 @@ if VERSION < v"0.7-"
"""
function groupreduce(by, op, f, iter; kw...)
# TODO Do this inference-free, like comprehensions...
nt = kw.data
T = eltype(iter)
K = promote_op(by, T)
T2 = promote_op(f, T)
Expand All @@ -161,12 +160,12 @@ if VERSION < v"0.7-"
if dict_index > 0
@inbounds out.vals[dict_index] = op(out.vals[dict_index], f(x))
else
if nt isa NamedTuple{()}
if length(kw) == 0
Base._setindex!(out, convert(V, f(x)), key, -dict_index)
elseif nt isa NamedTuple{(:init,)}
Base._setindex!(out, convert(V, op(nt.init, f(x))), key, -dict_index)
elseif length(kw) == 1 && kw[1][1]== :init
Base._setindex!(out, convert(V, op(kw[1][2], f(x))), key, -dict_index)
else
throw(ArgumentError("groupreduce doesn't support the keyword arguments $(setdiff(keys(nt), (:init,)))"))
throw(ArgumentError("groupreduce doesn't support the keyword arguments $(setdiff(first.(kw), [:init,]))"))
end
end
end
Expand All @@ -183,6 +182,7 @@ else
"""
function groupreduce(by, op, f, iter; kw...)
# TODO Do this inference-free, like comprehensions...
nt = kw.data
T = eltype(iter)
K = promote_op(by, T)
T2 = promote_op(f, T)
Expand All @@ -195,10 +195,12 @@ else
if dict_index > 0
@inbounds out.vals[dict_index] = op(out.vals[dict_index], f(x))
else
if haskey(kw, :init)
Base._setindex!(out, convert(V, op(kw[:init], f(x))), key, -dict_index)
else
if nt isa NamedTuple{()}
Base._setindex!(out, convert(V, f(x)), key, -dict_index)
elseif nt isa NamedTuple{(:init,)}
Base._setindex!(out, convert(V, op(nt.init, f(x))), key, -dict_index)
else
throw(ArgumentError("groupreduce doesn't support the keyword arguments $(setdiff(keys(nt), (:init,)))"))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/invert.jl
Expand Up @@ -81,12 +81,12 @@ function _invert!(out, a, innerkeys, outerkeys)
end

# Tuple-tuple
if VERSION < v"0.7-"
@static if VERSION < v"0.7-"
@generated function invert(a::NTuple{n, NTuple{m, Any}}) where {n, m}
exprs = [:(tuple($([:(a[$j][$i]) for j = 1:n]...))) for i = 1:m]
return quote
Base.@_inline_meta
return :(tuple($(exprs...)))
return tuple($(exprs...))
end
end
else
Expand Down

0 comments on commit 55287b3

Please sign in to comment.