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

relax view indices #232

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,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 @@ -1432,6 +1432,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