Skip to content

Commit 297f210

Browse files
committed
Add test for custom type dimensional reduction
1 parent 206df0a commit 297f210

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/reducedim.jl

+15
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,18 @@ end
358358
@test B[argmax(B, dims=[2, 3])] == maximum(B, dims=[2, 3])
359359
@test B[argmin(B, dims=[2, 3])] == minimum(B, dims=[2, 3])
360360
end
361+
362+
# issue #26709 (dimensional reduce with custom non-bitstype types)
363+
struct Variable
364+
name::Symbol
365+
end
366+
struct AffExpr
367+
vars::Vector{Variable}
368+
end
369+
Base.zero(::Union{Variable, Type{Variable}, AffExpr}) = AffExpr(Variable[])
370+
Base.:+(v::Variable, w::Variable) = AffExpr([v, w])
371+
Base.:+(aff::AffExpr, v::Variable) = AffExpr([aff.vars; v])
372+
Base.:+(aff1::AffExpr, aff2::AffExpr) = AffExpr([aff1.vars; aff2.vars])
373+
Base.:(==)(a::Variable, b::Variable) = a.name == b.name
374+
Base.:(==)(a::AffExpr, b::AffExpr) = a.vars == b.vars
375+
@test sum([Variable(:x), Variable(:y)], dims=1) == [AffExpr([Variable(:x), Variable(:y)])]

0 commit comments

Comments
 (0)