(a_gpu, k=None, which='LM', imag=False, return_eigenvectors=True)
Driver for eigenvalue solver for symmetric matrix
Driver for eigenvalue solver for symmetric matrix
Driver for eigenvalue solver for symmetric matrix
def eigs(a_gpu, k=None, which='LM', imag=False, return_eigenvectors=True):
    """
    Driver for eigenvalue solver for symmetric matrix
    """

    if len(a_gpu.shape) != 2:
        raise ValueError("M needs to be a rank 2 square array for eig.")

    magma.magma_init()
    ngpu=1

    dtype = a_gpu.dtype.type
    t = typedict_[dtype]
    N = a_gpu.shape[1]

    if k is None: k=int(np.ceil(N/2))

    if 'L' in which:
        a_gpu = -a_gpu

    if return_eigenvectors:
        jobz = 'V'
    else:
        jobz = 'N'

    rnge = 'I'; uplo = 'U'
    vl = 0; vu = 1e10
    il = 1; iu = k; m = 0
    print(f"k = {k}, iu = {iu}")

    w_gpu = np.empty((N,), dtype, order='F') # eigenvalues

    if t == 's':
        nb = magma.magma_get_ssytrd_nb(N)
    elif t == 'd':
        nb = magma.magma_get_dsytrd_nb(N)
    else:
        raise ValueError('unsupported type')

    lwork = N*(1 + 2*nb)
    if jobz:
        lwork = max(lwork, 1+6*N+2*N**2)
    work = np.empty(lwork, dtype)
    liwork = 3+5*N if jobz else 1
    iwork = np.empty(liwork, dtype)

    if t == 's':
        status = magma.magma_ssyevdx_m(ngpu, jobz, rnge, uplo, N, a_gpu.ctypes.data, N,
                                    vl, vu, il, iu, m, 
                                    w_gpu.ctypes.data, work.ctypes.data, lwork, iwork.ctypes.data, liwork)
    elif t == 'd':
        status = magma.magma_dsyevdx_m(ngpu, jobz, rnge, uplo, N, a_gpu.ctypes.data, N,
                                    vl, vu, il, iu, m, 
                                    w_gpu.ctypes.data, work.ctypes.data, lwork, iwork.ctypes.data, liwork)
    else:
        raise ValueError('unsupported type')

    if 'L' in which:
        w_gpu = -w_gpu

    magma.magma_finalize()

    if jobz:
        return w_gpu, a_gpu
    else:
        return w_gpu
def eigs ( a_gpu , k = None , which = 'LM' , imag = False , return_eigenvectors = True ) : if len ( a_gpu . shape ) != 2 : raise ValueError ( "M needs to be a rank 2 square array for eig." ) magma . magma_init ( ) ngpu = 1 dtype = a_gpu . dtype . type t = typedict_ [ dtype ] N = a_gpu . shape [ 1 ] if k is None : k = int ( np . ceil ( N / 2 ) ) if 'L' in which : a_gpu = - a_gpu if return_eigenvectors : jobz = 'V' else : jobz = 'N' rnge = 'I' uplo = 'U' vl = 0 vu = 1e10 il = 1 iu = k m = 0 print ( f"k = {k}, iu = {iu}" ) w_gpu = np . empty ( ( N , ) , dtype , order = 'F' ) # eigenvalues if t == 's' : nb = magma . magma_get_ssytrd_nb ( N ) elif t == 'd' : nb = magma . magma_get_dsytrd_nb ( N ) else : raise ValueError ( 'unsupported type' ) lwork = N * ( 1 + 2 * nb ) if jobz : lwork = max ( lwork , 1 + 6 * N + 2 * N ** 2 ) work = np . empty ( lwork , dtype ) liwork = 3 + 5 * N if jobz else 1 iwork = np . empty ( liwork , dtype ) if t == 's' : status = magma . magma_ssyevdx_m ( ngpu , jobz , rnge , uplo , N , a_gpu . ctypes . data , N , vl , vu , il , iu , m , w_gpu . ctypes . data , work . ctypes . data , lwork , iwork . ctypes . data , liwork ) elif t == 'd' : status = magma . magma_dsyevdx_m ( ngpu , jobz , rnge , uplo , N , a_gpu . ctypes . data , N , vl , vu , il , iu , m , w_gpu . ctypes . data , work . ctypes . data , lwork , iwork . ctypes . data , liwork ) else : raise ValueError ( 'unsupported type' ) if 'L' in which : w_gpu = - w_gpu magma . magma_finalize ( ) if jobz : return w_gpu , a_gpu else : return w_gpu