Repository: scipy/scipy
File: scipy/sparse/linalg/_eigen/arpack/tests/test_arpack.py (Python)

Code before:

        # standard complex nonsymmetric problem
        SNC = DictWithRepr("std-cmplx-nonsym")
        SNC['mat'] = Ac
        SNC['v0'] = v0
        SNC['eval'] = eig(SNC['mat'], left=False, right=False)

        # general complex nonsymmetric problem
        GNC = DictWithRepr("gen-cmplx-nonsym")
        GNC['mat'] = Ac
        GNC['bmat'] = M
        GNC['v0'] = v0
        GNC['eval'] = eig(GNC['mat'], GNC['bmat'], left=False, right=False)

        self.real_test_cases = [SNR, GNR]
        self.complex_test_cases = [SNC, GNC]


@pytest.mark.parametrize("sigma, mode", [(None, 'normal'), (0.5, 'normal'),
                                         (0.5, 'buckling'), (0.5, 'cayley')])
@pytest.mark.parametrize("mattype", [csr_array, aslinearoperator, np.asarray])
@pytest.mark.parametrize("which", ['LM', 'SM', 'LA', 'SA', 'BE'])
@pytest.mark.parametrize("typ", ['f', 'd'])
@pytest.mark.parametrize("D", SymmetricParams().real_test_cases)
def test_symmetric_modes(D, typ, which, mattype,
                         sigma, mode):
    rng = np.random.default_rng(1749531508689996)
    k = 2
    eval_evec(True, D, typ, k, which, None, sigma, mattype, None, mode, rng=rng)


@pytest.mark.parametrize("sigma", [None, 0.5])
@pytest.mark.parametrize("mattype", [csr_array, aslinearoperator, np.asarray])
@pytest.mark.parametrize("which", ['LM', 'SM', 'LA', 'SA'])
@pytest.mark.parametrize("typ", ['F', 'D'])
@pytest.mark.parametrize("D", SymmetricParams().complex_test_cases)
def test_hermitian_modes(D, typ, which, mattype, sigma):
    rng = np.random.default_rng(1749531706842957)
    k = 2
    eval_evec(True, D, typ, k, which, None, sigma, mattype, rng=rng)


@pytest.mark.parametrize("typ", ['f', 'd'])
@pytest.mark.parametrize("D", SymmetricParams().real_test_cases)
@pytest.mark.parametrize("k", [1, 2, 3, 4, 5])
def test_symmetric_starting_vector(k, D, typ):
    rng = np.random.default_rng(1749532110418901)
    v0 = rng.uniform(size=len(D['v0'])).astype(typ)
    eval_evec(True, D, typ, k, 'LM', v0, rng=rng)



Review comment (suggestion):
```suggestion
def test_symmetric_modes(D, typ, which, mattype, sigma, mode):
```

Code after:

        # standard complex nonsymmetric problem
        SNC = DictWithRepr("std-cmplx-nonsym")
        SNC['mat'] = Ac
        SNC['v0'] = v0
        SNC['eval'] = eig(SNC['mat'], left=False, right=False)

        # general complex nonsymmetric problem
        GNC = DictWithRepr("gen-cmplx-nonsym")
        GNC['mat'] = Ac
        GNC['bmat'] = M
        GNC['v0'] = v0
        GNC['eval'] = eig(GNC['mat'], GNC['bmat'], left=False, right=False)

        self.real_test_cases = [SNR, GNR]
        self.complex_test_cases = [SNC, GNC]


@pytest.mark.parametrize("sigma, mode", [(None, 'normal'), (0.5, 'normal'),
                                         (0.5, 'buckling'), (0.5, 'cayley')])
@pytest.mark.parametrize("mattype", [csr_array, aslinearoperator, np.asarray])
@pytest.mark.parametrize("which", ['LM', 'SM', 'LA', 'SA', 'BE'])
@pytest.mark.parametrize("typ", ['f', 'd'])
@pytest.mark.parametrize("D", SymmetricParams().real_test_cases)
def test_symmetric_modes(D, typ, which, mattype, sigma, mode):
    rng = np.random.default_rng(1749531508689996)
    k = 2
    eval_evec(True, D, typ, k, which, None, sigma, mattype, None, mode, rng=rng)


@pytest.mark.parametrize("sigma", [None, 0.5])
@pytest.mark.parametrize("mattype", [csr_array, aslinearoperator, np.asarray])
@pytest.mark.parametrize("which", ['LM', 'SM', 'LA', 'SA'])
@pytest.mark.parametrize("typ", ['F', 'D'])
@pytest.mark.parametrize("D", SymmetricParams().complex_test_cases)
def test_hermitian_modes(D, typ, which, mattype, sigma):
    rng = np.random.default_rng(1749531706842957)
    k = 2
    eval_evec(True, D, typ, k, which, None, sigma, mattype, rng=rng)


@pytest.mark.parametrize("typ", ['f', 'd'])
@pytest.mark.parametrize("D", SymmetricParams().real_test_cases)
@pytest.mark.parametrize("k", [1, 2, 3, 4, 5])
def test_symmetric_starting_vector(k, D, typ):
    rng = np.random.default_rng(1749532110418901)
    v0 = rng.uniform(size=len(D['v0'])).astype(typ)
    eval_evec(True, D, typ, k, 'LM', v0, rng=rng)


def test_symmetric_no_convergence():