Implement efficent methods for any/all#32
Implement efficent methods for any/all#32goretkin wants to merge 3 commits intoJuliaArrays:masterfrom
any/all#32Conversation
|
Nice observation! I'm too busy to dig into the implementation of #31, if you do I'd be very happy to review it. |
|
Would be nice to handle the predicate variants too. |
|
Turns out the first behavior was broken anyway, because it did not properly handle One test will be broken, which is due to #33 as far as I can tell. |
Relates to issue JuliaArrays#31
One test is failing, due to JuliaArrays#33 Handing `missing` at the cost of doing short-circuit evaluation, see JuliaLang/julia#35563
6fe1533 to
fadf55b
Compare
|
I rebased to pull in the change in #34 |
|
I've tested locally that this patch fixes julia 1.0 and 0.7 tests if v"0.7" <= VERSION < v"1.1"
# ambiguity patch
# https://github.com/JuliaLang/julia/pull/30904
Base.all(::typeof(isinteger), ::PaddedView{<:Integer}) = true
end |
|
Thanks for sorting that out! Feel free to push that fix, or let me know if I should. |
|
Looks like I don't have push permission to your branch so I'll leave it to you. |
|
I don't think I know how to do it either. It would have to be related to this remote, not the Anyway, thanks for the push! Looks like it worked. |
|
Do you have plans to work on #31? Otherwise, we could merge this PR and probably tag a new release. I'll merge it when you think it's ready.
@timholy May I ask what "predicate variants" are? Sorry about this but I've never heard this word. Is that |
I originally implemented e.g. I'd say this is a safe improvement over the current functionality, so it's good to merge. It's too bad it doesn't have the short-circuiting for efficiency, but that can be added later. |
| # The fallbacks work, but this is more efficient | ||
| # TODO use use short-circuit evaluation, | ||
| Base.any(f::Function, A::PaddedView) = f(A.fillvalue) | any(f, parent(A)) | ||
| Base.all(f::Function, A::PaddedView) = f(A.fillvalue) & all(f, parent(A)) |
There was a problem hiding this comment.
it doesn't support dims keyword
julia> pa = PaddedView(false, a, (1:2, 1:2));
julia> any(pa; dims=1)
ERROR: ArgumentError: No method is implemented for reducing index range of type typeof(i). Please implement
reduced_index for this index type or report this as an issue.| # The fallbacks work, but this is more efficient | ||
| # TODO use use short-circuit evaluation, | ||
| Base.any(f::Function, A::PaddedView) = f(A.fillvalue) | any(f, parent(A)) | ||
| Base.all(f::Function, A::PaddedView) = f(A.fillvalue) & all(f, parent(A)) |
There was a problem hiding this comment.
Base.all(A::PaddedView) = all(identity, A)is still needed, otherwise it calls the fallback.
| # The fallbacks work, but this is more efficient | ||
| # TODO use use short-circuit evaluation, | ||
| Base.any(f::Function, A::PaddedView) = f(A.fillvalue) | any(f, parent(A)) | ||
| Base.all(f::Function, A::PaddedView) = f(A.fillvalue) & all(f, parent(A)) |
There was a problem hiding this comment.
julia> a = fill(true, 2, 2)
2×2 Array{Bool,2}:
1 1
1 1
julia> A = PaddedView(false, a, axes(a))
2×2 PaddedView(false, ::Array{Bool,2}, (Base.OneTo(2), Base.OneTo(2))) with eltype Bool:
1 1
1 1
julia> all(identity, A)
false
julia> all(identity, collect(A))
trueThere was a problem hiding this comment.
@goretkin, I pointed this problem in JuliaLang/julia#35563 (comment).
There was a problem hiding this comment.
Similarly, there is a problem with cropping.
I have a sense of foreboding about the combination of those and dims.:fearful:
There was a problem hiding this comment.
@kimikage Yeah, I am not sure it is worthwhile to implement anything clever for dims. The required reasoning would be substantially more complex, and I can imagine it being slower for many cases where there isn't that much padding.
Not sure what problem with cropping you mean.
There was a problem hiding this comment.
julia> a = Bool[0 0; 1 1]
2×2 Array{Bool,2}:
0 0
1 1
julia> A = PaddedView(false, a, (1,3))
1×3 PaddedView(false, ::Array{Bool,2}, (Base.OneTo(1), Base.OneTo(3))) with eltype Bool:
0 0 0There was a problem hiding this comment.
Thanks for the example! Yeah, that would also need to be handled for sure.
|
@johnnychen94 Thanks for catching #32 (comment)! If we want to go forward with this idea, I can implement a [predicate] function that determines whether the On second thought, a function that counts the number of |


Relates to issue #31