
    `i                         d dl Z d dlZd dlmZ d dlmZ  G d d          Z ej        dddd	          Z ej        d
ddd          ZdS )    N)_core)internalc                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	e
d             Zd	 Zd
S )flatitera\  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                 "    || _         d| _        d S )Nr   )_base_index)selfas     j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_indexing/iterate.py__init__zflatiter.__init__   s    
    c                    |t           u r	|| d d <   d S t          |t                    rt          d          t          |t                    rt          d          t          j        |          r_t          |          }| j        }|j	        }g }|j
        D ]$}||z  }|                    ||z             ||z  }%||t          |          <   d S t          |t                    r| j        }t          j        ||j	                  }|j        }|j        }|j        |j        z
  }|dk    r|dz
  |z  dz   }n|dz   |z  dz   }t%          j        ||j                  }t+          |||||           d S t          d          )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__zflatiter.__setitem__!   s   (??DGFc5!! 	;9:::c4   	;9:::># 
	c((C:D9DGZ  qysd{+++t#(Dw Fc5!! 	:D'TY77AgGVF6AG#DzzqV+a/qV+a/Ldj999E#E7FDtLLLLF5666r   c                    |t           u r
| d d          S t          |t                    rt          d          t          |t                    rt          d          t          j        |          rrt          |          }| j        }|j	        }g }|j
        D ]$}||z  }|                    ||z             ||z  }%|t          |                                                   S t          |t                    rn| j        }t          j        ||j	                  }|j        }|j        }|j        |j        z
  }|dk    r|dz
  |z  dz   }n|dz   |z  dz   }t'          ||||          S t          d          )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+   r,   r-   s           r   __getitem__zflatiter.__getitem__H   s   (??7Nc5!! 	;9:::c4   	;9:::># 		/c((C:D9DGZ  qysd{+++tg',,...c5!! 
	M:D'TY77AgGVF6AG#DzzqV+a/qV+a/*4&tLLLL5666r   c                     | S N r
   s    r   __iter__zflatiter.__iter__k   s    r   c                     | j         }|t          |           k    rt                      | xj         dz  c_         | |         S )Nr   )r	   lenStopIteration)r
   indexs     r   __next__zflatiter.__next__n   s>    CII//!qE{r   c                 4    | j                                         S )z*Get a copy of the iterator as a 1-D array.)r)   flattenr6   s    r   r0   zflatiter.copyu   s    y  """r   c                     | j         S )z/A reference to the array that is iterated over.)r   r6   s    r   r)   zflatiter.basey   s     zr   c                     | j         j        S r4   )r)   r   r6   s    r   __len__zflatiter.__len__   s    y~r   N)__name__
__module____qualname____doc__r   r.   r2   r7   r<   r0   propertyr)   rA   r5   r   r   r   r      s         (  %7 %7 %7N!7 !7 !7F    # # #   X(    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)	r   r$   r   
cupy._corer   r   ElementwiseKernelr&   r1   r5   r   r   <module>rK      s                 G G G G G G G GT 2%1()/!# #  2%1&!# #   r   