
    
9j*                       % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SKJ
r
  S SKJr  S SKrS SKrS SKJr  S SKJr  \" 5       (       a   S SKr\R&                  R(                  rS\S	'   O\R.                  rS"S
 jrS#S jrS$S jr\\R6                  S4S jr\\R6                  4S jr\\R6                  SS S4S jrS\R6                  SSS 4S jr\\R6                  4S jr \\R6                  4SS.S jjr!\RD                  S 5       r# " S S\RH                  5      r% " S S\%5      r& " S S\%5      r'\RD                  SS .S! j5       r(\(r)g)%    )annotationsN)Callable)PackageNotFoundError)mock)internal)is_availablez-Callable[..., Callable[[Callable], Callable]]_skipifc                 T    SSR                  U 5       3n[        [        U 6 (       + US9$ )a  Run a test case only when given requirements are satisfied.

.. admonition:: Example

   This test case runs only when `numpy>=1.18` is installed.

   >>> from cupy import testing
   ...
   ...
   ... class Test(unittest.TestCase):
   ...     @testing.with_requires("numpy>=1.18")
   ...     def test_for_numpy_1_18(self):
   ...         pass

Args:
    requirements: A list of string representing requirement condition to
        run a given test case.

z
requires: ,)reason)joinr	   	installed)requirementsmsgs     N/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/testing/_helper.pywith_requiresr      s/    ( sxx-.
/Cy,//<<    c                     SSK Jn  U  Ha  nU" U5      n [        R                  R	                  UR
                  5      nUR                  nU(       d  MJ  UR                  USS9(       a  Ma    g   g! [         a       gf = f)zReturns True if the current environment satisfies the specified
package requirement.

Args:
    specifiers: Version specifiers (e.g., `numpy>=1.20.0`).
r   )RequirementFT)prereleases)	packaging.requirementsr   	importlibmetadataversionnamer   	specifiercontains)
specifiersr   specreqfoundexpecteds         r   r   r   3   s{     3$	&&..sxx8E ==8X..u$.GG   $ 		s   )A//
A=<A=c                    [        SU  35      $ )zReturns True if numpy version satisfies the specified criteria.

Args:
    version_range: A version specifier (e.g., `>=1.13.0`).
numpy)r   )version_ranges    r   numpy_satisfiesr&   J   s     u]O,--r   Cc                4   [         R                  " U5      n[         R                  " S[        R                  " U 5      S-   S5      nUS:X  a	  US-  S:H  nOUR
                  S:X  a  XDS-  -   nUR                  UR                  U5      R                  U 5      US9$ )aB  Returns an array with given shape, array module, and dtype.

Args:
     shape(tuple of int): Shape of returned ndarray.
     xp(numpy or cupy): Array module to use.
     dtype(dtype): Dtype of returned ndarray.
     order({'C', 'F'}): Order of returned ndarray.

Returns:
     numpy.ndarray or cupy.ndarray:
     The array filled with :math:`1, \cdots, N` with specified dtype
     with given shape, array module. Here, :math:`N` is
     the size of the returned array.
     If ``dtype`` is ``numpy.bool_``, evens (resp. odds) are converted to
     ``True`` (resp. ``False``).

   ?   r   c              ?)order)	r$   dtypearanger   prodkindarrayastypereshape)shapexpr/   r.   as        r   shaped_aranger9   S   s    $ KKEQe,q0!4A|EQJ	s	BJ88AHHUO++E2%8@@r   c                4   [         R                  " U5      n[        R                  " U 5      n[         R                  " USS5      nUS:X  a	  US-  S:H  nOUR
                  S:X  a  XDS-  -   nUR                  UR                  U5      R                  U 5      5      $ )a  Returns an array filled with decreasing numbers.

Args:
     shape(tuple of int): Shape of returned ndarray.
     xp(numpy or cupy): Array module to use.
     dtype(dtype): Dtype of returned ndarray.

Returns:
     numpy.ndarray or cupy.ndarray:
     The array filled with :math:`N, \cdots, 1` with specified dtype
     with given shape, array module.
     Here, :math:`N` is the size of the returned array.
     If ``dtype`` is ``numpy.bool_``, evens (resp. odds) are converted to
     ``True`` (resp. ``False``).
r   r*   r+   r,   r-   )	r$   r/   r   r1   r0   r2   r3   r4   r5   )r6   r7   r/   sizer8   s        r   shaped_reverse_aranger=   n   s      KKE==DT1b!A|EQJ	s	BJ88AHHUO++E233r   
   c                L   [         R                  R                  U5      n[         R                  " U5      nUS:X  a  UR	                  SU S9nOIUR
                  S:X  a'  UR                  " U 6 SUR                  " U 6 -  -   nXs-  nOUR                  " U 6 U-  nUR                  XrUS9$ )ay  Returns an array filled with random values.

Args:
     shape(tuple): Shape of returned ndarray.
     xp(numpy or cupy): Array module to use.
     dtype(dtype): Dtype of returned ndarray.
     scale(float): Scaling factor of elements.
     seed(int): Random seed.

Returns:
     numpy.ndarray or cupy.ndarray: The array with
     given shape, array module,

If ``dtype`` is ``numpy.bool_``, the elements are
independently drawn from ``True`` and ``False``
with same probabilities.
Otherwise, the array is filled with samples
independently and identically drawn
from uniform distribution over :math:`[0, scale)`
with specified dtype.
r*   r+   )r<   r,   r-   )r/   r.   )r$   randomRandomStater/   randintr2   randasarray)r6   r7   r/   scaleseedr.   rngr8   s           r   shaped_randomrH      s    . ,,
"
"4
(CKKE|KKK&	s	HHerCHHe$444	
HHeu$::aE:22r   g{Gz?cooc                   SSK nSSKnUc  UR                  R                  nU u  pUR                  R	                  XX5S9R                  U5      n
 UR                  U
5      R                  U5      $ ! [         a    [        SU S35      ef = f)a  Returns an array filled with random values.

Args:
    shape (tuple): Shape of returned sparse matrix.
    sp (scipy.sparse or cupyx.scipy.sparse): Sparse matrix module to use.
    dtype (dtype): Dtype of returned sparse matrix.
    density (float): Density of returned sparse matrix.
    format (str): Format of returned sparse matrix.
    seed (int): Random seed.

Returns:
    The sparse matrix with given shape, array module,
r   N)random_statezModule z' does not have the expected sparse APIs)
scipy.sparsecupyx.scipy.sparsescipysparser@   r4   
coo_matrixasformatAttributeError
ValueError)r6   spr/   densityformatrF   rN   cupyxn_rowsn_colsr8   s              r   shaped_sparse_randomrZ      s      	z[[NF 	 	44:F5M P}}Q((00 P72$&MNOOPs   A0 0B
c                \   [         R                  " U5      n[         R                  " U5      nUS:X  a  [        U S5      n [	        US5      nOUR
                  S:X  a  [        U S5      n [         R                  " XU5      nUR                  UR                  U5      R                  U5      5      $ )aD  Returns an array with given shape, array module, and dtype.

Args:
    start (int): The starting value.
    stop (int): The end value.
    shape (tuple of int): Shape of returned ndarray.
    xp (numpy or cupy): Array module to use.
    dtype (dtype): Dtype of returned ndarray.

Returns:
    numpy.ndarray or cupy.ndarray:
r*   r   r)   u)
r$   r/   r1   maxminr2   linspacer3   r4   r5   )startstopr6   r7   r/   r<   r8   s          r   shaped_linspacerb      s     KKE::eD|E14|	s	E1uD)A88AHHUO++E233r   )singular_valuesc                  [        U 5      S::  a  [        SR                  U 5      5      eUc  [        S5      eUR	                  U5      n[
        R                  " U5      nUR                  S;  a  [        SR                  U5      5      eUR                  U5      (       d  [        S5      eUS:  R                  5       (       a  [        S5      eUR                  R                  " U 6 nUR                  S	:X  a  US
UR                  R                  " U 6 -  -   nUR                  R                  USS9u  pVnUR                  X6R                  5      nUR!                  SXXU5      nUR#                  U5      $ )aq  Returns a matrix with specified singular values.

Generates a random matrix with given singular values.
This function generates a random NumPy matrix (or a stack of matrices) that
has specified singular values. It can be used to generate the inputs for a
test that can be instable when the input value behaves bad.
Notation: denote the shape of the generated array by :math:`(B..., M, N)`,
and :math:`K = min\{M, N\}`. :math:`B...` may be an empty sequence.

Args:
    shape (tuple of int): Shape of the generated array, i.e.,
        :math:`(B..., M, N)`.
    xp (numpy or cupy): Array module to use.
    dtype: Dtype of the generated array.
    singular_values (array-like): Singular values of the generated
        matrices. It must be broadcastable to shape :math:`(B..., K)`.

Returns:
    numpy.ndarray or cupy.ndarray: A random matrix that has specific
    singular values.
r)   z.shape {} is invalid for matrices: too few axeszsingular_values is not givenfczdtype {} is not supportedzsingular_values is not realr   z negative singular value is givenr,   r-   F)full_matricesz...ik,...k,...kj->...ij)lenrS   rV   	TypeErrorrD   r$   r/   r2   	isrealobjanyr@   randnlinalgsvdbroadcast_tor6   einsumr4   )	r6   r7   r/   rc   r8   r\   svhsvs	            r   generate_matrixrs      sA   0 5zQ<CCEJ
 	
 677jj1OKKEzz3::5ABB<<((566!  "";<<
 			AzzSRYY__e,,,yy}}Qe}4HA"	''	2B
		+QB7A88E?r   c              #  >  ^ #    [         R                  " SS9 n[         R                  " S5        S v   S S S 5        [        U 4S jW 5       5      (       a  g  T R                  n[        SU-  5      e! , (       d  f       ND= f! [
         a    [        T 5      n N6f = f7f)NT)recordalwaysc              3  P   >#    U  H  n[        UR                  T5      v   M     g 7fN)
isinstancemessage).0mr"   s     r   	<genexpr>assert_warns.<locals>.<genexpr>  s     
6Aq:aii**As   #&z%s not triggerred)warningscatch_warningssimplefilterrj   __name__rR   strAssertionError)r"   wexc_names   `  r   assert_warnsr     s     		 	 	-h' 
. 
6A
666!$$ ,x7
88 
.	-  !x=!s?   BA1#BB #B1
A?;BBBBBc                  D    \ rS rSr\S 5       r\S 5       r\S 5       rSrg)NumpyAliasTestBasei)  c                    [        5       erx   )NotImplementedErrorselfs    r   funcNumpyAliasTestBase.func+  s    !##r   c                6    [        [        U R                  5      $ rx   )getattrcupyr   r   s    r   	cupy_funcNumpyAliasTestBase.cupy_func/  s    tTYY''r   c                6    [        [        U R                  5      $ rx   )r   r$   r   r   s    r   
numpy_funcNumpyAliasTestBase.numpy_func3  s    udii((r    N)	r   
__module____qualname____firstlineno__propertyr   r   r   __static_attributes__r   r   r   r   r   )  s<    $ $ ( ( ) )r   r   c                       \ rS rSrS rS rSrg)NumpyAliasBasicTestBasei8  c                t    [         R                  nU" U R                  5      U" U R                  5      :X  d   eg rx   )inspect	signaturer   r   )r   fs     r   test_argspec$NumpyAliasBasicTestBase.test_argspec:  s-     Adoo$6666r   c                    U R                   nU R                  n[        US5      (       d   eUR                  c   eUR                  S:w  d   eUR                  UR                  Ld   eg )N__doc__ )r   r   hasattrr   )r   r   r   s      r   test_docstring&NumpyAliasBasicTestBase.test_docstring>  sg    NN	__
y),,,,  ,,,  B&&&  
(:(::::r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   8  s    7;r   r   c                      \ rS rSrS rSrg)NumpyAliasValuesTestBaseiG  c                p    U R                   " U R                  6 U R                  " U R                  6 :X  d   eg rx   )r   argsr   r   s    r   test_values$NumpyAliasValuesTestBase.test_valuesI  s*    ~~tyy)T__dii-HHHHr   r   N)r   r   r   r   r   r   r   r   r   r   r   G  s    Ir   r   r)   )times_calledc              /     #    [         R                  " U0 UD6 nSv   UR                  U :X  d   e SSS5        g! , (       d  f       g= f7f)a  A handy wrapper for unittest.mock to check if a function is called.

Args:
    *args: Arguments of `mock.patch`.
    times_called (int): The number of times the function should be
        called. Default is ``1``.
    **kwargs: Keyword arguments of `mock.patch`.

N)r   patch
call_count)r   r   kwargshandles       r   assert_function_is_calledr   M  s<      
T	$V	$  L000 
%	$	$s   A:	A
AA)r   r   returnzCallable[[Callable], Callable])r   r   r   bool)r%   r   r   r   )*
__future__r   
contextlibimportlib.metadatar   r   unittestr   collections.abcr   r   r   r$   r   
cupy._corer   cupy.testing._pytest_implr   pytestmarkskipifr	   __annotations__skipIfr   r   r&   float32r9   r=   rH   rZ   rb   rs   contextmanagerr   TestCaser   r   r   r   AssertFunctionIsCalledr   r   r   <module>r      sM   "      $ 3     2>>=C[[=O=OG:OooG=0.. !S A6 %) 46 emm2AS 3H emmUP> ,0u}} 42 emm3@D3l 9 9 )** );0 ;I1 I 23 1 1  3 r   