Skip to content

Commit e57d690

Browse files
committed
test structarray broadcasting
1 parent a43dedc commit e57d690

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/integration/structarrays.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ using StructArrays, Reactant, Test
3939
Int64,
4040
}
4141
end
42+
43+
@noinline function elwise(e::NamedTuple)
44+
return (; c=e.b, d=sin(e.a))
45+
end
46+
47+
function broadcast_elwise(x)
48+
return elwise.(x)
49+
end
50+
51+
@testset "structarray broadcasting" begin
52+
x = StructVector(; a=rand(10), b=rand(Float32, 10))
53+
54+
x_ra = Reactant.to_rarray(x)
55+
56+
result = @jit broadcast_elwise(x_ra)
57+
58+
@test typeof(result) == StructVector{
59+
@NamedTuple{c::ConcretePJRTNumber{Float32,1}, d::ConcretePJRTNumber{Float64,1}},
60+
@NamedTuple{c::ConcretePJRTArray{Float32,1,1}, d::ConcretePJRTArray{Float64,1,1}},
61+
CartesianIndex{1},
62+
}
63+
for (component_ra, component) in
64+
zip(components(result), components(broadcast_elwise(x)))
65+
@test component_ra component
66+
end
67+
end

0 commit comments

Comments
 (0)