From 17450eb3fecc5cdf804f54b158f4b0d50d345549 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 12 Nov 2025 17:35:00 +0100 Subject: [PATCH 1/7] Infer outputtype by return_types --- src/DAT/broadcast.jl | 7 +++++-- test/DAT/broadcast.jl | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/DAT/broadcast.jl b/src/DAT/broadcast.jl index 4ab4e94c..743da1b0 100644 --- a/src/DAT/broadcast.jl +++ b/src/DAT/broadcast.jl @@ -17,8 +17,11 @@ function Base.materialize(bc::Broadcast.Broadcasted{XStyle}) args2 = map(arg -> arg isa Broadcast.Broadcasted ? Base.materialize(arg) : arg, bc.args) args2 = map(to_yax, args2) # determine output type by calling `eltype` on a dummy function call - dummy_args = map(a -> first(a.data), args2) - outtype = typeof(bc.f(dummy_args...)) + intypes = (eltype.(args2)...,) + @debug intypes + outtypes = Base.return_types(bc.f, intypes) + outtype = Union{outtypes...} + @debug outtype return xmap(XFunction(bc.f; inplace=false), args2..., output=XOutput(; outtype)) end function Base.materialize!(bc::Broadcast.Broadcasted{XStyle}) diff --git a/test/DAT/broadcast.jl b/test/DAT/broadcast.jl index 93d1074d..4a0214b6 100644 --- a/test/DAT/broadcast.jl +++ b/test/DAT/broadcast.jl @@ -60,4 +60,12 @@ a, b, c = sample_arrays() xscalar = a .* 3 .+ 1 @test all(xscalar[:] .== 4.0) @test isa(a .+ b, YAXArray) +end + +@testset "missing handling" begin + am = YAXArray([missing 1 ; 1 2]) + aeq = am .== am + @test eltype(aeq) == Union{Missing, Bool} + @test ismissing(aeq[1,1]) + @test aeq[1,2] end \ No newline at end of file From 3d4cbc62be4d91242c2aa23d318eac42723a1e30 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 12 Nov 2025 19:09:25 +0100 Subject: [PATCH 2/7] Apply change to materialize! as well --- src/DAT/broadcast.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DAT/broadcast.jl b/src/DAT/broadcast.jl index 743da1b0..3d6754e3 100644 --- a/src/DAT/broadcast.jl +++ b/src/DAT/broadcast.jl @@ -27,7 +27,9 @@ end function Base.materialize!(bc::Broadcast.Broadcasted{XStyle}) args2 = map(arg -> arg isa Broadcast.Broadcasted ? Base.materialize(arg) : arg, bc.args) args2 = map(to_yax, args2) - dummy_args = map(a -> first(a.data), args2) - outtype = typeof(bc.f(dummy_args...)) + intypes = (eltype.(args2)...,) + @debug intypes + outtypes = Base.return_types(bc.f, intypes) + outtype = Union{outtypes...} return xmap(XFunction(bc.f; inplace=true), args2..., output=XOutput(; outtype)) end \ No newline at end of file From fbbee4463f4a2654457623cc5de367f9dbfba4a1 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 12 Nov 2025 19:11:55 +0100 Subject: [PATCH 3/7] Include broadcast tests --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index dd8f12bd..e9b26177 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,6 +17,7 @@ include("Datasets/datasets.jl") include("DAT/PickAxisArray.jl") include("DAT/MovingWindow.jl") +include("DAT/broadcast.jl") include("DAT/tablestats.jl") include("DAT/mapcube.jl") include("DAT/xmap.jl") From 58791f75a7d9eac3c7f7e06a703c8dcea5041e1f Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 12 Nov 2025 21:58:21 +0100 Subject: [PATCH 4/7] Add test for materialize! --- test/DAT/broadcast.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/DAT/broadcast.jl b/test/DAT/broadcast.jl index 4a0214b6..b528b196 100644 --- a/test/DAT/broadcast.jl +++ b/test/DAT/broadcast.jl @@ -68,4 +68,9 @@ end @test eltype(aeq) == Union{Missing, Bool} @test ismissing(aeq[1,1]) @test aeq[1,2] + aeq2 = similar(aeq) + aeq2 .= am .== am + @test eltype(aeq2) == Union{Missing, Bool} + @test ismissing(aeq2[1,1]) + @test aeq2[2,2] end \ No newline at end of file From b6a33482a6f5a6121ea3a47d21da0da8b83d6da1 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 12 Nov 2025 23:12:35 +0100 Subject: [PATCH 5/7] Use promote_type instead of Union --- src/DAT/broadcast.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DAT/broadcast.jl b/src/DAT/broadcast.jl index 3d6754e3..32e3f861 100644 --- a/src/DAT/broadcast.jl +++ b/src/DAT/broadcast.jl @@ -30,6 +30,6 @@ function Base.materialize!(bc::Broadcast.Broadcasted{XStyle}) intypes = (eltype.(args2)...,) @debug intypes outtypes = Base.return_types(bc.f, intypes) - outtype = Union{outtypes...} + outtype = promote_type{outtypes...} return xmap(XFunction(bc.f; inplace=true), args2..., output=XOutput(; outtype)) end \ No newline at end of file From 9b2ef538631e95822d628bab81aef2c45f53f670 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Thu, 13 Nov 2025 10:16:47 +0100 Subject: [PATCH 6/7] Delete materialize! for XStyle --- src/DAT/broadcast.jl | 9 --------- test/DAT/broadcast.jl | 5 ----- 2 files changed, 14 deletions(-) diff --git a/src/DAT/broadcast.jl b/src/DAT/broadcast.jl index 32e3f861..8956bb23 100644 --- a/src/DAT/broadcast.jl +++ b/src/DAT/broadcast.jl @@ -23,13 +23,4 @@ function Base.materialize(bc::Broadcast.Broadcasted{XStyle}) outtype = Union{outtypes...} @debug outtype return xmap(XFunction(bc.f; inplace=false), args2..., output=XOutput(; outtype)) -end -function Base.materialize!(bc::Broadcast.Broadcasted{XStyle}) - args2 = map(arg -> arg isa Broadcast.Broadcasted ? Base.materialize(arg) : arg, bc.args) - args2 = map(to_yax, args2) - intypes = (eltype.(args2)...,) - @debug intypes - outtypes = Base.return_types(bc.f, intypes) - outtype = promote_type{outtypes...} - return xmap(XFunction(bc.f; inplace=true), args2..., output=XOutput(; outtype)) end \ No newline at end of file diff --git a/test/DAT/broadcast.jl b/test/DAT/broadcast.jl index b528b196..4a0214b6 100644 --- a/test/DAT/broadcast.jl +++ b/test/DAT/broadcast.jl @@ -68,9 +68,4 @@ end @test eltype(aeq) == Union{Missing, Bool} @test ismissing(aeq[1,1]) @test aeq[1,2] - aeq2 = similar(aeq) - aeq2 .= am .== am - @test eltype(aeq2) == Union{Missing, Bool} - @test ismissing(aeq2[1,1]) - @test aeq2[2,2] end \ No newline at end of file From 1317d32dde7a1ca4568f69ca2cf90621d0a451b8 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Thu, 13 Nov 2025 10:20:17 +0100 Subject: [PATCH 7/7] Use promote_type instead of Union --- src/DAT/broadcast.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DAT/broadcast.jl b/src/DAT/broadcast.jl index 8956bb23..4b64d36e 100644 --- a/src/DAT/broadcast.jl +++ b/src/DAT/broadcast.jl @@ -20,7 +20,7 @@ function Base.materialize(bc::Broadcast.Broadcasted{XStyle}) intypes = (eltype.(args2)...,) @debug intypes outtypes = Base.return_types(bc.f, intypes) - outtype = Union{outtypes...} + outtype = Base.promote_type(outtypes...) @debug outtype return xmap(XFunction(bc.f; inplace=false), args2..., output=XOutput(; outtype)) end \ No newline at end of file