Merge pull request #419 from r3tex/master

update utils.jl for 1.0
This commit is contained in:
Mike J Innes 2018-10-03 11:21:40 +01:00 committed by GitHub
commit 3a7b77d104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ julia> chunk(1:10, 3)
""" """
chunk(xs, n) = collect(Iterators.partition(xs, ceil(Int, length(xs)/n))) chunk(xs, n) = collect(Iterators.partition(xs, ceil(Int, length(xs)/n)))
batchindex(xs, i) = (reverse(Base.tail(reverse(indices(xs))))..., i) batchindex(xs, i) = (reverse(Base.tail(reverse(axes(xs))))..., i)
""" """
frequencies(xs) frequencies(xs)
@ -66,7 +66,7 @@ julia> batch([[1,2,3],[4,5,6]])
function batch(xs) function batch(xs)
data = first(xs) isa AbstractArray ? data = first(xs) isa AbstractArray ?
similar(first(xs), size(first(xs))..., length(xs)) : similar(first(xs), size(first(xs))..., length(xs)) :
Vector{eltype(xs)}(length(xs)) Vector{eltype(xs)}(undef, length(xs))
for (i, x) in enumerate(xs) for (i, x) in enumerate(xs)
data[batchindex(data, i)...] = x data[batchindex(data, i)...] = x
end end