Skip to content
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

Euclidean on Cartesian indices #177

Open
Dale-Black opened this issue Sep 16, 2020 · 5 comments
Open

Euclidean on Cartesian indices #177

Dale-Black opened this issue Sep 16, 2020 · 5 comments

Comments

@Dale-Black
Copy link

Is there a way to compute the euclidean distance between arrays that are of the type CartesianIndex?

@Dale-Black Dale-Black changed the title Euclidean on cartesian indeces Euclidean on Cartesian indices Sep 17, 2020
@dkarrasch
Copy link
Member

Do you mean something like this?

julia> A = reshape(collect(1:9), 3, 3)
3×3 Array{Int64,2}:
 1  4  7
 2  5  8
 3  6  9

julia> inds1 = findall(iseven, A)
4-element Array{CartesianIndex{2},1}:
 CartesianIndex(2, 1)
 CartesianIndex(1, 2)
 CartesianIndex(3, 2)
 CartesianIndex(2, 3)

julia> inds2 = findall(isodd, A)
5-element Array{CartesianIndex{2},1}:
 CartesianIndex(1, 1)
 CartesianIndex(3, 1)
 CartesianIndex(2, 2)
 CartesianIndex(1, 3)
 CartesianIndex(3, 3)

julia> pairwise(SqEuclidean(), inds1, inds2)
4×5 Array{Int64,2}:
 1  1  1  5  5
 1  5  1  1  5
 5  1  1  5  1
 5  5  1  1  1

julia> euclidean(inds1[1], inds1[1]) === 0.0
true

I have added support for this special, noniterable type in #194.

@nalimilan
Copy link
Member

Could you explain why this would be useful? Since CartesianIndex isn't iterable (on purpose), this would require specific support in Distances.

@Dale-Black
Copy link
Author

I think what @dkarrasch implemented is what I wanted. I would have to go back to this specific project to find out for sure but from what I can tell that solves my use case

@nalimilan
Copy link
Member

Yes but we decided to revert that change until we have a clearer view of why this would be needed.

@dkarrasch
Copy link
Member

@nalimilan convinced me that supporting CartesianIndexes directly (at least in the context of #194) is awkward, because it targets iterable objects, and CartesianIndexes are intentionally non-iterable. I believe the correct way of handling it is to pass the responsibility to the callee, asking her/him to pass iterable objects to Distances.jl. In the context here, this would mean to convert CartesianIndexes to tuples via Tuple(cartind), as suggested by the error message. Once you have that, the new iterator-based implementation will work just fast and fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants