
    7Thwp                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJrJrJrJrJr  SSKJrJrJr  SSKJrJrJrJrJrJrJ r J!r!  \" S	\" 5       5        \" S
\" 5       5        \" S\" 5       5        \" S\" 5       5        \" S\" 5       5        \" S\" 5       5        Sr" " S S\#5      r$ " S S\5      r% " S S\5      r&SS jr'SS jr(S r)SS jr*g)zFUtilities for fast persistence of big data, with optional compression.    N)Path   )make_memmap)_COMPRESSORSLZ4_NOT_INSTALLED_ERRORBinaryZlibFileBZ2CompressorWrapperGzipCompressorWrapperLZ4CompressorWrapperLZMACompressorWrapperXZCompressorWrapperZlibCompressorWrapperlz4register_compressor)NDArrayWrapperZNDArrayWrapperload_compatibility)BUFFER_SIZEPickler	Unpickler_ensure_native_byte_order_read_bytes_reconstruct_validate_fileobject_and_memmap_write_fileobjectzlibgzipbz2lzmaxzr      c                   D    \ rS rSrSrS\4S jrS rS rS r	S r
S	 rS
rg)NumpyArrayWrapper@   a  An object to be persisted instead of numpy arrays.

This object is used to hack into the pickle machinery and read numpy
array data from our custom persistence format.
More precisely, this object is used for:
* carrying the information of the persisted array: subclass, shape, order,
dtype. Those ndarray metadata are used to correctly reconstruct the array
with low level numpy functions.
* determining if memmap is allowed on the array.
* reading the array bytes from a file.
* reading the array using memorymap from a file.
* writing the array bytes to a file.

Attributes
----------
subclass: numpy.ndarray subclass
    Determine the subclass of the wrapped array.
shape: numpy.ndarray shape
    Determine the shape of the wrapped array.
order: {'C', 'F'}
    Determine the order of wrapped array data. 'C' is for C order, 'F' is
    for fortran order.
dtype: numpy.ndarray dtype
    Determine the data type of the wrapped array.
allow_mmap: bool
    Determine if memory mapping is allowed on the wrapped array.
    Default: False.
Fc                 L    Xl         X l        X0l        X@l        XPl        X`l        g)z4Constructor. Store the useful information for later.N)subclassshapeorderdtype
allow_mmapnumpy_array_alignment_bytes)selfr&   r'   r(   r)   r*   r+   s          K/var/www/auris/envauris/lib/python3.13/site-packages/joblib/numpy_pickle.py__init__NumpyArrayWrapper.__init__^   s&     !


$ ,G(    c                     [        U SS 5      $ )Nr+   )getattr)r,   s    r-   $safe_get_numpy_array_alignment_bytes6NumpyArrayWrapper.safe_get_numpy_array_alignment_bytesr   s     t:DAAr0   c                 |   [        SUR                  -  S5      nUR                  R                  (       a   [        R
                  " XR                  SS9  gU R                  5       nUb|  UR                  R                  5       nUS-   nUXd-  -
  n[        R                  USSS9nUR                  R                  U5        US:w  a   S	U-  n	UR                  R                  U	5        UR                  R                  U/ S
QUU R                  S9 H-  n
UR                  R                  U
R                  S5      5        M/     g)zWrite array bytes to pickler file handle.

This function is an adaptation of the numpy write_array function
available in version 1.10.1 in numpy/lib/format.py.
i   r      protocolNlittle)length	byteorderr      )external_loopbufferedzerosize_ok)flags
buffersizer(   C)maxitemsizer)   	hasobjectpickledumpfile_handler3   tellintto_byteswritenpnditerr(   tobytes)r,   arraypicklerrA   r+   current_pospos_after_padding_bytepadding_lengthpadding_length_bytepaddingchunks              r-   write_arrayNumpyArrayWrapper.write_arrayw   s&    7;
;;   KK22Q?*.*S*S*U'*6%11668)4q&!<*H"
 '*ll"1 '3 '# ##))*=>!Q&%6G''--g6 **B%jj	 +  ##))%--*<=r0   c                    [        U R                  5      S:X  a  SnOYU R                   Vs/ s H  oAR                  R                  U5      PM     nnUR                  R                  R                  U5      nU R                  R                  (       a"  [        R                  " UR                  5      nGO|U R                  5       nUbP  UR                  R                  S5      n[        R                  USS9n	U	S:w  a  UR                  R                  U	5        [        [!        [        U R                  R"                  5      -  n
UR                  R%                  X0R                  S9n['        SX:5       Hr  n[!        XU-
  5      n[        XR                  R"                  -  5      n[)        UR                  US5      nUR                  R+                  XR                  US9XkX-   & AMt     U R,                  S	:X  a(  U R                  SSS
2   Ul        UR/                  5       nOU R                  Ul        U(       a  [1        U5      nU$ s  snf )zRead array from unpickler file handle.

This function is an adaptation of the numpy read_array function
available in version 1.10.1 in numpy/lib/format.py.
r   r   Nr9   r;   )r)   z
array data)r)   countF)lenr'   rM   int64multiplyreducer)   rE   rF   loadrH   r3   readrJ   
from_bytesr   minrD   emptyranger   
frombufferr(   	transposer   )r,   	unpicklerensure_native_byte_orderr\   xshape_int64rP   r+   padding_byterT   max_read_counti
read_count	read_sizedatas                  r-   
read_arrayNumpyArrayWrapper.read_array   s    tzz?aE ;?**E*Q<<--a0*KELL))00=E::KK	 5 56E*.*S*S*U'*6(4499!<!$!Q!Q&))..~> )CTZZ=P=P,QQNLL&&uJJ&?E1e4 ;

ZZ-@-@ @A	"9#8#8)\R,5LL,C,C

* -D -!.)  5 zzS "jj2.)"jj#-e4EW Fs   $Ic           	      R   UR                   R                  5       nUnU R                  5       nUb6  UR                   R                  S5      n[        R                  USS9nX6S-   -  nUR                  S:X  a  SUl        [        UR                  U R                  U R                  U R                  UR                  US9nUR                   R                  X7R                  -   5        Uc@  U[        -  S:w  a3  SU S	UR                   R                   S
3n[         R"                  " U5        U$ )z!Read an array using numpy memmap.r   r9   r[   zw+zr+)r)   r'   r(   modeoffsetr   zThe memmapped array z loaded from the file a   is not byte aligned. This may cause segmentation faults if this memmapped array is used in some libraries like BLAS or PyTorch. To get rid of this warning, regenerate your pickle file with joblib >= 1.2.0. See https://github.com/joblib/joblib/issues/563 for more details)rH   rI   r3   rd   rJ   re   	mmap_moder   filenamer)   r'   r(   seeknbytesNUMPY_ARRAY_ALIGNMENT_BYTESnamewarningswarn)	r,   rk   rR   ry   r+   ro   rT   marraymessages	            r-   	read_mmapNumpyArrayWrapper.read_mmap   s"   ++002&*&O&O&Q#&2$0055a8L ^^LH^MNq((F$&"&I******$$
 	""6MM#9: (/99Q> 'vh.D((--. /##  MM'"r0   c                    UR                   b1  U R                  (       a   U(       a   S5       eU R                  U5      nOU R                  X5      n[	        US5      (       ab  U R
                  UR                  R                  UR                  R                  4;  a(  [        U R
                  SS5      nUR                  U5      $ U$ )a?  Read the array corresponding to this wrapper.

Use the unpickler to get all information to correctly read the array.

Parameters
----------
unpickler: NumpyUnpickler
ensure_native_byte_order: bool
    If true, coerce the array to use the native endianness of the
    host system.

Returns
-------
array: numpy.ndarray

zNMemmaps cannot be coerced to a given byte order, this code path is impossible.__array_prepare__)r   b)rz   r*   r   ru   hasattrr&   rM   ndarraymemmapr   r   )r,   rk   rl   rP   	new_arrays        r-   rd   NumpyArrayWrapper.read  s    $ *t/ 0/ NN9-EOOIHE 5-..4==LL  LLI
 4

 %T]]D#>I..u55Lr0   )r*   r)   r+   r(   r'   r&   N)__name__
__module____qualname____firstlineno____doc__r~   r.   r3   rX   ru   r   rd   __static_attributes__ r0   r-   r#   r#   @   s3    F $?G(B
&>P6p*X$r0   r#   c                   b    \ rS rSrSr\R                  R                  5       rSS jrS r	S r
Srg)	NumpyPickleri.  a|  A pickler to persist big data efficiently.

The main features of this object are:
* persistence of numpy arrays in a single file.
* optional compression with a special care on avoiding memory copies.

Attributes
----------
fp: file
    File object handle used for serializing the input object.
protocol: int, optional
    Pickle protocol used. Default is pickle.DEFAULT_PROTOCOL.
Nc                     Xl         [        U R                   [        5      U l        Uc  [        R
                  n[        R                  " X R                   US9   SS KnX0l
        g ! [         a    S n Nf = f)Nr7   r   )rH   
isinstancer   r>   rF   DEFAULT_PROTOCOLr   r.   numpyImportErrorrM   )r,   fpr8   rM   s       r-   r.   NumpyPickler.__init__?  sj    "4#3#3^D ..H//(C	   	B	s   A$ $A32A3c                    UR                   R                  (       a  UR                   R                  (       d  SOSnU R                  (       + =(       a    UR                  R
                  (       + n0 n U R                  R                  5         [        [        U5      UR                  UUR                  4SU0UD6nU$ ! [        R                   a    SS0n NJf = f)z<Create and returns a numpy array wrapper from a numpy array.r]   rB   r+   Nr*   )r@   f_contiguousc_contiguousr>   r)   rE   rH   rI   ioUnsupportedOperationr#   typer'   )r,   rP   r(   r*   kwargswrappers         r-   _create_array_wrapper"NumpyPickler._create_array_wrapperP  s     KK,,U[[5M5MCTW 	 &Du{{/D/D+D
	;!!# $KKKKK	

 "
 
  && 	;3T:F	;s   1B; ;CCc                 "   U R                   b  [        U5      U R                   R                  U R                   R                  U R                   R                  4;   a  [        U5      U R                   R                  L a  U R                   R                  U5      nU R                  U5      n[        R                  " X5        U R                  S:  a  U R                  R                  SS9  UR                  X5        g[        R                  " X5      $ )a  Subclass the Pickler `save` method.

This is a total abuse of the Pickler class in order to use the numpy
persistence function `save` instead of the default pickle
implementation. The numpy array is replaced by a custom wrapper in the
pickle persistence stack and the serialized array is written right
after in the file. Warning: the file produced does not follow the
pickle format. As such it can not be read with `pickle.load`.
N   T)force)rM   r   r   matrixr   
asanyarrayr   r   saveprotoframercommit_framerX   )r,   objr   s      r-   r   NumpyPickler.saveh  s     7749GGOOGGNNGGNN1
 $

 CyDGGNN*gg((- 005GLL' zzQ((t(4 *||D&&r0   )r>   rH   rM   N)r   r   r   r   r   r   dispatchcopyr.   r   r   r   r   r0   r-   r   r   .  s,     $$&H"0#'r0   r   c                       \ rS rSrSr\R                  R                  5       rSS jrS r	\	\\
R                  S   '   Srg)	NumpyUnpickleri  a  A subclass of the Unpickler to unpickle our numpy pickles.

Attributes
----------
mmap_mode: str
    The memorymap mode to use for reading numpy arrays.
file_handle: file_like
    File object to unpickle from.
ensure_native_byte_order: bool
    If True, coerce the array to use the native endianness of the
    host system.
filename: str
    Name of the file to unpickle from. It should correspond to file_handle.
    This parameter is required when using mmap_mode.
np: module
    Reference to numpy module if numpy is installed else None.

Nc                    [         R                  R                  U5      U l        X@l        X l        Xl        SU l        X0l        [        R                  " X R
                  5         SS KnXPl        g ! [         a    S n Nf = f)NFr   )ospathdirname_dirnamerz   rH   r{   compat_moderl   r   r.   r   r   rM   )r,   r{   rH   rl   rz   rM   s         r-   r.   NumpyUnpickler.__init__  so     1"&  (@%4!1!12	   	B	s   %A0 0A?>A?c                    [         R                  " U 5        [        U R                  S   [        [
        45      (       a  U R                  c  [        S5      eU R                  R                  5       n[        U[        5      (       a  SU l	        UR                  U 5      nOUR                  X R                  5      nU R                  R                  U5        gg)a'  Called to set the state of a newly created object.

We capture it to replace our place-holder objects, NDArrayWrapper or
NumpyArrayWrapper, by the array we are interested in. We
replace them directly in the stack of pickler.
NDArrayWrapper is used for backward compatibility with joblib <= 0.9.
r^   Nz@Trying to unpickle an ndarray, but numpy didn't import correctlyT)r   
load_buildr   stackr   r#   rM   r   popr   rd   rl   append)r,   array_wrapper_array_payloads      r-   r   NumpyUnpickler.load_build  s     	T" djjn~7H&IJJww!V  !JJNN,M -88#' !.!3!3D!9!.!3!3D:W:W!XJJn- Kr0   r   )r   r   rl   rH   r{   rz   rM   r   )r   r   r   r   r   r   r   r   r.   r   rF   BUILDr   r   r0   r-   r   r     s;    & !!&&(H$.: !+HV\\!_r0   r   c           
         [         b   [        U[         5      (       a  [        U5      n[        U[        5      n[        US5      nSnUSL a  SnOb[        U[        5      (       a.  [        U5      S:w  a  [        SR                  U5      5      eUu  pgO[        U[        5      (       a  UnSnXg4nOUnUS:X  a  [        c  [        [        5      eUbA  USLa<  U[        S	5      ;  a-  [        S
R                  U[        [        S	5      5      5      5      eU[        ;  a  [        SR                  U[        5      5      eU(       d$  U(       d  [        SU< S[        U5      < S35      eU(       ak  [        U[        5      (       dV  Sn[        R                  " 5        H)  u  pUR                  U	R                   5      (       d  M'  UnM+     U[        ;   a  US:X  a  SnUS:w  a-  [#        XU4S9 n
[%        XS9R'                  U 5        SSS5        OMU(       a.  [)        US5       n
[%        XS9R'                  U 5        SSS5        O[%        XS9R'                  U 5        U(       a  gU/$ ! , (       d  f       N= f! , (       d  f       N*= f)a,  Persist an arbitrary Python object into one file.

Read more in the :ref:`User Guide <persistence>`.

Parameters
----------
value: any Python object
    The object to store to disk.
filename: str, pathlib.Path, or file object.
    The file object or path of the file in which it is to be stored.
    The compression method corresponding to one of the supported filename
    extensions ('.z', '.gz', '.bz2', '.xz' or '.lzma') will be used
    automatically.
compress: int from 0 to 9 or bool or 2-tuple, optional
    Optional compression level for the data. 0 or False is no compression.
    Higher value means more compression, but also slower read and
    write times. Using a value of 3 is often a good compromise.
    See the notes for more details.
    If compress is True, the compression level used is 3.
    If compress is a 2-tuple, the first element must correspond to a string
    between supported compressors (e.g 'zlib', 'gzip', 'bz2', 'lzma'
    'xz'), the second element must be an integer from 0 to 9, corresponding
    to the compression level.
protocol: int, optional
    Pickle protocol, see pickle.dump documentation for more details.

Returns
-------
filenames: list of strings
    The list of file names in which the data is stored. If
    compress is false, each array is stored in a different file.

See Also
--------
joblib.load : corresponding loader

Notes
-----
Memmapping on load cannot be used for compressed files. Thus
using compression can significantly slow down loading. In
addition, compressed files take up extra memory during
dump and load.

NrL   r   T   zkCompress argument tuple should contain exactly 2 elements: (compress method, compress level), you passed {}r   F
   z=Non valid compress level given: "{}". Possible values are {}.zANon valid compression method given: "{}". Possible values are {}.z<Second argument should be a filename or a file-like object, z (type z) was given.r   )compressr7   wb)r   r   strr   tupler_   
ValueErrorformatr   r   rh   listr   r   itemsendswith	extensionr   r   rG   open)valuer{   r   r8   is_filename
is_fileobjcompress_methodcompress_levelr   
compressorfs              r-   rG   rG     s`   \ Jx66x=Xs+K7+JO4 	He	$	$x=ACCI6(CS  +3'	Hc	"	""#4!%CK011 	"%'%)+ KRRU2Y
 	
 l*OVV
 	
 z )14>C
 	

 :h66  , 2 2 4D  !5!566"& !5 l*~/B "N@
.33E:
 
 
(D!Q.33E: "! 	X166u=  :!
 

 "!s   'I!I2!
I/2
J c                     [        X XS9nSn UR                  5       nUR                  (       a  [        R                  " SU-  [
        SS9  U$ ! [         a  n[        S5      nXgl        UeSnAff = f)zInternal unpickling function.)rz   NzjThe file '%s' has been generated with a joblib version less than 0.10. Please regenerate this pickle file.   )
stacklevelzyYou may be trying to read with python 3 a joblib pickle generated with python 2. This feature is not supported by joblib.)	r   rc   r   r   r   DeprecationWarningUnicodeDecodeErrorr   	__cause__)fobjrl   r{   rz   rk   r   excnew_excs           r-   	_unpickler   e  s     0I Cnn  MM68@A #  J  7

  s   >A 
A0A++A0c           	          SSK JnJn  [        U S5       n[	        XPU5       u  nn[        USU US9nS S S 5        S S S 5        UR                  WR                  5        U(       a  U" U5        U$ ! , (       d  f       NB= f! , (       d  f       NK= f)Nr   )JOBLIB_MMAPSadd_maybe_unlink_finalizerrbFrl   r{   rz   )_memmapping_reducerr   r   r   r   r   addr{   )	r{   rz   unlink_on_gc_collectr   r   r   r   validated_mmap_moder   s	            r-   load_temporary_memmapr     s    M	h	,Q)D I
 ).!-	C E 
$ S\\""3'J) ED 
	s!   A?A.A?.
A<	8A??
Bc           	      ^   US:X  a  USL nU(       a  Ub  [        SU S35      e[        b   [        U [        5      (       a  [        U 5      n [	        U S5      (       a1  U n[        USS5      n [        X0U5       u  p4[        X2S9nSSS5        U$ [        U S	5       n[        X`U5       u  nn[        U[        5      (       a  [        U5      sSSS5        sSSS5        $ [        UUU US
9nSSS5        SSS5        W$ ! , (       d  f       W$ = f! , (       d  f       N*= f! , (       d  f       W$ = f)aT  Reconstruct a Python object from a file persisted with joblib.dump.

Read more in the :ref:`User Guide <persistence>`.

WARNING: joblib.load relies on the pickle module and can therefore
execute arbitrary Python code. It should therefore never be used
to load files from untrusted sources.

Parameters
----------
filename: str, pathlib.Path, or file object.
    The file object or path of the file from which to load the object
mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional
    If not None, the arrays are memory-mapped from the disk. This
    mode has no effect for compressed files. Note that in this
    case the reconstructed object might no longer match exactly
    the originally pickled object.
ensure_native_byte_order: bool, or 'auto', default=='auto'
    If True, ensures that the byte order of the loaded arrays matches the
    native byte ordering (or _endianness_) of the host system. This is not
    compatible with memory-mapped arrays and using non-null `mmap_mode`
    parameter at the same time will raise an error. The default 'auto'
    parameter is equivalent to True if `mmap_mode` is None, else False.

Returns
-------
result: any Python object
    The object stored in the file.

See Also
--------
joblib.dump : function to save an object

Notes
-----

This function can load numpy array files saved separately during the
dump. If the mmap_mode argument is given, it is passed to np.load and
arrays are loaded as memmaps. As a consequence, the reconstructed
object might not match the original pickled object. Note that if the
file was saved with compression, the arrays cannot be memmapped.
autoNzfNative byte ordering can only be enforced if 'mmap_mode' parameter is set to None, but got 'mmap_mode=z
' instead.rd   r    )rl   r   r   )
r   r   r   r   r   r2   r   r   r   r   )r{   rz   rl   r   _r   r   r   s           r-   rc   rc     sB   V  6)#,#4 I$922;JH
 	

 Jx66x=x  4,,TYG9DDTC H0 J+ (D!Q0iH M#dC(( .d3 IH "!  -E%1	 I "* J1 HG0 J) IH "!* Js<   7C:D&#D		DD(D:
D	
D	D
D,)r   N)r   N)Nr   )+r   r   r   rF   r   pathlibr   	backportsr   r   r   r   r   r	   r
   r   r   r   r   r   r   numpy_pickle_compatr   r   r   numpy_pickle_utilsr   r   r   r   r   r   r   r   r~   objectr#   r   r   rG   r   r   rc   r   r0   r-   <module>r      s    L 
 	    "     
	 	 	 F13 4 F13 4 E/1 2 F13 4 D-/ 0 E/1 2 ! g g\]'7 ]'@E+Y E+XHVD6Rr0   