Skip to content

Commit

Permalink
Forbid IteratorSize of HasShape for Indices
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
andyferris committed Jun 11, 2020
1 parent 5bc53c5 commit bdc07ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AbstractIndices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Base.in(i, indices::AbstractIndices{I}) where I
end

# Match the default setting from Base - the majority of containers will know their size
Base.IteratorSize(indices::AbstractIndices) = Base.HasLength()
Base.IteratorSize(::AbstractIndices) = Base.HasLength()

function Base.length(indices::AbstractIndices)
if Base.IteratorSize(indices) isa Base.SizeUnknown
Expand Down
8 changes: 7 additions & 1 deletion src/Indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ Indices{I}(iter) where {I} = Indices{I, typeof(iter)}(iter) # There is a corner
end

Base.in(i::I, inds::Indices{I}) where {I} = in(i, inds.inds)
Base.IteratorSize(i::Indices) = Base.IteratorSize(i.inds)
function Base.IteratorSize(i::Indices)
out = Base.IteratorSize(i.inds)
if out isa Base.HasShape
return Base.HasLength()
end
return out
end
Base.length(i::Indices) = length(i.inds)

# Specialize for `Vector` elements. Satisfy the tokenization and insertion interface
Expand Down

0 comments on commit bdc07ed

Please sign in to comment.