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

Copy for CartesianIndices/LinearIndices need not materialize #53901

Merged
merged 1 commit into from
Mar 31, 2024

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Mar 30, 2024

Currently,

julia> C = CartesianIndices((1:2, 1:2))
CartesianIndices((1:2, 1:2))

julia> copy(C)
2×2 Matrix{CartesianIndex{2}}:
 CartesianIndex(1, 1)  CartesianIndex(1, 2)
 CartesianIndex(2, 1)  CartesianIndex(2, 2)

However, seeing that a CartesianIndices is equivalent to an n-D range, there doesn't seem to be a need to materialize the result. This PR also ensures that copy(C) returns the same type as C.

After this PR:

julia> C = CartesianIndices((1:2, 1:2))
CartesianIndices((1:2, 1:2))

julia> copy(C)
CartesianIndices((1:2, 1:2))

Also, a similar change for LinearIndices is added.

@jishnub jishnub added the arrays [a, r, r, a, y, s] label Mar 30, 2024
@N5N3 N5N3 merged commit a3f710e into master Mar 31, 2024
8 checks passed
@N5N3 N5N3 deleted the jishnub/copycartlininds branch March 31, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants