Skip to content
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

Add isonebased trait to opt out of OffsetArray wrappers #335

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jul 3, 2023

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
Copy link

codecov bot commented Jul 3, 2023

Codecov Report

Merging #335 (71565b6) into master (1cae070) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
src/OffsetArrays.jl 98.33% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@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