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

add wrap function which is the safe counterpart to unsafe_wrap. #52049

Merged
merged 16 commits into from
Dec 9, 2023

Conversation

MasonProtter
Copy link
Contributor

@MasonProtter MasonProtter commented Nov 6, 2023

This gives users a way to create new Arrays out of existing Memory since Array has no constructors still. There's a @test_broken in there due to #52048

@LilithHafner
Copy link
Member

LilithHafner commented Nov 6, 2023

This LGTM except for the length issue which is definitely blocking. We can't have arrays floating around with incorrect lengths.

I wish we could call this function Array, but the existing Array "constructors" are copying and this isn't.

EDIT: yipes, I didn't realize these internals still had so many gotchas. Thank you for the review, @vtjnash.

base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated
mem = ref.mem
mem_len = length(mem)
len = Core.checked_dims(dims...)
@boundscheck mem_len >= len || invalid_wrap_err(men_len, dims)
Copy link
Contributor Author

@MasonProtter MasonProtter Nov 6, 2023

Choose a reason for hiding this comment

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

should this check be behind a @boundscheck or should it just always be there?

base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
MasonProtter and others added 3 commits November 26, 2023 22:20
base/array.jl Outdated Show resolved Hide resolved
@MasonProtter
Copy link
Contributor Author

okay this should be ready now

@brenhinkeller brenhinkeller added arrays [a, r, r, a, y, s] feature Indicates new feature / enhancement requests merge me PR is reviewed. Merge when all tests are passing labels Dec 8, 2023
@LilithHafner
Copy link
Member

@vtjnash do you concur?

@vtjnash vtjnash merged commit 84cfe04 into JuliaLang:master Dec 9, 2023
10 checks passed
@vtjnash
Copy link
Member

vtjnash commented Dec 9, 2023

Should we consider adding support to view now too, that calls into this?

@MasonProtter
Copy link
Contributor Author

MasonProtter commented Dec 9, 2023

I'm not sure it'd really be that useful for view, since the call to jl_genericmemory_slice would induce an allocation 😞

That's why I wanted a way to wrap without re-allocating the memory slice as in #52048

@MasonProtter
Copy link
Contributor Author

I guess actually we could do it for 1D views without allocations. But it's kinda unsatisfying to have it only be nice for 1D.

@LilithHafner LilithHafner removed the merge me PR is reviewed. Merge when all tests are passing label Dec 11, 2023
@MasonProtter MasonProtter deleted the wrap branch December 13, 2023 11:29
fatteneder added a commit that referenced this pull request Feb 17, 2024
I thought that's reasonable in the light that `view` was not
implemented:
#52049 (comment)
tecosaur pushed a commit to tecosaur/julia that referenced this pull request Mar 4, 2024
I thought that's reasonable in the light that `view` was not
implemented:
JuliaLang#52049 (comment)
KristofferC pushed a commit that referenced this pull request Jun 18, 2024
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] feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants