在Julia中显示函数的所有方法 [英] Show all methods of a function in Julia
本文介绍了在Julia中显示函数的所有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Julia中显示所有功能的方法(多次派发)?
How can I show all the methods of a function in Julia (multiple dispatch)?
例如,函数abs
的命名空间中存在的所有方法.
For example, all the methods that exist in the namespace for the function abs
.
推荐答案
julia> methods(abs)
# 13 methods for generic function "abs":
[1] abs(a::Pkg.Resolve.FieldValue) in Pkg.Resolve at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Pkg/src/Resolve/fieldvalues.jl:61
[2] abs(a::Pkg.Resolve.VersionWeight) in Pkg.Resolve at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Pkg/src/Resolve/versionweights.jl:36
[3] abs(::Missing) in Base at missing.jl:100
[4] abs(x::Float64) in Base at float.jl:528
...
从Julia 1.4开始,您可以按模块过滤方法表.例如,列出Dates
模块中定义的abs
方法:
As of Julia 1.4, you can filter the method table by module. For example, listing the methods of abs
which were defined in the Dates
module:
julia> methods(abs, Dates)
# 1 method for generic function "abs":
[1] abs(a::T) where T<:Dates.Period in Dates at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Dates/src/periods.jl:95
这篇关于在Julia中显示函数的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文