-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Closed
Copy link
Description
When defining f(x) = maximum(f, x)
plus an appropriate base case, julia fails to infer the return type of f
. The equivalent definition f(x) = mapreduce(f, max, x)
does not have this problem. minimum
is the same.
julia> x = [[1, 2], [3, 4]];
julia> f(x) = maximum(f, x); f(x::Number) = x;
julia> @code_warntype f(x)
MethodInstance for f(::Vector{Vector{Int64}})
from f(x) in Main at REPL[19]:1
Arguments
#self#::Core.Const(f)
x::Vector{Vector{Int64}}
Body::Any
1 ─ %1 = Main.maximum(Main.f, x)::Any
└── return %1
julia> g(x) = mapreduce(g, max, x); g(x::Number) = x;
julia> @code_warntype g(x)
MethodInstance for g(::Vector{Vector{Int64}})
from g(x) in Main at REPL[21]:1
Arguments
#self#::Core.Const(g)
x::Vector{Vector{Int64}}
Body::Int64
1 ─ %1 = Main.mapreduce(Main.g, Main.max, x)::Int64
└── return %1
Stumbled upon this in #44893. Perhaps related to #43461, but not the same as this is still a problem after #43467, and maximum(f, x[1])
infers.
I'm using version 1.7.2. @MasonProtter confirmed this is still an issue on master.
julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
MasonProtter and SobhanMP
Metadata
Metadata
Assignees
Labels
No labels