首页 > 解决方案 > 如何在 Julia 1.0.0 中访问 c​​onv 函数

问题描述

stackoverflow 上的这个问题使用 Julia 0.6.1,如下所示:

The convolution function in Julia has the following behaviour:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.1 (2017-10-24 22:15 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> conv([1,2,NaN],[1])

3-element Array{Float64,1}:
 NaN
 NaN
 NaN

Julia 1.0.0 中的相同内容会产生以下错误输出:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> conv([1,2,NaN],[1])
ERROR: UndefVarError: conv not defined
Stacktrace:
 [1] top-level scope at none:0

如何访问convJulia 1.0.0 中的函数?

标签: julia

解决方案


卷积函数已移至代表数字信号处理的包DSP.jl。

在尝试将 v0.7 之前的代码移植到 Julia v1.0 时,通常建议使用 Julia v0.7。事实上,这是 v0.7 存在的唯一原因。

在 v0.7 中调用conv时,您将获得所需的所有信息:

julia> conv(rand(10))
ERROR: conv has been moved to the package DSP.jl.
Run `Pkg.add("DSP")` to install it, restart Julia,
and then run `using DSP` to load it.

如果您想避免在您的机器上运行 v0.7 只是为了找出某些东西已移动到哪里,您还可以在deprecated.jl中搜索旧函数的名称。搜索conv我们发现:

for f in [:conv, :conv2, :deconv, :filt, :filt!, :xcorr]
    @eval Base.@deprecate_moved $f "DSP"
end

虽然是源代码,我相信@deprecate_moved "DSP"是可以理解的。


推荐阅读