
    ^j                        U d Z ddlZddlZddlm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c mc m	Z ddlmZmZ ddlmZ d	dd
 fZddd fZej2                  j5                  dd      Zeez  ed<   ej2                  j5                  dd      Z G d dej@                        Z! ed      dde"de!fd       Z#dddedefdZ$y)z|
Override functions from array_api_compat, for use by array-api-extra
and internally.

See also _array_api_compat_vendor.py
    N)	lru_cache)
ModuleTypeAny)array_api_compat)is_array_api_objis_jax_array)	SparseABCArrayc                      t         S Nr        W/opt/ringagent/.cad-venv/lib/python3.12/site-packages/scipy/_lib/_array_api_override.pyr   r      s    S r   	ArrayLikec                  0    t         t        j                  z  S r   )r   nptr   r   r   r   r   r      s    & &r   SCIPY_ARRAY_APIFSCIPY_DEVICEcpuc                       e Zd ZdZdZdZdZy)_ArrayClsInfor            N)__name__
__module____qualname__skipnumpy
array_likeunknownr   r   r   r   r       s    DEJGr   r   d   clsreturnc                 n   t        | t        t        z        rt        j                  S t        | t
              r|sd}t        |      t        j                  S t        | t        j                  j                        rt        d      t        | t        j                        rt        d      t        | t        j                  t        j                  z        rt        j                  S t        | t        t         z  t"        z  t$        z  t'        d       z        rt        j(                  S t        j*                  S )NzSparse arrays/matrices are not supported by this function. Perhaps one of the `scipy.sparse.linalg` functions would work instead.z8Inputs of type `numpy.ma.MaskedArray` are not supported.z0Inputs of type `numpy.matrix` are not supported.)
issubclasslisttupler   r!   r
   
ValueErrorr    npmaMaskedArray	TypeErrormatrixndarraygenericintfloatcomplexbooltyper   r"   )r$   	sparse_okmsgs      r   _validate_array_clsr9   '   s    #te|$''' #y!*C S/! """#ruu(()RSS#ryy!JKK#rzzBJJ./"""
 #sU{W,t3d4j@A!!!   r   r7   arraysc                    t         st        S g }g }|D ]>  }t        t        |      |       }|t        j
                  u r-|t        j                  u ry|j                  j                  dv r|j                  |       i|j                  j                  dk(  rt        |      r|j                  |       t        d|j                  d      |t        j                  u rt        |      r|j                  |       	 t        j                  |      }|j                  j                  dvrt        d|j                  d      |j                  |       A |st        S t!        j"                  g || S # t        $ r t        d      w xY w)a  Get the array API compatible namespace for the arrays xs.

    Parameters
    ----------
    *arrays : sequence of array_like
        Arrays used to infer the common namespace.
    sparse_ok : bool
        ``True`` if `scipy.sparse` arrays should be accepted where the
        namespace would otherwise be NumPy. Default: ``False``.

    Returns
    -------
    namespace : module
        Common namespace.

    Notes
    -----
    Wrapper around `array_api_compat.array_namespace`.

    1. Check for the global switch `SCIPY_ARRAY_API`. If disabled, just
       return array_api_compat.numpy namespace and skip all compliance checks.

    2. Check for known-bad array classes.
       The following subclasses are not supported and raise and error:

       - `numpy.ma.MaskedArray`
       - `numpy.matrix`
       - NumPy arrays which do not have a boolean or numerical dtype

    3. Coerce array-likes to NumPy arrays and check their dtype.
       Note that non-scalar array-likes can't be mixed with non-NumPy Array
       API objects; e.g.

       - `array_namespace([1, 2])` returns NumPy namespace;
       - `array_namespace(np.asarray([1, 2], [3, 4])` returns NumPy namespace;
       - `array_namespace(cp.asarray([1, 2], [3, 4])` raises an error.
    r:   iufcbVzAn argument has dtype `z3`; only boolean and numerical dtypes are supported.zCAn argument is neither array API compatible nor coercible by NumPy.)r   	np_compatr9   r6   r   r   r    dtypekindappendr	   r.   r"   r   r+   
asanyarrayr   array_namespace)r7   r;   numpy_arrays
api_arraysarrayarr_infos         r   rD   rD   I   s   L LJ '&tE{iH}))),,,{{7*##E*!!S(\%-@ !!%("9%++ IS !S T T ...3CE3Je$7e, {{w."9%++ IS !S T T&;'B  ++G\GJGG  7 !6 7 77s   ;E44F	)F)%__doc__enumos	functoolsr   typesr   typingr   r    r+   numpy.typingr   scipy._externalr   &scipy._external.array_api_compat.numpy	_externalr?    scipy._external.array_api_compatr   r	   scipy._lib._sparser
   r   r   environgetr   strr5   __annotations__r   Enumr   r6   r9   rD   r   r   r   <module>rZ      s     	      , : : K (  & !jjnn->Ft Fzz~~ne4DII  3!T !} ! !B /4 SHU SH
 SHr   