如何在我的代码中获得所有在Julia中具有特定名称的可用方法?

如何在我的代码中获得所有在Julia中具有特定名称的可用方法?,julia,Julia,我知道在我的代码中有一系列特定方法的不同实现,我希望看到它们的列表。如何查看具有特定名称的所有方法 在Julia Base中,有一个方法函数,其工作原理如下: julia> methods(rand) # where rand is the the function name in question # 68 methods for generic function "rand": [1] rand(rd::Random.RandomDevice, sp::Union{Random.Sam

我知道在我的代码中有一系列特定方法的不同实现,我希望看到它们的列表。如何查看具有特定名称的所有方法

在Julia Base中,有一个
方法
函数,其工作原理如下:

julia> methods(rand) # where rand is the the function name in question
# 68 methods for generic function "rand":
[1] rand(rd::Random.RandomDevice, sp::Union{Random.SamplerType{Bool}, Random.SamplerType{Int128}, Random.SamplerType{Int16}, Random.SamplerType{Int32}, Random.SamplerType{Int64}, Random.SamplerType{Int8}, Random.SamplerType{UInt128}, Random.SamplerType{UInt16}, Random.SamplerType{UInt32}, Random.SamplerType{UInt64}, Random.SamplerType{UInt8}}) in Random at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Random/src/RNGs.jl:29
[2] rand(::Random._GLOBAL_RNG, x::Union{Random.SamplerType{Int128}, Random.SamplerType{Int64}, Random.SamplerType{UInt128}, Random.SamplerType{UInt64}}) in Random at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Random/src/RNGs.jl:337
#...etc
此函数允许我们查看与传入的名称匹配的所有函数

还值得注意的是,此函数的范围可能会根据您当前使用的软件包而变化。请参见下面的示例,其中我加载了POMDPs包,可用的rand函数数量显著增加

julia> using POMDPs

julia> methods(rand)
# 170 methods for generic function "rand":
[1] rand(rd::Random.RandomDevice, sp::Union{Random.SamplerType{Bool}, Random.SamplerType{Int128}, Random.SamplerType{Int16}, Random.SamplerType{Int32}, Random.SamplerType{Int64}, Random.SamplerType{Int8}, Random.SamplerType{UInt128}, Random.SamplerType{UInt16}, Random.SamplerType{UInt32}, Random.SamplerType{UInt64}, Random.SamplerType{UInt8}}) in Random at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Random/src/RNGs.jl:29
#.. ETC. 

使用
方法()
的一种非常方便的方法是键入方法名称,后跟
),然后在REPL处键入
选项卡
,例如:

rand(
然后按TAB键。但是,
rand(
的列表很长。如果您继续使用参数编写函数调用并再次按TAB键,列表将根据所有匹配方法进行筛选。在您的情况下:

julia> rand(1,
rand(dims::Integer...) in Random at C:\Julia\Julia-1.4.0\share\julia\stdlib\v1.4\Random\src\Random.jl:277
rand(X) in Random at C:\Julia\Julia-1.4.0\share\julia\stdlib\v1.4\Random\src\Random.jl:258
rand(X, dims::Tuple{Vararg{Int64,N}} where N) in Random at C:\Julia\Julia-1.4.0\share\julia\stdlib\v1.4\Random\src\Random.jl:280
rand(X, d::Integer, dims::Integer...) in Random at C:\Julia\Julia-1.4.0\share\julia\stdlib\v1.4\Random\src\Random.jl:283
编辑:

朱莉娅打电话给我

方法(rand,(typeof(1),Any))


在一段代码中,哪种是相应的过滤方法(文档中还没有示例)

这是否回答了您的问题?