From 17ac92f054e9b59a619c9a717940b0b40507f626 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 16 Sep 2020 08:35:37 -0700 Subject: [PATCH 1/5] Update weights.jl --- src/weights.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/weights.jl b/src/weights.jl index e5df6b738..99b7c2781 100644 --- a/src/weights.jl +++ b/src/weights.jl @@ -289,6 +289,11 @@ end UnitWeights{T}(length(i)) end +function getindex(wv::UnitWeights{T}, kr::AbstractVector{Bool}) + length(wv) == length(kr) || throw(DimensionMismatch()) + UnitWeights{T}(count(kr)) +end + Base.getindex(wv::UnitWeights{T}, ::Colon) where {T} = UnitWeights{T}(wv.len) """ From 878aa7e5f60ab8a29e370f253bbc0c1b48922ff4 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 16 Sep 2020 08:37:28 -0700 Subject: [PATCH 2/5] Update weights.jl --- test/weights.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/weights.jl b/test/weights.jl index 9f071483e..7735e04f7 100644 --- a/test/weights.jl +++ b/test/weights.jl @@ -112,6 +112,7 @@ end @test isequal(wv, uweights(3)) @test wv != fweights(fill(1.0, 3)) @test wv == uweights(3) + @test wv[[true, false, false]] == uweights(Float64, 1) end ## wsum From 44d4b45ebd95e34c6e60dc82df32ae931e85a71c Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 16 Sep 2020 08:41:08 -0700 Subject: [PATCH 3/5] Update weights.jl --- src/weights.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/weights.jl b/src/weights.jl index 99b7c2781..fdde6e174 100644 --- a/src/weights.jl +++ b/src/weights.jl @@ -289,7 +289,7 @@ end UnitWeights{T}(length(i)) end -function getindex(wv::UnitWeights{T}, kr::AbstractVector{Bool}) +function getindex(wv::UnitWeights{T}, kr::AbstractArray{Bool}) where T length(wv) == length(kr) || throw(DimensionMismatch()) UnitWeights{T}(count(kr)) end From 10359da48b1b88997fa2fe5b43c8c5dc3c0b523f Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 16 Sep 2020 08:46:17 -0700 Subject: [PATCH 4/5] Update weights.jl --- src/weights.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/weights.jl b/src/weights.jl index fdde6e174..1e835396c 100644 --- a/src/weights.jl +++ b/src/weights.jl @@ -289,7 +289,7 @@ end UnitWeights{T}(length(i)) end -function getindex(wv::UnitWeights{T}, kr::AbstractArray{Bool}) where T +function Base.getindex(wv::UnitWeights{T}, kr::AbstractArray{Bool}) where T length(wv) == length(kr) || throw(DimensionMismatch()) UnitWeights{T}(count(kr)) end From 4d935fe9459744a451ad6e447e9abee256041f2f Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Tue, 29 Sep 2020 14:28:11 +0200 Subject: [PATCH 5/5] Update src/weights.jl --- src/weights.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/weights.jl b/src/weights.jl index 1e835396c..a1389c0c7 100644 --- a/src/weights.jl +++ b/src/weights.jl @@ -289,9 +289,9 @@ end UnitWeights{T}(length(i)) end -function Base.getindex(wv::UnitWeights{T}, kr::AbstractArray{Bool}) where T - length(wv) == length(kr) || throw(DimensionMismatch()) - UnitWeights{T}(count(kr)) +function Base.getindex(wv::UnitWeights{T}, i::AbstractArray{Bool}) where T + length(wv) == length(i) || throw(DimensionMismatch()) + UnitWeights{T}(count(i)) end Base.getindex(wv::UnitWeights{T}, ::Colon) where {T} = UnitWeights{T}(wv.len)