
    HR-e6                    v   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 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          Zd,dZ edd          d-d            Zd.d Zd/d#Zed$d%d0d*            Z ed$d%d0d+            Z!dS )1z
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Union)False_True_ndarray)table)	Cosmology.zastropy.cosmologyzset[Any]
_COSMO_AOKc                  R    e Zd ZU dZdZej        ej        fZde	d<   	 de	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   returnNonec                    || _         d S Nr   )selfr   s     Blib/python3.11/site-packages/astropy/cosmology/funcs/comparison.py__init__z_CosmologyWrapper.__init__:   s        N)r   r   r   r   )__name__
__module____qualname____doc__	__slots__r
   RowTabler   __annotations__r    r   r   r   r   (   sg          
 I ).	5;'?N???? LLL     r   r   ninintnoutr   Callable[[_CompFnT], np.ufunc]c                    dd}|S )Npyfunc_CompFnTr   np.ufuncc                2    t          j        | dd          }|S )N      )np
frompyfunc)r(   ufuncs     r   wrapperz_wrap_to_ufunc.<locals>.wrapperB   s    fa++r   )r(   r)   r   r*   r"   )r#   r%   r1   s      r   _wrap_to_ufuncr2   A   s        Nr   r,   r-   cosmor   format_FormatTyper   c                  t          | t                    r| j        } t          | t                    rM|t          vrBd                    t          t          t                              }t          d| d|           | S |t          k    rt          d|            |t          k    rdn|}t          j        | |          }|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r4   )
isinstancer   r   r   r   joinmapstr
ValueErrorr   	TypeErrorr   from_format)r3   r4   allowedouts       r   _parse_formatrB   I   s    : %*++  %## :##hhs3
3344GTWTTFTT   	6		OOO
 
 	
  5f#E&999Jr   cosmosobject	_FormatsTr	   c                    t          j        t          j        | t                    t	          |                    }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`.
    )dtypec              3  J   K   | ]}t          |t          j                  V  d S r   )r9   r   r   ).0r3   s     r   	<genexpr>z!_parse_formats.<locals>.<genexpr>   s0      VVej 1 @AAVVVVVVr   c                :    g | ]\  }}|s|nt          |          S r"   )r   )rI   cwraps      r   
<listcomp>z"_parse_formats.<locals>.<listcomp>   s;       4;At/,Q//  r   )r.   broadcast_toarrayrD   lenziprB   )r4   rC   formatstowrapwcosmoss        r   _parse_formatsrV   }   sz    8 obhvV<<<c&kkJJG WVvVVVF ?B66?R?R  G '***r   r(   Callable[..., Any]c                    t          j        |           }t          d |j                                        D                       t          j        |           dddf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              3  ,   K   | ]}|j         d k    V  dS )r   N)kind)rI   ps     r   rJ   z(_comparison_decorator.<locals>.<genexpr>   s(      ;;aafk;;;;;;r   Fr8   rC   r   r4   rE   kwargsr   boolc           	         t          |          k    r/t          j        j         d dt          |           d          t	          |d| i} j        |i |}|S )Nz takes z positional arguments but z were givenr4   )rQ   r>   __wrapped__r   rV   )r4   rC   r\   resultr#   r1   s       r   r1   z&_comparison_decorator.<locals>.wrapper   s    v;;&/ ; ; ; ;"%f++; ; ;  
  777$$f777r   )rC   r   r4   rE   r\   r   r   r]   )inspect	signaturesum
parametersvalues	functoolswraps)r(   sigr#   r1   s     @@r   _comparison_decoratorri      s    4 
F
#
#C
;;3>#8#8#:#:;;;
;
;C _V27          Nr   Fallow_equivalentcosmo1cosmo2rk   r]   c                  |s| |k    }n@|                      |          }|t          u r|                     |           }|t          u rd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)	__equiv__NotImplemented)rl   rm   rk   eqs       r   cosmology_equalrr      sf    D  3v f%%!!&))BN**UU Ir   c              ,    t          | ||           }|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.
    rj   )rr   )rl   rm   rk   neqs       r   _cosmology_not_equalru   O  s$    R ff?OPPP
PC Jr   )r#   r$   r%   r$   r   r&   )r3   r   r4   r5   r   r   )rC   rD   r4   rE   r   r	   )r(   rW   r   rW   )rl   r   rm   r   rk   r]   r   r]   )"r   
__future__r   rf   ra   typingr   r   r   numpyr.   r   r   r	   astropyr
   astropy.cosmology.corer   __all__r]   r<   r5   tuplerE   r)   r   r!   r   r2   rB   rV   ri   rr   ru   r"   r   r   <module>r}      s	     # " " " " "      ' ' ' ' ' ' ' ' ' '     ( ( ( ( ( ( ( ( ( (       , , , , , ,
 D$O$+u[#%5667	S+&	12eV-@A
 A A A A       2    10 0 0 0f'+ '+ '+ '+T, , , ,f =Bq q q q q qh =B, , , , , , , ,r   