
    
9j                        S SK Jr  S SKrS SKrS SKJr  S SKJr   " S S5      r\R                  " SSS	S
5      r	\R                  " SSSS5      r
g)    )annotationsN)_core)internalc                  R    \ rS rSrSrS rS rS rS rS r	S r
\S	 5       rS
 rSrg)flatiter
   a,  Flat iterator object to iterate over arrays.

A flatiter iterator is returned by ``x.flat`` for any array ``x``. It
allows iterating over the array as if it were a 1-D array, either in a
for-loop or by calling its ``next`` method.

Iteration is done in row-major, C-style order (the last index varying the
fastest).

Attributes:
    base (cupy.ndarray): A reference to the array that is iterated over.

.. note::
   Restricted support of basic slicing is currently supplied. Advanced
   indexing is not supported yet.

.. seealso:: :func:`numpy.flatiter`

c                    Xl         SU l        g )Nr   _base_index)selfas     P/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_indexing/iterate.py__init__flatiter.__init__   s    
    c                   U[         L a  X S S & g [        U[        5      (       a  [        S5      e[        U[        5      (       a  [        S5      e[
        R                  " U5      (       aa  [        U5      nU R                  nUR                  n/ nUR                   H  nXF-  nUR                  X-  5        X-  nM      X#[        U5      '   g [        U[        5      (       a  U R                  n[        R                  " XR                  5      nUR                  nUR                   nUR"                  UR                  -
  nUS:  a  US-
  U-  S-   nOUS-   U-  S-   n[$        R&                  " X#R(                  S9n[+        X'XUS9  g [        S5      e)Nunsupported iterator indexr      )dtypesize)Ellipsis
isinstancetuple
IndexErrorboolnumpyisscalarintr   r   shapeappendslicer   complete_slicestartstepstopcupyasarrayr   _flatiter_setitem_slice)	r   indvaluebaser   indicesss_starts_steps	            r   __setitem__flatiter.__setitem__#   sW   (?Gc5!!9::c4  9::>>#c(C::D99DGZZys{+   $)w c5!!::D''YY7AggGVVF66AGG#DzqV+a/qV+a/LLjj9E#EFtL566r   c                   U[         L a  U S S  $ [        U[        5      (       a  [        S5      e[        U[        5      (       a  [        S5      e[
        R                  " U5      (       ao  [        U5      nU R                  nUR                  n/ nUR                   H  nX5-  nUR                  X-  5        X-  nM      U[        U5         R                  5       $ [        U[        5      (       a  U R                  n[        R                  " XR                  5      nUR                   nUR"                  nUR$                  UR                   -
  nUS:  a  US-
  U-  S-   nOUS-   U-  S-   n['        X&XsS9$ [        S5      e)Nr   r   r   r   )r   r   r   r   r   r   r   r    r   r   r!   r"   copyr#   r   r$   r%   r&   r'   _flatiter_getitem_slice)r   r+   r-   r   r.   r/   r0   r1   s           r   __getitem__flatiter.__getitem__J   sK   (?7Nc5!!9::c4  9::>>#c(C::D99DGZZys{+   g',,..c5!!::D''YY7AggGVVF66AGG#DzqV+a/qV+a/*4&LL566r   c                    U $ N r   s    r   __iter__flatiter.__iter__m   s    r   c                ~    U R                   nU[        U 5      :X  a
  [        5       eU =R                   S-  sl         X   $ )Nr   )r   lenStopIteration)r   indexs     r   __next__flatiter.__next__p   s5    CI/!q{r   c                6    U R                   R                  5       $ )z*Get a copy of the iterator as a 1-D array.)r-   flattenr<   s    r   r5   flatiter.copyw   s    yy  ""r   c                    U R                   $ )z/A reference to the array that is iterated over.)r   r<   s    r   r-   flatiter.base{   s     zzr   c                .    U R                   R                  $ r:   )r-   r   r<   s    r   __len__flatiter.__len__   s    yy~~r   r
   N)__name__
__module____qualname____firstlineno____doc__r   r2   r7   r=   rC   r5   propertyr-   rK   __static_attributes__r;   r   r   r   r   
   s@    (%7N!7F#  (r   r   z"raw T val, int64 start, int64 stepzraw T az)a[start + i * step] = val[i % val.size()]cupy_flatiter_setitem_slicez raw T a, int64 start, int64 stepzT ozo = a[start + i * step]cupy_flatiter_getitem_slice)
__future__r   r   r(   r   
cupy._corer   r   ElementwiseKernelr*   r6   r;   r   r   <module>rY      s]    "    G GT  11()/!#   11&!# r   