-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement efficent methods for any
/all
#32
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,4 +309,14 @@ function Base.showarg(io::IO, A::PaddedView, toplevel) | |
toplevel && print(io, " with eltype ", eltype(A)) | ||
end | ||
|
||
# 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Base.all(A::PaddedView) = all(identity, A) is still needed, otherwise it calls the fallback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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))
true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @goretkin, I pointed this problem in JuliaLang/julia#35563 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, there is a problem with cropping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kimikage Yeah, I am not sure it is worthwhile to implement anything clever for Not sure what problem with cropping you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the example! Yeah, that would also need to be handled for sure. |
||
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 | ||
|
||
end # module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't support
dims
keyword