Skip to content

Add isonebased trait to opt out of OffsetArray wrappers#335

Open
jishnub wants to merge 3 commits into
JuliaArrays:masterfrom
jishnub:isonebased
Open

Add isonebased trait to opt out of OffsetArray wrappers#335
jishnub wants to merge 3 commits into
JuliaArrays:masterfrom
jishnub:isonebased

Conversation

@jishnub

@jishnub jishnub commented Jul 3, 2023

Copy link
Copy Markdown
Member

The idea is

julia> OffsetArrays.no_offset_view(SMatrix{2,2}(1:4))
2×2 OffsetArray(::SMatrix{2, 2, Int64, 4}, 1:2, 1:2) with eltype Int64 with indices 1:2×1:2:
 1  3
 2  4

julia> OffsetArrays.isonebased(::SOneTo) = true

julia> OffsetArrays.no_offset_view(SMatrix{2,2}(1:4)) # no wrapper anymore
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 1  3
 2  4

Also, in this case, the similar method in this package will forward the lengths of the axes to Base, so the result will usually be an Array instead of an OffsetArray:

julia> similar(rand(2), Int, Base.IdentityUnitRange(Base.OneTo(2)))
2-element Vector{Int64}:
              -1
 140522905523888

@codecov

codecov Bot commented Jul 3, 2023

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.69%. Comparing base (1cae070) to head (71565b6).
⚠️ Report is 39 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #335      +/-   ##
==========================================
+ Coverage   98.67%   98.69%   +0.02%     
==========================================
  Files           5        5              
  Lines         452      459       +7     
==========================================
+ Hits          446      453       +7     
  Misses          6        6              

☔ View full report in Codecov by Harness.
📢 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.

@jishnub jishnub changed the title Add isonebased trait to opt-out of OffsetArray wrappers Add isonebased trait to opt out of OffsetArray wrappers Jul 4, 2023
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