U
    e»{j•6  ã                   @  sV  U d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
Zddl
mZmZmZ ddlmZ ddlmZ g Ze	edef Ze	eeedf f Zeeegef Zdeed	hZd
ed< G dd„ dƒZddddœdd„Zeddƒddddœdd„ƒZddddœdd „Zd!d!d"œd#d$„Zed%d&œddd'd'd(œd)d*„ƒZ ed%d&œddd'd'd(œd+d,„ƒZ!dS )-zÖ
Comparison functions for `astropy.cosmology.Cosmology`.

This module is **NOT** public API. To use these functions, import them from
the top-level namespace -- :mod:`astropy.cosmology`.
This module will be moved.
é    )ÚannotationsN)ÚAnyÚCallableÚTupleÚUnion)ÚFalse_ÚTrue_Úndarray)Útable)Ú	Cosmology.zastropy.cosmologyzset[Any]Ú
_COSMO_AOKc                   @  sB   e Zd ZU dZdZejejfZde	d< de	d< dddœd	d
„Z
dS )Ú_CosmologyWrapperzq
    A private wrapper class to hide things from :mod:`numpy`.
    This should never be exposed to the user.
    ©Úwrappedztuple[type, ...]Ú_cantbroadcastr   r   ÚNone)r   Úreturnc                 C  s
   || _ d S ©Nr   )Úselfr   © r   úa/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/funcs/comparison.pyÚ__init__:   s    z_CosmologyWrapper.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r
   ÚRowÚTabler   Ú__annotations__r   r   r   r   r   r   (   s
   
r   ÚintzCallable[[_CompFnT], np.ufunc])ÚninÚnoutr   c                 C  s   dddœdd„}|S )NÚ_CompFnTznp.ufunc©Úpyfuncr   c                 S  s   t  | dd¡}|S )Né   é   )ÚnpZ
frompyfunc)r%   Zufuncr   r   r   ÚwrapperB   s    z_wrap_to_ufunc.<locals>.wrapperr   )r!   r"   r)   r   r   r   Ú_wrap_to_ufuncA   s    r*   r&   r'   r   Ú_FormatTyper   )ÚcosmoÚformatr   c                C  s„   t | tƒr| j} t | tƒrJ|tkrFd tttƒ¡}td|› d|› �ƒ‚| S |t	krbt
d| › �ƒ‚n|tkrndn|}tj| |d�}|S )aš  Parse Cosmology-like input into Cosmologies, given a format hint.

    Parameters
    ----------
    cosmo : |Cosmology|-like, positional-only
        |Cosmology| to parse.
    format : bool or None or str, positional-only
        Whether to allow, before equivalence is checked, the object to be
        converted to a |Cosmology|. This allows, e.g. a |Table| to be equivalent
        to a |Cosmology|. `False` (default) will not allow conversion. `True` or
        `None` will, and will use the auto-identification to try to infer the
        correct format. A `str` is assumed to be the correct format to use when
        converting.

    Returns
    -------
    |Cosmology| or generator thereof

    Raises
    ------
    TypeError
        If ``cosmo`` is not a |Cosmology| and ``format`` equals `False`.
    TypeError
        If ``cosmo`` is a |Cosmology| and ``format`` is not `None` or equal to
        `True`.
    ú/z*for parsing a Cosmology, 'format' must be z, not z9if 'format' is False, arguments must be a Cosmology, not N©r-   )Ú
isinstancer   r   r   r   ÚjoinÚmapÚstrÚ
ValueErrorr   Ú	TypeErrorr   Zfrom_format)r,   r-   ÚallowedÚoutr   r   r   Ú_parse_formatI   s     

ÿÿr8   ÚobjectÚ	_FormatsTr	   )Úcosmosr-   r   c                 G  sF   t  t j| td�t|ƒ¡}dd„ |D ƒ}dd„ t||ƒD ƒ}t||ƒS )a¿  Parse Cosmology-like to |Cosmology|, using provided formats.

    ``format`` is broadcast to match the shape of the cosmology arguments. Note
    that the cosmology arguments are not broadcast against ``format``, so it
    cannot determine the output shape.

    Parameters
    ----------
    *cosmos : |Cosmology|-like
        The objects to compare. Must be convertible to |Cosmology|, as specified
        by the corresponding ``format``.

    format : bool or None or str or array-like thereof, positional-only
        Whether to allow, before equivalence is checked, the object to be
        converted to a |Cosmology|. This allows, e.g. a |Table| to be equivalent
        to a |Cosmology|. `False` (default) will not allow conversion. `True` or
        `None` will, and will use the auto-identification to try to infer the
        correct format. A `str` is assumed to be the correct format to use when
        converting. Note ``format`` is broadcast as an object array to match the
        shape of ``cosmos`` so ``format`` cannot determine the output shape.

    Raises
    ------
    TypeError
        If any in ``cosmos`` is not a |Cosmology| and the corresponding
        ``format`` equals `False`.
    )Zdtypec                 s  s   | ]}t |tjƒV  qd S r   )r0   r   r   )Ú.0r,   r   r   r   Ú	<genexpr>Ÿ   s     z!_parse_formats.<locals>.<genexpr>c                 S  s    g | ]\}}|s|nt |ƒ‘qS r   )r   )r<   ÚcÚwrapr   r   r   Ú
<listcomp>    s    z"_parse_formats.<locals>.<listcomp>)r(   Zbroadcast_toÚarrayr9   ÚlenÚzipr8   )r-   r;   ÚformatsZtowrapZwcosmosr   r   r   Ú_parse_formats}   s    ÿrE   zCallable[..., Any]r$   c                   sP   t  | ¡}tdd„ |j ¡ D ƒƒ‰ t | ¡ddœdddddœ‡ ‡fd	d
„ƒ‰ˆS )aÈ  Decorator to make wrapper function that parses |Cosmology|-like inputs.

    Parameters
    ----------
    pyfunc : Python function object
        An arbitrary Python function.

    Returns
    -------
    callable[..., Any]
        Wrapped `pyfunc`, as described above.

    Notes
    -----
    All decorated functions should add the following to 'Parameters'.

    format : bool or None or str or array-like thereof, optional keyword-only
        Whether to allow the arguments to be converted to a |Cosmology|. This
        allows, e.g. a |Table| to be given instead a |Cosmology|. `False`
        (default) will not allow conversion. `True` or `None` will, and will use
        the auto-identification to try to infer the correct format. A `str` is
        assumed to be the correct format to use when converting. Note ``format``
        is broadcast as an object array to match the shape of ``cosmos`` so
        ``format`` cannot determine the output shape.
    c                 s  s   | ]}|j d kV  qdS )r   N)Úkind)r<   Úpr   r   r   r=   Â   s     z(_comparison_decorator.<locals>.<genexpr>Fr/   r   r:   Úbool)r;   r-   Úkwargsr   c                   sL   t |ƒˆ kr.tˆjj› dˆ › dt |ƒ› d�ƒ‚t|d| iŽ}ˆj||Ž}|S )Nz takes z positional arguments but z were givenr-   )rB   r5   Ú__wrapped__r   rE   )r-   r;   rI   Úresult©r!   r)   r   r   r)   Å   s    ÿz&_comparison_decorator.<locals>.wrapper)ÚinspectÚ	signatureÚsumÚ
parametersÚvaluesÚ	functoolsÚwraps)r%   Úsigr   rL   r   Ú_comparison_decorator§   s
    
"rU   F©Úallow_equivalentrH   )Úcosmo1Úcosmo2rW   r   c               C  s>   |s| |k}n,|   |¡}|tkr*|  | ¡}|tkr6dn|}|S )a£  Return element-wise equality check on the cosmologies.

    .. note::

        Cosmologies are currently scalar in their parameters.

    Parameters
    ----------
    cosmo1, cosmo2 : |Cosmology|-like
        The objects to compare. Must be convertible to |Cosmology|, as specified
        by ``format``.

    format : bool or None or str or tuple thereof, optional keyword-only
        Whether to allow the arguments to be converted to a |Cosmology|. This
        allows, e.g. a |Table| to be given instead a |Cosmology|. `False`
        (default) will not allow conversion. `True` or `None` will, and will use
        the auto-identification to try to infer the correct format. A `str` is
        assumed to be the correct format to use when converting. Note ``format``
        is broadcast as an object array to match the shape of ``cosmos`` so
        ``format`` cannot determine the output shape.

    allow_equivalent : bool, optional keyword-only
        Whether to allow cosmologies to be equal even if not of the same class.
        For example, an instance of |LambdaCDM| might have :math:`\Omega_0=1`
        and :math:`\Omega_k=0` and therefore be flat, like |FlatLambdaCDM|.

    Examples
    --------
    Assuming the following imports

        >>> import astropy.units as u
        >>> from astropy.cosmology import FlatLambdaCDM

    Two identical cosmologies are equal.

        >>> cosmo1 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3)
        >>> cosmo2 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3)
        >>> cosmology_equal(cosmo1, cosmo2)
        True

    And cosmologies with different parameters are not.

        >>> cosmo3 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.4)
        >>> cosmology_equal(cosmo1, cosmo3)
        False

    Two cosmologies may be equivalent even if not of the same class. In these
    examples the |LambdaCDM| has :attr:`~astropy.cosmology.LambdaCDM.Ode0` set
    to the same value calculated in |FlatLambdaCDM|.

        >>> from astropy.cosmology import LambdaCDM
        >>> cosmo3 = LambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3, 0.7)
        >>> cosmology_equal(cosmo1, cosmo3)
        False
        >>> cosmology_equal(cosmo1, cosmo3, allow_equivalent=True)
        True

    While in this example, the cosmologies are not equivalent.

        >>> cosmo4 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3, Tcmb0=3 * u.K)
        >>> cosmology_equal(cosmo3, cosmo4, allow_equivalent=True)
        False

    Also, using the keyword argument, the notion of equality is extended to any
    Python object that can be converted to a |Cosmology|.

        >>> mapping = cosmo2.to_format("mapping")
        >>> cosmology_equal(cosmo1, mapping, format=True)
        True

    Either (or both) arguments can be |Cosmology|-like.

        >>> cosmology_equal(mapping, cosmo2, format=True)
        True

    The list of valid formats, e.g. the |Table| in this example, may be checked
    with ``Cosmology.from_format.list_formats()``.

    As can be seen in the list of formats, not all formats can be
    auto-identified by ``Cosmology.from_format.registry``. Objects of these
    kinds can still be checked for equality, but the correct format string must
    be used.

        >>> yml = cosmo2.to_format("yaml")
        >>> cosmology_equal(cosmo1, yml, format=(None, "yaml"))
        True

    This also works with an array of ``format`` matching the number of
    cosmologies.

        >>> cosmology_equal(mapping, yml, format=[True, "yaml"])
        True
    F)Z	__equiv__ÚNotImplemented)rX   rY   rW   Úeqr   r   r   Úcosmology_equalÚ   s    b


r\   c               C  s   t | ||d� }|S )aT  Return element-wise cosmology non-equality check.

    .. note::

        Cosmologies are currently scalar in their parameters.

    Parameters
    ----------
    cosmo1, cosmo2 : |Cosmology|-like
        The objects to compare. Must be convertible to |Cosmology|, as specified
        by ``format``.

    out : ndarray, None, optional
        A location into which the result is stored. If provided, it must have a
        shape that the inputs broadcast to. If not provided or None, a
        freshly-allocated array is returned.

    format : bool or None or str or tuple thereof, optional keyword-only
        Whether to allow the arguments to be converted to a |Cosmology|. This
        allows, e.g. a |Table| to be given instead a Cosmology. `False`
        (default) will not allow conversion. `True` or `None` will, and will use
        the auto-identification to try to infer the correct format. A `str` is
        assumed to be the correct format to use when converting. ``format`` is
        broadcast to match the shape of the cosmology arguments. Note that the
        cosmology arguments are not broadcast against ``format``, so it cannot
        determine the output shape.

    allow_equivalent : bool, optional keyword-only
        Whether to allow cosmologies to be equal even if not of the same class.
        For example, an instance of |LambdaCDM| might have :math:`\Omega_0=1`
        and :math:`\Omega_k=0` and therefore be flat, like |FlatLambdaCDM|.

    See Also
    --------
    astropy.cosmology.cosmology_equal
        Element-wise equality check, with argument conversion to Cosmology.
    rV   )r\   )rX   rY   rW   Zneqr   r   r   Ú_cosmology_not_equalO  s    )r]   )"r   Ú
__future__r   rR   rM   Útypingr   r   r   r   Únumpyr(   r   r   r	   Zastropyr
   Zastropy.cosmology.corer   Ú__all__rH   r3   r+   r:   r#   r   r   r   r*   r8   rE   rU   r\   r]   r   r   r   r   Ú<module>   s2   3*3ÿtÿ