� I�gi��L�dZddlZddlZddlZddlZddlmZddlmZm Z ddlm Z m Z m Z ddlm Z mZmZmZmZmZddlmZmZdd lmZmZdd lmZmZdd lmZdd lmZdd lmZddlmZddlm Z e de ����e de����e de����e de����e de����e de����dZ!Gd�de"��Z#Gd�de��Z$Gd�de��Z%d"d�Z&d#d�Z'd �Z(d$d!�Z)dS)%zFUtilities for fast persistence of big data, with optional compression.�N)�Path�)�lz4�LZ4_NOT_INSTALLED_ERROR)� _COMPRESSORS�register_compressor�BinaryZlibFile)�ZlibCompressorWrapper�GzipCompressorWrapper�BZ2CompressorWrapper�LZMACompressorWrapper�XZCompressorWrapper�LZ4CompressorWrapper)� Unpickler�Pickler)�_read_fileobject�_write_fileobject)� _read_bytes� BUFFER_SIZE)�_ensure_native_byte_order)�load_compatibility)�NDArrayWrapper)�ZNDArrayWrapper)� make_memmap�zlib�gzip�bz2�lzma�xzr�c�<�eZdZdZdefd�Zd�Zd�Zd�Zd�Z d�Z d S) �NumpyArrayWrapperapAn 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�Z�||_||_||_||_||_||_dS)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 �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/joblib/numpy_pickle.py�__init__zNumpyArrayWrapper.__init__Os8��!�� ��� ��� ��� �$���,G��(�(�(�c�$�t|dd��S)Nr))�getattr)r*s r+�$safe_get_numpy_array_alignment_bytesz6NumpyArrayWrapper.safe_get_numpy_array_alignment_bytes\s���t�:�D�A�A�Ar-c�d�td|jzd��}|jjrt j||jd���dS|���}|��|j���}|dz}|||zz }t� |dd���}|j� |��|dkrd |z} |j� | ��|j � |gd �||j� ��D]/} |j� | �d �����0dS) z�Write 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. ir���protocolN�little)�length� byteorderr��)� external_loop�buffered� zerosize_ok)�flags� buffersizer&�C)�max�itemsizer'� hasobject�pickle�dump� file_handler0�tell�int�to_bytes�write�np�nditerr&�tobytes) r*�array�picklerr=r)� current_pos�pos_after_padding_byte�padding_length�padding_length_byte�padding�chunks r+� write_arrayzNumpyArrayWrapper.write_arrayasv����5�>�9�1�=�=� � �;� � >� �K��w�2�Q� ?� ?� ?� ?� ?� ?��9�9�;�;� (�*�6�%�1�6�6�8�8� �)4�q��&�!<�*�-H�H�"J��'*�l�l�"�1��'3�'B�'B�#��#�)�)�*=�>�>�>�!�Q�&�&�%��6�G��'�-�-�g�6�6�6� ��*�*�5�2A�2A�2A�7A�15�� +�=�=� >� >�� �#�)�)�%�-�-��*<�*<�=�=�=�=�  >� >r-c����t|j��dkrd}n2�fd�|jD��}�jj�|��}|jjrtj�j ��}�ny|� ��}|�V�j � d��}t� |d���}|dkr�j � |��ttt|jj��z}�j�||j���}t%d||��D]r} t||| z ��} t| |jjz��} t'�j | d��} �j�| |j| � ��|| | | z�<~ �s|jd kr*|jddd �|_|���}n |j|_t/|��S) z�Read 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. rrc�D��g|]}�j�|����S�)rI�int64)�.0�x� unpicklers �r+� <listcomp>z0NumpyArrayWrapper.read_array.<locals>.<listcomp>�s)���E�E�E�Q�9�<�-�-�a�0�0�E�E�Er-Nr5�r7)r'z array data)r'�count�F�����)�lenr%rI�multiply�reducer'rArB�loadrDr0�readrF� from_bytesr�minr@�empty�ranger� frombufferr&� transposer) r*r[r^� shape_int64rLr)� padding_byterP�max_read_count�i� read_count� read_size�datas ` r+� read_arrayzNumpyArrayWrapper.read_array�s��� �t�z�?�?�a� � ��E�E�F�E�E�E�$�*�E�E�E�K��L�)�0�0��=�=�E� �:� �& )��K� � 5�6�6�E�E��9�9�;�;� (�*�6�(�4�9�9�!�<�<� �!$��� �H�"0�"6�"6��!�Q�&�&��)�.�.�~�>�>�>�)�C� �04� �0C�-E�-E�E�N��L�&�&�u�D�J�&�?�?�E��1�e�^�4�4� � �� �����;�;� �� �T�Z�-@� @�A�A� �"�9�#8�#,�l�<�<���L�+�+�D�� �2<�,�>�>��a��J��&�'��D��z�S� � �"�j���2��.�� ����)�)���"�j�� �)��/�/�/r-c�0�|j���}|}|���}|�>|j�d��}t�|d���}||dzz }|jdkrd|_t|j|j |j |j |j|���}|j� ||j z��|�5|tzdkr'd |�d |jj�d �}t!j|��t%|��S) z!Read an array using numpy memmap.Nrr5r]zw+zr+)r'r%r&�mode�offsetrzThe 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)rDrEr0rerFrf� mmap_moder�filenamer'r%r&�seek�nbytes�NUMPY_ARRAY_ALIGNMENT_BYTES�name�warnings�warnr) r*r[rNrvr)rmrP�marray�messages r+� read_mmapzNumpyArrayWrapper.read_mmap�s=���+�0�0�2�2� ��� � 5� 5� 7� 7� $� '� 2�$�0�5�5�a�8�8�L� �^�^�L�H�^�M�M�N� �n�q�(� (�F� � �$� &� &�"&�I� ��Y�/�#'�:�#'�:�#'�:�"+�"5�$*� ,�,�,�� ��"�"�6�F�M�#9�:�:�:� '� /��9�9�Q�>�>�#�v�#�#��(�-�#�#�#� � �M�'� "� "� "�(��0�0�0r-c�V�|j�|jr|�|��}n|�|��}t |d��r_|j|jj|jjfvr@|jj j � |jdd��}|� |��S|S)a Read the array corresponding to this wrapper. Use the unpickler to get all information to correctly read the array. Parameters ---------- unpickler: NumpyUnpickler Returns ------- array: numpy.ndarray N�__array_prepare__)r�b) rwr(r�rs�hasattrr$rI�ndarray�memmap�core� multiarray� _reconstructr�)r*r[rL� new_arrays r+rezNumpyArrayWrapper.read�s��� � � *�t�� *��N�N�9�-�-�E�E��O�O�I�.�.�E� �E�.� /� /� � �M�)�,�"6�"+�,�"5�"7� 7� 7�"� �)�4�A�A�� �t�S�*�*�I��.�.�u�5�5� 5��Lr-N) �__name__� __module__� __qualname__�__doc__r{r,r0rTrsr�rerWr-r+r"r"1s���������:BG�-H� G� G� G� G�B�B�B� %>�%>�%>�N70�70�70�r'1�'1�'1�R����r-r"c�X�eZdZdZej���Zdd�Zd�Zd�Z dS)� NumpyPicklera�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���||_t|jt��|_|� tj}t j||j|��� ddl}n#t$rd}YnwxYw||_ dS)Nr3r) rD� isinstancer r:rB�DEFAULT_PROTOCOLrr,�numpy� ImportErrorrI)r*�fpr4rIs r+r,zNumpyPickler.__init__s������"�4�#3�^�D�D�� � � ��.�H����t�/�(�C�C�C�C� � � � � � ��� � � ��B�B�B� ��������s�A� A&�%A&c�&�|jjr|jjsdnd}|j o |jj }i} |j���n#tj $rddi}YnwxYwtt|��|j ||jfd|i|��}|S)z<Create and returns a numpy array wrapper from a numpy array.r_r>r)Nr() r<� f_contiguous� c_contiguousr:r'rArDrE�io�UnsupportedOperationr"�typer%)r*rLr&r(�kwargs�wrappers r+�_create_array_wrapperz"NumpyPickler._create_array_wrapper/s���� �0�?�!�K�4�?���;>� ���&�D�u�{�/D�+D� ��� ;� � � !� !� #� #� #� #���&� ;� ;� ;�3�T�:�F�F�F� ;����$�D��K�K�$)�K��� �.�.�/9�.�'-�.�.�� �s�A�A%�$A%c���|j��t|��|jj|jj|jjfvr�t|��|jjur|j�|��}|�|��}tj||��|j dkr|j � d���|� ||��dStj||��S)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) rIr�r��matrixr�� asanyarrayr�r�save�proto�framer� commit_framerT)r*�objr�s r+r�zNumpyPickler.saveBs��� �7� �4��9�9����15���15���1A�$A�$A��C�y�y�D�G�N�*�*��g�(�(��-�-���0�0��5�5�G� �L��w� '� '� '��z�Q���� �(�(�t�(�4�4�4� � � ��T� *� *� *� �F��|�D�#�&�&�&r-�N) r�r�r�r�r�dispatch�copyr,r�r�rWr-r+r�r� sf������ � ���$�$�&�&�H�����"���&!'�!'�!'�!'�!'r-r�c�r�eZdZdZej���Zdd�Zd�Zeee j d<dS)�NumpyUnpicklera�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. 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���tj�|��|_||_||_||_d|_tj ||j�� ddl }n#t$rd}YnwxYw||_ dS)NFr) �os�path�dirname�_dirnamerwrDrx� compat_moderr,r�r�rI)r*rxrDrwrIs r+r,zNumpyUnpickler.__init__ys��������1�1�� �"���&��� �� � �����4��!1�2�2�2� � � � � � ��� � � ��B�B�B� ��������s�A!�! A0�/A0c�p�tj|��t|jdtt f��rz|j�td���|j���}t|t��rd|_ |j� |� |����dSdS)aOCalled 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��stackrr"rIr��popr��appendre)r*� array_wrappers r+r�zNumpyUnpickler.load_build�s��� ��T�"�"�"� �d�j��n�~�7H�&I� J� J� 8��w��!�#F�G�G�G� �J�N�N�,�,�M��-��8�8� (�#'�� � �J� � �m�0�0��6�6� 7� 7� 7� 7� 7� 8� 8r-rr�) r�r�r�r�rr�r�r,r�rB�BUILDrWr-r+r�r�fse�������� �!�&�&�(�(�H�����"8�8�8�0!+�H�V�\�!�_���r-r�c ���t�$t|t��rt|��}t|t��}t|d��}d}|durd}npt|t��r;t |��dkr"t d�|�����|\}}n t|t��r |}d}||f}n|}|dkrt�t t���|�R|durN|td ��vr=t d �|ttd ���������|tvr(t d �|t�����|s%|s#t d |�d t|���d����|r]t|t��sHd}tj��D]!\} } |�| j��r| }�"|tvr|dkrd}|�/t#jd�|��t&d���|dkrPt)|||f���5} t+| |����|��ddd��n #1swxYwYns|rMt/|d��5} t+| |����|��ddd��n #1swxYwYn$t+||����|��|rdS|gS)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. cache_size: positive int, optional This option is deprecated in 0.10 and has no effect. 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. NrHrTr2zkCompress argument tuple should contain exactly 2 elements: (compress method, compress level), you passed {}rF� 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.rzyPlease do not set 'cache_size' in joblib.dump, this parameter has no effect and will be removed. You used 'cache_size={}'�� stacklevel)�compressr3�wb)rr��strr��tuplera� ValueError�formatrrri�listrr��items�endswith� extensionr}r~�DeprecationWarningrr�rC�open) �valuerxr�r4� cache_size� is_filename� is_fileobj�compress_method�compress_levelr|� compressor�fs r+rCrC�s���` ��J�x��6�6���x�=�=���X�s�+�+�K���7�+�+�J��O��4������ �H�e� $� $� "� �x�=�=�A� � ��C����!�!�#�#� #�+3�'���� �H�c� "� "�"�"����#�^�4���!���%���C�K��0�1�1�1��"� �%� '� '� �%��)�)� +� +�� ��&���e�B�i�i���9�9�;�;� ;��l�*�*�� ��&��,�7�7�9�9� 9� � �z� ��j��x�x��h����� )� � � � �"�:�h��6�6�"� �� ,� 2� 4� 4� '� '� �D�*�� � ��!5�6�6� '�"&��� �l� *� *�~��/B�/B�"�N���� �1�17�� �1C�1C�(�Q� 8� 8� 8� 8� ���� �x�?�3A�3C�D�D�D� ;�GH� ��X� .� .� .� 3� 3�E� :� :� :� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;�� �>� �(�D� !� !� ;�Q� ��X� .� .� .� 3� 3�E� :� :� :� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;�� �X��1�1�1�6�6�u�=�=�=����� �:�s$�%I1�1I5�8I5�%K�K�K�c���t|||���}d} |���}|jrtjd|zt d���n*#t $r}td��}||_|�d}~wwxYw|S)zInternal unpickling function.)rwNzjThe file '%s' has been generated with a joblib version less than 0.10. Please regenerate this pickle file.�r�zyYou may be trying to read with python 3 a joblib pickle generated with python 2. This feature is not supported by joblib.) r�rdr�r}r~r��UnicodeDecodeErrorr�� __cause__)�fobjrxrwr[r��exc�new_excs r+� _unpickler�6s����x���C�C�C�I� �C���n�n���� � � <� �M�@�%�%�-��  <� <� <� <��� ����� 7�8�8�� ���� ��������� �Js�:A� A8�A3�3A8c��ddlm}m}t||��}|�|j��|r ||��|S)Nr)� JOBLIB_MMAPS�add_maybe_unlink_finalizer)�_memmapping_reducerr�r�rd�addrx)rxrw�unlink_on_gc_collectr�r�r�s r+�load_temporary_memmapr�Ss]��M�M�M�M�M�M�M�M� �x�� #� #�C����S�\�"�"�"��(�"�"�3�'�'�'� �Jr-c�P�t�$t|t��rt|��}t|d��rL|}t |dd��}t |||��5}t |��}ddd��n #1swxYwYn�t|d��5}t |||��5}t|t��r't|��cddd��cddd��St |||��}ddd��n #1swxYwYddd��n #1swxYwY|S)aReconstruct 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. 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. Nrer|r��rb) rr�r�r�r/rr�r�r)rxrwr�r�r�s r+rdrd\s ��J ��J�x��6�6���x�=�=���x�� � �;����4���,�,�� �d�H�i� 8� 8� "�D��D�/�/�C� "� "� "� "� "� "� "� "� "� "� "���� "� "� "� "���(�D� !� !� ;�Q�!�!�X�y�9�9� ;�T��d�C�(�(�4�.�d�3�3�  ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ��h� �:�:�� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;� �JsT� A<�<B�B�D�*$D� D�'D�8 D�D �D� D � D�D�"D)rNN)r�Nr�)*r�rBr�r}r��pathlibrr�rrrrr r r r r rr�numpy_pickle_utilsrrrrrrr�numpy_pickle_compatrrr� backportsrr{�objectr"r�r�rCr�r�rdrWr-r+�<module>r�s"��L�L� � � � � � � � ����� � � � �������4�4�4�4�4�4�4�4�I�I�I�I�I�I�I�I�I�I�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�3�2�2�2�2�2�2�2�C�C�C�C�C�C�C�C�8�8�8�8�8�8�8�8�9�9�9�9�9�9�3�3�3�3�3�3�/�/�/�/�/�/� 1�0�0�0�0�0�"�"�"�"�"�"���F�1�1�3�3�4�4�4���F�1�1�3�3�4�4�4���E�/�/�1�1�2�2�2���F�1�1�3�3�4�4�4���D�-�-�/�/�0�0�0���E�/�/�1�1�2�2�2�!��V�V�V�V�V��V�V�V�xV'�V'�V'�V'�V'�7�V'�V'�V'�r<+�<+�<+�<+�<+�Y�<+�<+�<+�DK�K�K�K�\����:���7�7�7�7�7�7r-
Memory