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

improve type stability #255

Closed
wants to merge 1 commit into from
Closed

Conversation

aplavin
Copy link
Member

@aplavin aplavin commented Nov 24, 2022

Fixes #247 - added tests would fail before.
Thanks @jishnub for help in understanding that issue.

I think the updated code is not only more type-stable, but also cleaner in general.

@aplavin aplavin mentioned this pull request Nov 24, 2022
@aplavin
Copy link
Member Author

aplavin commented Nov 28, 2022

bump...
@piever

T = mapreduce(eltype, promote_type, args)
StructArray{T}(map(f, propertynames(args[1])))
StructArray{T}(map((oargs...) -> $op(oargs...; kwargs...), map(components, args)...))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with the change (iterating on a Tuple as it was done before seems incorrect).

This is a little bit hard to read though. Could it be split over several lines giving meaningful names to the variables? Maybe something like

for op in [:cat, :hcat, :vcat]
    f = Symbol(:curried, op) # or another descriptive name
    @eval begin
        function Base.$op(args::StructArray...; kwargs...)
            $f(vs...) = $op(vs...; kwargs...)

From what I understand named functions are a bit better than anonymous functions here for the purpose of error messages (if the anonymous function throws, the stack trace is a bit harder to read).

@piever
Copy link
Collaborator

piever commented Nov 30, 2022

Left a small comment, but I agree with the change overall. Note that this should also be rebased to include the piracy fix in #254

@jishnub
Copy link
Member

jishnub commented Dec 8, 2022

Gentle bump, would be good to have this included

@piever
Copy link
Collaborator

piever commented Dec 10, 2022

Sure, merged and tagged in #258

@piever piever closed this Dec 10, 2022
@aplavin
Copy link
Member Author

aplavin commented Dec 11, 2022

Great, thanks! I'm still travelling, didn't have time to update this PR.

@aplavin aplavin deleted the typestab branch January 11, 2023 14:31
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.

vcat is type-unstable
3 participants