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
Min/max of CartesianIndex are implicitly "vectorized" and conflict with ordering #31208
Comments
AFAICT the operation |
julia> isless(CartesianIndex(5, 1), CartesianIndex(1, 5))
true so shouldn't the infimum just be |
Sorry you are right. Now I am confused about the order on |
Right, ordering on CartesianIndex is defined such that if you sort them, they go in column major order. |
You can multiply and add You cannot multiply and add Note also that |
Not sure what you mean with "you cannot multiply and add julia> CartesianIndex(1,1) * 5 + CartesianIndex(2,2)
CartesianIndex(7, 7)
|
You're right that they behave like vectors, with scalar multiplication and addition. I stand corrected. Part of the distinction that I meant to draw, however, is that there is no |
I hesitate to open this issue because gosh this behavior is so very useful. But it's probably worth thinking about a better name/idiom here. In short
min
andmax
for CartesianIndex break the function's contract: they don't return one of the arguments.Of course this means that
minimum
also returns an element that is different fromfirst(sort(idxs))
(whereidxs
is a vector of cartesian indices).While strange, it is a hugely helpful behavior — e.g., to select the rectangular extents of a found object, you can just do:
idxs = findall(...); region = minimum(idxs):maximum(idxs)
. I similarly don't really want to change sorting of cartesian indices — it'll put them in column-major order for you! So if we change this, we'll need to find a new way of spellingmin
/minimum
/max
/maximum
.One possible alternative is broadcasting: it's currently acting as though we've broadcast
min
across the elements. We don't support broadcasting over CartesianIndex, but perhaps we should implement tuple-like broadcasting semantics:That would probably also be helpful in other situations, but it's of no help for
minimum
andmaximum
.The text was updated successfully, but these errors were encountered: