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

Move StaticArrays support to extension #265

Merged
merged 9 commits into from
Dec 6, 2023
Merged

Conversation

N5N3
Copy link
Contributor

@N5N3 N5N3 commented Mar 3, 2023

close #263.
Now StructSizedArray's broadcast won't causes extra allocation.
I think we'd better wait for the release of 1.9.

@aplavin
Copy link
Member

aplavin commented Mar 9, 2023

Why replace StaticArraysCore with Requires on earlier Julia versions?

@N5N3
Copy link
Contributor Author

N5N3 commented Mar 9, 2023

Not sure if guys want a hard dependency or a Require.jl here.
The code should be easy to switch if we decide the other is better.

Update Project.toml
@N5N3
Copy link
Contributor Author

N5N3 commented Oct 14, 2023

@piever I think this PR is ready to go. (#270 has been included as the 1st commit with table part excluded)

@piever
Copy link
Collaborator

piever commented Oct 25, 2023

Hey, sorry for the slow reply! So, looks good overall, I've just left a comment to propose to split the changes to broadcast and the refactor into separate PRs (unless there's a strong reason to do them at the same time). EDIT: I now remembered the problem of the extra allocations if the implementation only relies on StaticArraysCore, so I imagine that is the strong reason.

Just to make sure I understand, Adapt is still a hard dependency as it doesn't really impact load time? I imagine we could move to weakdeps in the future anyways.

Project.toml Outdated Show resolved Hide resolved
Project.toml Show resolved Hide resolved
And use curried adapter to avoid possible instability
Project.toml Show resolved Hide resolved
ext/StructArraysAdaptExt.jl Outdated Show resolved Hide resolved
ext/StructArraysAdaptExt.jl Show resolved Hide resolved
Project.toml Show resolved Hide resolved
Project.toml Show resolved Hide resolved
ext/StructArraysAdaptExt.jl Outdated Show resolved Hide resolved
@oschulz
Copy link
Contributor

oschulz commented Nov 2, 2023

What's the state on this?

@N5N3
Copy link
Contributor Author

N5N3 commented Nov 2, 2023

What's the state on this?

It's almost done. Most of the suggestions have been resolved.

ext/StructArraysAdaptExt.jl Show resolved Hide resolved
ext/StructArraysStaticArraysExt.jl Outdated Show resolved Hide resolved
ext/StructArraysStaticArraysExt.jl Outdated Show resolved Hide resolved
ext/StructArraysStaticArraysExt.jl Outdated Show resolved Hide resolved
ext/StructArraysStaticArraysExt.jl Outdated Show resolved Hide resolved
ext/StructArraysStaticArraysExt.jl Show resolved Hide resolved
eltys = Tuple{map(eltype, a)...}
(), Core.Compiler.return_type(f, eltys)
else
temp = __broadcast(f, sz, s, a...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part worries me a little bit, we are using something explicitly marked as internal in StaticArrays. Is there no way to achieve this using only public methods? Or maybe we could check over at StaticArrays if they can offer some solution (maybe add a public method that does what we need).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well __broadcast was splitted from _broadcast in JuliaArrays/StaticArrays.jl#1001.
So perhaps the best solution is defining it ourselves.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, thanks for pointing out that discussion. In that case, maybe one could just add a small docstring in StaticArrays.__broadcast to mention that it is the method to be used by outside packages to implement broadcasting of wrapped static arrays (in that way it doesn't accidentally get removed in some StaticArrays refactor that would accidentally break our code).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense too.
Anyway, there's not much code added here. Should we just merge this PR as is, and revert that specific commit once StaticArrays get that mention.

@piever
Copy link
Collaborator

piever commented Nov 30, 2023

Perfect, thanks for all the great work here @N5N3! I'll go ahead and merge this in a few days if nobody has additional comments.

What is the relation with #284? I wanted to make sure, but it seems to me that they are mostly independent and #284 can be rebased and merged after this one gets in?

@oschulz
Copy link
Contributor

oschulz commented Nov 30, 2023

My thanks as well @N5N3 ! I'm depending on StructArrays more and more, and having it more lightweight is awesome.

@N5N3
Copy link
Contributor Author

N5N3 commented Nov 30, 2023

Yes, they are independent @piever

@piever piever merged commit 3b38c22 into JuliaArrays:master Dec 6, 2023
6 of 7 checks passed
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

Successfully merging this pull request may close these issues.

Add StaticArray support via the new extension mechanism
4 participants