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

mention getindex() shouldn't return a "view" #47099

Merged
merged 7 commits into from
Sep 17, 2023

Conversation

Moelf
Copy link
Sponsor Contributor

@Moelf Moelf commented Oct 8, 2022

fix #47078

@ViralBShah
Copy link
Member

While the added statement is correct, I don't think it addresses the issue.

@ViralBShah ViralBShah added the domain:docs This change adds or pertains to documentation label Oct 19, 2022
@Moelf
Copy link
Sponsor Contributor Author

Moelf commented Oct 19, 2022

isn't the issue we agree it should never be a view but just didn't mention it? what DataFrames.jl does is not our issue (technically)

@ViralBShah
Copy link
Member

Never mind, I missed the second file in the PR. Yes, the issue is basically whether getindex is allowed to return a view or not.

@Moelf
Copy link
Sponsor Contributor Author

Moelf commented Nov 16, 2022

can we merge this?

@ViralBShah
Copy link
Member

I'd like a few more eyes on it. @KristofferC Is this reasonable to merge?

@KristofferC
Copy link
Sponsor Member

Shouldn't this be in the documentation for getindex or something? It somehow doesn't feel like this is the right place for a side note like this.

@jishnub
Copy link
Contributor

jishnub commented Nov 16, 2022

I'd prefer the phrasing to suggest what to do instead of warning against what not to do. A view is one of the many wrappers that getindex shouldn't return. It shouldn't return a reshaped array either, for example getindex(a::AbstractArray, ::Colon) = reshape(a, Val(1)) isn't a view technically, but it shares the underlying memory with the parent array.

@Moelf
Copy link
Sponsor Contributor Author

Moelf commented Nov 16, 2022

@KristofferC this is for developers.

for base vectors, getindex don't return view as outlined in multi-dimensional array manual, and we already tell user to use @view if they don't want a copy.

@nalimilan
Copy link
Member

Can we revive this? I hope my suggestions can help addressing the comments.

doc/src/manual/interfaces.md Outdated Show resolved Hide resolved
base/abstractarray.jl Outdated Show resolved Hide resolved
@@ -1256,6 +1256,9 @@ end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about specifying A::AbstractArray on the line above while we're at it? The description below isn't guaranteed to match non-array objects.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that page is specific to array interface, i think thats implied

Moelf and others added 2 commits September 1, 2023 09:05
Co-authored-by: Milan Bouchet-Valat <[email protected]>
Co-authored-by: Milan Bouchet-Valat <[email protected]>
@adienes
Copy link
Contributor

adienes commented Sep 16, 2023

+1

@Moelf Moelf changed the title mention getindex shouldn't be view mention getindex() shouldn't return a "view" Sep 16, 2023
@timholy timholy merged commit ee371a1 into JuliaLang:master Sep 17, 2023
4 of 6 checks passed
@timholy
Copy link
Sponsor Member

timholy commented Sep 17, 2023

Thanks!

@Moelf Moelf deleted the array_getindex_neverview branch September 18, 2023 02:50
NHDaly pushed a commit that referenced this pull request Sep 20, 2023
fix  #47078

---------

Co-authored-by: Milan Bouchet-Valat <[email protected]>
Co-authored-by: Tim Holy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can getindex(A::AbstractArray, inds::AbstractArray) result be a view?
7 participants