Skip to content

Commit f4fcca4

Browse files
fixed floating point error (#713)
* fixed floating point error * Update counts.jl * switched from inv() to / --------- Co-authored-by: Andreas Noack <[email protected]>
1 parent cf0f318 commit f4fcca4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/counts.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ Equivalent to `counts(x, levels) / length(x)`.
9999
If a vector of weights `wv` is provided, the proportion of weights is computed rather
100100
than the proportion of raw counts.
101101
"""
102-
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) = counts(x, levels) .* inv(length(x))
102+
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) = counts(x, levels) / length(x)
103103
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) =
104-
counts(x, levels, wv) .* inv(sum(wv))
104+
counts(x, levels, wv) / sum(wv)
105105

106106
"""
107107
proportions(x, k::Integer, [wv::AbstractWeights])
@@ -204,9 +204,9 @@ counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}) = counts(x, y,
204204
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, wv::AbstractWeights) = counts(x, y, (span(x), span(y)), wv)
205205

206206
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) =
207-
counts(x, y, levels) .* inv(length(x))
207+
counts(x, y, levels) / length(x)
208208
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) =
209-
counts(x, y, levels, wv) .* inv(sum(wv))
209+
counts(x, y, levels, wv) / sum(wv)
210210

211211
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}) =
212212
proportions(x, y, (1:ks[1], 1:ks[2]))

0 commit comments

Comments
 (0)