Skip to content

Commit 665068e

Browse files
committed
Add test for custom type dimensional reduction
1 parent 76d9b4b commit 665068e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/reducedim.jl

+18
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,21 @@ end
398398
@test_throws DimensionMismatch maximum!(fill(0, 1, 1, 2, 1), B)
399399
@test_throws DimensionMismatch minimum!(fill(0, 1, 1, 2, 1), B)
400400
end
401+
402+
# issue #26709
403+
@testset "dimensional reduce with custom non-bitstype types" begin
404+
struct Variable
405+
name::Symbol
406+
end
407+
struct AffExpr
408+
vars::Vector{Variable}
409+
end
410+
Base.zero(::Union{Variable, Type{Variable}, AffExpr}) = AffExpr(Variable[])
411+
Base.:+(v::Variable, w::Variable) = AffExpr([v, w])
412+
Base.:+(aff::AffExpr, v::Variable) = AffExpr([aff.vars; v])
413+
Base.:+(aff1::AffExpr, aff2::AffExpr) = AffExpr([aff1.vars; aff2.vars])
414+
Base.:(==)(a::Variable, b::Variable) = a.name == b.name
415+
Base.:(==)(a::AffExpr, b::AffExpr) = a.vars == b.vars
416+
417+
@test sum([Variable(:x), Variable(:y)], dims=1) == [AffExpr([Variable(:x), Variable(:y)])]
418+
end#@testset

0 commit comments

Comments
 (0)