-
Notifications
You must be signed in to change notification settings - Fork 0
Return ReshapedArray from acquire! for N-D arrays #4
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
Conversation
- get_nd_view! now uses reshape(1D_view, dims) for N-D arrays - Zero unsafe_wrap cost (0 bytes vs 112 bytes on cache miss) - Works with any dimension pattern (no N-way cache limit) - Update docstrings for acquire! and unsafe_acquire!
Add ReshapedArray detection to pool validation:
- ReshapedArray wraps SubArray{T,1,Vector{T},...}
- Check pointer overlap with pool's internal vectors
- acquire! N-D now returns ReshapedArray{T,N} instead of SubArray
- Add StridedArray compatibility tests (BLAS compatible)
- Update _validate_pool_return tests for ReshapedArray
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4 +/- ##
==========================================
- Coverage 97.39% 97.16% -0.23%
==========================================
Files 6 6
Lines 422 424 +2
==========================================
+ Hits 411 412 +1
- Misses 11 12 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the N-dimensional array acquisition path in AdaptiveArrayPools to return Base.ReshapedArray instead of SubArray{Array}, eliminating the 112-byte allocation cost of unsafe_wrap on cache misses. The implementation now calls reshape(flat_view, dims) on a cached 1D view, providing zero-cost array shaping that works with any dimension pattern while maintaining BLAS compatibility via StridedArray.
Key Changes:
- Simplified
get_nd_view!to usereshape()instead of view caching withunsafe_wrap - Updated
_validate_pool_returnto properly unwrap and validateReshapedArrayinstances - Comprehensively updated tests to check for
Base.ReshapedArrayreturn types
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/core.jl |
Refactored get_nd_view! to return ReshapedArray via reshape() instead of cached SubArray views; updated docstrings for acquire! and unsafe_acquire! |
src/utils.jl |
Added ReshapedArray detection branch in _validate_pool_return to unwrap ReshapedArray→SubArray→Array for pool memory overlap validation |
test/test_multidimensional.jl |
Updated type assertions from SubArray to Base.ReshapedArray and added StridedArray checks for BLAS compatibility verification |
test/test_utils.jl |
Updated comments and type assertions for validation tests to reflect ReshapedArray returns |
Project.toml |
Version bump from 0.2.0 to 0.2.1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
842f83c to
bc3e7c6
Compare
Summary
Change
acquire!N-D path to returnReshapedArrayinstead ofSubArray{Array}.Key benefit: Zero allocation even on cache miss - no
unsafe_wrapcall needed regardless of dimension pattern.API Design
acquire!1DSubArray{T,1,Vector{T}}acquire!N-DReshapedArray{T,N}unsafe_acquire!Array{T,N}Why ReshapedArray?
Before (SubArray{Array})
After (ReshapedArray)
Allocation Comparison
When to Use Each API
Type-Specified Path (use
acquire!)Type-Unspecified Path (use
unsafe_acquire!)API Aliases
Added explicit naming aliases for users who prefer symmetric naming:
acquire!acquire_view!SubArray/ReshapedArray)unsafe_acquire!acquire_array!Array{T,N}Both names are exported and fully interchangeable (same function via
constbinding).Changes
get_nd_view!usesreshape(1D_view, dims), added aliases_validate_pool_returndetects ReshapedArrayacquire_view!,acquire_array!Commits
refactor: return ReshapedArray from get_nd_view! instead of SubArrayfix: detect ReshapedArray in _validate_pool_returntest: update type checks for ReshapedArray returnsfeat: add acquire_view!/acquire_array! aliases