Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/lib/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/lib/__pycache__/arrayterator.cpython-311.pyc

�

�܋f���B�dZddlmZddlmZdgZGd�d��ZdS)a$
A buffered iterator for big arrays.

This module solves the problem of iterating over a big file-based array
without having to read it into memory. The `Arrayterator` class wraps
an array object, and when iterated it will return sub-arrays with at most
a user-specified number of elements.

�)�mul)�reduce�Arrayteratorc�^�eZdZdZd
d�Zd�Zd�Zd�Zed���Z	ed���Z
d	�ZdS)ra�
    Buffered iterator for big arrays.

    `Arrayterator` creates a buffered iterator for reading big arrays in small
    contiguous blocks. The class is useful for objects stored in the
    file system. It allows iteration over the object *without* reading
    everything in memory; instead, small blocks are read and iterated over.

    `Arrayterator` can be used with any object that supports multidimensional
    slices. This includes NumPy arrays, but also variables from
    Scientific.IO.NetCDF or pynetcdf for example.

    Parameters
    ----------
    var : array_like
        The object to iterate over.
    buf_size : int, optional
        The buffer size. If `buf_size` is supplied, the maximum amount of
        data that will be read into memory is `buf_size` elements.
        Default is None, which will read as many element as possible
        into memory.

    Attributes
    ----------
    var
    buf_size
    start
    stop
    step
    shape
    flat

    See Also
    --------
    ndenumerate : Multidimensional array iterator.
    flatiter : Flat array iterator.
    memmap : Create a memory-map to an array stored in a binary file on disk.

    Notes
    -----
    The algorithm works by first finding a "running dimension", along which
    the blocks will be extracted. Given an array of dimensions
    ``(d1, d2, ..., dn)``, e.g. if `buf_size` is smaller than ``d1``, the
    first dimension will be used. If, on the other hand,
    ``d1 < buf_size < d1*d2`` the second dimension will be used, and so on.
    Blocks are extracted along this dimension, and when the last block is
    returned the process continues from the next dimension, until all
    elements have been read.

    Examples
    --------
    >>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
    >>> a_itor = np.lib.Arrayterator(a, 2)
    >>> a_itor.shape
    (3, 4, 5, 6)

    Now we can iterate over ``a_itor``, and it will return arrays of size
    two. Since `buf_size` was smaller than any dimension, the first
    dimension will be iterated over first:

    >>> for subarr in a_itor:
    ...     if not subarr.all():
    ...         print(subarr, subarr.shape) # doctest: +SKIP
    >>> # [[[[0 1]]]] (1, 1, 1, 2)

    Nc��||_||_d�|jD��|_d�|jD��|_d�|jD��|_dS)Nc��g|]}d��S�r���.0�dims  �M/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/lib/arrayterator.py�
<listcomp>z)Arrayterator.__init__.<locals>.<listcomp>Xs��-�-�-�C�a�-�-�-�c��g|]}|��Sr
r
rs  rrz)Arrayterator.__init__.<locals>.<listcomp>Ys��.�.�.�S�S�.�.�.rc��g|]}d��S)�r
rs  rrz)Arrayterator.__init__.<locals>.<listcomp>Zs��,�,�,�3�Q�,�,�,r)�var�buf_size�shape�start�stop�step)�selfrrs   r�__init__zArrayterator.__init__TsY����� ��
�-�-�3�9�-�-�-��
�.�.�C�I�.�.�.��	�,�,�#�)�,�,�,��	�	�	rc�,�t|j|��S�N)�getattrr)r�attrs  r�__getattr__zArrayterator.__getattr__\s���t�x��&�&�&rc��t|t��s|f}g}t|��|j}}|D]�}|tur<|�t
d��g||z
dzz��t|��}�Gt|t��r(|�t
||dzd������|�|����t|��}t|��|kr&|t
d��f|t|��z
zz
}|�	|j
|j��}tt|j|j|j|����D]l\}\}}	}
}||jpdz|j|<|
|jpdz|j|<||jp|	|z
z|j|<t#|	|j|��|j|<�m|S)z-
        Return a new arrayterator.

        Nrr)�
isinstance�tuple�len�ndim�Ellipsis�extend�slice�int�append�	__class__rr�	enumerate�ziprrr�min)r�index�fixed�length�dims�slice_�out�irrrs           r�__getitem__zArrayterator.__getitem___s����%��'�'�	��H�E����5�z�z�4�9����	%�	%�F���!�!����e�D�k�k�]�d�6�k�!�m�<�=�=�=��U������F�C�(�(�
%����U�6�6�!�8�Q�7�7�8�8�8�8����V�$�$�$�$��e�����u�:�:�����e�D�k�k�^�t�C��J�J��7�7�E��n�n�T�X�t�}�5�5��.7��D�J��	�4�9�e�<�<�/>�/>�	1�	1�*�A�*��t�T�6� �F�L�$5�A�6�C�I�a�L��&�+�"2��3�C�H�Q�K��6�;�#<�$�u�*�=�C�H�Q�K��d�C�H�Q�K�0�0�C�H�Q�K�K��
rc��td�t|j|j|j��D����}|j|S)z-
        Return corresponding data.

        c3�(K�|]
}t|�V��dSr�r(�r�ts  r�	<genexpr>z)Arrayterator.__array__.<locals>.<genexpr>�s6����3�3�Q�u�a�y�3�3�3�3�3�3r)r#r-rrrr)rr3s  r�	__array__zArrayterator.__array__sR��
�3�3�#��
�D�I�t�y�+2�+2�3�3�3�3�3���x���rc#�.K�|D]}|jEd{V���dS)aG
        A 1-D flat iterator for Arrayterator objects.

        This iterator returns elements of the array to be iterated over in
        `Arrayterator` one by one. It is similar to `flatiter`.

        See Also
        --------
        Arrayterator
        flatiter

        Examples
        --------
        >>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
        >>> a_itor = np.lib.Arrayterator(a, 2)

        >>> for subarr in a_itor.flat:
        ...     if not subarr:
        ...         print(subarr, type(subarr))
        ...
        0 <class 'numpy.int64'>

        N)�flat)r�blocks  rr?zArrayterator.flat�s>����2�	"�	"�E��z�!�!�!�!�!�!�!�!�	"�	"rc�p�td�t|j|j|j��D����S)zk
        The shape of the array to be iterated over.

        For an example, see `Arrayterator`.

        c3�:K�|]\}}}||z
dz
|zdzV��dS)rNr
)rrrrs    rr<z%Arrayterator.shape.<locals>.<genexpr>�sK����7�7�2C�%��t�t�E�z�!�|�d�*�1�,�7�7�7�7�7�7r)r#r-rrr)rs rrzArrayterator.shape�sD���7�7��D�J��	�4�9�5�5�7�7�7�7�7�	7rc#�K�d�|jD��rdS|jdd�}|jdd�}|jdd�}|jj}	|jptt|j��}d}t|dz
dd��D]�}|dkr||dz||<n;||j|kr|||||zz||<|}n|j|||<t|j|||��||<||j|z}��td�t|||��D����}|j|V�||||<t|dz
dd��D]J}|||j|kr1|j|||<||dz
xx|j|dz
z
cc<�K|d|jdkrdS��z)Nc��g|]
}|dk�|��Sr	r
rs  rrz)Arrayterator.__iter__.<locals>.<listcomp>�s��2�2�2�C�����C���rTrr���c3�(K�|]
}t|�V��dSrr9r:s  rr<z(Arrayterator.__iter__.<locals>.<genexpr>�s&����E�E��5�!�9�E�E�E�E�E�Er)
rrrrrr%rrr�ranger.r#r-)	rrrr�ndims�count�rundimr5r3s	         r�__iter__zArrayterator.__iter__�s����2�2�4�:�2�2�2�	��F��
�1�1�1�
���y����|���y����|����
��"	��M�<�V�C���%<�%<�E�
�F��5��7�B��+�+�

-�

-���A�:�:�#�A�h�q�j�D��G�G��d�j��m�+�+�#�A�h��t�A�w��6�D��G��F�F�#�i��l�D��G��d�i��l�D��G�4�4��Q���t�z�!�}�,����E�E�c�%��t�.D�.D�E�E�E�E�E�F��(�6�"�"�"�"�!��L�E�&�M��5��7�A�r�*�*�
1�
1����8�t�y��|�+�+�#�z�!�}�E�!�H��!�A�#�J�J�J�$�)�A�a�C�.�0�J�J�J���Q�x�4�9�Q�<�'�'���E"	rr)�__name__�
__module__�__qualname__�__doc__rr r6r=�propertyr?rrKr
rrrrs�������A�A�F-�-�-�-�'�'�'����@ � � ��"�"��X�"�6�7�7��X�7�,�,�,�,�,rN)rO�operatorr�	functoolsr�__all__rr
rr�<module>rTsy�����������������
��K�K�K�K�K�K�K�K�K�Kr

Hacked By AnonymousFox1.0, Coded By AnonymousFox