Skip to content

Commit b3fc658

Browse files
committed
Add @functorize(centralizedabs2fun)
Note that `@functorize(centralizedabs2fun)` returns the type which can then be used to construct the actual functor as e.g. `@functorize(centralizedabs2fun)(23)`.
1 parent f98208e commit b3fc658

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Compat.jl

+2
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ macro functorize(f)
986986
if VERSION >= v"0.5.0-" && !isdefined(Base, :BitFunctorUnary)
987987
f === :scalarmax ? :(Base.scalarmax) :
988988
f === :scalarmin ? :(Base.scalarmin) :
989+
f === :centralizedabs2fun ? :(typeof(Base.centralizedabs2fun(0)).name.primary) :
989990
f
990991
else
991992
f = f === :identity ? :(Base.IdFun()) :
@@ -999,6 +1000,7 @@ macro functorize(f)
9991000
f === :* ? :(Base.MulFun()) :
10001001
f === :scalarmax ? :(Base.MaxFun()) :
10011002
f === :scalarmin ? :(Base.MinFun()) :
1003+
f === :centralizedabs2fun ? :(Base.CentralizedAbs2Fun) :
10021004
f
10031005
if VERSION >= v"0.4.0-dev+4902"
10041006
f = f === :< ? :(Base.LessFun()) :

test/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1088,3 +1088,8 @@ end
10881088
let a = rand(1:10, 10)
10891089
@test mapreduce(identity, dot, a) == mapreduce(identity, @functorize(dot), a)
10901090
end
1091+
@test isa(@functorize(centralizedabs2fun)(1), @functorize(centralizedabs2fun))
1092+
@test isa(@functorize(centralizedabs2fun)(1.0), @functorize(centralizedabs2fun))
1093+
let a = rand(1:10, 10)
1094+
@eval @test mapreduce(x -> abs2(x - 1), +, $(a)) == mapreduce(@functorize(centralizedabs2fun)(1), +, $(a))
1095+
end

0 commit comments

Comments
 (0)