
    IR-e<                         d Z ddlZddlZddlmZmZmZmZ g dZ	 G d de
          Z e            Zej        Zd Zd Zd
d	ZdS )zConverters for Quantity.    N)UnitConversionError
UnitsErrorUnitTypeErrordimensionless_unscaled)can_have_arbitrary_unitconverters_and_unitcheck_outputUFUNC_HELPERSUNSUPPORTED_UFUNCSc                   >     e Zd ZdZ fdZd Zd Zd Z fdZ xZ	S )UfuncHelpersa  Registry of unit conversion functions to help ufunc evaluation.

    Based on dict for quick access, but with a missing method to load
    helpers for additional modules such as scipy.special and erfa.

    Such modules should be registered using ``register_module``.
    c                     i | _         t                      | _        t          j                    | _         t                      j        |i | d S N)modulessetUNSUPPORTED	threadingRLock_locksuper__init__)selfargskwargs	__class__s      Hlib/python3.11/site-packages/astropy/units/quantity_helper/converters.pyr   zUfuncHelpers.__init__!   sG    55_&&
$)&)))))    c                 `    | j         5  ||d| j        |<   ddd           dS # 1 swxY w Y   dS )a  Register (but do not import) a set of ufunc helpers.

        Parameters
        ----------
        module : str
            Name of the module with the ufuncs (e.g., 'scipy.special').
        names : iterable of str
            Names of the module ufuncs for which helpers are available.
        importer : callable
            Function that imports the ufuncs and returns a dict of helpers
            keyed by those ufuncs.  If the value is `None`, the ufunc is
            explicitly *not* supported.
        )namesimporterN)r   r   )r   moduler   r    s       r   register_modulezUfuncHelpers.register_module'   s     Z 	J 	J-2#I#IDL 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   #''c                     | j         5  | j                            |          }|                      |d                                ddd           dS # 1 swxY w Y   dS )zImport the helpers from the given module using its helper function.

        Parameters
        ----------
        module : str
            Name of the module. Has to have been registered beforehand.
        r    N)r   r   popupdate)r   r!   module_infos      r   import_modulezUfuncHelpers.import_module8   s     Z 	3 	3,**622KKK/J/11222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   >AAAc                    | j         5  || v r| |         cddd           S || j        v rt          d|j         d          t	          | j                                                  D ]P\  }}|j        |d         v r<	 |                     |           | |         c cddd           S # t          $ r Y Lw xY wQ	 ddd           n# 1 swxY w Y   t          d|j         d          )zCalled if a ufunc is not found.

        Check if the ufunc is in any of the available modules, and, if so,
        import the helpers for that module.
        NzCannot use ufunc 'z' with quantitiesr   zunknown ufunc zm.  If you believe this ufunc should be supported, please raise an issue on https://github.com/astropy/astropy)	r   r   	TypeError__name__listr   itemsr'   ImportError)r   ufuncr!   r&   s       r   __missing__zUfuncHelpers.__missing__D   s    Z 	+ 	+}}E{	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 ((( VU^ V V VWWW'+DL,>,>,@,@'A'A + +#>[%999+**6222  $E{**/	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+( '    :+	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+2 1U^ 1 1 1
 
 	
s;   CAC=B(	C(
B52C4B55CC
C
c                    | j         5  |(| xj        |hz  c_        |                     |d            n3t                                          ||           | xj        |hz  c_        d d d            d S # 1 swxY w Y   d S r   )r   r   r$   r   __setitem__)r   keyvaluer   s      r   r1   zUfuncHelpers.__setitem__i   s    
 Z 	* 	*}  SE)  d######C///  SE)  	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   AA44A8;A8)
r*   
__module____qualname____doc__r   r"   r'   r/   r1   __classcell__)r   s   @r   r   r      s         * * * * *J J J"
3 
3 
3#
 #
 #
J* * * * * * * * *r   r   c                     t          j        t          j        t          j        | d          t          j        |                                S )aP  Test whether the items in value can have arbitrary units.

    Numbers whose value does not change upon a unit change, i.e.,
    zero, infinity, or not-a-number

    Parameters
    ----------
    value : number or array

    Returns
    -------
    bool
        `True` if each member is either zero or not finite, `False` otherwise
    g        )npall
logical_orequalisfinite)r3   s    r   r   r   {   s9     6"- 4 4r{57I7I6IJJKKKr   c           
         t           |          }|dk    s|dk    r| j        dk    rd |D             } || g|R  \  }}t          d |D                       r	 t          |          D ]<\  }}|dur
t	          ||                   rd||<   %t          d| j         d	          nS# t          $ rF t          d
                    | j        d	                    d |D                                           w xY w|du r|d         |d         t          k    r	t          }n|d         	|d         }	n%|d                             t                    j        }		 |d         |	z  }n# t          $ rG}
	 |d                             t                    |d<   t          }n# t
          $ r |
w xY wY d}
~
nPd}
~
ww xY wnF| j        }t          |d         dd          }|dk    rL|dk    rF|dk    r|g}n|t          |d         dd          g} || g|R  \  }}|                    dd           n`|dv r-|dk    r' || ||          \  }}|dd         }|dk    r|dgz  }n/|dv r|dk    rt          | d          t          d| d          ||t          d| d| j         d          |d         4|M||urI|                    |          r|                    |          dk    rt%          d| d| j         d          ||fS )a>  Determine the required converters and the unit of the ufunc result.

    Converters are functions required to convert to a ufunc's expected unit,
    e.g., radian for np.sin; or to ensure units of two inputs are consistent,
    e.g., for np.add.  In these examples, the unit of the result would be
    dimensionless_unscaled for np.sin, and the same consistent unit for np.add.

    Parameters
    ----------
    function : `~numpy.ufunc`
        Numpy universal function
    method : str
        Method with which the function is evaluated, e.g.,
        '__call__', 'reduce', etc.
    *args :  `~astropy.units.Quantity` or ndarray subclass
        Input arguments to the function

    Raises
    ------
    TypeError : when the specified function cannot be used with Quantities
        (e.g., np.logical_or), or when the routine does not know how to handle
        the specified function (in which case an issue should be raised on
        https://github.com/astropy/astropy).
    UnitTypeError : when the conversion to the required (or consistent) units
        is not possible.
    __call__outer   c                 0    g | ]}t          |d d          S )unitN)getattr.0args     r   
<listcomp>z'converters_and_unit.<locals>.<listcomp>   s$    <<<fd++<<<r   c              3      K   | ]}|d u V  	dS )FN )rF   	converters     r   	<genexpr>z&converters_and_unit.<locals>.<genexpr>   s'      >>iyE!>>>>>>r   FNzCan only apply 'zz' function to dimensionless quantities when other argument is not a quantity (unless the latter is all zero/infinity/nan).z.Unsupported operand type(s) for ufunc {}: '{}',c                 &    g | ]}|j         j        S rJ   )r   r*   rE   s     r   rH   z'converters_and_unit.<locals>.<listcomp>   s    !I!I!IS#-"8!I!I!Ir   r      rC   at>   reducereduceat
accumulaterR   >   r@   rQ   rR   rS   z$ only supported for binary functionszUnexpected ufunc method zS.  If this should work, please raise an issue on https://github.com/astropy/astropyzCannot use 'z' method on ufunc z: with a Quantity instance as the result is not a Quantity.g      ?z6 with a Quantity instance as it would change the unit.)r
   ninany	enumerater   r   r*   r)   formatjoinr   tor3   
ValueError_get_converterrD   insertis_equivalentr   )functionmethodr   ufunc_helperunits
convertersresult_unitirK   pexcrT   rC   s                r   r   r      sv   > !*L' 1 1hla6G6G =<t<<< #/,x"@%"@"@"@
K>>:>>>>> 	 %.j$9$9 
 
LAy -- .tAw77 (,
11Wx/@ W W W  
      DKK )!I!ID!I!I!IJJ    %Qx58/E#E#E48#QAAQ

#9::@A
="'(a-KK! = = ==(-a(?(?@V(W(W
1 '= / " " "!	" $=  , ltAw--T>>cQhhaxxwtAw==>&2l8&De&D&D&D#J a&&&&;;;q&2l8T4&H&H#J#BQBJ##tf$
 FFF3RS88 F!P!P!PQQQG6 G G G    3Ev E E9J E E E  
 a=$K'' ..t44 (8Ct8L8LPS8S8S
 Av A A9J A A A  
 {""s8   AB& &AC6E# #
F4.#FF/F&&F//F4c           	      b   t          | t                    r*t          fdt          | |          D                       S | dS t          | d          r|=t	          d                    dj         dndt          |                               |                     |          \  }}|sP|t          |           u s?t          d                    |dj         dndt          |           |                    rT| j
        j        sHt          j         }|j        s3t          j        || j
        d	
          st	          d| j
                   |                     t          j                  S |8|t"          u s/t          d                    dj         dnd                    | S )a  Check that function output can be stored in the output array given.

    Parameters
    ----------
    output : array or `~astropy.units.Quantity` or tuple
        Array that should hold the function output (or tuple of such arrays).
    unit : `~astropy.units.Unit` or None, or tuple
        Unit that the output will have, or `None` for pure numbers (should be
        tuple of same if output is a tuple of outputs).
    inputs : tuple
        Any input arguments.  These should be castable to the output.
    function : callable
        The function that will be producing the output.  If given, used to
        give a more informative error message.

    Returns
    -------
    arrays : ndarray view or tuple thereof
        The view(s) is of ``output``.

    Raises
    ------
    UnitTypeError : If ``unit`` is inconsistent with the class of ``output``

    TypeError : If the ``inputs`` cannot be cast safely to ``output``.
    c              3   B   K   | ]\  }}t          ||          V  d S r   )r	   )rF   output_unit_r^   inputss      r   rL   zcheck_output.<locals>.<genexpr>@  sI       
 
 %::
 
 
 
 
 
r   N__quantity_subclass__z1Cannot store non-quantity output{} in {} instancez from z	 function zNCannot store output with unit '{}'{} in {} instance.  Use {} instance instead.	same_kind)castingz=Arguments cannot be cast safely to inplace output with dtype=zBCannot store quantity with dimension {}in a non-Quantity instance.zresulting from z
 function )
isinstancetupleziphasattrr)   rW   r*   typerl   r   dtyper   r9   result_typecan_castviewndarrayr   )outputrC   rk   r^   q_clssubokrv   s     ``   r   r	   r	   $  s@   6 &%   
 
 
 
 
 
"%fd"3"3
 
 
 
 
 	
 ~tv.// > <CJJ $/ >!2====LL 	 	 	 33D99u 	$v,,..<<BF $/ >!2====LL	= 	=  &  		&,, 		.&1K!;{FL+NNN  8)/8 8   {{2:&&& (> > >006+ Dh&7CCCC1 1   r   r   )r6   r   numpyr9   astropy.units.corer   r   r   r   __all__dictr   r
   r   r   r   r   r	   rJ   r   r   <module>r      s                         \* \* \* \* \*4 \* \* \*~ ". L L L$T# T# T#nd d d d d dr   