Repository: scipy/scipy
File: scipy/optimize/_qap.py (Python)

Code before:
    >>> print(res)
         fun: 176
     col_ind: [1 2 3 0]
         nit: 17

    """

    if options is None:
        options = {}

    method = method.lower()
    methods = {"faq": _quadratic_assignment_faq,
               "2opt": _quadratic_assignment_2opt}
    if method not in methods:
        raise ValueError(f"method {method} must be in {methods}.")

    _spec007_transition(options.get("rng", None))
    res = methods[method](A, B, **options)
    return res


def _spec007_transition(rng):
    if isinstance(rng, np.random.RandomState):
        warnings.warn(
            "Use of `RandomState` with `quadratic_assignment`is being phased out"
            " and will result in an Exception in SciPy 1.17",
            DeprecationWarning,
            stacklevel=2
        )
    if rng is None and np.random.mtrand._rand._bit_generator._seed_seq is None:
        warnings.warn(
            "The NumPy global RNG was seeded by calling `np.random.seed`."
            " From SciPy 1.17, this function will no longer use the global RNG.",
            FutureWarning,
            stacklevel=2
        )
    if isinstance(rng, numbers.Integral | np.integer):
        warnings.warn(
            "From SciPy 1.17, use of an integer seed will be normalized via"
            " `np.random.default_rng`, rather than `np.random.RandomState`",
            FutureWarning,
            stacklevel=2
        )


def _calc_score(A, B, perm):
    # equivalent to objective function but avoids matmul
    return np.sum(A * B[perm][:, perm])


def _common_input_validation(A, B, partial_match):

Review comment (suggestion):
```suggestion
            "Use of `RandomState` with `quadratic_assignment` is deprecated"
            " and will result in an exception in SciPy 1.17",
```

Code after:
    ...     options = {'rng': rng, 'partial_guess': guess})
    >>> print(res)
         fun: 176
     col_ind: [1 2 3 0]
         nit: 17

    """

    if options is None:
        options = {}

    method = method.lower()
    methods = {"faq": _quadratic_assignment_faq,
               "2opt": _quadratic_assignment_2opt}
    if method not in methods:
        raise ValueError(f"method {method} must be in {methods}.")

    _spec007_transition(options.get("rng", None))
    res = methods[method](A, B, **options)
    return res


def _spec007_transition(rng):
    if isinstance(rng, np.random.RandomState):
        warnings.warn(
            "Use of `RandomState` with `quadratic_assignment` is deprecated"
            " and will result in an exception in SciPy 1.17",
            DeprecationWarning,
            stacklevel=2
        )
    if ((rng is None or rng is np.random) and
            np.random.mtrand._rand._bit_generator._seed_seq is None):
        warnings.warn(
            "The NumPy global RNG was seeded by calling `np.random.seed`."
            " From SciPy 1.17, this function will no longer use the global RNG.",
            FutureWarning,
            stacklevel=2
        )
    if isinstance(rng, numbers.Integral | np.integer):
        warnings.warn(
            "The behavior when the rng option is an integer is changing: the value"
            " will be normalized using np.random.default_rng beginning in SciPy 1.17,"
            " and the resulting Generator will be used to generate random numbers.",
            FutureWarning,
            stacklevel=2
        )


def _calc_score(A, B, perm):
    # equivalent to objective function but avoids matmul
    return np.sum(A * B[perm][:, perm])