Repository: scipy/scipy
File: scipy/optimize/tests/test_quadratic_assignment.py (Python)

Code before:
        n = 20
        rng = default_rng(51982908)
        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))
        res1 = quadratic_assignment(A, B, method=self.method, options={'rng': rng})

        rng = default_rng(51982908)
        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))
        res2 = quadratic_assignment(A, B, method=self.method, options={'rng': rng})

        assert_equal(res1.nit, res2.nit)

    def test_partial_guess(self):
        n = 5
        rng = np.random.default_rng(4358764578823597324)

        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))

        res1 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng})
        guess = np.array([np.arange(5), res1.col_ind]).T
        res2 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng, 'partial_guess': guess}
        )
        fix = [2, 4]
        match = np.array([np.arange(5)[fix], res1.col_ind[fix]]).T
        res3 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng, 'partial_guess': guess,
                                             'partial_match': match})
        assert_(res1.nit != n*(n+1)/2)
        assert_equal(res2.nit, n*(n+1)/2)      # tests each swap exactly once
        assert_equal(res3.nit, (n-2)*(n-1)/2)  # tests free swaps exactly once

    def test_specific_input_validation(self):
        # can't have more seed nodes than cost/dist nodes
        _rm = _range_matrix
        with pytest.raises(
                ValueError,
                match="`partial_guess` can have only as many entries as"):
            quadratic_assignment(np.identity(3), np.identity(3),
                                 method=self.method,
                                 options={'partial_guess': _rm(5, 2)})
        # test for only two seed columns
        with pytest.raises(
                ValueError, match="`partial_guess` must have two columns"):
            quadratic_assignment(
                np.identity(3), np.identity(3), method=self.method,
                options={'partial_guess': _range_matrix(2, 3)}
            )

Review comment (suggestion):
```suggestion
                                    options={'rng': rng, 'partial_guess': guess})
```

Code after:
        n = 20
        rng = default_rng(51982908)
        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))
        res1 = quadratic_assignment(A, B, method=self.method, options={'rng': rng})

        rng = default_rng(51982908)
        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))
        res2 = quadratic_assignment(A, B, method=self.method, options={'rng': rng})

        assert_equal(res1.nit, res2.nit)

    def test_partial_guess(self):
        n = 5
        rng = np.random.default_rng(4358764578823597324)

        A = rng.random(size=(n, n))
        B = rng.random(size=(n, n))

        res1 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng})
        guess = np.array([np.arange(5), res1.col_ind]).T
        res2 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng, 'partial_guess': guess})
        fix = [2, 4]
        match = np.array([np.arange(5)[fix], res1.col_ind[fix]]).T
        res3 = quadratic_assignment(A, B, method=self.method,
                                    options={'rng': rng, 'partial_guess': guess,
                                             'partial_match': match})
        assert_(res1.nit != n*(n+1)/2)
        assert_equal(res2.nit, n*(n+1)/2)      # tests each swap exactly once
        assert_equal(res3.nit, (n-2)*(n-1)/2)  # tests free swaps exactly once

    def test_specific_input_validation(self):
        # can't have more seed nodes than cost/dist nodes
        _rm = _range_matrix
        with pytest.raises(
                ValueError,
                match="`partial_guess` can have only as many entries as"):
            quadratic_assignment(np.identity(3), np.identity(3),
                                 method=self.method,
                                 options={'partial_guess': _rm(5, 2)})
        # test for only two seed columns
        with pytest.raises(
                ValueError, match="`partial_guess` must have two columns"):
            quadratic_assignment(
                np.identity(3), np.identity(3), method=self.method,
                options={'partial_guess': _range_matrix(2, 3)}
            )
        # test that seed has no more than two dimensions