Skip to content

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

Merged
vtjnash merged 16 commits intoJuliaLang:masterfrom
MasonProtter:wrap
Dec 9, 2023
Merged

add wrap function which is the safe counterpart to unsafe_wrap.#52049
vtjnash merged 16 commits intoJuliaLang:masterfrom
MasonProtter:wrap

Conversation

@MasonProtter
Copy link
Copy Markdown
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
Copy Markdown
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
mem = ref.mem
mem_len = length(mem)
len = Core.checked_dims(dims...)
@boundscheck mem_len >= len || invalid_wrap_err(men_len, dims)
Copy link
Copy Markdown
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?

MasonProtter and others added 3 commits November 26, 2023 22:20
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@MasonProtter
Copy link
Copy Markdown
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
Copy Markdown
Member

@vtjnash do you concur?

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

vtjnash commented Dec 9, 2023

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

@MasonProtter
Copy link
Copy Markdown
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
Copy Markdown
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