<commit_before>"""
Find a few eigenvectors and eigenvalues of a matrix.


Uses ARPACK: http://www.caam.rice.edu/software/ARPACK/

"""
# Wrapper implementation notes
#
# ARPACK Entry Points
# -------------------
# The entry points to ARPACK are
# - (s,d)seupd : single and double precision symmetric matrix
# - (s,d,c,z)neupd: single,double,complex,double complex general matrix
# This wrapper puts the *neupd (general matrix) interfaces in eigen()
# and the *seupd (symmetric matrix) in eigen_symmetric().
# There is no Hermetian complex/double complex interface.
# To find eigenvalues of a Hermetian matrix you
# must use eigen() and not eigen_symmetric()
# It might be desirable to handle the Hermetian case differently
# and, for example, return real eigenvalues.

# Number of eigenvalues returned and complex eigenvalues
# ------------------------------------------------------
# The ARPACK nonsymmetric real and double interface (s,d)naupd return
# eigenvalues and eigenvectors in real (float,double) arrays.
# Since the eigenvalues and eigenvectors are, in general, complex
# ARPACK puts the real and imaginary parts in consecutive entries
# in real-valued arrays.   This wrapper puts the real entries
# into complex data types and attempts to return the requested eigenvalues
# and eigenvectors.


# Solver modes
# ------------
# ARPACK and handle shifted and shift-inverse computations
# for eigenvalues by providing a shift (sigma) and a solver.
# This is currently not implemented

__docformat__ = "restructuredtext en"

__all___=['eigen','eigen_symmetric', 'svd']

import warnings

import _arpack
import numpy as np
from scipy.sparse.linalg.interface import aslinearoperator
from scipy.sparse import csc_matrix, csr_matrix

_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'}
_ndigits = {'f':5, 'd':12, 'F':5, 'D':12}

class _ArpackParams(object):
    def __init__(self, n, k, tp, matvec, sigma=None,
                 ncv=None, v0=None, maxiter=None, which="LM", tol=0):
        if k <= 0:
            raise ValueError("k must be positive, k=%d" % k)
        if k == n:
            raise ValueError("k must be less than rank(A), k=%d" % k)

        if maxiter is None:
            maxiter = n * 10
        if maxiter <= 0:
            raise ValueError("maxiter must be positive, maxiter=%d" % maxiter)

        if tp not in 'fdFD':
            raise ValueError("matrix type must be 'f', 'd', 'F', or 'D'")

        if v0 is not None:
            self.resid = v0
            info = 1
        else:
            self.resid = np.zeros(n, tp)
            info = 0

        if sigma is not None:
            raise NotImplementedError("shifted eigenproblem not supported yet")

        if ncv is None:
            ncv = 2 * k + 1
        ncv = min(ncv, n)

        if ncv > n or ncv < k:
            raise ValueError("ncv must be k<=ncv<=n, ncv=%s" % ncv)

        self.v = np.zeros((n, ncv), tp) # holds Ritz vectors
        self.iparam = np.zeros(11, "int")

        # set solver mode and parameters
        # only supported mode is 1: Ax=lx
        ishfts = 1
        mode1 = 1
        self.iparam[0] = ishfts
        self.iparam[2] = maxiter<commit_msg>BUG: sparse/arpack: fix ARPACK overwriting the initial vector (#1313)<commit_after>"""
Find a few eigenvectors and eigenvalues of a matrix.


Uses ARPACK: http://www.caam.rice.edu/software/ARPACK/

"""
# Wrapper implementation notes
#
# ARPACK Entry Points
# -------------------
# The entry points to ARPACK are
# - (s,d)seupd : single and double precision symmetric matrix
# - (s,d,c,z)neupd: single,double,complex,double complex general matrix
# This wrapper puts the *neupd (general matrix) interfaces in eigen()
# and the *seupd (symmetric matrix) in eigen_symmetric().
# There is no Hermetian complex/double complex interface.
# To find eigenvalues of a Hermetian matrix you
# must use eigen() and not eigen_symmetric()
# It might be desirable to handle the Hermetian case differently
# and, for example, return real eigenvalues.

# Number of eigenvalues returned and complex eigenvalues
# ------------------------------------------------------
# The ARPACK nonsymmetric real and double interface (s,d)naupd return
# eigenvalues and eigenvectors in real (float,double) arrays.
# Since the eigenvalues and eigenvectors are, in general, complex
# ARPACK puts the real and imaginary parts in consecutive entries
# in real-valued arrays.   This wrapper puts the real entries
# into complex data types and attempts to return the requested eigenvalues
# and eigenvectors.


# Solver modes
# ------------
# ARPACK and handle shifted and shift-inverse computations
# for eigenvalues by providing a shift (sigma) and a solver.
# This is currently not implemented

__docformat__ = "restructuredtext en"

__all___=['eigen','eigen_symmetric', 'svd']

import warnings

import _arpack
import numpy as np
from scipy.sparse.linalg.interface import aslinearoperator
from scipy.sparse import csc_matrix, csr_matrix

_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'}
_ndigits = {'f':5, 'd':12, 'F':5, 'D':12}

class _ArpackParams(object):
    def __init__(self, n, k, tp, matvec, sigma=None,
                 ncv=None, v0=None, maxiter=None, which="LM", tol=0):
        if k <= 0:
            raise ValueError("k must be positive, k=%d" % k)
        if k == n:
            raise ValueError("k must be less than rank(A), k=%d" % k)

        if maxiter is None:
            maxiter = n * 10
        if maxiter <= 0:
            raise ValueError("maxiter must be positive, maxiter=%d" % maxiter)

        if tp not in 'fdFD':
            raise ValueError("matrix type must be 'f', 'd', 'F', or 'D'")

        if v0 is not None:
            # ARPACK overwrites its initial resid,  make a copy
            self.resid = np.array(v0, copy=True)
            info = 1
        else:
            self.resid = np.zeros(n, tp)
            info = 0

        if sigma is not None:
            raise NotImplementedError("shifted eigenproblem not supported yet")

        if ncv is None:
            ncv = 2 * k + 1
        ncv = min(ncv, n)

        if ncv > n or ncv < k:
            raise ValueError("ncv must be k<=ncv<=n, ncv=%s" % ncv)

        self.v = np.zeros((n, ncv), tp) # holds Ritz vectors
        self.iparam = np.zeros(11, "int")

        # set solver mode and parameters
        # only supported mode is 1: Ax=lx
        ishfts = 1
        mode1 = 1
        self.iparam[0] = ishfts
        self.iparam[2] = maxiter
{'fraction_non_alphanumeric': 0.1255612323889147, 'fraction_numerical': 0.00867007276668215, 'mean_word_length': 2.596881959910913, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '121542', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1902, 'n_words': 732}