Skip to content

Commit

Permalink
Add test for custom type dimensional reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
non-Jedi committed Jun 21, 2018
1 parent 206df0a commit 297f210
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,18 @@ end
@test B[argmax(B, dims=[2, 3])] == maximum(B, dims=[2, 3])
@test B[argmin(B, dims=[2, 3])] == minimum(B, dims=[2, 3])
end

# issue #26709 (dimensional reduce with custom non-bitstype types)
struct Variable
name::Symbol
end
struct AffExpr
vars::Vector{Variable}
end
Base.zero(::Union{Variable, Type{Variable}, AffExpr}) = AffExpr(Variable[])
Base.:+(v::Variable, w::Variable) = AffExpr([v, w])
Base.:+(aff::AffExpr, v::Variable) = AffExpr([aff.vars; v])
Base.:+(aff1::AffExpr, aff2::AffExpr) = AffExpr([aff1.vars; aff2.vars])
Base.:(==)(a::Variable, b::Variable) = a.name == b.name
Base.:(==)(a::AffExpr, b::AffExpr) = a.vars == b.vars
@test sum([Variable(:x), Variable(:y)], dims=1) == [AffExpr([Variable(:x), Variable(:y)])]

0 comments on commit 297f210

Please sign in to comment.