original_docstring: Solve eigenvalue problem for sparse matrix.
  
      Parameters
      ----------
      matrix : scipy.sparse.spmatrix
          A matrix in compressed sparse row format.
      num_eigenpairs : int, optional
          Number of eigenpairs to compute. Default is 10.
      sigma : float, optional
          Find eigenvalues close to the value of sigma. The default value is
          near 1.0. Currently unsupported on the GPU.
      initial_vector : np.array, optional
          Initial vector to use in the Arnoldi iteration. If not set, a vector
          with all entries equal to one will be used.
  
      Returns
      -------
      ew : np.array
          Eigenvalues in descending order of magnitude.
      ev : np.array
          Eigenvectors corresponding to the eigenvalues in `ew`.
  
      
docstring: Solve eigenvalue problem for sparse matrix.
  Parameters
  
  matrix : scipy.sparse.spmatrix
  A matrix in compressed sparse row format.
  num_eigenpairs : int, optional
  Number of eigenpairs to compute. Default is 10.
  sigma : float, optional
  Find eigenvalues close to the value of sigma. The default value is
  near 1.0. Currently unsupported on the GPU.
  initial_vector : np.array, optional
  Initial vector to use in the Arnoldi iteration. If not set, a vector
  with all entries equal to one will be used.
  
  Returns
  
  ew : np.array
  Eigenvalues in descending order of magnitude.
  ev : np.array
  Eigenvectors corresponding to the eigenvalues in `ew`.
docstring_tokens: Solve eigenvalue problem for sparse matrix . Parameters matrix : scipy . sparse . spmatrix A matrix in compressed sparse row format . num_eigenpairs : int optional Number of eigenpairs to compute . Default is 10 . sigma : float optional Find eigenvalues close to the value of sigma . The default value is near 1 . 0 . Currently unsupported on the GPU . initial_vector : np . array optional Initial vector to use in the Arnoldi iteration . If not set a vector with all entries equal to one will be used . Returns ew : np . array Eigenvalues in descending order of magnitude . ev : np . array Eigenvectors corresponding to the eigenvalues in ` ew ` .
code: def eigensolver(matrix: scipy.sparse.csr_matrix,
                  num_eigenpairs: Optional[int] = 10,
                  sigma: Optional[float] = None,
                  initial_vector: Optional[np.array] = None) \
          -> Tuple[np.array, np.array]:
      """Solve eigenvalue problem for sparse matrix.
  
      Parameters
      ----------
      matrix : scipy.sparse.spmatrix
          A matrix in compressed sparse row format.
      num_eigenpairs : int, optional
          Number of eigenpairs to compute. Default is 10.
      sigma : float, optional
          Find eigenvalues close to the value of sigma. The default value is
          near 1.0. Currently unsupported on the GPU.
      initial_vector : np.array, optional
          Initial vector to use in the Arnoldi iteration. If not set, a vector
          with all entries equal to one will be used.
  
      Returns
      -------
      ew : np.array
          Eigenvalues in descending order of magnitude.
      ev : np.array
          Eigenvectors corresponding to the eigenvalues in `ew`.
  
      """
      if sigma is not None:
          raise RuntimeError('Shift/invert mode not implemented on the GPU')
  
      N = matrix.shape[0]
  
      if initial_vector is None:
          initial_vector = np.ones(N)
  
      n = c_int(N)                # Dimension of the eigenproblem.
      maxn = n
      nev = c_int(num_eigenpairs + 1)  # Number of eigenvalues to compute.
      ncv = c_int(num_eigenpairs + 3)  # Number of columns of the matrix V.
      maxncv = ncv.value
      ldv = c_int(maxn.value)
  
      # assert 0 < nev.value < n.value - 1
      # assert 2 - nev.value <= ncv.value <= n.value
  
      tol = c_double(EPSILON)
  
      d = (c_double * (3 * maxncv))()
  
      resid = initial_vector.ctypes.data_as(POINTER(c_double))
  
      vnp = np.zeros((maxncv, ldv.value), dtype=np.float64)
      v = vnp.ctypes.data_as(POINTER(c_double))
  
      workdnp = np.zeros(3 * maxn.value, dtype=np.float64)
      workd = workdnp.ctypes.data_as(POINTER(c_double))
      workev = (c_double * (3 * maxncv))()
      workl = (c_double * (3 * maxncv * maxncv + 6 * maxncv))()
  
      ipntr = (c_int * 14)()
      select = (c_int * maxncv)()
  
      bmat = create_string_buffer(b'I')  # B = I, standard eigenvalue problem.
      which = create_string_buffer(b'LM')  # Eigenvalues of largest magnitude.
      ido = c_int(0)
      lworkl = c_int(len(workl))
      info = c_int(1)
  
      ishfts = c_int(1)   # Use exact shifts.
      maxitr = c_int(MAX_ITERATIONS)
      # mode = c_int(3)           # A x = lambda x (OP = inv(A - sigma I), B = I)
      mode = c_int(1)           # A x = lambda x (OP = A, B = I)
      iparam = (c_int * 11)(ishfts, 0, maxitr, 0, 0, 0, mode)
  
      ierr = c_int(0)
      rvec = c_int(1)
      howmny = c_char(b'A')
      if sigma is not None:
          sigmar = c_double(np.real(sigma))
          sigmai = c_double(np.imag(sigma))
      else:
          sigmar = c_double()
          sigmai = c_double()
  
      MVP = mvp.MatrixVectorProduct(matrix)
  
      # eye = scipy.sparse.spdiags(np.ones(N), 0, N, N)
      # A = (matrix - (sigma) * eye).tocsc()
      # solve = scipy.sparse.linalg.factorized(A)
  
      logging.debug('Running Arnoldi iteration with tolerance {:g}...'
                    .format(tol.value))
  
      clk = clock.Clock()
      clk.tic()
      for itr in range(maxitr.value):
          dnaupd(byref(ido), bmat, byref(n), which, byref(nev), byref(tol),
                 resid, byref(ncv), v, byref(ldv), iparam, ipntr, workd, workl,
                 byref(lworkl), byref(info))
  
          if info.value != 0:
              raise ArpackError(dnaupd_messages[info.value])
  
          if ido.value == 99:
              break
          elif abs(ido.value) != 1:
              logging.warning('DNAUPD repoted IDO = {}'.format(ido.value))
              break
  
          idx_rhs, idx_sol = ipntr[0] - 1, ipntr[1] - 1
          rhs = workdnp[idx_rhs:(idx_rhs+N)]
  
          # # sol = solve(rhs)
          # sol = matrix @ rhs
          # workdnp[idx_sol:idx_sol+N] = sol
          sol = MVP.product(cuda.to_device(rhs.astype(np.float64)))
          workdnp[idx_sol:idx_sol+N] = sol.copy_to_host() # XXX pin memory
      clk.toc()
  
      logging.debug('Done with Arnoldi iteration after {} steps. '
                    'Elapsed time: {} seconds'.format(itr, clk))
  
      logging.debug('Running post-processing step...')
  
      clk.tic()
      d0 = byref(d, 0)
      d1 = byref(d, maxncv * sizeof(c_double))
      dneupd(byref(rvec), byref(howmny), select, d0, d1, v, byref(ldv),
             byref(sigmar), byref(sigmai), workev, byref(bmat), byref(n),
             which, byref(nev), byref(tol), resid, byref(ncv), v, byref(ldv),
             iparam, ipntr, workd, workl, byref(lworkl), byref(ierr))
      clk.toc()
  
      logging.debug('Done with postprocessing step after {} seconds. '
                    'Status: {}'.format(clk, ('OK' if ierr.value == 0
                                              else 'FAIL')))
  
      if ierr.value != 0:
          raise ArpackError(dneupd_messages[ierr.value])
  
      nconv = iparam[4] - 1
      logging.debug('Converged on {} eigenpairs.'.format(nconv))
  
      ew = np.array(d[:num_eigenpairs])
      ii = np.argsort(np.abs(ew))[::-1]
      ev = vnp[ii, :]
  
      return ew[ii], ev
code_tokens: def eigensolver ( matrix : scipy . sparse . csr_matrix , num_eigenpairs : Optional [ int ] = 10 , sigma : Optional [ float ] = None , initial_vector : Optional [ np . array ] = None ) -> Tuple [ np . array , np . array ] : if sigma is not None : raise RuntimeError ( 'Shift/invert mode not implemented on the GPU' ) N = matrix . shape [ 0 ] if initial_vector is None : initial_vector = np . ones ( N ) n = c_int ( N ) maxn = n nev = c_int ( num_eigenpairs + 1 ) ncv = c_int ( num_eigenpairs + 3 ) maxncv = ncv . value ldv = c_int ( maxn . value ) tol = c_double ( EPSILON ) d = ( c_double * ( 3 * maxncv ) ) ( ) resid = initial_vector . ctypes . data_as ( POINTER ( c_double ) ) vnp = np . zeros ( ( maxncv , ldv . value ) , dtype = np . float64 ) v = vnp . ctypes . data_as ( POINTER ( c_double ) ) workdnp = np . zeros ( 3 * maxn . value , dtype = np . float64 ) workd = workdnp . ctypes . data_as ( POINTER ( c_double ) ) workev = ( c_double * ( 3 * maxncv ) ) ( ) workl = ( c_double * ( 3 * maxncv * maxncv + 6 * maxncv ) ) ( ) ipntr = ( c_int * 14 ) ( ) select = ( c_int * maxncv ) ( ) bmat = create_string_buffer ( b'I' ) which = create_string_buffer ( b'LM' ) ido = c_int ( 0 ) lworkl = c_int ( len ( workl ) ) info = c_int ( 1 ) ishfts = c_int ( 1 ) maxitr = c_int ( MAX_ITERATIONS ) mode = c_int ( 1 ) iparam = ( c_int * 11 ) ( ishfts , 0 , maxitr , 0 , 0 , 0 , mode ) ierr = c_int ( 0 ) rvec = c_int ( 1 ) howmny = c_char ( b'A' ) if sigma is not None : sigmar = c_double ( np . real ( sigma ) ) sigmai = c_double ( np . imag ( sigma ) ) else : sigmar = c_double ( ) sigmai = c_double ( ) MVP = mvp . MatrixVectorProduct ( matrix ) logging . debug ( 'Running Arnoldi iteration with tolerance {:g}...' . format ( tol . value ) ) clk = clock . Clock ( ) clk . tic ( ) for itr in range ( maxitr . value ) : dnaupd ( byref ( ido ) , bmat , byref ( n ) , which , byref ( nev ) , byref ( tol ) , resid , byref ( ncv ) , v , byref ( ldv ) , iparam , ipntr , workd , workl , byref ( lworkl ) , byref ( info ) ) if info . value != 0 : raise ArpackError ( dnaupd_messages [ info . value ] ) if ido . value == 99 : break elif abs ( ido . value ) != 1 : logging . warning ( 'DNAUPD repoted IDO = {}' . format ( ido . value ) ) break idx_rhs , idx_sol = ipntr [ 0 ] - 1 , ipntr [ 1 ] - 1 rhs = workdnp [ idx_rhs : ( idx_rhs + N ) ] sol = MVP . product ( cuda . to_device ( rhs . astype ( np . float64 ) ) ) workdnp [ idx_sol : idx_sol + N ] = sol . copy_to_host ( ) clk . toc ( ) logging . debug ( 'Done with Arnoldi iteration after {} steps. ' 'Elapsed time: {} seconds' . format ( itr , clk ) ) logging . debug ( 'Running post-processing step...' ) clk . tic ( ) d0 = byref ( d , 0 ) d1 = byref ( d , maxncv * sizeof ( c_double ) ) dneupd ( byref ( rvec ) , byref ( howmny ) , select , d0 , d1 , v , byref ( ldv ) , byref ( sigmar ) , byref ( sigmai ) , workev , byref ( bmat ) , byref ( n ) , which , byref ( nev ) , byref ( tol ) , resid , byref ( ncv ) , v , byref ( ldv ) , iparam , ipntr , workd , workl , byref ( lworkl ) , byref ( ierr ) ) clk . toc ( ) logging . debug ( 'Done with postprocessing step after {} seconds. ' 'Status: {}' . format ( clk , ( 'OK' if ierr . value == 0 else 'FAIL' ) ) ) if ierr . value != 0 : raise ArpackError ( dneupd_messages [ ierr . value ] ) nconv = iparam [ 4 ] - 1 logging . debug ( 'Converged on {} eigenpairs.' . format ( nconv ) ) ew = np . array ( d [ : num_eigenpairs ] ) ii = np . argsort ( np . abs ( ew ) ) [ : : - 1 ] ev = vnp [ ii , : ] return ew [ ii ] , ev
short_docstring: Solve eigenvalue problem for sparse matrix.
short_docstring_tokens: Solve eigenvalue problem for sparse matrix .
comment: """Solve eigenvalue problem for sparse matrix.
  
      Parameters
      ----------
      matrix : scipy.sparse.spmatrix
          A matrix in compressed sparse row format.
      num_eigenpairs : int, optional
          Number of eigenpairs to compute. Default is 10.
      sigma : float, optional
          Find eigenvalues close to the value of sigma. The default value is
          near 1.0. Currently unsupported on the GPU.
      initial_vector : np.array, optional
          Initial vector to use in the Arnoldi iteration. If not set, a vector
          with all entries equal to one will be used.
  
      Returns
      -------
      ew : np.array
          Eigenvalues in descending order of magnitude.
      ev : np.array
          Eigenvectors corresponding to the eigenvalues in `ew`.
  
      """$SEP$# Dimension of the eigenproblem.$SEP$# Number of eigenvalues to compute.$SEP$# Number of columns of the matrix V.$SEP$# assert 0 < nev.value < n.value - 1$SEP$# assert 2 - nev.value <= ncv.value <= n.value$SEP$# B = I, standard eigenvalue problem.$SEP$# Eigenvalues of largest magnitude.$SEP$# Use exact shifts.$SEP$# mode = c_int(3)           # A x = lambda x (OP = inv(A - sigma I), B = I)$SEP$# A x = lambda x (OP = A, B = I)$SEP$# eye = scipy.sparse.spdiags(np.ones(N), 0, N, N)$SEP$# A = (matrix - (sigma) * eye).tocsc()$SEP$# solve = scipy.sparse.linalg.factorized(A)$SEP$# # sol = solve(rhs)$SEP$# sol = matrix @ rhs$SEP$# workdnp[idx_sol:idx_sol+N] = sol$SEP$# XXX pin memory