Skip to content

Commit 3ff043e

Browse files
committed
add length parameter to type
1 parent af24d40 commit 3ff043e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/univariate.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ function kde_range(boundary::(@compat Tuple{Real,Real}), npoints::Int)
7070
lo:step:hi
7171
end
7272

73-
immutable UniformWeights
74-
w
73+
immutable UniformWeights{N} end
7574

76-
UniformWeights(n) = new(1/n)
77-
end
75+
UniformWeights(n) = UniformWeights{n}()
7876

7977
Base.sum(x::UniformWeights) = 1.
80-
Base.getindex(x::UniformWeights, i) = x.w
78+
Base.getindex{N}(x::UniformWeights{N}, i) = 1/N
79+
Base.length{N}(x::UniformWeights{N}) = N
80+
values{N}(x::UniformWeights{N}) = fill(x[1], N)
81+
eltype(x::UniformWeights) = eltype(x[1])
82+
isempty{N}(x::UniformWeights{N}) = N==0
8183

8284
typealias Weights Union{UniformWeights, RealVector, WeightVec}
8385

0 commit comments

Comments
 (0)