Skip to content

Commit

Permalink
relax view indices (#232)
Browse files Browse the repository at this point in the history
* relax view indices

* fully relax indices

* Add tests for various index types
  • Loading branch information
jishnub authored Mar 29, 2023
1 parent 4cfd7c9 commit 269fd41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ copy(a::LinearAlgebra.Transpose{<:Any,<:AbstractFill}) = transpose(parent(a))

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

# not getindex since we need array-like indexing
Base.@propagate_inbounds function view(A::AbstractFill{<:Any,N}, I::Vararg{Real, N}) where N
Base.@propagate_inbounds function view(A::AbstractFill, I::Vararg{Real})
@boundscheck checkbounds(A, I...)
fillsimilar(A)
end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,15 @@ end
@test FillArrays.getindex_value(v) == FillArrays.unique_value(v) == 2.0
@test convert(Fill, v) Fill(2.0,2)
@test view(a,1) Fill(2.0)
@test view(a,1,1) Fill(2.0)
@test view(a, :) === a
@test view(a, CartesianIndices(a)) === a
vv = view(a, CartesianIndices(a), :, 1)
@test ndims(vv) == 2
@test vv isa Fill && FillArrays.getindex_value(vv) == 2.0
vv = view(a, CartesianIndices(a), :, 1:1)
@test ndims(vv) == 3
@test vv isa Fill && FillArrays.getindex_value(vv) == 2.0
end

@testset "view with bool" begin
Expand Down

0 comments on commit 269fd41

Please sign in to comment.