Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StatsBase"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
authors = ["JuliaStats"]
version = "0.33.21"
version = "0.33.22"

[deps]
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down
1 change: 1 addition & 0 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) w
p = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, sum(lens) on the line above can be negative, which throws an ErrorException instead of the expected ArgumentError. Should we add a check like this?

n = sum(lens)
n >= 0 || throw(ArgumentError("lengths must be non-negative"))

Otherwise, let's go back to the previous version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check on the sum per your suggestion since we need to compute the sum anyway in order to initialize the output array.

@inbounds for i = 1 : m
Comment thread
ararslan marked this conversation as resolved.
j = lens[i]
j >= 0 || throw(ArgumentError("lengths must be non-negative"))
v = vals[i]
while j > 0
r[p+=1] = v
Expand Down
1 change: 1 addition & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ z = [1, 1, 2, 2, 2, 3, 1, 2, 2, 3, 3, 3, 3]
@test vals == [1, 2, 3, 1, 2, 3]
@test lens == [2, 3, 1, 1, 2, 4]
@test inverse_rle(vals, lens) == z
@test_throws ArgumentError inverse_rle(vals, fill(-1, length(lens)))

z = [true, true, false, false, true, false, true, true, true]
vals, lens = rle(z)
Expand Down