The following implements a wrapper to the LAPACK functions dlanv2/slanv2:
import LinearAlgebra.BLAS.@blasfunc
using LinearAlgebra
import LinearAlgebra: libblastrampoline, BlasFloat, BlasReal, BlasComplex, BlasInt
const liblapack = Base.liblapack_name
for (fn, elty) in ((:dlanv2_, :Float64),
(:slanv2_, :Float32))
@eval begin
function lanv2(A::$elty, B::$elty, C::$elty, D::$elty)
"""
SUBROUTINE DLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN )
DOUBLE PRECISION A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN
"""
RT1R = Ref{$elty}(1.0)
RT1I = Ref{$elty}(1.0)
RT2R = Ref{$elty}(1.0)
RT2I = Ref{$elty}(1.0)
CS = Ref{$elty}(1.0)
SN = Ref{$elty}(1.0)
ccall((@blasfunc($fn), liblapack), Cvoid,
(Ref{$elty},Ref{$elty},Ref{$elty},Ref{$elty},
Ref{$elty},Ref{$elty},Ref{$elty},Ref{$elty},Ref{$elty},Ref{$elty}),
A, B, C, D,
RT1R, RT1I, RT2R, RT2I, CS, SN)
return RT1R[], RT1I[], RT2R[], RT2I[], CS[], SN[]
end
end
end
"""
lanv2(A, B, C, D) -> (RT1R, RT1I, RT2R, RT2I, CS, SN)
Compute the Schur factorization of a real 2-by-2 nonsymmetric matrix `[A,B;C,D]` in
standard form. `A`, `B`, `C`, `D` are overwritten on output by the corresponding elements of the
standardised Schur form. `RT1R+im*RT1I` and `RT2R+im*RT2I` are the resulting eigenvalues.
`CS` and `SN` are the parameters of the rotation matrix.
Interface to the LAPACK subroutines DLANV2/SLANV2.
"""
lanv2(A::BlasReal, B::BlasReal, C::BlasReal, D::BlasReal)
I can call lanv2
and get the correct result
julia> lanv2(1.,2.,3.,4.)
(-0.3722813232690143, 0.0, 5.372281323269014, 0.0, -0.8245648401323938, 0.5657674649689923)
After loading MKL
, I get an error message and wrong results:
julia> using MKL
julia> lanv2(1.,2.,3.,4.)
Error: no BLAS/LAPACK library loaded!
(1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
I wonder what is wrong with my interface. It would be desirable that this routine works with both OpenBLAS and MKL.