forked from SciML/RecursiveArrayTools.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursiveArrayToolsFastBroadcastPolyesterExt.jl
More file actions
48 lines (42 loc) · 1.42 KB
/
RecursiveArrayToolsFastBroadcastPolyesterExt.jl
File metadata and controls
48 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module RecursiveArrayToolsFastBroadcastPolyesterExt
using RecursiveArrayTools
using FastBroadcast
using FastBroadcast: Serial, Threaded
using Polyester
using StaticArraysCore
const AbstractVectorOfSArray = AbstractVectorOfArray{
T, N, <:AbstractVector{<:StaticArraysCore.SArray},
} where {T, N}
@inline function _polyester_fast_materialize!(
dst::AbstractVectorOfSArray,
bc::Broadcast.Broadcasted{S}
) where {S}
if FastBroadcast.use_fast_broadcast(S)
@batch for i in 1:length(dst.u)
unpacked = RecursiveArrayTools.unpack_voa(bc, i)
dst.u[i] = StaticArraysCore.similar_type(dst.u[i])(
unpacked[j]
for j in eachindex(unpacked)
)
end
else
Broadcast.materialize!(dst, bc)
end
return dst
end
@inline function FastBroadcast.fast_materialize!(
::Threaded, dst::AbstractVectorOfSArray,
bc::Broadcast.Broadcasted{S}
) where {S}
return _polyester_fast_materialize!(dst, bc)
end
# Disambiguation: this method is more specific than both the base ext's
# (::Threaded, ::AbstractVectorOfArray, ::Broadcasted) fallback and
# the above (::Threaded, ::AbstractVectorOfSArray, ::Broadcasted{S}).
@inline function FastBroadcast.fast_materialize!(
::Threaded, dst::AbstractVectorOfSArray,
bc::Broadcast.Broadcasted
)
return _polyester_fast_materialize!(dst, bc)
end
end # module