feat: add numc_array_stack with tests and benchmark#2
Merged
Conversation
Stack multiple equally shaped arrays along a new axis, producing an output of rank+1. The new axis (size n) is spliced in at the requested position, so axis 0 lines up whole arrays while the last axis interleaves elements. Fix three bugs in the initial implementation: an inverted dtype check that rejected every valid call, an out shape validation loop that tested the wrong index variable, and a copy block nested inside the per array loop that wrote the output n times. Add tests/core/test_stack.c covering positive, negative, and edge cases (15 cases, all passing, full suite green at 50/50), plus bench/numc/bench_stack.c measuring the fast path, the interleaved path, array count, dtype, and size scaling.
Wrap an over length comment in array_core.c, the long ASSERT_MSG_CTX calls in test_stack.c, and the ternary in bench_stack.c to satisfy clang-format, no behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
numc_array_stack, which combines several equally shaped arrays along a brand new axis, producing an output of rank+1. The new axis (sizen) is inserted at the requested position, soaxis=0lines up whole arrays while the last axis interleaves elements. This is the shape manipulation op described in ROADMAP.md, the close cousin ofnumc_array_concat.Bug fixes
The initial implementation always returned
-1. Three bugs were fixed:ntimes.Tests
tests/core/test_stack.c, 15 cases covering positive, negative, and edge scenarios:n == 0, dim mismatch, shape mismatch, dtype mismatch, bad axis, wrong out shape.All 15 pass, and the full suite stays green at 50/50.
Benchmark
bench/numc/bench_stack.cmeasures the fast path (axis=0, large memcpy) versus the interleaved path (last axis, per element copies), plus array count, dtype, and size scaling. The interleaved path runs roughly 12 to 40 times slower because copy granularity drops to a single element, a candidate for a future strided kernel.