+
    ,ie                        a  R t0 t R t^ RIHtHt ^ RIHtHtH	t
 . t] ^ k RR/R ltRR/R ltRR/R	 ltRR/R
 lt	RR ltRR ltR# )a  
Extra testing functions that forbid 0d-input, see #21044

While the xp_assert_* functions generally aim to follow the conventions of the
underlying `xp` library, NumPy in particular is inconsistent in its handling
of scalars vs. 0d-arrays, see https://github.com/numpy/numpy/issues/24897.

For example, this means that the following operations (as of v2.0.1) currently
return scalars, even though a 0d-array would often be more appropriate:

    import numpy as np
    np.array(0) * 2     # scalar, not 0d array
    - np.array(0)       # scalar, not 0d-array
    np.sin(np.array(0)) # scalar, not 0d array
    np.mean([1, 2, 3])  # scalar, not 0d array

Libraries like CuPy tend to return a 0d-array in scenarios like those above,
and even `xp.asarray(0)[()]` remains a 0d-array there. To deal with the reality
of the inconsistencies present in NumPy, as well as 20+ years of code on top,
the `xp_assert_*` functions here enforce consistency in the only way that
doesn't go against the tide, i.e. by forbidding 0d-arrays as the return type.

However, when scalars are not generally the expected NumPy return type,
it remains preferable to use the assert functions from
the `scipy._lib._array_api` module, which have less surprising behaviour.
)array_namespaceis_numpy)xp_assert_closexp_assert_equalxp_assert_lessxpNc                    R pVf   \        V 4      pVP                  V4      p\        V4      '       d   VP                  R8X  g   R# RpVP	                  V 4      '       g   Q V4       hR# )TNa  Result is a NumPy 0d-array. Many SciPy functions intend to follow the convention of many NumPy functions, returning a scalar when a 0d-array would be correct. The specialized `xp_assert_*` functions in the `scipy._lib._array_api_no_0d` module err on the side of caution and do not accept 0d-arrays by default. If the correct result may legitimately be a 0d-array, pass `check_0d=True`, or use the `xp_assert_*` functions from `scipy._lib._array_api`. )r   asarrayr   shapeisscalar)actualdesiredr   kwargs__tracebackhide___msgs   &&$,  =/usr/lib/python3/dist-packages/scipy/_lib/_array_api_no_0d.py_check_scalarr   #   sd    	zV$ jj!G RLLW]]b0OD ;;v$$    check_0dFc                J    R pV'       g   \        W3/ VB  \        W3RV/VB # Tr   )r   xp_assert_equal_baser   r   r   r   r   s   &&$, r   r   r   ;   s1      f00M(MfMMr   c                J    R pV'       g   \        W3/ VB  \        W3RV/VB # r   )r   xp_assert_close_baser   s   &&$, r   r   r   F   s-    f00M(MfMMr   c                J    R pV'       g   \        W3/ VB  \        W3RV/VB # r   )r   xp_assert_less_baser   s   &&$, r   r   r   O   s-    f00vLLVLLr   c                T    ^ R^
V) ,          ,          re\        W.VO5RVRVRRRR/VB # zPBackwards compatible replacement. In new code, use xp_assert_close instead.
    g      ?atolrtolcheck_dtypeFcheck_shaper   r   r   decimalargskwdsr!   r    s   &&&*,  r   assert_array_almost_equalr)   X   U     CgX&$6 * * $*+/*=B*PU*$(* *r   c                T    ^ R^
V) ,          ,          re\        W.VO5RVRVRRRR/VB # r   r$   r%   s   &&&*,  r   assert_almost_equalr,   a   r*   r   c                V    V ^8  d   Qh/ ^ \         9   d   \        \        ,          ;R&   # )   __all__)__conditional_annotations__liststr)formats   "r   __annotate__r4      s"      >  c ?r   )   )   )r0   __doc__scipy._lib._array_apir   r   r   r   r   r   r   r   r/   r   r)   r,   r4   )r0   s   @r   <module>r9      sf   4 <J J  % %0N NN NM M**r   