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

Set IndexStyle to IndexLinear for AbstractFill #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Oct 17, 2022

Closes #195 by setting the default IndexStyle to IndexLinear for all AbstractFill

Edit: Oddly, this makes certain benchmarks worse, so let's hold off on merging this for a bit

julia> f = Fill(1, (SOneTo(32),));

julia> fo = OffsetArray(f, 4);

julia> @btime sum($fo);
  3.353 ns (0 allocations: 0 bytes) # master
  17.115 ns (0 allocations: 0 bytes) # PR

@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #196 (3536c0e) into master (de36a50) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #196   +/-   ##
=======================================
  Coverage   97.87%   97.87%           
=======================================
  Files           4        4           
  Lines         660      660           
=======================================
  Hits          646      646           
  Misses         14       14           
Impacted Files Coverage Δ
src/FillArrays.jl 97.36% <100.00%> (ø)

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

@dlfivefifty
Copy link
Member

Btw I take back my justification for IndexCartesian due to OffsetArrays.jl as they always use IndexLinear. Though its a bit inconsistent:

julia> a = OffsetArray([1,2,3],-1)
3-element OffsetArray(::Vector{Int64}, 0:2) with eltype Int64 with indices 0:2:
 1
 2
 3

julia> Base.IndexStyle(typeof(a))
IndexLinear()

julia> a[1]
2

julia> a = OffsetArray(randn(3,4),-1,-2)
3×4 OffsetArray(::Matrix{Float64}, 0:2, -1:2) with eltype Float64 with indices 0:2×-1:2:
 1.39984   0.983014   0.74824    1.19955
 1.32323   0.434697   0.68893   -1.77555
 1.41984  -0.503202  -0.704223  -1.04858

julia> Base.IndexStyle(typeof(a))
IndexLinear()

julia> a[1]
1.3998366656381436

@dlfivefifty
Copy link
Member

Nevermind, I see the key is firstindex:

julia> a = OffsetArray([1,2,3],-1)
3-element OffsetArray(::Vector{Int64}, 0:2) with eltype Int64 with indices 0:2:
 1
 2
 3

julia> firstindex(a)
0

julia> a = OffsetArray(randn(3,4),-1,-2)
3×4 OffsetArray(::Matrix{Float64}, 0:2, -1:2) with eltype Float64 with indices 0:2×-1:2:
  0.817174  -0.3924     0.477989  -1.00355
 -1.22104   -0.765553  -0.233384   0.965962
  0.231041  -0.445986   0.781096  -0.257998

julia> firstindex(a)
1

We should make sure we test this behaviour is correct for offset FillArrays.jl

@jishnub
Copy link
Member Author

jishnub commented Oct 17, 2022

I've included tests for offset FillArrays, with the axes being Base.IdentityUnitRanges. Tests comparing linear and Cartesian indexing seem to work fine.

@dlfivefifty
Copy link
Member

Can you add firstindex tests?

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.

Why is IndexStyle specialized for Base.OneTo?
2 participants