Skip to content

Commit 6814130

Browse files
overloaded broadcast
1 parent 58bb091 commit 6814130

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/array_partition.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,23 @@ Base.done(iter::ArrayPartition,state) = done(state,state)
5959
Base.length(A::ArrayPartition) = sum((length(x) for x in A.x))
6060
Base.size(A::ArrayPartition) = (length(A),)
6161
Base.indices(A::ArrayPartition) = ((indices(x) for x in A.x)...)
62-
Base.eachindex(A::ArrayPartition) = ((indices(x) for x in A.x)...)
62+
Base.eachindex(A::ArrayPartition) = Base.OneTo(length(A))
63+
64+
add_idxs(x,expr) = expr
65+
add_idxs{T<:ArrayPartition}(::Type{T},expr) = :($(expr).x[i])
66+
67+
@generated function Base.broadcast!(f,A::ArrayPartition,B...)
68+
exs = ((add_idxs(B[i],:(B[$i])) for i in eachindex(B))...)
69+
res = :(for i in eachindex(A.x)
70+
broadcast!(f,A.x[i],$(exs...))
71+
end)
72+
res
73+
end
74+
75+
@generated function Base.broadcast(f,B::Union{Number,ArrayPartition}...)
76+
exs = ((add_idxs(B[i],:(B[$i])) for i in eachindex(B))...)
77+
res = :(for i in eachindex(A.x)
78+
broadcast(f,$(exs...))
79+
end)
80+
res
81+
end

0 commit comments

Comments
 (0)