Skip to content

Commit 8c72283

Browse files
committed
update code to 0.7
1 parent 2fc683b commit 8c72283

23 files changed

+87
-107
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
1+
julia 0.7
22
ImageCore 0.1.2
33
FixedPointNumbers 0.3
44
ColorTypes 0.4

src/CIFAR10/CIFAR10.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ module CIFAR10
55
using ImageCore
66
using ColorTypes
77
using FixedPointNumbers
8-
using ..bytes_to_type
9-
using ..datafile
10-
using ..download_dep
11-
using ..download_docstring
8+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
129

1310
export
1411

src/CIFAR10/Reader/Reader.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ function readdata!(buffer::Array{UInt8}, io::IO, index::Integer)
2323
end
2424

2525
function readdata(io::IO, index::Integer)
26-
buffer = Array{UInt8}(NROW, NCOL, NCHAN)
26+
buffer = Array{UInt8}(undef, NROW, NCOL, NCHAN)
2727
readdata!(buffer, io, index)
2828
end
2929

3030
function readdata(io::IO)
31-
X = Array{UInt8}(NROW, NCOL, NCHAN, CHUNK_SIZE)
32-
Y = Array{Int}(CHUNK_SIZE)
33-
buffer = Array{UInt8}(NROW, NCOL, NCHAN)
31+
X = Array{UInt8}(undef, NROW, NCOL, NCHAN, CHUNK_SIZE)
32+
Y = Array{Int}(undef, CHUNK_SIZE)
33+
buffer = Array{UInt8}(undef, NROW, NCOL, NCHAN)
3434
@inbounds for index in 1:CHUNK_SIZE
3535
_, ty = readnext!(buffer, io)
36-
copy!(view(X,:,:,:,index), buffer)
36+
copyto!(view(X,:,:,:,index), buffer)
3737
Y[index] = ty
3838
end
3939
X, Y

src/CIFAR10/interface.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ end
241241

242242
function traindata(::Type{T}; dir = nothing) where T
243243
# placeholders for the chunks
244-
Xs = Vector{Array{UInt8,4}}(NCHUNKS)
245-
Ys = Vector{Vector{Int}}(NCHUNKS)
244+
Xs = Vector{Array{UInt8,4}}(undef, NCHUNKS)
245+
Ys = Vector{Vector{Int}}(undef, NCHUNKS)
246246
# loop over all 5 trainingset files (i.e. chunks)
247247
for file_index in 1:NCHUNKS
248248
file_name = filename_for_chunk(file_index)
@@ -255,7 +255,7 @@ function traindata(::Type{T}; dir = nothing) where T
255255
end
256256
# cat all the placeholders into one image array
257257
# and one label array. (good enough)
258-
images = cat(4, Xs...)::Array{UInt8,4}
258+
images = cat(Xs..., dims=4)::Array{UInt8,4}
259259
labels = vcat(Ys...)::Vector{Int}
260260
# optionally transform the image array before returning
261261
bytes_to_type(T, images), labels
@@ -281,11 +281,11 @@ function traindata(::Type{T}, indices::AbstractVector; dir = nothing) where T
281281
@assert mi >= 1 && ma <= NCHUNKS * Reader.CHUNK_SIZE "not all elements in parameter \"indices\" are in 1:$(NCHUNKS*Reader.CHUNK_SIZE)"
282282
# preallocate a buffer we will reuse for reading individual
283283
# images. "buffer" is written to length(indices) times
284-
buffer = Array{UInt8,3}(Reader.NROW, Reader.NCOL, Reader.NCHAN)
284+
buffer = Array{UInt8,3}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN)
285285
# we know the types and dimensions of the return values,
286286
# so we can preallocate them
287-
images = Array{UInt8,4}(Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
288-
labels = Array{Int,1}(length(indices))
287+
images = Array{UInt8,4}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
288+
labels = Array{Int,1}(undef, length(indices))
289289
# loop over all 5 trainingset files (i.e. chunks)
290290
for file_index in 1:NCHUNKS
291291
file_name = filename_for_chunk(file_index)
@@ -303,7 +303,7 @@ function traindata(::Type{T}, indices::AbstractVector; dir = nothing) where T
303303
_, y = Reader.readdata!(buffer, io, sub_index)
304304
# write the image into the appropriate position
305305
# of our preallocated "images" array.
306-
copy!(view(images,:,:,:,i), buffer)
306+
copyto!(view(images,:,:,:,i), buffer)
307307
# same with labels
308308
labels[i] = y
309309
end
@@ -366,11 +366,11 @@ function testdata(::Type{T}, indices::AbstractVector; dir = nothing) where T
366366
@assert mi >= 1 && ma <= Reader.CHUNK_SIZE "not all elements in parameter \"indices\" are in 1:$(Reader.CHUNK_SIZE)"
367367
# preallocate a buffer we will reuse for reading individual
368368
# images. "buffer" is written to length(indices) times
369-
buffer = Array{UInt8,3}(Reader.NROW, Reader.NCOL, Reader.NCHAN)
369+
buffer = Array{UInt8,3}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN)
370370
# we know the types and dimensions of the return values,
371371
# so we can preallocate them
372-
images = Array{UInt8,4}(Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
373-
labels = Array{Int,1}(length(indices))
372+
images = Array{UInt8,4}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
373+
labels = Array{Int,1}(undef, length(indices))
374374
# in contrast to the trainset, the testset only has one file
375375
file_path = datafile(DEPNAME, TESTSET_FILENAME, dir)
376376
open(file_path, "r") do io
@@ -381,7 +381,7 @@ function testdata(::Type{T}, indices::AbstractVector; dir = nothing) where T
381381
_, y = Reader.readdata!(buffer, io, index)
382382
# write the image into the appropriate position
383383
# of our preallocated "images" array.
384-
copy!(view(images,:,:,:,i), buffer)
384+
copyto!(view(images,:,:,:,i), buffer)
385385
# same with labels
386386
labels[i] = y
387387
end

src/CIFAR100/CIFAR100.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ module CIFAR100
33
using DataDeps
44
using BinDeps
55
using FixedPointNumbers
6-
using ..bytes_to_type
7-
using ..datafile
8-
using ..download_dep
9-
using ..download_docstring
10-
import ..CIFAR10.convert2image
11-
import ..CIFAR10.convert2features
6+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
7+
import ..CIFAR10: convert2image, convert2features
128

139
export
1410

src/CIFAR100/Reader/Reader.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ function readdata!(buffer::Array{UInt8}, io::IO, index::Integer)
2323
end
2424

2525
function readdata(io::IO, nobs::Int, index::Integer)
26-
buffer = Array{UInt8}(NROW, NCOL, NCHAN)
26+
buffer = Array{UInt8}(undef, NROW, NCOL, NCHAN)
2727
readdata!(buffer, io, index)
2828
end
2929

3030
function readdata(io::IO, nobs::Int)
31-
X = Array{UInt8}(NROW, NCOL, NCHAN, nobs)
32-
C = Array{Int}(nobs)
33-
F = Array{Int}(nobs)
34-
buffer = Array{UInt8}(NROW, NCOL, NCHAN)
31+
X = Array{UInt8}(undef, NROW, NCOL, NCHAN, nobs)
32+
C = Array{Int}(undef, nobs)
33+
F = Array{Int}(undef, nobs)
34+
buffer = Array{UInt8}(undef, NROW, NCOL, NCHAN)
3535
@inbounds for index in 1:nobs
3636
_, tc, tf = readnext!(buffer, io)
37-
copy!(view(X,:,:,:,index), buffer)
37+
copyto!(view(X,:,:,:,index), buffer)
3838
C[index] = tc
3939
F[index] = tf
4040
end

src/CIFAR100/interface.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ function traindata(::Type{T}, indices::AbstractVector; dir = nothing) where T
286286
@assert mi >= 1 && ma <= TRAINSET_SIZE "not all elements in parameter \"indices\" are in 1:$(TRAINSET_SIZE)"
287287
# preallocate a buffer we will reuse for reading individual
288288
# images. "buffer" is written to length(indices) times
289-
buffer = Array{UInt8,3}(Reader.NROW, Reader.NCOL, Reader.NCHAN)
289+
buffer = Array{UInt8,3}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN)
290290
# we know the types and dimensions of the return values,
291291
# so we can preallocate them
292-
images = Array{UInt8,4}(Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
293-
labels_c = Array{Int,1}(length(indices))
294-
labels_f = Array{Int,1}(length(indices))
292+
images = Array{UInt8,4}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
293+
labels_c = Array{Int,1}(undef, length(indices))
294+
labels_f = Array{Int,1}(undef, length(indices))
295295
file_path = datafile(DEPNAME, TRAINSET_FILENAME, dir)
296296
open(file_path, "r") do io
297297
# iterate over the given "indices"
@@ -302,7 +302,7 @@ function traindata(::Type{T}, indices::AbstractVector; dir = nothing) where T
302302
_, yc, yf = Reader.readdata!(buffer, io, index)
303303
# write the image into the appropriate position
304304
# of our preallocated "images" array.
305-
copy!(view(images,:,:,:,i), buffer)
305+
copyto!(view(images,:,:,:,i), buffer)
306306
# same with labels
307307
labels_c[i] = yc
308308
labels_f[i] = yf
@@ -367,12 +367,12 @@ function testdata(::Type{T}, indices::AbstractVector; dir = nothing) where T
367367
@assert mi >= 1 && ma <= TESTSET_SIZE "not all elements in parameter \"indices\" are in 1:$(TESTSET_SIZE)"
368368
# preallocate a buffer we will reuse for reading individual
369369
# images. "buffer" is written to length(indices) times
370-
buffer = Array{UInt8,3}(Reader.NROW, Reader.NCOL, Reader.NCHAN)
370+
buffer = Array{UInt8,3}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN)
371371
# we know the types and dimensions of the return values,
372372
# so we can preallocate them
373-
images = Array{UInt8,4}(Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
374-
labels_c = Array{Int,1}(length(indices))
375-
labels_f = Array{Int,1}(length(indices))
373+
images = Array{UInt8,4}(undef, Reader.NROW, Reader.NCOL, Reader.NCHAN, length(indices))
374+
labels_c = Array{Int,1}(undef, length(indices))
375+
labels_f = Array{Int,1}(undef, length(indices))
376376
file_path = datafile(DEPNAME, TESTSET_FILENAME, dir)
377377
open(file_path, "r") do io
378378
# iterate over the given "indices"
@@ -383,7 +383,7 @@ function testdata(::Type{T}, indices::AbstractVector; dir = nothing) where T
383383
_, yc, yf = Reader.readdata!(buffer, io, index)
384384
# write the image into the appropriate position
385385
# of our preallocated "images" array.
386-
copy!(view(images,:,:,:,i), buffer)
386+
copyto!(view(images,:,:,:,i), buffer)
387387
# same with labels
388388
labels_c[i] = yc
389389
labels_f[i] = yf

src/FashionMNIST/FashionMNIST.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ replacement for MNIST.
2626
module FashionMNIST
2727
using DataDeps
2828
using FixedPointNumbers
29-
using ..bytes_to_type
30-
using ..datafile
31-
using ..download_dep
32-
using ..download_docstring
33-
import ..MNIST.convert2image
34-
import ..MNIST.convert2features
29+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
30+
import ..MNIST: convert2image, convert2features
3531
import ..MNIST.Reader
3632

3733
export

src/MLDatasets.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
__precompile__()
21
module MLDatasets
32

43
using FixedPointNumbers

src/MNIST/MNIST.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ module MNIST
2828
using ImageCore
2929
using ColorTypes
3030
using FixedPointNumbers
31-
using ..bytes_to_type
32-
using ..datafile
33-
using ..download_dep
34-
using ..download_docstring
31+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
3532

3633
export
3734

0 commit comments

Comments
 (0)