<commit_before>__usage__ = """
To run tests locally:
  python tests/test_arpack.py [-l<int>] [-v<int>]

"""

import numpy as np

from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
        assert_array_almost_equal_nulp, TestCase, run_module_suite, dec, \
        assert_raises, verbose, assert_equal

from numpy import array, finfo, argsort, dot, round, conj, random
from scipy.linalg import eig, eigh
from scipy.sparse import csc_matrix, csr_matrix, lil_matrix, isspmatrix
from scipy.sparse.linalg import LinearOperator, aslinearoperator
from scipy.sparse.linalg.eigen.arpack import eigs, eigsh, svds, \
     ArpackNoConvergence

from scipy.linalg import svd

def generate_matrix(N, complex=False, hermitian=False, 
                    pos_definite=False, sparse=False):
    M = np.random.random((N,N))
    if complex:
        M = M + 1j * np.random.random((N,N))

    if hermitian:
        if pos_definite:
            if sparse:
                i = np.arange(N)
                j = np.random.randint(N, size=N-2)
                i, j = np.meshgrid(i, j)
                M[i,j] = 0
            M = np.dot(M.conj(), M.T)
        else:
            M = np.dot(M.conj(), M.T)
            if sparse:
                i = np.random.randint(N, size=N * N / 4)
                j = np.random.randint(N, size=N * N / 4)
                ind = np.where(i == j)
                j[ind] = (j[ind] + 1) % N
                M[i,j] = 0
                M[j,i] = 0
    else:
        if sparse:
            i = np.random.randint(N, size=N * N / 2)
            j = np.random.randint(N, size=N * N / 2)
            M[i,j] = 0
    return M

def _aslinearoperator_with_dtype(m):
    m = aslinearoperator(m)
    if not hasattr(m, 'dtype'):
        x = np.zeros(m.shape[1])
        m.dtype = (m * x).dtype
    return m


def assert_almost_equal_cc(actual, desired, decimal=7,
                           err_msg='', verbose=True):
    # almost equal or complex conjugates almost equal
    try:
        assert_almost_equal(actual, desired, decimal, err_msg, verbose)
    except:
        assert_almost_equal(actual, conj(desired), decimal, err_msg, verbose)


def assert_array_almost_equal_cc(actual, desired, decimal=7,
                                 err_msg='', verbose=True):
    # almost equal or complex conjugates almost equal
    try:
        assert_array_almost_equal(actual, desired, decimal, err_msg, verbose)
    except:
        assert_array_almost_equal(actual, conj(desired), decimal,
                                  err_msg, verbose)

# precision for tests
_ndigits = {'f': 3, 'd': 11, 'F': 2, 'D': 8}

class TestArpack(TestCase):
    def argsort_which(self, eval, typ, k, which, 
                      sigma=None, OPpart=None, mode=None):
        if sigma is None:
            reval = np.round(eval, decimals=_ndigits[typ])
        else:
            if mode is None or mode=='normal':
                if OPpart is None:
                    reval = 1. / (eval - sigma)<commit_msg>sparse/arpack: restored original test precisions<commit_after>__usage__ = """
To run tests locally:
  python tests/test_arpack.py [-l<int>] [-v<int>]

"""

import numpy as np

from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
        assert_array_almost_equal_nulp, TestCase, run_module_suite, dec, \
        assert_raises, verbose, assert_equal

from numpy import array, finfo, argsort, dot, round, conj, random
from scipy.linalg import eig, eigh
from scipy.sparse import csc_matrix, csr_matrix, lil_matrix, isspmatrix
from scipy.sparse.linalg import LinearOperator, aslinearoperator
from scipy.sparse.linalg.eigen.arpack import eigs, eigsh, svds, \
     ArpackNoConvergence

from scipy.linalg import svd

def generate_matrix(N, complex=False, hermitian=False, 
                    pos_definite=False, sparse=False):
    M = np.random.random((N,N))
    if complex:
        M = M + 1j * np.random.random((N,N))

    if hermitian:
        if pos_definite:
            if sparse:
                i = np.arange(N)
                j = np.random.randint(N, size=N-2)
                i, j = np.meshgrid(i, j)
                M[i,j] = 0
            M = np.dot(M.conj(), M.T)
        else:
            M = np.dot(M.conj(), M.T)
            if sparse:
                i = np.random.randint(N, size=N * N / 4)
                j = np.random.randint(N, size=N * N / 4)
                ind = np.where(i == j)
                j[ind] = (j[ind] + 1) % N
                M[i,j] = 0
                M[j,i] = 0
    else:
        if sparse:
            i = np.random.randint(N, size=N * N / 2)
            j = np.random.randint(N, size=N * N / 2)
            M[i,j] = 0
    return M

def _aslinearoperator_with_dtype(m):
    m = aslinearoperator(m)
    if not hasattr(m, 'dtype'):
        x = np.zeros(m.shape[1])
        m.dtype = (m * x).dtype
    return m


def assert_almost_equal_cc(actual, desired, decimal=7,
                           err_msg='', verbose=True):
    # almost equal or complex conjugates almost equal
    try:
        assert_almost_equal(actual, desired, decimal, err_msg, verbose)
    except:
        assert_almost_equal(actual, conj(desired), decimal, err_msg, verbose)


def assert_array_almost_equal_cc(actual, desired, decimal=7,
                                 err_msg='', verbose=True):
    # almost equal or complex conjugates almost equal
    try:
        assert_array_almost_equal(actual, desired, decimal, err_msg, verbose)
    except:
        assert_array_almost_equal(actual, conj(desired), decimal,
                                  err_msg, verbose)

# precision for tests
_ndigits = {'f': 3, 'd': 11, 'F': 3, 'D': 11}

class TestArpack(TestCase):
    def argsort_which(self, eval, typ, k, which, 
                      sigma=None, OPpart=None, mode=None):
        if sigma is None:
            reval = np.round(eval, decimals=_ndigits[typ])
        else:
            if mode is None or mode=='normal':
                if OPpart is None:
                    reval = 1. / (eval - sigma)
{'fraction_non_alphanumeric': 0.11254980079681275, 'fraction_numerical': 0.006806108897742364, 'mean_word_length': 2.046006066734075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6642538', 'n_tokens_mistral': 2114, 'n_tokens_neox': 1983, 'n_words': 505}