@@ -12,7 +12,12 @@ macro weights(name)
12
12
mutable struct $ name{S<: Real , T<: Real , V<: AbstractVector{T} } <: AbstractWeights{S, T, V}
13
13
values:: V
14
14
sum:: S
15
+ function $ (esc (name)){S, T, V}(values, sum) where {S<: Real , T<: Real , V<: AbstractVector{T} }
16
+ isfinite (sum) || throw (ArgumentError (" weights cannot contain Inf or NaN values" ))
17
+ return new {S, T, V} (values, sum)
18
+ end
15
19
end
20
+ $ (esc (name))(values:: AbstractVector{T} , sum:: S ) where {S<: Real , T<: Real } = $ (esc (name)){S, T, typeof (values)}(values, sum)
16
21
$ (esc (name))(values:: AbstractVector{<:Real} ) = $ (esc (name))(values, sum (values))
17
22
end
18
23
end
@@ -44,8 +49,10 @@ Base.getindex(wv::W, ::Colon) where {W <: AbstractWeights} = W(copy(wv.values),
44
49
45
50
@propagate_inbounds function Base. setindex! (wv:: AbstractWeights , v:: Real , i:: Int )
46
51
s = v - wv[i]
52
+ sum = wv. sum + s
53
+ isfinite (sum) || throw (ArgumentError (" weights cannot contain Inf or NaN values" ))
47
54
wv. values[i] = v
48
- wv. sum += s
55
+ wv. sum = sum
49
56
v
50
57
end
51
58
@@ -707,7 +714,6 @@ function quantile(v::RealVector{V}, w::AbstractWeights{W}, p::RealVector) where
707
714
length (v) == length (w) || throw (ArgumentError (" data and weight vectors must be the same size," *
708
715
" got $(length (v)) and $(length (w)) " ))
709
716
for x in w. values
710
- isnan (x) && throw (ArgumentError (" weight vector cannot contain NaN entries" ))
711
717
x < 0 && throw (ArgumentError (" weight vector cannot contain negative entries" ))
712
718
end
713
719
0 commit comments