Skip to content

fix and refactor Arrays.getindex!#1213

Open
Antoinemarteau wants to merge 5 commits intogridap:masterfrom
Antoinemarteau:master
Open

fix and refactor Arrays.getindex!#1213
Antoinemarteau wants to merge 5 commits intogridap:masterfrom
Antoinemarteau:master

Conversation

@Antoinemarteau
Copy link
Contributor

getindex! would ignore the cache if the given indices did not match the IndexStyle of the array. This could lead to re-alocating the cache of LazyArrays at each access in hot loops.

Now, the indices are converted using LinearIndices or CartesianIndices, so the cache should never be ignored if the indices index a single element in the array.

This also cleans the implementation by using @propagate_inbounds, limiting number of method and using Base to transform the indices.

getindex! would ignore the cache if the given indices did not match the
`IndexStyle` of the array.

Now, the indices are converted using LinearIndices or CartesianIndices.

This also cleans the implementation by using @propagate_inbounds, limiting
number of method and using Base to transform the indices.
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 94.28571% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.97%. Comparing base (bbaf662) to head (392bcfb).

Files with missing lines Patch % Lines
src/Arrays/VectorsWithEntryInserted.jl 66.66% 3 Missing ⚠️
src/Arrays/VectorsWithEntryRemoved.jl 66.66% 3 Missing ⚠️
src/Arrays/ArrayBlocks.jl 97.77% 1 Missing ⚠️
src/Arrays/LazyArrays.jl 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1213      +/-   ##
==========================================
- Coverage   89.04%   88.97%   -0.07%     
==========================================
  Files         213      213              
  Lines       27529    27556      +27     
==========================================
+ Hits        24512    24519       +7     
- Misses       3017     3037      +20     
Flag Coverage Δ
drivers 0.00% <0.00%> (ø)
extensions 0.00% <0.00%> (ø)
tests 88.98% <94.28%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- marked most `getindex`, `getindex!` and `setindex!` method @propagate_inbounds
- optimized these method with `@inbounds` where usefull
- added a lot of `@inbounds` where safe (use of `eachindex`/ via @check of Array
  sizes),
    - especially in `ArrayBlocks` (those `@inbounds` rely on the fields of
      `ArrayBlock` being `Base.Array`, more precisely that they are 1-based
      indexed and of `IndexLinear` style)
- some more `@inbounds` are probably possible in `Tables.jl`
@Antoinemarteau
Copy link
Contributor Author

I also took the opportunity to add @Base.propagate_inbounds to loads of getindex! / setindex! methods in Arrays, and add @inbounds where I felt it was safe in the module.

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.

1 participant