Skip to content

Commit 21a2556

Browse files
authored
Fix uplo function (#730)
1 parent d39b4a1 commit 21a2556

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/robust.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ function uplo(x::AbstractVector; prop::Real=0.0, count::Integer=0)
2121
end
2222

2323
# indices for lowest count values
24-
x2 = copy(x)
25-
lo = partialsort!(x2, 1:count+1)[end]
26-
# indices for largest count values
27-
up = partialsort!(x2, n-count:n)[1]
24+
x2 = Base.copymutable(x)
25+
lo = partialsort!(x2, count+1)
26+
up = partialsort!(x2, n-count)
2827

2928
up, lo
3029
end

test/robust.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using StatsBase
2-
using Test
2+
using Test, Random
33

44
### Trimming outliers
55

@@ -53,3 +53,11 @@ using Test
5353

5454
@test mean(trim([-Inf,1,2,3,4], count=1)) == 2
5555
@test mean(winsor([-Inf,1,2,3,4], count=1)) == 2
56+
57+
Random.seed!(1234)
58+
for n in 2100:2120, c in 0:1000
59+
x = randperm(n)
60+
@test sort!(collect(winsor(x, count=c))) ==
61+
reverse!(collect(winsor(n:-1:1, count=c))) ==
62+
collect(winsor(1:n, count=c))
63+
end

0 commit comments

Comments
 (0)