Skip to content

runtime/array.c: expose {uniform_,float}array_concat, use it in Float.Array - #13362

Merged
gasche merged 2 commits into
ocaml:trunkfrom
gasche:floatarray_concat
Apr 3, 2025
Merged

gasche merged 2 commits into
ocaml:trunkfrom
gasche:floatarray_concat

Conversation

@gasche

@gasche gasche commented Aug 5, 2024 •

Copy link
Copy Markdown
Member

This is an immediate follow-up over #13361, sorry for the noise.

Yesterday I was intimidated by the length of the implementation of caml_array_concat (it is 43 lines of C code that traverses an OCaml list of arrays and accumulates them and their sizes into separate arrays to call caml_array_gather, with a cool optimization to avoid dynamic allocations below a certain input size). I gave up on the idea of finding out how to refactor it cleverly to avoid duplicating it twice into a uniform_array and a floatarray version.

Today I realized that I could use the power of Functional Programming, in this case, function pointers. I just abstract over the gather function, then define three one-liner instances for each usage.

Note: This is the last primitive function over arrays that is implemented in C in array.c and exposed as an external in array.ml. The present PR brings Float.Array at complete parity in terms of runtime support.

(cc @nojb)

@gasche

gasche commented Apr 2, 2025

Copy link
Copy Markdown
Member Author

@nojb I'm going through my old PRs to bring them to closure, and took the initiative of assigning you on this one. There is of course no urgency, so feel free to wait until the right time to look at this.

@nojb nojb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM (modulo a cosmetic tweak)

Comment thread runtime/array.c
{
return generic_array_concat(&caml_array_gather, al);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change

Comment thread runtime/array.c Resolved
@gasche
gasche force-pushed the floatarray_concat branch from b61d671 to 59dcd8d Compare April 3, 2025 07:00
@gasche gasche added the merge-me label Apr 3, 2025
@gasche

gasche commented Apr 3, 2025

Copy link
Copy Markdown
Member Author

Thanks for the review! This is good to merge if/when the CI agrees.

@gasche
gasche merged commit d9060b3 into ocaml:trunk Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants