-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 faster issubset for CartesianIndices{N} #56282
Conversation
Do you have some benchmarks showing a performance improvement? |
Thanks for looking into this, @xili-h! This is a good specialization to have. This clearly has higher performance than the generic fallback, especially because the indices themselves have O(1) subset checking. However, there's a correctness problem: if the first argument is empty, then it is always a subset, even if some of its indices are not subsets because there are no elements to witness that axis being larger: julia> a = CartesianIndices((0, 1))
CartesianIndices((0, 1))
julia> b = CartesianIndices((1,0))
CartesianIndices((1, 0))
julia> issubset(a, b)
true
julia> _issubset(a::CartesianIndices{N}, b::CartesianIndices{N}) where N =
all(map(issubset, a.indices, b.indices))
_issubset (generic function with 2 methods)
julia> _issubset(a,b)
false
julia> _issubset2(a::CartesianIndices{N}, b::CartesianIndices{N}) where N =
isempty(a) || all(map(issubset, a.indices, b.indices))
_issubset2 (generic function with 1 method)
julia> _issubset2(a,b)
true As an aside, I prefer if you paste results as text rather than screenshots because that makes it easier for folks to copy your code and reproduce it locally. |
Thanks @LilithHafner. I have fix the problem base on your suggestion. I will paste results as text next time. |
Thanks! |
No description provided.