From a96faf57ec5621b16bf09ab001a0242ac7c38893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 24 Dec 2019 11:02:36 +0100 Subject: [PATCH] Update operate fallbacks --- src/interface.jl | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index df1812d..f30a3d2 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -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 """