§ <ˆj—ãó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 „Z dS) 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ú z)Arrayterator.__init__..Xs€Ð-Ð-Ð-˜C�aÐ-Ð-Ð-ócó—g|]}|‘ŒSr r r s rrz)Arrayterator.__init__..Ys€Ð.Ð.Ð.˜S�SÐ.Ð.Ð.rcó—g|]}d‘ŒS)ér r s rrz)Arrayterator.__init__..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ú z)Arrayterator.__array__..„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 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..¬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 r s rrz)Arrayterator.__iter__..±s€Ð 2Ð 2Ð 2�C¨°ª¨ˆC¨¨¨rTrréÿÿÿÿc3ó(K—|] }t|ŽV—ŒdSrr9r:s rr<z(Arrayterator.__iter__..Ð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úrTsyððððÐÐÐÐÐØÐÐÐÐÐà Ð €ðKðKðKðKðKñKôKðKðKðKr