Skip to content

Commit 269fd41

Browse files
authored
relax view indices (#232)
* relax view indices * fully relax indices * Add tests for various index types
1 parent 4cfd7c9 commit 269fd41

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/FillArrays.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,11 @@ copy(a::LinearAlgebra.Transpose{<:Any,<:AbstractFill}) = transpose(parent(a))
709709

710710
Base.@propagate_inbounds view(A::AbstractFill{<:Any,N}, kr::AbstractArray{Bool,N}) where N = _fill_getindex(A, kr)
711711
Base.@propagate_inbounds view(A::AbstractFill{<:Any,1}, kr::AbstractVector{Bool}) = _fill_getindex(A, kr)
712-
Base.@propagate_inbounds view(A::AbstractFill{<:Any,N}, I::Vararg{Union{Real, AbstractArray}, N}) where N =
712+
Base.@propagate_inbounds view(A::AbstractFill, I...) =
713713
_fill_getindex(A, Base.to_indices(A,I)...)
714714

715715
# not getindex since we need array-like indexing
716-
Base.@propagate_inbounds function view(A::AbstractFill{<:Any,N}, I::Vararg{Real, N}) where N
716+
Base.@propagate_inbounds function view(A::AbstractFill, I::Vararg{Real})
717717
@boundscheck checkbounds(A, I...)
718718
fillsimilar(A)
719719
end

test/runtests.jl

+9
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,15 @@ end
14341434
@test FillArrays.getindex_value(v) == FillArrays.unique_value(v) == 2.0
14351435
@test convert(Fill, v) Fill(2.0,2)
14361436
@test view(a,1) Fill(2.0)
1437+
@test view(a,1,1) Fill(2.0)
1438+
@test view(a, :) === a
1439+
@test view(a, CartesianIndices(a)) === a
1440+
vv = view(a, CartesianIndices(a), :, 1)
1441+
@test ndims(vv) == 2
1442+
@test vv isa Fill && FillArrays.getindex_value(vv) == 2.0
1443+
vv = view(a, CartesianIndices(a), :, 1:1)
1444+
@test ndims(vv) == 3
1445+
@test vv isa Fill && FillArrays.getindex_value(vv) == 2.0
14371446
end
14381447

14391448
@testset "view with bool" begin

0 commit comments

Comments
 (0)