ronantakizawa/codereview-bench huggingface dataset:
Repository: scipy/scipy
File: scipy/sparse/_base.py (Python)

Code before:
        np.rad2deg, np.floor, np.ceil, np.trunc, np.sqrt])


MAXPRINT = 50


# helper dicts to manipulate comparison operators
# We negate operators (with warning) when all implicit values would be True
op_neg = {operator.eq: operator.ne, operator.ne: operator.eq,
          operator.lt: operator.ge, operator.ge: operator.lt,
          operator.gt: operator.le, operator.le: operator.gt}


# We use symbolic version of operators in warning messages.
op_sym = {operator.eq: '==', operator.ge: '>=', operator.le: '<=',
          operator.ne: '!=', operator.gt: '>', operator.lt: '<'}


# `_spbase` is a subclass of `SparseABC`.
# This allows other submodules to check for instances of sparse subclasses
# via `scipy._lib._sparse.issparse`, without introducing
# an import dependency on `scipy.sparse`.
class _spbase(SparseABC):
    """
    Base class for sparse arrays.

    Attributes
    ----------
    dtype : dtype
        Data type of the array.
    shape : tuple
        Shape of the array.
    ndim : int
        Number of dimensions.
    nnz : int
        Number of stored values.
    size : int
        Number of elements in the array.
    format : str
        Sparse storage format of the array (e.g. 'csr', 'csc', 'coo', 'dia').
    """

    __array_priority__ = 10.1
    _format = 'und'  # undefined
    _allow_nd = (2,)

    @property
    def ndim(self) -> int:
        return len(self._shape)

    @property

Review comment (suggestion):
This change isn't helpful, as _spbase won't be rendered in the docs. I'd rather we preserve the existing docstring here.

Code after:
        np.rad2deg, np.floor, np.ceil, np.trunc, np.sqrt])


MAXPRINT = 50


# helper dicts to manipulate comparison operators
# We negate operators (with warning) when all implicit values would be True
op_neg = {operator.eq: operator.ne, operator.ne: operator.eq,
          operator.lt: operator.ge, operator.ge: operator.lt,
          operator.gt: operator.le, operator.le: operator.gt}


# We use symbolic version of operators in warning messages.
op_sym = {operator.eq: '==', operator.ge: '>=', operator.le: '<=',
          operator.ne: '!=', operator.gt: '>', operator.lt: '<'}


# `_spbase` is a subclass of `SparseABC`.
# This allows other submodules to check for instances of sparse subclasses
# via `scipy._lib._sparse.issparse`, without introducing
# an import dependency on `scipy.sparse`.
class _spbase(SparseABC):
    """ This class provides a base class for all sparse array and matrix classes.
    It cannot be instantiated.  Most of the work is provided by subclasses.
    """

    __array_priority__ = 10.1
    _format = 'und'  # undefined
    _allow_nd = (2,)

    @property
    def ndim(self) -> int:
        return len(self._shape)

    @property
    def _shape_as_2d(self):
        s = self._shape
        return (1, s[-1]) if len(s) == 1 else s

    @property
    def _bsr_container(self):
        from ._bsr import bsr_array
        return bsr_array

    @property
    def _coo_container(self):
        from ._coo import coo_array
        return coo_array

    @property
Repository: scipy/scipy
File: .spin/cmds.py (Python)

Code before:
    '--submodule', '-s', default=None, metavar='SUBMODULE',
    help="Submodule whose tests to run (cluster, constants, ...)")
@click.option(
    '--compare', '-c',
    is_flag=True,
    default=False,
    help="Compare benchmarks between the current branch and main "
         "(unless other branches specified). "
         "The benchmarks are each executed in a new isolated "
         "environment."
)
@click.option(
    '--verbose', '-v', is_flag=True, default=False
)
@click.option(
    '--quick', '-q', is_flag=True, default=False,
    help="Run each benchmark only once (timings won't be accurate)"
)
@click.argument(
    'commits', metavar='',
    required=False,
    nargs=-1
)
@click.option(
    '--no-build', default=False, is_flag=True,
    help='Build SciPy before running benchmarks')
@click.option(
    '--array-api-backend', '-b', default=None, metavar='ARRAY_BACKEND',
    multiple=True,
    help=(
        "Array API backend "
        "('all', 'numpy', 'torch', 'cupy', 'array_api_strict', "
        "'jax.numpy', 'dask.array')."
    )
)
@meson.build_dir_option
@click.pass_context
def bench(ctx, tests, submodule, compare, verbose, quick,
          commits, array_api_backend, no_build, build_dir=None, *args, **kwargs):
    """🔧 Run benchmarks.

    \b
    ```python
     Examples:

    $ spin bench -t integrate.SolveBVP
    $ spin bench -t linalg.Norm
    $ spin bench --compare main
    ```
    """
    build_dir = os.path.abspath(build_dir)

Review comment (suggestion):
we can use `@meson.build_option` instead, see https://github.com/scipy/scipy/pull/24336

Code after:
    default=None, metavar='TESTS', multiple=True,
    help="Which tests to run"
)
@click.option(
    '--submodule', '-s', default=None, metavar='SUBMODULE',
    help="Submodule whose tests to run (cluster, constants, ...)")
@click.option(
    '--compare', '-c',
    is_flag=True,
    default=False,
    help="Compare benchmarks between the current branch and main "
         "(unless other branches specified). "
         "The benchmarks are each executed in a new isolated "
         "environment."
)
@click.option(
    '--verbose', '-v', is_flag=True, default=False
)
@click.option(
    '--quick', '-q', is_flag=True, default=False,
    help="Run each benchmark only once (timings won't be accurate)"
)
@click.argument(
    'commits', metavar='',
    required=False,
    nargs=-1
)
@click.option(
    '--array-api-backend', '-b', default=None, metavar='ARRAY_BACKEND',
    multiple=True,
    help=(
        "Array API backend "
        "('all', 'numpy', 'torch', 'cupy', 'array_api_strict', "
        "'jax.numpy', 'dask.array')."
    )
)
@meson.build_option
@meson.build_dir_option
@click.pass_context
def bench(ctx, tests, submodule, compare, verbose, quick,
          commits, array_api_backend, build, build_dir=None, *args, **kwargs):
    """🔧 Run benchmarks.

    \b
    ```python
     Examples:

    $ spin bench -t integrate.SolveBVP
    $ spin bench -t linalg.Norm
    $ spin bench --compare main
    ```
Repository: scipy/scipy
File: scipy/special/boost_special_functions.h (C/C++)

Code before:
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<float, StatsPolicy>(r, p));
}

double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    if ((k <= 0) || (y < 0) || (y > 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrik", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)

Review comment (suggestion):
```suggestion
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy()>::find_minimum_number_of_trials(k, p, y);
```

Code after:
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<float, StatsPolicy>(r, p));
}

double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}
Repository: scipy/scipy
File: scipy/special/boost_special_functions.h (C/C++)

Code before:
        return NAN;
    }
    if ((k <= 0) || (y < 0) || (y > 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrik", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)
{
    return nbinom_invn_wrap(k, y, p);
}

template<typename Real>
Real
hypergeom_pmf_wrap(const Real k, const Real n, const Real N, const Real M)
{
    if (std::isfinite(k)) {
        return boost::math::pdf(
            boost::math::hypergeometric_distribution<Real, StatsPolicy>(n, N, M), k);
    }
    return NAN; // inf or -inf returns NAN
}

float
hypergeom_pmf_float(float k, float n, float N, float M)
{

Review comment (bug):
```suggestion
    if (n < 0) {
        n = NAN;
    }
    return n;
```

We have seen that boost can sometimes produce obscure results outside of the meant domain for edge cases, so I always include a check of the output now.

Code after:
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)
{
    return nbinom_invn_wrap(k, y, p);
}

template<typename Real>
Real
hypergeom_pmf_wrap(const Real k, const Real n, const Real N, const Real M)
{
    if (std::isfinite(k)) {
        return boost::math::pdf(
            boost::math::hypergeometric_distribution<Real, StatsPolicy>(n, N, M), k);
    }
    return NAN; // inf or -inf returns NAN
}
Repository: scipy/scipy
File: scipy/special/boost_special_functions.h (C/C++)

Code before:

float
nbinom_kurtosis_excess_float(float r, float p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<float, StatsPolicy>(r, p));
}

double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrik", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float

Review comment (suggestion):
```suggestion
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
```

Code after:

float
nbinom_kurtosis_excess_float(float r, float p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<float, StatsPolicy>(r, p));
}

double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
Repository: scipy/scipy
File: scipy/special/boost_special_functions.h (C/C++)

Code before:
double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrik", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)

Review comment (suggestion):
```suggestion
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
```

Code after:
double
nbinom_kurtosis_excess_double(double r, double p)
{
    return boost::math::kurtosis_excess(boost::math::negative_binomial_distribution<double, StatsPolicy>(r, p));
}

template<typename Real>
static inline
Real nbinom_invn_wrap(Real k, Real y, Real p)
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)
Repository: scipy/scipy
File: scipy/special/boost_special_functions.h (C/C++)

Code before:
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrik", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrik", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrik", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)
{
    return nbinom_invn_wrap(k, y, p);
}

template<typename Real>
Real
hypergeom_pmf_wrap(const Real k, const Real n, const Real N, const Real M)
{
    if (std::isfinite(k)) {

Review comment (bug):
```suggestion
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
```

Code after:
{
    Real n;
    Real num_trials;

    if (std::isnan(k) || std::isnan(y) || std::isnan(p)) {
        return NAN;
    }
    // The edge cases of p=0,1 is handled in boost 
    if ((k < 0) || (y <= 0) || (y >= 1) || (p < 0) || (p > 1)) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        return NAN;
    }
    try {
        num_trials = boost::math::negative_binomial_distribution<Real, SpecialPolicy>::find_minimum_number_of_trials(k, p, y);
        n = num_trials - k;
    } catch (const std::domain_error& e) {
        sf_error("nbdtrin", SF_ERROR_DOMAIN, NULL);
        n = NAN;
    } catch (const std::overflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_OVERFLOW, NULL);
        n = INFINITY;
    } catch (const std::underflow_error& e) {
        sf_error("nbdtrin", SF_ERROR_UNDERFLOW, NULL);
        n = 0;
    } catch (...) {
        sf_error("nbdtrin", SF_ERROR_OTHER, NULL);
        n = NAN;
    }
    if (n < 0) {
        n = NAN;
    }
    return n;
}

float
nbinom_invn_float(float k, float y, float p)
{
    return nbinom_invn_wrap(k, y, p);
}

double
nbinom_invn_double(double k, double y, double p)
{
    return nbinom_invn_wrap(k, y, p);
}

template<typename Real>
Real
hypergeom_pmf_wrap(const Real k, const Real n, const Real N, const Real M)
{
    if (std::isfinite(k)) {
Repository: scipy/scipy
File: scipy/optimize/_cobyqa_py.py (Python)

Code before:
        the value of `tol` in the `minimize` function. Default is ``1e-6``.
    scale : bool
        Set to True to scale the variables according to the bounds. If True and
        if all the lower and upper bounds are finite, the variables are scaled
        to be within the range :math:`[-1, 1]`. If any of the lower or upper
        bounds is infinite, the variables are not scaled. Default is ``False``.

    References
    ----------
    .. [1] COBYQA
           https://www.cobyqa.com/stable/
    """
    from .._lib.cobyqa import minimize  # import here to avoid circular imports

    _check_unknown_options(unknown_options)
    options = {
        'disp': bool(disp),
        'maxfev': int(maxfev) if maxfev is not None else 500 * len(x0),
        'maxiter': int(maxiter) if maxiter is not None else 1000 * len(x0),
        'target': float(f_target),
        'feasibility_tol': float(feasibility_tol),
        'radius_init': float(initial_tr_radius),
        'radius_final': float(final_tr_radius),
        'scale': bool(scale),
    }
    return minimize(fun, x0, args, bounds, constraints, callback, options)


Review comment (suggestion):
```suggestion
    return _cobqa_minimize(fun, x0, args, bounds, constraints, callback, options)
```

Code after:
        Set to True to scale the variables according to the bounds. If True and
        if all the lower and upper bounds are finite, the variables are scaled
        to be within the range :math:`[-1, 1]`. If any of the lower or upper
        bounds is infinite, the variables are not scaled. Default is ``False``.

    References
    ----------
    .. [1] COBYQA
           https://www.cobyqa.com/stable/
    """
    # Import here to avoid circular imports
    from .._external.cobyqa import minimize as _cobyqa_minimize

    _check_unknown_options(unknown_options)
    options = {
        'disp': bool(disp),
        'maxfev': int(maxfev) if maxfev is not None else 500 * len(x0),
        'maxiter': int(maxiter) if maxiter is not None else 1000 * len(x0),
        'target': float(f_target),
        'feasibility_tol': float(feasibility_tol),
        'radius_init': float(initial_tr_radius),
        'radius_final': float(final_tr_radius),
        'scale': bool(scale),
    }
    return _cobyqa_minimize(fun, x0, args, bounds, constraints, callback, options)