# Path: pyswarms/utils/functions/single_obj.py
# def rosenbrock(x):
#     """Rosenbrock objective function.
# 
#     Also known as the Rosenbrock's valley or Rosenbrock's banana
#     function. Has a global minimum of :code:`np.ones(dimensions)` where
#     :code:`dimensions` is :code:`x.shape[1]`. The search domain is
#     :code:`[-inf, inf]`.
# 
#     Parameters
#     ----------
#     x : numpy.ndarray
#         set of inputs of shape :code:`(n_particles, dimensions)`
# 
#     Returns
#     -------
#     numpy.ndarray
#         computed cost of size :code:`(n_particles, )`
#     """
# 
#     r = np.sum(
#         100 * (x.T[1:] - x.T[:-1] ** 2.0) ** 2 + (1 - x.T[:-1]) ** 2.0, axis=0
#     )
# 
#     return r
# 
# def sphere(x):
#     """Sphere objective function.
# 
#     Has a global minimum at :code:`0` and with a search domain of
#         :code:`[-inf, inf]`
# 
#     Parameters
#     ----------
#     x : numpy.ndarray
#         set of inputs of shape :code:`(n_particles, dimensions)`
# 
#     Returns
#     -------
#     numpy.ndarray
#         computed cost of size :code:`(n_particles, )`
#     """
#     j = (x ** 2.0).sum(axis=1)
# 
#     return j


import abc
import numpy as np
import pytest
        import multiprocessing
from pyswarms.utils.functions.single_obj import rosenbrock, sphere
    @pytest.fixture
    def obj_without_args(self):
        """Objective function without arguments"""
        return rosenbrock

    @pytest.mark.parametrize(
        "history, expected_shape",
        [
            ("cost_history", (1000,)),
            ("mean_pbest_history", (1000,)),
            ("mean_neighbor_history", (1000,)),
            ("pos_history", (1000, 10, 2)),
            ("velocity_history", (1000, 10, 2)),
        ],
    )
    def test_train_history(self, optimizer_history, history, expected_shape):
        """Test if training histories are of expected shape"""
        opt = vars(optimizer_history)
        assert np.array(opt[history]).shape == expected_shape

    def test_reset_default_values(self, optimizer_reset):
        """Test if best cost and best pos are set properly when the reset()
        method is called"""
        assert optimizer_reset.swarm.best_cost == np.inf
        assert set(optimizer_reset.swarm.best_pos) == set(np.array([]))

    @pytest.mark.skip(reason="The Ring topology converges too slowly")
    def test_ftol_effect(self, options, optimizer):
        """Test if setting the ftol breaks the optimization process"""
        opt = optimizer(10, 2, options=options, ftol=1e-1)

# Path: pyswarms/utils/functions/single_obj.py
# def rosenbrock(x):
#     """Rosenbrock objective function.
# 
#     Also known as the Rosenbrock's valley or Rosenbrock's banana
#     function. Has a global minimum of :code:`np.ones(dimensions)` where
#     :code:`dimensions` is :code:`x.shape[1]`. The search domain is
#     :code:`[-inf, inf]`.
# 
#     Parameters
#     ----------
#     x : numpy.ndarray
#         set of inputs of shape :code:`(n_particles, dimensions)`
# 
#     Returns
#     -------
#     numpy.ndarray
#         computed cost of size :code:`(n_particles, )`
#     """
# 
#     r = np.sum(
#         100 * (x.T[1:] - x.T[:-1] ** 2.0) ** 2 + (1 - x.T[:-1]) ** 2.0, axis=0
#     )
# 
#     return r
# 
# def sphere(x):
#     """Sphere objective function.
# 
#     Has a global minimum at :code:`0` and with a search domain of
#         :code:`[-inf, inf]`
# 
#     Parameters
#     ----------
#     x : numpy.ndarray
#         set of inputs of shape :code:`(n_particles, dimensions)`
# 
#     Returns
#     -------
#     numpy.ndarray
#         computed cost of size :code:`(n_particles, )`
#     """
#     j = (x ** 2.0).sum(axis=1)
# 
#     return j


# Path: tests/optimizers/abc_test_optimizer.py
import abc
import numpy as np
import pytest
        import multiprocessing
from pyswarms.utils.functions.single_obj import rosenbrock, sphere

    @pytest.fixture
    def obj_without_args(self):
        """Objective function without arguments"""
        return rosenbrock

    @pytest.mark.parametrize(
        "history, expected_shape",
        [
            ("cost_history", (1000,)),
            ("mean_pbest_history", (1000,)),
            ("mean_neighbor_history", (1000,)),
            ("pos_history", (1000, 10, 2)),
            ("velocity_history", (1000, 10, 2)),
        ],
    )
    def test_train_history(self, optimizer_history, history, expected_shape):
        """Test if training histories are of expected shape"""
        opt = vars(optimizer_history)
        assert np.array(opt[history]).shape == expected_shape

    def test_reset_default_values(self, optimizer_reset):
        """Test if best cost and best pos are set properly when the reset()
        method is called"""
        assert optimizer_reset.swarm.best_cost == np.inf
        assert set(optimizer_reset.swarm.best_pos) == set(np.array([]))

    @pytest.mark.skip(reason="The Ring topology converges too slowly")
    def test_ftol_effect(self, options, optimizer):
        """Test if setting the ftol breaks the optimization process"""
        opt = optimizer(10, 2, options=options, ftol=1e-1)

        opt.optimize(sphere, 2000)