我正在尝试从LAPACK(链接:http://www.netlib.org/lapack/explore-html/da/dba/group__double_o_t_h_e_rcomputational_gacb35e85b362ce8ccf9d653cc3f8fb89c.html#gacb35e85b362ce8ccf9d653cc3f8fb89c)给Julia,但当我调用函数时收到了这个错误
error: no method matching Array{Float64,1}(::Int64)
这是我的代码:
for (hseqr, elty) in
((:dhseqr_,:Float64),
(:shseqr_,:Float32))
@eval begin
"""
JOB
JOB is CHARACTER*1
= 'E': compute eigenvalues only;
= 'S': compute eigenvalues and the Schur form T.
COMPZ
COMPZ is CHARACTER*1
= 'N': no Schur vectors are computed;
= 'I': Z is initialized to the unit matrix and the matrix Z
of Schur vectors of H is returned;
= 'V': Z must contain an orthogonal matrix Q on entry, and
the product Q*Z is returned.
"""
function hseqr!(job::Char,compz::Char,ilo::Integer,ihi::Integer,H::StridedMatrix{$elty}, Z::StridedMatrix{$elty})
N=size(H,1)
ldh=size(H,1)
ldz=size(Z,1)
work = Vector{$elty}(1)
lwork = BlasInt(-1)
info = Ref{BlasInt}()
for i = 1:2 # first call returns lwork as work[1]
ccall((@blasfunc($hseqr), liblapack),Void,
(Ref{UInt8},Ref{UInt8}, Ref{BlasInt},Ref{BlasInt},Ref{BlasInt},
Ptr{$elty}, Ref{BlasInt},Ptr{$elty}, Ptr{$elty}, Ptr{$elty},
Ref{BlasInt}, Ptr{BlasInt}, Ref{BlasInt}, Ref{BlasInt}),
job,compz, N,ilo,ihi,H,ldh,wr,wi,Z,ldz,work,
lwork,info)
chklapackerror(info[])
if i == 1
lwork = BlasInt(real(work[1]))
resize!(work, lwork)
end
end
return wr,wi,Z
end
end
end
hseqr!(job::Char,compz::Char,H::StridedMatrix{},Z::StridedMatrix{}) = hseqr!(job,compz,1, size(H, 1), H,Z)
这是我的电话:CCD_ 2(H是维数为5的Hessenberg矩阵(。
我不确定我是否正确理解如何制作包装纸,所以任何提示都会有所帮助。
这是一个很好的问题示例,可以从剥离大量内容以隔离问题中获益。
如果我读对了你的代码,行
work = Vector{$elty}(1)
以Float64
作为元素类型调用,因此整个过程可以归结为:
julia> Vector{Float64}(1)
ERROR: MethodError: no method matching Array{Float64,1}(::Int64)
您正在滥用向量的构造函数。现在我不确定你想在这里做什么,但如果你想创建一个长度为1的Float64
数的向量,你可能会寻找其中一个:
julia> Array{Float64}(undef, 1)
1-element Array{Float64,1}:
6.9274314537094e-310
julia> zeros(1)
1-element Array{Float64,1}:
0.0
请注意,第一个调用使数组处于未初始化状态,即它填充了以前内存中的任何东西,因此您需要确保只有在以后实际覆盖它时才使用它。