Skip to content

Commit

Permalink
Merge pull request #85 from elaine-ran/main
Browse files Browse the repository at this point in the history
Add some more base methods
  • Loading branch information
brianguenter authored Jun 29, 2024
2 parents 30f279c + 76e04ce commit 3e57e16
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ExpressionGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ Base.zero(::Node) = Node(0)
Base.one(::Type{Node}) = Node(1)
Base.one(::Node) = Node(1)

# These are essentially copied from Symbolics.jl:
# https://github.com/JuliaSymbolics/Symbolics.jl/blob/e4c328103ece494eaaab2a265524a64bfbe43dbd/src/num.jl#L31-L34
Base.eps(::Type{Node}) = Node(0)
Base.typemin(::Type{Node}) = Node(-Inf)
Base.typemax(::Type{Node}) = Node(Inf)
Base.float(x::Node) = x

# This one is needed because julia/base/float.jl only defines `isinf` for `Real`, but `Node
# <: Number`. (See https://github.com/brianguenter/FastDifferentiation.jl/issues/73)
Base.isinf(x::Node) = !isnan(x) & !isfinite(x)


Broadcast.broadcastable(a::Node) = (a,)

value(a::Node) = a.node_value
Expand Down Expand Up @@ -324,6 +336,7 @@ rules = Any[]

Base.convert(::Type{Node}, a::T) where {T<:Real} = Node(a)
Base.promote_rule(::Type{<:Real}, ::Type{Node}) = Node
Base.promote_rule(::Type{Bool}, ::Type{Node}) = Node

function Base.:-(a::AbstractArray{<:Node,N}) where {N}
if length(a) == 0
Expand Down

0 comments on commit 3e57e16

Please sign in to comment.