from typing import Dict
from typing import Any


def _search_space(hparams: Dict[str, Any]) -> Dict[str, Any]:
    """ Create a search_space from hyper-parameter bounds.

    For hyper-parameters a min and max value determines what bounds to search
    between, when these are equal the hyper-parameter won't be optimized.
    When `num` is passed it generates `num` many identical hyper-parameters.

    Returns:
        A search space for configurations.
    """
    search_space = {}
    for hparam in hparams:
        hparam_values = hparams[hparam]
        hparam_min = hparam_values['min']
        hparam_max = hparam_values['max']
        interval = (hparam_min
                    if hparam_min == hparam_max
                    else (hparam_min, hparam_max))
        if 'num' in hparam_values:
            for i in range(hparam_values['num']):
                search_space[hparam+'_{}'.format(i+1)]=interval
        else:
            search_space[hparam]=interval
    return search_space