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 535ac98 commit 2aacc82
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 @@ -985,6 +985,7 @@ macro functorize(f)
if VERSION >= v"0.5.0-dev+3701"
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 @@ -998,6 +999,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 @@ -1086,3 +1086,8 @@ end
let a = rand(1:10, 10)
@test mapreduce(identity, dot, a) == mapreduce(identity, @functorize(dot), a)
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 2aacc82

Please sign in to comment.