Skip to content

Add extension for FixedSizeArrays (collect_structarray initializer)#344

Closed
qwjyh wants to merge 1 commit intoJuliaArrays:masterfrom
qwjyh:feat-fixed-size-arrays-ext
Closed

Add extension for FixedSizeArrays (collect_structarray initializer)#344
qwjyh wants to merge 1 commit intoJuliaArrays:masterfrom
qwjyh:feat-fixed-size-arrays-ext

Conversation

@qwjyh
Copy link

@qwjyh qwjyh commented Jan 25, 2026

Adding small package extension for FixedSizeArrays to provide initializer for collect_structarray to collect an iterator into a StructArray of FixedSizeArray.
I used a hack code in __init__ of the extension to export the new initializer under StructArrays module.
(The name of the initializer is still so long.)

@aplavin
Copy link
Member

aplavin commented Jan 25, 2026

I wonder, why does it need to live in StructArrays? The new code doesn't use any of the internals (doesn't use any code from StructArrays at all, for that matter), seems like it can just as well be independent.
Note that we don't have custom initializers for StaticArrays to be used with collect_structarray here, even though there's already an extension for StaticArrays.

@qwjyh
Copy link
Author

qwjyh commented Jan 25, 2026

I thought that StructArrayInitializer is internal API since it is not documented and that collect_structarray is a bit difficult to use as its document is not so detailed.
So is it better to add some docs to collect_structarray and StructArrayInitializer with examples on FixedSizeArray instead?

@aplavin
Copy link
Member

aplavin commented Jan 25, 2026

Sorry, I must've missed the StructArrayInitializer part originally :)
Why is this needed? Looking at the docs for collect_structarray, they say:

The user can optionally pass a `initializer`, that is to say
a function `(S, d) -> v` that associates to a type and a size an array of eltype `S`
and size `d`. By default `initializer` returns a `StructArray` of `Array` but custom array types
may be used.

Can initializer be just a function (S, d) -> similar(FixedSizeArrayDefault{S, length(d)}, d)?

@qwjyh
Copy link
Author

qwjyh commented Jan 25, 2026

Can initializer be just a function (S, d) -> similar(FixedSizeArrayDefault{S, length(d)}, d)?

I think this is totally fine so I'm closing this PR.

@qwjyh qwjyh closed this Jan 25, 2026
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.

2 participants