Skip to content

Commit

Permalink
Merge pull request #186 from JuliaAI/rh/type-piracy-zero
Browse files Browse the repository at this point in the history
Fix type piracy on `zero`
  • Loading branch information
ablaom authored Jul 5, 2022
2 parents a3f6541 + 1595ad5 commit 8d5984d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/DecisionTree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ end
is_leaf(l::Leaf) = true
is_leaf(n::Node) = false

zero(::Type{String}) = ""
convert(::Type{Node{S, T}}, lf::Leaf{T}) where {S, T} = Node(0, zero(S), lf, Leaf(zero(T), [zero(T)]))
_zero(::Type{String}) = ""
_zero(x::Any) = zero(x)
convert(::Type{Node{S, T}}, lf::Leaf{T}) where {S, T} = Node(0, _zero(S), lf, Leaf(_zero(T), [_zero(T)]))
convert(::Type{Root{S, T}}, node::LeafOrNode{S, T}) where {S, T} = Root{S, T}(node, 0, Float64[])
convert(::Type{LeafOrNode{S, T}}, tree::Root{S, T}) where {S, T} = tree.node
promote_rule(::Type{Node{S, T}}, ::Type{Leaf{T}}) where {S, T} = Node{S, T}
Expand Down

0 comments on commit 8d5984d

Please sign in to comment.