8
8
_broadcast (f, broadcast_sizes (a... ), a... )
9
9
end
10
10
11
+ @propagate_inbounds function broadcast {T} (f:: Function , a:: Type{T} , x:: StaticArray )
12
+ _broadcast (f, (Size (), Size (x)), T, x)
13
+ end
14
+
11
15
@inline broadcast_sizes (a... ) = _broadcast_sizes ((), a... )
12
16
@inline _broadcast_sizes (t:: Tuple ) = t
13
17
@inline _broadcast_sizes (t:: Tuple , a:: StaticArray , as... ) = _broadcast_sizes ((t... , Size (a)), as... )
@@ -23,7 +27,7 @@ function broadcasted_index(oldsize, newindex)
23
27
return sub2ind (oldsize, index... )
24
28
end
25
29
26
- @generated function _broadcast (f, s:: Tuple{Vararg{Size}} , a:: Union{Number, StaticArray} ...)
30
+ @generated function _broadcast (f, s:: Tuple{Vararg{Size}} , a... )
27
31
first_staticarray = 0
28
32
for i = 1 : length (a)
29
33
if a[i] <: StaticArray
57
61
current_ind = ones (Int, length (newsize))
58
62
59
63
while more
60
- exprs_vals = [(a[i] <: Number ? :(a[$ i]) : :(a[$ i][$ (broadcasted_index (sizes[i], current_ind))])) for i = 1 : length (sizes)]
64
+ exprs_vals = [(! ( a[i] <: AbstractArray ) ? :(a[$ i]) : :(a[$ i][$ (broadcasted_index (sizes[i], current_ind))])) for i = 1 : length (sizes)]
61
65
exprs[current_ind... ] = :(f ($ (exprs_vals... )))
62
66
63
67
# increment current_ind (maybe use CartesianRange?)
77
81
end
78
82
end
79
83
80
- eltype_exprs = [:( eltype ($ t) ) for t ∈ a]
84
+ eltype_exprs = [t <: AbstractArray ? :( $ ( eltype (t))) : :( $ t ) for t ∈ a]
81
85
newtype_expr = :(Core. Inference. return_type (f, Tuple{$ (eltype_exprs... )}))
82
86
83
87
return quote
0 commit comments