function mean(arr; dims=nothing)
if dims === nothing
return mean(arr) = sum(arr) / length(arr)
else
return sum(arr, dims=dims) / prod(size(arr, r) for r in dims)
end
end
I also saw this: Keyword arguments affect methods dispatch · Issue #9498 · JuliaLang/julia · GitHub
I hope this will be figured out. I believe the “keyword” error should be handled from the compiler side. So the compiler should know “Just In Time”, that the function just doesn’t exist and offer similar methods. It would be more beneficial to send a “it just doesn’t exist” instead of it generating these boilerplate functions with UndefKeywordError. If that could avoid these kind of overwrite issues in the future.
Mainly, because this became serious issues of today, from 1.10 as it treats precompilation error very seriously already!
Julia does not dispatch on keyword arguments. If you want dispatch, you can use a helper function which turns the keyword argument into a positional argument:
mean(arr; dims=nothing) = _mean(arr, dims)
_mean(arr, ::Nothing) = sum(arr) / length(arr)
_mean(arr, dims) = sum(arr; dims) / prod(size(arr, r) for r in dims)