Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
introduce compat for 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Evizero committed Mar 14, 2017
1 parent 10208c6 commit 4ef9201
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.5
Iterators 0.3
StatsBase 0.13
LearnBase 0.1.2 0.2.0
LearnBase 0.1.3 0.2.0
MLLabelUtils
Compat 0.17
1 change: 1 addition & 0 deletions src/MLDataUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module MLDataUtils
using StatsBase
using LearnBase
using MLLabelUtils
using Compat

using LearnBase: ObsDimension, obs_dim
import LearnBase: nobs, getobs, getobs!, datasubset, default_obsdim
Expand Down
4 changes: 2 additions & 2 deletions src/accesspattern/datasubset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ immutable DataSubset{T, I<:Union{Int,AbstractVector}, O<:ObsDimension}
indices::I
obsdim::O

function DataSubset(data::T, indices::I, obsdim::O)
function (::Type{DataSubset{T,I,O}}){T,I,O}(data::T, indices::I, obsdim::O)
if T <: Tuple
error("Inner constructor should not be called using a Tuple")
end
1 <= minimum(indices) || throw(BoundsError(data, indices))
maximum(indices) <= nobs(data, obsdim) || throw(BoundsError(data, indices))
new(data, indices, obsdim)
new{T,I,O}(data, indices, obsdim)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/accesspattern/kfolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ immutable KFolds{T,O}
k::Int
obsdim::O

function KFolds(data::T, k::Int, obsdim::O)
function (::Type{KFolds{T,O}}){T,O}(data::T, k::Int, obsdim::O)
n = nobs(data, obsdim)
1 < k <= n || throw(ArgumentError("k needs to be within 2:$(nobs(data,obsdim))"))
# Compute the size of each fold. This is important because
Expand All @@ -95,7 +95,7 @@ immutable KFolds{T,O}
end
# Compute start index for each fold
indices = cumsum(sizes) .- sizes .+ 1
new(data, indices, sizes, k, obsdim)
new{T,O}(data, indices, sizes, k, obsdim)
end
end

Expand Down
19 changes: 9 additions & 10 deletions src/accesspattern/learnbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ individual observation-vectors instead of one matrix.
see `MLDataUtils.ObsView` and `MLDataUtils.BatchView` for examples.
"""
abstract DataView{TElem, TData} <: AbstractVector{TElem}
@compat abstract type DataView{TElem, TData} <: AbstractVector{TElem} end

"""
abstract AbstractObsView{TElem, TData} <: DataView{TElem, TData}
Expand All @@ -155,7 +155,7 @@ that views it as some form or vector of observations.
see `MLDataUtils.ObsView` for a concrete example.
"""
abstract AbstractObsView{TElem, TData} <: DataView{TElem, TData}
@compat abstract type AbstractObsView{TElem, TData} <: DataView{TElem, TData} end

"""
abstract AbstractBatchView{TElem, TData} <: DataView{TElem, TData}
Expand All @@ -165,7 +165,7 @@ that views it as some form or vector of equally sized batches.
see `MLDataUtils.BatchView` for a concrete example.
"""
abstract AbstractBatchView{TElem, TData} <: DataView{TElem, TData}
@compat abstract type AbstractBatchView{TElem, TData} <: DataView{TElem, TData} end

# --------------------------------------------------------------------

Expand All @@ -182,7 +182,7 @@ true amount of observations available (if known).
see `MLDataUtils.RandomObs`, `MLDataUtils.RandomBatches`
"""
abstract DataIterator{TElem,TData}
@compat abstract type DataIterator{TElem,TData} end

"""
abstract ObsIterator{TElem,TData} <: DataIterator{TElem,TData}
Expand All @@ -201,7 +201,7 @@ end
see `MLDataUtils.RandomObs`
"""
abstract ObsIterator{TElem,TData} <: DataIterator{TElem,TData}
@compat abstract type ObsIterator{TElem,TData} <: DataIterator{TElem,TData} end

"""
abstract BatchIterator{TElem,TData} <: DataIterator{TElem,TData}
Expand All @@ -220,12 +220,11 @@ end
see `MLDataUtils.RandomBatches`
"""
abstract BatchIterator{TElem,TData} <: DataIterator{TElem,TData}
@compat abstract type BatchIterator{TElem,TData} <: DataIterator{TElem,TData} end

# --------------------------------------------------------------------

# just for dispatch for those who care to
typealias AbstractDataIterator{E,T} Union{DataIterator{E,T}, DataView{E,T}}
typealias AbstractObsIterator{E,T} Union{ObsIterator{E,T}, AbstractObsView{E,T}}
typealias AbstractBatchIterator{E,T} Union{BatchIterator{E,T},AbstractBatchView{E,T}}

@compat const AbstractDataIterator{E,T} = Union{DataIterator{E,T}, DataView{E,T}}
@compat const AbstractObsIterator{E,T} = Union{ObsIterator{E,T}, AbstractObsView{E,T}}
@compat const AbstractBatchIterator{E,T} = Union{BatchIterator{E,T},AbstractBatchView{E,T}}
14 changes: 14 additions & 0 deletions test/tst_datasubset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ end
end
end

println("<HEARTBEAT>")

@testset "datasubset" begin
@testset "Array and SubArray" begin
@test @inferred(datasubset(X)) == Xv
Expand Down Expand Up @@ -657,6 +659,8 @@ end
end
end

println("<HEARTBEAT>")

@testset "SparseArray" begin
@test @inferred(datasubset(Xs)) === DataSubset(Xs)
@test @inferred(datasubset(ys)) === DataSubset(ys)
Expand Down Expand Up @@ -710,6 +714,8 @@ end
end
end

println("<HEARTBEAT>")

@testset "shuffleobs" begin
@test_throws DimensionMismatch shuffleobs((X, rand(149)))
@test_throws DimensionMismatch shuffleobs((X, rand(149)), obsdim=:last)
Expand Down Expand Up @@ -742,6 +748,8 @@ end
@test sum(shuffleobs(Y1, obsdim=:first)) == 11325
end

println("<HEARTBEAT>")

@testset "Tuple of Array and SubArray" begin
for var in ((X,yv), (Xv,y), tuples...)
@test_throws MethodError shuffleobs(var, ObsDim.Undefined())
Expand Down Expand Up @@ -797,6 +805,8 @@ end
end
end

println("<HEARTBEAT>")

@testset "splitobs" begin
@test_throws DimensionMismatch splitobs((X, rand(149)))
@test_throws DimensionMismatch splitobs((X, rand(149)), obsdim=:last)
Expand Down Expand Up @@ -852,6 +862,8 @@ end
@test sum.(splitobs(Y1, obsdim=:first)) == [5565, 5760]
end

println("<HEARTBEAT>")

@testset "Tuple of Array, SparseArray, and SubArray" begin
for tup in ((Xs,ys), (X,ys), (Xs,y), (Xs,Xs), (XX,X,ys), (X,yv), (Xv,y), tuples...)
@test_throws MethodError splitobs(tup, 0.5, ObsDim.Undefined())
Expand Down Expand Up @@ -890,6 +902,8 @@ end
end
end

println("<HEARTBEAT>")

@testset "deprecated" begin
@test splitdata(X, y) == splitobs((X, y), at=0.5)
(xtr,ytr), (xte,yte) = partitiondata(X1, Y1)
Expand Down
14 changes: 14 additions & 0 deletions test/tst_dataview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@test A == ObsView(X',obsdim=:first)
end

println("<HEARTBEAT>")

@testset "typestability" begin
@test_throws Exception @inferred(ObsView(X, obsdim=2))
for var in (vars..., tuples..., Xs, ys)
Expand All @@ -55,6 +57,8 @@
@test typeof(@inferred(ObsView(CustomType(), ObsDim.Undefined()))) <: ObsView
end

println("<HEARTBEAT>")

@testset "AbstractArray interface" begin
for var in (vars..., tuples..., Xs, ys)
A = ObsView(var)
Expand Down Expand Up @@ -91,6 +95,8 @@
@test @inferred(getobs(A,150)) == getobs(X', 150, obsdim=1)
end

println("<HEARTBEAT>")

@testset "subsetting" begin
for var_raw in (vars..., tuples..., Xs, ys)
for var in (var_raw, DataSubset(var_raw))
Expand Down Expand Up @@ -195,6 +201,8 @@ end
@test A == BatchView(X',obsdim=:first)
end

println("<HEARTBEAT>")

@testset "typestability" begin
for var in (vars..., tuples..., Xs, ys)
@test typeof(@inferred(BatchView(var))) <: BatchView
Expand All @@ -213,6 +221,8 @@ end
@test typeof(@inferred(BatchView(CustomType(), 10, ObsDim.Undefined()))) <: BatchView
end

println("<HEARTBEAT>")

@testset "AbstractArray interface" begin
for var in (vars..., tuples..., Xs, ys)
A = BatchView(var, 15)
Expand Down Expand Up @@ -252,6 +262,8 @@ end
@test @inferred(getobs(A,3)) == getobs(X', 31:45, obsdim=1)
end

println("<HEARTBEAT>")

@testset "subsetting" begin
for var in (vars..., tuples..., Xs, ys)
A = BatchView(var)
Expand Down Expand Up @@ -280,6 +292,8 @@ end
@test typeof(S.data) <: SubArray
end

println("<HEARTBEAT>")

@testset "nesting with ObsView" begin
for var in vars
@test eltype(@inferred(BatchView(ObsView(var)))[1]) <: Union{SubArray,String}
Expand Down

0 comments on commit 4ef9201

Please sign in to comment.