|
1 |
| -@inline _first(a1, as...) = a1 |
2 |
| - |
3 | 1 | ################
|
4 | 2 | ## map / map! ##
|
5 | 3 | ################
|
6 | 4 |
|
7 |
| -@inline map(f, as::StaticArray...) = |
| 5 | +@inline function map(f, as::Union{SA,AbstractArray}...) where {SA<:StaticArray} |
8 | 6 | _map(f, same_size(as...), as...)
|
9 |
| -# Mixed StaticArray + AbstractArray; various versions to avoid ambiguities. |
10 |
| -# With the versions below, if a StaticArray isn't present in the first two |
11 |
| -# arguments, we'll end up in Base.map() instead. |
12 |
| -@inline map(f, a1::StaticArray, as::AbstractArray...) = |
13 |
| - _map(f, same_size(a1, as...), a1, as...) |
14 |
| -@inline map(f, a1::AbstractArray, a2::StaticArray, as::AbstractArray...) = |
15 |
| - _map(f, same_size(a1, a2, as...), a1, a2, as...) |
16 |
| -@inline map(f, a1::StaticArray, a2::AbstractArray, as::AbstractArray...) = |
17 |
| - _map(f, same_size(a1, a2, as...), a1, a2, as...) |
18 |
| -@inline map(f, a1::StaticArray, a2::StaticArray, as::AbstractArray...) = |
19 |
| - _map(f, same_size(a1, a2, as...), a1, a2, as...) |
| 7 | +end |
20 | 8 |
|
21 | 9 | @generated function _map(f, ::Size{S}, a::AbstractArray...) where {S}
|
22 | 10 | exprs = Vector{Expr}(prod(S))
|
|
28 | 16 | newT = :(Core.Inference.return_type(f, Tuple{$(eltypes...)}))
|
29 | 17 | return quote
|
30 | 18 | @_inline_meta
|
31 |
| - @inbounds return similar_type(typeof(_first(a...)), $newT, Size(S))(tuple($(exprs...))) |
| 19 | + @inbounds return similar_type(typeof(_first_static(a...)), $newT, Size(S))(tuple($(exprs...))) |
32 | 20 | end
|
33 | 21 | end
|
34 | 22 |
|
|
0 commit comments