a
    ߙfbY                     @   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u 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                    sn   dd |d D }t dd |D rJ | g||d R i |S j| g||d R i |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   6lib/python3.9/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>4       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messageZalternativec                 O   s,   t tt|r$tj| fi || 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
   ?   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	   \   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".
    shapeZunit)	r   r   r   r   hasattrr   r   valuer   )r   r   r   r   aszarr   s    

r/   )Nr   )r!   Zmathr   Znumbersr   Znumpyr   Zastropy.unitsr   Zastropy.utilsr   Zastropy.utils.decoratorsr    r   r   __all__Z__doctest_skip__r#   r
   r	   r/   r   r   r   r   <module>   s.   
+

 