Skip to content

Commit 946a98b

Browse files
authored
Merge pull request #23 from alyst/opt_deps
Make ImageCore and MAT packages optional
2 parents f491eac + 16d131e commit 946a98b

21 files changed

+83
-40
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ install:
3030

3131
after_success:
3232
- julia -e 'using Pkg, MLDatasets; cd(joinpath(dirname(pathof(MLDatasets)), "..")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
33-
- julie -e 'using Pkg; Pkg.add("Documenter"); cd(joinpath(dirname(pathof(MLDatasets)), "..")); include(joinpath("docs", "make.jl"))'
33+
- julia -e 'using Pkg, MLDatasets; Pkg.add("Documenter"); cd(joinpath(dirname(pathof(MLDatasets)), "..")); include(joinpath("docs", "make.jl"))'

REQUIRE

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
julia 0.7
2-
ImageCore 0.1.2
2+
Requires
33
FixedPointNumbers 0.3
44
ColorTypes 0.4
55
DataDeps 0.3
6-
GZip
6+
GZip 0.5
77
BinDeps
8-
MAT

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ makedocs(
3030
deploydocs(
3131
repo = "github.com/JuliaML/MLDatasets.jl.git",
3232
target = "build",
33-
julia = "0.6",
33+
julia = "0.7",
3434
deps = nothing,
3535
make = nothing,
3636
)

docs/src/LICENSE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# LICENSE
22

33
```@eval
4-
Markdown.parse_file(joinpath(@__DIR__, "../LICENSE"))
4+
using Markdown
5+
Markdown.parse_file(joinpath(@__DIR__, "..", "..", "LICENSE"))
56
```

src/CIFAR10/CIFAR10.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ export CIFAR10
22
module CIFAR10
33
using DataDeps
44
using BinDeps
5-
using ImageCore
65
using ColorTypes
76
using FixedPointNumbers
8-
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
7+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring,
8+
_colorview, _channelview
99

1010
export
1111

src/CIFAR10/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ function convert2features(array::AbstractArray{<:Number,4})
2929
end
3030

3131
convert2features(array::AbstractArray{<:RGB,2}) =
32-
convert2features(permutedims(channelview(array), (3,2,1)))
32+
convert2features(permutedims(_channelview(array), (3,2,1)))
3333

3434
convert2features(array::AbstractArray{<:RGB,3}) =
35-
convert2features(permutedims(channelview(array), (3,2,1,4)))
35+
convert2features(permutedims(_channelview(array), (3,2,1,4)))
3636

3737
"""
3838
convert2image(array) -> Array{RGB}
@@ -68,13 +68,13 @@ end
6868
function convert2image(array::AbstractArray{<:Number,3})
6969
nrows, ncols, nchan = size(array)
7070
@assert nchan == 3 "the given array should have the RGB channel in the third dimension"
71-
colorview(RGB, permutedims(_norm_array(array), (3,2,1)))
71+
_colorview(RGB, permutedims(_norm_array(array), (3,2,1)))
7272
end
7373

7474
function convert2image(array::AbstractArray{<:Number,4})
7575
nrows, ncols, nchan, nimages = size(array)
7676
@assert nchan == 3 "the given array should have the RGB channel in the third dimension"
77-
colorview(RGB, permutedims(_norm_array(array), (3,2,1,4)))
77+
_colorview(RGB, permutedims(_norm_array(array), (3,2,1,4)))
7878
end
7979

8080
_norm_array(array::AbstractArray) = array

src/CIFAR100/CIFAR100.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module CIFAR100
44
using BinDeps
55
using FixedPointNumbers
66
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
7-
import ..CIFAR10: convert2image, convert2features
7+
using ..CIFAR10: convert2image, convert2features
88

99
export
1010

src/FashionMNIST/FashionMNIST.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module FashionMNIST
2727
using DataDeps
2828
using FixedPointNumbers
2929
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
30-
import ..MNIST: convert2image, convert2features
31-
import ..MNIST.Reader
30+
using ..MNIST: convert2image, convert2features
31+
using ..MNIST.Reader
3232

3333
export
3434

src/MLDatasets.jl

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
module MLDatasets
22

3-
using FixedPointNumbers
3+
using Requires
4+
using FixedPointNumbers, ColorTypes
45

56
bytes_to_type(::Type{UInt8}, A::Array{UInt8}) = A
67
bytes_to_type(::Type{N0f8}, A::Array{UInt8}) = reinterpret(N0f8, A)
78
bytes_to_type(::Type{T}, A::Array{UInt8}) where T<:Integer = convert(Array{T}, A)
89
bytes_to_type(::Type{T}, A::Array{UInt8}) where T<:AbstractFloat = A ./ T(255)
910
bytes_to_type(::Type{T}, A::Array{UInt8}) where T<:Number = convert(Array{T}, reinterpret(N0f8, A))
1011

12+
global __images_supported__ = false
13+
global __matfiles_supported__ = false
14+
15+
function _channelview(image::AbstractArray{<:Color})
16+
__images_supported__ ||
17+
error("Converting to/from image requires ImageCore package.")
18+
channelview(image)
19+
end
20+
21+
function _colorview(::Type{T}, array::AbstractArray{<:Number}) where T <: Color
22+
__images_supported__ ||
23+
error("Converting to image requires ImageCore package.")
24+
colorview(T, array)
25+
end
26+
27+
function _matopen(f::Function, path::AbstractString)
28+
__matfiles_supported__ ||
29+
error("Reading .mat files requires MAT package.")
30+
matopen(f, path)
31+
end
32+
33+
function _matread(path::AbstractString)
34+
__matfiles_supported__ ||
35+
error("Reading .mat files requires MAT package.")
36+
matread(path)
37+
end
38+
39+
1140
include("download.jl")
1241
include("CoNLL.jl")
1342

@@ -19,4 +48,16 @@ include("SVHN2/SVHN2.jl")
1948
include("PTBLM/PTBLM.jl")
2049
include("UD_English/UD_English.jl")
2150

51+
function __init__()
52+
# initialize optional dependencies
53+
@require ImageCore="a09fc81d-aa75-5fe9-8630-4744c3626534" begin
54+
using ImageCore
55+
global __images_supported__ = true
56+
end
57+
@require MAT="23992714-dd62-5051-b70f-ba57cb901cac" begin
58+
using MAT
59+
global __matfiles_supported__ = true
60+
end
61+
end
62+
2263
end

src/MNIST/MNIST.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ the 10 possible digits (0-9).
2525
"""
2626
module MNIST
2727
using DataDeps
28-
using ImageCore
2928
using ColorTypes
3029
using FixedPointNumbers
31-
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring
30+
using ..MLDatasets: bytes_to_type, datafile, download_dep, download_docstring,
31+
_colorview
3232

3333
export
3434

0 commit comments

Comments
 (0)