
    Khx1                         S SK Jr  S SKrS SKrSSKJr  SSKJrJ	r	J
r
  S/r\
r/ SQrS	S
/rSSS	S
S.r\" S5       " S S\	5      5       rg)    )nullcontextN   )
set_module   )uint8ndarraydtypememmap)rcr+w+r   r   r   r   )readonlycopyonwrite	readwritewritenumpyc                   `   ^  \ rS rSrSrSr\SSSS4S jrS	 rS
 r	SU 4S jjr
U 4S jrSrU =r$ )r
      a  Create a memory-map to an array stored in a *binary* file on disk.

Memory-mapped files are used for accessing small segments of large files
on disk, without reading the entire file into memory.  NumPy's
memmap's are array-like objects.  This differs from Python's ``mmap``
module, which uses file-like objects.

This subclass of ndarray has some unpleasant interactions with
some operations, because it doesn't quite fit properly as a subclass.
An alternative to using this subclass is to create the ``mmap``
object yourself, then create an ndarray with ndarray.__new__ directly,
passing the object created in its 'buffer=' parameter.

This class may at some point be turned into a factory function
which returns a view into an mmap buffer.

Flush the memmap instance to write the changes to the file. Currently there
is no API to close the underlying ``mmap``. It is tricky to ensure the
resource is actually closed, since it may be shared between different
memmap instances.


Parameters
----------
filename : str, file-like object, or pathlib.Path instance
    The file name or file object to be used as the array data buffer.
dtype : data-type, optional
    The data-type used to interpret the file contents.
    Default is `uint8`.
mode : {'r+', 'r', 'w+', 'c'}, optional
    The file is opened in this mode:

    +------+-------------------------------------------------------------+
    | 'r'  | Open existing file for reading only.                        |
    +------+-------------------------------------------------------------+
    | 'r+' | Open existing file for reading and writing.                 |
    +------+-------------------------------------------------------------+
    | 'w+' | Create or overwrite existing file for reading and writing.  |
    |      | If ``mode == 'w+'`` then `shape` must also be specified.    |
    +------+-------------------------------------------------------------+
    | 'c'  | Copy-on-write: assignments affect data in memory, but       |
    |      | changes are not saved to disk.  The file on disk is         |
    |      | read-only.                                                  |
    +------+-------------------------------------------------------------+

    Default is 'r+'.
offset : int, optional
    In the file, array data starts at this offset. Since `offset` is
    measured in bytes, it should normally be a multiple of the byte-size
    of `dtype`. When ``mode != 'r'``, even positive offsets beyond end of
    file are valid; The file will be extended to accommodate the
    additional data. By default, ``memmap`` will start at the beginning of
    the file, even if ``filename`` is a file pointer ``fp`` and
    ``fp.tell() != 0``.
shape : int or sequence of ints, optional
    The desired shape of the array. If ``mode == 'r'`` and the number
    of remaining bytes after `offset` is not a multiple of the byte-size
    of `dtype`, you must specify `shape`. By default, the returned array
    will be 1-D with the number of elements determined by file size
    and data-type.

    .. versionchanged:: 2.0
     The shape parameter can now be any integer sequence type, previously
     types were limited to tuple and int.

order : {'C', 'F'}, optional
    Specify the order of the ndarray memory layout:
    :term:`row-major`, C-style or :term:`column-major`,
    Fortran-style.  This only has an effect if the shape is
    greater than 1-D.  The default order is 'C'.

Attributes
----------
filename : str or pathlib.Path instance
    Path to the mapped file.
offset : int
    Offset position in the file.
mode : str
    File mode.

Methods
-------
flush
    Flush any changes in memory to file on disk.
    When you delete a memmap object, flush is called first to write
    changes to disk.


See also
--------
lib.format.open_memmap : Create or load a memory-mapped ``.npy`` file.

Notes
-----
The memmap object can be used anywhere an ndarray is accepted.
Given a memmap ``fp``, ``isinstance(fp, numpy.ndarray)`` returns
``True``.

Memory-mapped files cannot be larger than 2GB on 32-bit systems.

When a memmap causes a file to be created or extended beyond its
current size in the filesystem, the contents of the new part are
unspecified. On systems with POSIX filesystem semantics, the extended
part will be filled with zero bytes.

Examples
--------
>>> import numpy as np
>>> data = np.arange(12, dtype='float32')
>>> data.resize((3,4))

This example uses a temporary file so that doctest doesn't write
files to your directory. You would use a 'normal' filename.

>>> from tempfile import mkdtemp
>>> import os.path as path
>>> filename = path.join(mkdtemp(), 'newfile.dat')

Create a memmap with dtype and shape that matches our data:

>>> fp = np.memmap(filename, dtype='float32', mode='w+', shape=(3,4))
>>> fp
memmap([[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]], dtype=float32)

Write data to memmap array:

>>> fp[:] = data[:]
>>> fp
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)

>>> fp.filename == path.abspath(filename)
True

Flushes memory changes to disk in order to read them back

>>> fp.flush()

Load the memmap and verify data was stored:

>>> newfp = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> newfp
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)

Read-only memmap:

>>> fpr = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> fpr.flags.writeable
False

Copy-on-write memmap:

>>> fpc = np.memmap(filename, dtype='float32', mode='c', shape=(3,4))
>>> fpc.flags.writeable
True

It's possible to assign to copy-on-write array, but values are only
written into the memory copy of the array, and not written to disk:

>>> fpc
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
>>> fpc[0,:] = 0
>>> fpc
memmap([[  0.,   0.,   0.,   0.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)

File on disk is unchanged:

>>> fpr
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)

Offset into a memmap:

>>> fpo = np.memmap(filename, dtype='float32', mode='r', offset=16)
>>> fpo
memmap([  4.,   5.,   6.,   7.,   8.,   9.,  10.,  11.], dtype=float32)

g      Yr   r   NCc           
         SS K nSS Kn [        U   nUS:X  a  Uc  [        S5      e[        US5      (       a  [        U5      n
O&[        UR                  U5      US:X  a  SOUS-   5      n
U
 nUR                  SS	5        UR                  5       n[        U5      nUR                   nUc   X-
  nX-  (       a  [        S
5      eX-  nU4nO`[#        U5      [$        [        4;  a   [&        R(                  " U5      /n[%        U5      n[,        R.                  " S5      nU H  nUU-  nM
     [1        UUU-  -   5      nUS;   aG  [3        US5      nX:  a6  UR                  US-
  S5        UR5                  S5        UR7                  5         US:X  a  UR8                  nOUS:X  a  UR:                  nOUR<                  nXDUR>                  -  -
  nUU-  nUS:X  a#  US:  a  XR>                  -  nUUR>                  -  nUU-
  nUR                  URA                  5       UUUS9n[B        RD                  " XUUUUS9nUUl#        UUl$        UUl%        [M        XRN                  5      (       a  URQ                  5       Ul)        Ob[        US5      (       aJ  [M        URT                  [V        5      (       a+  URX                  R[                  URT                  5      Ul)        OS Ul)        S S S 5        U$ ! [         aS  n	U[        ;  a>  [        SR                  [        [        [        R                  5       5      -   U5      5      S e S n	A	GN+S n	A	ff = f! [*         a     GNYf = f! , (       d  f       W$ = f)Nr   z#mode must be one of {!r} (got {!r})r   z#shape must be given if mode == 'w+'readr   r   br   z?Size of available data is not a multiple of the data-type size.r   )r   r       )accessoffset)r	   bufferr   ordername).mmapos.pathmode_equivalentsKeyErrorvalid_filemodes
ValueErrorformatlistkeyshasattrr   openfspathseektell
dtypedescritemsizetypetupleoperatorindex	TypeErrornpintpintmaxr   flushACCESS_COPYACCESS_READACCESS_WRITEALLOCATIONGRANULARITYfilenor   __new___mmapr   mode
isinstancePathLikeresolvefilenamer   strpathabspath)subtyperE   r	   rA   r   shaper   r    osef_ctxfidflendescr_dbytesbytessizekaccstartarray_offsetmmselfs                          D/var/www/html/env/lib/python3.13/site-packages/numpy/_core/memmap.pyr?   memmap.__new__   s,    		#D)D 4<EMBCC8V$$)E		(#s2E
 cHHQN88:Du%EnnG}?$ &> ? ?';udm3!)!6 7 ewwqzAAID  g-.E|# E1<HHUQY*IIe$IIKs{&&&&''d&@&@@@EUNE zeai333333!E>L3::<s5IB??7r*6eEDDJ DKDI(KK00 !) 0 0 2f%%*SXXs*C*C " 9 !%G J o  	?* 9VOd3C3H3H3J.KKTR  +	F % # UJ sJ   	K& ,A6M#M:G"M&
M0AL>>M
MMMM
M&c                    [        US5      (       a`  [        R                  " X5      (       aE  UR                  U l        UR                  U l        UR
                  U l        UR                  U l        g S U l        S U l        S U l        S U l        g )Nr@   )r)   r5   may_share_memoryr@   rE   r   rA   )rY   objs     rZ   __array_finalize__memmap.__array_finalize__6  sg    3  R%8%8%C%CDJLLDM**DKDIDJ DMDKDI    c                     U R                   b7  [        U R                   S5      (       a  U R                   R                  5         ggg)z
Write any changes in the array to the file on disk.

For further information, see `memmap`.

Parameters
----------
None

See Also
--------
memmap

Nr9   )baser)   r9   )rY   s    rZ   r9   memmap.flushB  s5     99 WTYY%@%@IIOO &A ra   c                    > [         TU ]  X5      nXL d  [        U 5      [        La  U$ U(       a  US   $ UR	                  [
        R                  5      $ )N )super__array_wrap__r0   r
   viewr5   r   )rY   arrcontextreturn_scalar	__class__s       rZ   rh   memmap.__array_wrap__T  sL    g$S2
 ;$t*F2J r7N xx

##ra   c                    > [         TU ]  U5      n[        U5      [        L a   UR                  c  UR                  [        S9$ U$ )N)r0   )rg   __getitem__r0   r
   r@   ri   r   )rY   r3   resrm   s      rZ   rp   memmap.__getitem__e  s=    g!%(9399#4888))
ra   )r@   rE   rA   r   )NF)__name__
__module____qualname____firstlineno____doc____array_priority__r   r?   r_   r9   rh   rp   __static_attributes____classcell__)rm   s   @rZ   r
   r
      s>    {z  ).T!#^@
$$" ra   )
contextlibr   r2   r   r5   _utilsr   numericr   r   r	   __all__r.   r$   writeable_filemodesr"   r
   rf   ra   rZ   <module>r      sk    "    * **
(Tl  	  GSW S Sra   