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

Commit 249de8a

Browse files
Merge pull request #48 from JuliaML/cl/nobs
import StatsBase: nobs
2 parents 236ff5c + f12f4db commit 249de8a

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

Project.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ name = "LearnBase"
22
uuid = "7f8f8fb0-2700-5f03-b4bd-41f8cfc144b6"
33
version = "0.5.0"
44

5+
[deps]
6+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
7+
58
[compat]
9+
StatsBase = "0.32, 0.33"
610
julia = "1.0"
711

812
[extras]
913
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
10-
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1114
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1215

1316
[targets]
14-
test = ["Test", "SparseArrays", "StatsBase"]
17+
test = ["Test", "SparseArrays"]

src/LearnBase.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module LearnBase
22

3+
using StatsBase: nobs
4+
35
# AGGREGATION MODES
46
include("aggmode.jl")
57

68
# VIEW AND ITERATORS
79
include("iteration.jl")
810

911
# OBSERVATION DIMENSIONS
10-
export default_obsdim, getobs, getobs!
1112
include("observation.jl")
1213

1314
# LEARNING COSTS (e.g. loss & penalty)

src/observation.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ implement `StatsBase.nobs`.
3838
Let's see how to implement a dataset interface for a dataset
3939
represented by an array:
4040
```julia
41-
using LearnBase, StatsBase
41+
using LearnBase
4242
4343
function LearnBase.getobs(x::AbstractArray{T,N}, idx; obsdim=default_obsdim(x)) where {T,N}
4444
_idx = ntuple(i-> i == obsdim ? idx : Colon(), N)
4545
return x[_idx...]
4646
end
4747
48-
StatsBase.nobs(x::AbstractArray; obsdim=default_obsdim(x)) = size(x, obsdim)
48+
# LearnBase imports nobs from StatsBase
49+
LearnBase.nobs(x::AbstractArray; obsdim=default_obsdim(x)) = size(x, obsdim)
4950
5051
X = rand(2,3)
5152
@@ -61,7 +62,7 @@ LearnBase.getobs(t::Tuple, idx) = getobs.(t, Ref(idx))
6162
6263
# Assume all elements have the same nummber of observations.
6364
# It would be safer to check explicitely though.
64-
StatsBase.nobs(t::Tuple) = nobs(t[1])
65+
LearnBase.nobs(t::Tuple) = nobs(t[1])
6566
6667
# A dataset with 3 observations, each with 2 input features
6768
X, Y = rand(2, 3), rand(3)

test/observation.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using LearnBase: getobs, nobs, default_obsdim
2+
13
@test typeof(LearnBase.getobs) <: Function
24
@test typeof(LearnBase.getobs!) <: Function
35
@test typeof(LearnBase.gettargets) <: Function
@@ -9,7 +11,7 @@
911
_idx = ntuple(i-> i == obsdim ? idx : Colon(), N)
1012
return x[_idx...]
1113
end
12-
StatsBase.nobs(x::AbstractArray; obsdim=default_obsdim(x)) = size(x, obsdim)
14+
LearnBase.nobs(x::AbstractArray; obsdim=default_obsdim(x)) = size(x, obsdim)
1315

1416
a = rand(2,3)
1517
@test nobs(a) == 3
@@ -22,7 +24,7 @@
2224
LearnBase.getobs(t::Tuple, idx) = getobs.(t, Ref(idx))
2325
# Assume all elements have the same nummber of observations.
2426
# It would be safer to check explicitely though.
25-
StatsBase.nobs(t::Tuple) = nobs(t[1])
27+
LearnBase.nobs(t::Tuple) = nobs(t[1])
2628

2729
# A dataset with 3 observations, each with 2 input features
2830
X, Y = rand(2, 3), rand(3)

0 commit comments

Comments
 (0)