U
    d»{j¥  ã                   @   s¦   d dl Z d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ ddlmZ g Zd	d
gZddd„Zedddd�dd
„ ƒZedddd�dd	„ ƒZdd„ ZdS )é    N)Úinf)ÚNumber)ÚQuantity)Ú
isiterable)Ú
deprecatedé   )ÚunitsÚinf_likeÚvectorize_if_neededc                    s@   ˆ dkrt jtˆd�S t  ˆ ¡‡ ‡‡fdd„ƒ‰t ˆ ¡ˆ_ˆS )aÃ  Vectorize a method of redshift(s).

    Parameters
    ----------
    func : callable or None
        method to wrap. If `None` returns a :func:`functools.partial`
        with ``nin`` loaded.
    nin : int
        Number of positional redshift arguments.

    Returns
    -------
    wrapper : callable
        :func:`functools.wraps` of ``func`` where the first ``nin``
        arguments are converted from |Quantity| to :class:`numpy.ndarray`.
    N)Úninc                    s^   dd„ |dˆ… D ƒ}t dd„ |D ƒƒrBˆ | f||ˆd… ž|ŽS ˆj| f||ˆd… ž|ŽS )z›
        :func:`functools.wraps` of ``func`` where the first ``nin``
        arguments are converted from |Quantity| to `numpy.ndarray` or scalar.
        c                 S   s&   g | ]}t |tƒs|n
| tj¡‘qS © )Ú
isinstancer   Zto_valueÚcuÚredshift©Ú.0Úzr   r   úV/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/utils.pyÚ
<listcomp>1   s   ÿz>vectorize_redshift_method.<locals>.wrapper.<locals>.<listcomp>Nc                 s   s   | ]}t |ttjfƒV  qd S )N)r   r   ÚnpÚgenericr   r   r   r   Ú	<genexpr>6   s     z=vectorize_redshift_method.<locals>.wrapper.<locals>.<genexpr>)ÚallÚ__vectorized__)ÚselfÚargsÚkwargsZzs©Úfuncr   Úwrapperr   r   r   )   s    
þz*vectorize_redshift_method.<locals>.wrapper)Ú	functoolsÚpartialÚvectorize_redshift_methodÚwrapsr   Ú	vectorizer   )r   r   r   r   r   r"      s    r"   z5.0zSvectorize_if_needed has been removed because it constructs a new ufunc on each callz<use a pre-vectorized function instead for a target array 'z')ZsinceÚmessageÚalternativec                 O   s(   t tt|ƒƒr tj| f|Ž|Ž S | |Ž S )aÖ  Helper function to vectorize scalar functions on array inputs.

    Parameters
    ----------
    f : callable
        'f' must accept positional arguments and no mandatory keyword
        arguments.
    *x
        Arguments into ``f``.
    **vkw
        Keyword arguments into :class:`numpy.vectorize`.

    Examples
    --------
    >>> func = lambda x: x ** 2
    >>> vectorize_if_needed(func, 2)
    4
    >>> vectorize_if_needed(func, [2, 3])
    array([4, 9])
    )ÚanyÚmapr   r   r$   )ÚfÚxZvkwr   r   r   r
   A   s    z[inf_like has been removed because it duplicates functionality provided by numpy.full_like()z@Use numpy.full_like(z, numpy.inf) instead for a target array 'z'c                 C   s   t  | ¡rtS t j| ttd�S )aL  Return the shape of x with value infinity and dtype='float'.

    Preserves 'shape' for both array and scalar inputs.
    But always returns a float array, even if x is of integer type.

    Parameters
    ----------
    x : scalar or array-like
        Must work with functions `numpy.isscalar` and `numpy.full_like` (if `x`
        is not a scalar`

    Returns
    -------
    `math.inf` or ndarray[float] thereof
        Returns a scalar `~math.inf` if `x` is a scalar, an array of floats
        otherwise.

    Examples
    --------
    >>> inf_like(0.)  # float scalar
    inf
    >>> inf_like(1)  # integer scalar should give float output
    inf
    >>> inf_like([0., 1., 2., 3.])  # float list
    array([inf, inf, inf, inf])
    >>> inf_like([0, 1, 2, 3])  # integer list should give float output
    array([inf, inf, inf, inf])
    )Zdtype)r   Zisscalarr   Z	full_likeÚfloat)r*   r   r   r   r	   a   s    %c                 C   sF   t | ttjfƒr| S t| dƒr8t| dƒr4| tj> jS | S t| tjƒjS )z�
    Redshift as a `~numbers.Number` or `~numpy.ndarray` / |Quantity| / |Column|.
    Allows for any ndarray ducktype by checking for attribute "shape".
    ÚshapeÚunit)	r   r   r   r   Úhasattrr   r   Úvaluer   )r   r   r   r   Úaszarr‰   s    

r0   )Nr   )r    Úmathr   Únumbersr   Únumpyr   Zastropy.unitsr   Zastropy.utilsr   Zastropy.utils.decoratorsr   Ú r   r   Ú__all__Z__doctest_skip__r"   r
   r	   r0   r   r   r   r   Ú<module>   s.   
-ú
ú
 