Skip to content

Commit

Permalink
Merge a96faf5 into fb52798
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 24, 2019
2 parents fb52798 + a96faf5 commit 1c1df1b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,15 @@ function operate end
# API without altering `x` and `y`. If it is not the case, implement a
# custom `operate` method.
operate(::typeof(-), x) = -x
operate(op::Union{typeof(+), typeof(-), typeof(*)}, x, y) where {N} = op(x, y)
operate(op::Union{typeof(+), typeof(-), typeof(*), typeof(add_mul)}, x, y, args::Vararg{Any, N}) where {N} = op(x, y, args...)

operate(::Union{typeof(+), typeof(*)}, x) = copy_if_mutable(x)

# We only give the type to `zero` and `one` to be sure that modifying the
# returned object cannot alter `x`.
operate(::typeof(zero), x) = zero(typeof(x))
operate(::typeof(one), x) = one(typeof(x))

operate(::Union{typeof(+), typeof(*)}, x) = copy_if_mutable(x)
function operate(op::Union{typeof(+), typeof(*)}, x, y, z, args::Vararg{Any, N}) where N
return operate(op, x, operate(op, y, z, args...))
end

operate(::typeof(add_mul), x, y) = operate(+, x, y)
function operate(::typeof(add_mul), x, y, z, args::Vararg{Any, N}) where N
return operate(+, x, operate(*, y, z, args...))
end

# Define Traits

"""
Expand Down

0 comments on commit 1c1df1b

Please sign in to comment.