Skip to content

Commit 6ed6ec5

Browse files
authored
Specialize iterate (#181)
* add iterate * version bump to v0.13.3 * bugfix in upper limit
1 parent 1636cbd commit 6ed6ec5

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.13.2"
3+
version = "0.13.3"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/FillArrays.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Fill{T,0}(x::T, ::Tuple{}) where T = Fill{T,0,Tuple{}}(x, ()) # ambiguity fix
121121
@inline Fill{T,N,Axes}(F::Fill{T,N,Axes}) where {T,N,Axes} = F
122122

123123
@inline axes(F::Fill) = F.axes
124-
@inline size(F::Fill) = length.(F.axes)
124+
@inline size(F::Fill) = map(length, F.axes)
125125

126126
@inline getindex_value(F::Fill) = F.value
127127

@@ -183,6 +183,12 @@ Base.@propagate_inbounds @inline Base._unsafe_getindex(::IndexStyle, F::Abstract
183183
getindex(A::AbstractFill, kr::AbstractVector{Bool}) = _fill_getindex(A, kr)
184184
getindex(A::AbstractFill, kr::AbstractArray{Bool}) = _fill_getindex(A, kr)
185185

186+
@inline Base.iterate(F::AbstractFill) = length(F) == 0 ? nothing : (v = getindex_value(F); (v, (v, 1)))
187+
@inline function Base.iterate(F::AbstractFill, (v, n))
188+
n >= length(F) && return nothing
189+
v, (v, n+1)
190+
end
191+
186192
sort(a::AbstractFill; kwds...) = a
187193
sort!(a::AbstractFill; kwds...) = a
188194
svdvals!(a::AbstractFill{<:Any,2}) = [getindex_value(a)*sqrt(prod(size(a))); Zeros(min(size(a)...)-1)]
@@ -509,11 +515,8 @@ end
509515
# Cumsum
510516
#########
511517

512-
sum(x::AbstractFill) = getindex_value(x)*length(x)
513518
sum(x::Zeros) = getindex_value(x)
514519

515-
sum(f, x::AbstractFill) = length(x) * f(getindex_value(x))
516-
517520
cumsum(x::AbstractFill{<:Any,1}) = range(getindex_value(x); step=getindex_value(x),
518521
length=length(x))
519522

0 commit comments

Comments
 (0)