scipy - Calling MKL from Python : DSTEVR -


dstevr computes eigensolutions of triangular symmetric matrix. cool. except not 1 of routines ported wrapper scipy. i've followed instructions on how call mkl directly python , attached seems give correct answer. gosh.... there someway clean up?!

  import numpy np    scipy import linalg   ctypes import *     c_double_p = pointer(c_double)   c_int_p = pointer(c_int)   c_char_p = pointer(c_char)    mkl = cdll('mkl_rt.dll')   dstevr = mkl.dstevr    #subroutine dstevr( jobz, range, n, d, e, vl, vu, il, iu, abstol, m,    # *      w, z, ldz, isuppz, work, lwork, iwork, liwork, info)   #  character * 1 jobz, range   #  integer n, il, iu, m, ldz, lwork, liwork, info   #  integer isuppz(*), iwork(*)   #  double precision vl, vu, abstol   #  double precision d(*), e(*), w(*), z(ldz,*), work(*)    dstevr.argtypes = [ c_char_p, c_char_p, c_int_p, c_double_p, c_double_p,  c_double_p, c_double_p, c_int_p, c_int_p, c_double_p,  \  c_int_p, c_double_p, c_double_p, c_int_p, c_int_p, c_double_p, c_int_p, c_int_p, c_int_p, c_int_p]     sv = "v"   eig_j = c_char_p(c_char(sv[0]))   sr = "a"   eig_r = c_char_p(c_char(sr[0]))    vl = c_double(0.0)   vu = c_double(0.0)   il = c_int(0)   iu = c_int(0)   abstol = c_double(0.0)   cm = c_int(0)   eig_info = c_int(0)    n = 6   cn = c_int(n)   ldz = cn     lwork = c_int(20*n)   liwork = c_int(10*n)    diag = np.ascontiguousarray(np.ones(n)*2)   diag_p = diag.ctypes.data_as(c_double_p)    offdiag = np.ascontiguousarray(np.ones(n-1)*(-1))   offdiag_p = offdiag.ctypes.data_as(c_double_p)    isuppz = np.ascontiguousarray(np.ones(n*2),dtype=int)   isuppz_p = isuppz.ctypes.data_as(c_int_p)    eigw = np.ascontiguousarray(np.zeros(n))   eigw_p = eigw.ctypes.data_as(c_double_p)    workz = np.ascontiguousarray(np.ones(20*n))   workz_p = workz.ctypes.data_as(c_double_p)    iworkz = np.ascontiguousarray(np.ones(10*n),dtype=int)   iworkz_p = iworkz.ctypes.data_as(c_int_p)    eigz = np.ascontiguousarray(np.ones(n*n))   eigz_p = eigz.ctypes.data_as(c_double_p)     dstevr( eig_j, eig_r, byref(cn), diag_p, offdiag_p, byref(vl),byref(vu),byref(il),byref(iu),byref(abstol),byref(cm),\   eigw_p, eigz_p, byref(ldz), isuppz_p, workz_p, byref(lwork), iworkz_p, byref(liwork), byref(eig_info))     print "eig_info", eig_info    print eigz    = np.eye(n,n,k=-1)*(-1) + np.eye(n,n)*2 + np.eye(n,n,k=1)*(-1)    w,v= linalg.eigh(a)    print v.t 

thanks,

you can use instead cython wrapper in cython_lapack, http://docs.scipy.org/doc/scipy/reference/linalg.cython_lapack.html

you'll need cython though.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -