From 3536c0eb8fcc30198d7c70a5e7678db96fc06926 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 17 Oct 2022 14:22:20 +0400 Subject: [PATCH] Set IndexStyle to IndexLinear for AbstractFill --- src/FillArrays.jl | 2 +- test/runtests.jl | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 94cb8e1b..5496df39 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -56,7 +56,7 @@ end end rank(F::AbstractFill) = iszero(getindex_value(F)) ? 0 : 1 -IndexStyle(::Type{<:AbstractFill{<:Any,N,<:NTuple{N,Base.OneTo{Int}}}}) where N = IndexLinear() +IndexStyle(::Type{<:AbstractFill}) = IndexLinear() issymmetric(F::AbstractFill{<:Any, 2}) = axes(F,1) == axes(F,2) ishermitian(F::AbstractFill{<:Any, 2}) = issymmetric(F) && iszero(imag(getindex_value(F))) diff --git a/test/runtests.jl b/test/runtests.jl index 368ac186..0e9c9fc8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -478,6 +478,17 @@ end @testset "IndexStyle" begin @test IndexStyle(Zeros(5,5)) == IndexStyle(typeof(Zeros(5,5))) == IndexLinear() + for ax in (Base.OneTo(2), SOneTo(2), Base.IdentityUnitRange(2:3)) + for f in (Fill(1, (ax,)), Fill(1, (ax,ax)), + Zeros{Int}((ax,)), Zeros{Int}((ax, ax)), + Ones{Int}((ax,)), Ones{Int}((ax, ax)), + ) + @test IndexStyle(f) == IndexLinear() + for (CI, LI) in zip(CartesianIndices(f), LinearIndices(f)) + @test f[CI] == f[LI] + end + end + end end @testset "Identities" begin