import multiprocessing


def valid_n_jobs(n_jobs):
    """
    Validates and assigns correct number of cpu cores.

    Parameters
    ----------
    n_jobs : int
        Number of desired cpu cores.
    
    Returns
    -------
    Valid number of cpu cores.
    """
    max_cpus = multiprocessing.cpu_count()
    if n_jobs < 1:
        n_jobs = max_cpus

    if n_jobs > max_cpus:
        n_jobs = max_cpus
    
    return n_jobs