Skip to content

Commit

Permalink
Add @functorize(centralizedabs2fun)
Browse files Browse the repository at this point in the history
Note that `@functorize(centralizedabs2fun)` returns the type which can
then be used to construct the actual functor as e.g.
`@functorize(centralizedabs2fun)(23)`.
  • Loading branch information
martinholters committed Apr 22, 2016
1 parent 726124e commit 28bf081
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ macro functorize(f)
if VERSION >= v"0.5.0-" && !isdefined(Base, :BitFunctorUnary)
f === :scalarmax ? :(Base.scalarmax) :
f === :scalarmin ? :(Base.scalarmin) :
f === :centralizedabs2fun ? :(typeof(Base.centralizedabs2fun(0)).name.primary) :
f
else
f = f === :identity ? :(Base.IdFun()) :
Expand All @@ -996,6 +997,7 @@ macro functorize(f)
f === :* ? :(Base.MulFun()) :
f === :scalarmax ? :(Base.MaxFun()) :
f === :scalarmin ? :(Base.MinFun()) :
f === :centralizedabs2fun ? :(Base.CentralizedAbs2Fun) :
f
if VERSION >= v"0.4.0-dev+4902"
f = f === :< ? :(Base.LessFun()) :
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1060,3 +1060,8 @@ for (Fun, func) in [(:AndFun, :&),
end
end
end
@test isa(@functorize(centralizedabs2fun)(1), @functorize(centralizedabs2fun))
@test isa(@functorize(centralizedabs2fun)(1.0), @functorize(centralizedabs2fun))
let a = rand(1:10, 10)
@eval @test mapreduce(x -> abs2(x - 1), +, $(a)) == mapreduce(@functorize(centralizedabs2fun)(1), +, $(a))
end

0 comments on commit 28bf081

Please sign in to comment.