§
    ÐÁ³g‹¼  ã                   ó  — d dl Z d dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZmZ d„ Zd!d„Zd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z G d„ d¦  «        Z d„ Z!d"d„Z"d„ Z#d„ Z$d„ Z%d„ Z&d„ Z'd „ Z(dS )#é    N)	Ú	DirectMapÚ
IDSelectorÚIDSelectorArrayÚIDSelectorBatchÚOperatingPointsÚRangeSearchResultÚrev_swig_ptrÚswig_ptrÚtry_extract_index_ivfc                 ót   — | j         dk    rt          dd›d| j         ›�¦  «        ‚t          j        | ¦  «        S )NÚuint8zInput argument Úcodesz, must be ndarray of dtype  uint8, but found )ÚdtypeÚ	TypeErrorÚnpÚascontiguousarray)r   s    úR/var/www/html/mpstechhub/venv/lib/python3.11/site-packages/faiss/class_wrappers.pyÚ_check_dtype_uint8r   '   sJ   € Ø„{�gÒÐÝˆiØ29°'°'¸5¼;¸;ðHñ Iô Ið 	IåÔ Ñ&Ô&Ð&ó    Fc                 ó¼   — 	 t          | |¦  «        }n# t          $ r |rY dS ‚ w xY w|j        d|z   k    rdS t          | |dz   |¦  «         t          | ||¦  «         dS )z� Replaces a method in a class with another version. The old method
    is renamed to method_name_c (because presumably it was implemented in C) NÚreplacement_Ú_c)ÚgetattrÚAttributeErrorÚ__name__Úsetattr)Ú	the_classÚnameÚreplacementÚignore_missingÚorig_methods        r   Úreplace_methodr"   .   s�   € ðÝ˜i¨Ñ.Ô.ˆˆøÝð ð ð Øð 	ØˆFˆFØðøøøð Ô˜~°Ñ4Ò4Ð4àˆÝˆI�t˜d‘{ KÑ0Ô0Ð0ÝˆI�t˜[Ñ)Ô)Ð)Ð)Ð)s   ‚ “$¢$c                 óZ   — dd„}dd„}t          | d|¦  «         t          | d|¦  «         d S )Nc                 ó\  — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚|�Xt          j        |d¬¦  «        }|j         |fk    sJ ‚|                      |t          |¦  «        |t          |¦  «        ¦  «         dS |                      |t          |¦  «        |¦  «         dS )a  Perform clustering on a set of vectors. The index is used for assignment.

        Parameters
        ----------
        x : array_like
            Training vectors, shape (n, self.d). `dtype` must be float32.
        index : faiss.Index
            Index used for assignment. The dimension of the index should be `self.d`.
        weights : array_like, optional
            Per training sample weight (size n) used when computing the weighted
            average to obtain the centroid (default is 1 for all training vectors).
        Úfloat32©r   N©Úshaper   r   ÚdÚtrain_cr
   )ÚselfÚxÚindexÚweightsÚnr)   s         r   Úreplacement_trainz,handle_Clustering.<locals>.replacement_train@   s±   € ð Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{ØÐÝÔ*¨7¸)ÐDÑDÔDˆGØ”= Q EÒ)Ð)Ð)Ð)Ø�LŠL˜�H Q™KœK¨µ¸Ñ0AÔ0AÑBÔBÐBÐBÐBà�LŠL˜�H Q™KœK¨Ñ/Ô/Ð/Ð/Ð/r   c           	      ó�  — |j         \  }}t          |¦  «        }||                     ¦   «         k    sJ ‚|j        |j        k    sJ ‚|�Yt	          j        |d¬¦  «        }|j         |fk    sJ ‚|                      |t          |¦  «        ||t          |¦  «        ¦  «         dS |                      |t          |¦  «        ||¦  «         dS )aÌ   Perform clustering on a set of compressed vectors. The index is used for assignment.
        The decompression is performed on-the-fly.

        Parameters
        ----------
        x : array_like
            Training vectors, shape (n, codec.code_size()). `dtype` must be `uint8`.
        codec : faiss.Index
            Index used to decode the vectors. Should have dimension `self.d`.
        index : faiss.Index
            Index used for assignment. The dimension of the index should be `self.d`.
        weights : array_like, optional
            Per training sample weight (size n) used when computing the weighted
            average to obtain the centroid (default is 1 for all training vectors).
        Nr%   r&   )r(   r   Úsa_code_sizer)   r   r   Útrain_encoded_cr
   )r+   r,   Úcodecr-   r.   r/   r)   s          r   Úreplacement_train_encodedz4handle_Clustering.<locals>.replacement_train_encodedW   sá   € ð  Œw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�E×&Ò&Ñ(Ô(Ò(Ð(Ð(Ð(ØŒw˜%œ'Ò!Ð!Ð!Ð!ØÐÝÔ*¨7¸)ÐDÑDÔDˆGØ”= Q EÒ)Ð)Ð)Ð)Ø× Ò  ¥H¨Q¡K¤K°Ø!&­°Ñ(9Ô(9ñ;ô ;ð ;ð ;ð ;ð × Ò  ¥H¨Q¡K¤K°¸Ñ>Ô>Ð>Ð>Ð>r   ÚtrainÚtrain_encoded©N©r"   )r   r0   r5   s      r   Úhandle_Clusteringr:   >   sX   € ð0ð 0ð 0ð 0ð.?ð ?ð ?ð ?õ8 �9˜gÐ'8Ñ9Ô9Ð9Ý�9˜oÐ/HÑIÔIÐIÐIÐIr   c                 ó.   — d„ }t          | d|¦  «         d S )Nc                 ó¦   — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚|                      |t          |¦  «        ¦  «         dS )z¶Perform clustering on a set of 1D vectors.

        Parameters
        ----------
        x : array_like
            Training vectors, shape (n, 1). `dtype` must be float32.
        r%   r&   N)r(   r   r   r)   Útrain_exact_cr
   ©r+   r,   r/   r)   s       r   Úreplacement_train_exactz4handle_Clustering1D.<locals>.replacement_train_exacty   sU   € ð Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{Ø×Ò˜1�h q™kœkÑ*Ô*Ð*Ð*Ð*r   Útrain_exactr9   )r   r?   s     r   Úhandle_Clustering1DrA   w   s,   € ð+ð +ð +õ �9˜mÐ-DÑEÔEÐEÐEÐEr   c                 ó~   — d„ }d„ }d„ }t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         d S )Nc                 ó¦   — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚|                      |t          |¦  «        ¦  «         dS )zÃ Train the quantizer on a set of training vectors.

        Parameters
        ----------
        x : array_like
            Training vectors, shape (n, self.d). `dtype` must be float32.
        r%   r&   Nr'   r>   s       r   r0   z+handle_Quantizer.<locals>.replacement_train‹   sS   € ð Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{Ø�Š�Q� ™œÑ$Ô$Ð$Ð$Ð$r   c                 óü   — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚t          j        || j        fd¬¦  «        }|                      t          |¦  «        t          |¦  «        |¦  «         |S )al   Compute the codes corresponding to a set of vectors.

        Parameters
        ----------
        x : array_like
            Vectors to encode, shape (n, self.d). `dtype` must be float32.

        Returns
        -------
        codes : array_like
            Corresponding code for each vector, shape (n, self.code_size)
            and `dtype` uint8.
        r%   r&   r   )r(   r   r   r)   ÚemptyÚ	code_sizeÚcompute_codes_cr
   )r+   r,   r/   r)   r   s        r   Úreplacement_compute_codesz3handle_Quantizer.<locals>.replacement_compute_codes˜   sw   € ð Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{Ý”˜!˜Tœ^Ð,°GÐ<Ñ<Ô<ˆØ×Ò�X a™[œ[­(°5©/¬/¸1Ñ=Ô=Ð=Øˆr   c                 óî   — |j         \  }}t          |¦  «        }|| j        k    sJ ‚t          j        || j        fd¬¦  «        }|                      t          |¦  «        t          |¦  «        |¦  «         |S )aJ  Reconstruct an approximation of vectors given their codes.

        Parameters
        ----------
        codes : array_like
            Codes to decode, shape (n, self.code_size). `dtype` must be uint8.

        Returns
        -------
            Reconstructed vectors for each code, shape `(n, d)` and `dtype` float32.
        r%   r&   )r(   r   rF   r   rE   r)   Údecode_cr
   )r+   r   r/   Úcsr,   s        r   Úreplacement_decodez,handle_Quantizer.<locals>.replacement_decode­   sp   € ð ”‰ˆˆ2Ý" 5Ñ)Ô)ˆØ�T”^Ò#Ð#Ð#Ð#ÝŒH�a˜œ�[¨	Ð2Ñ2Ô2ˆØ�Š•h˜u‘o”o¥x°¡{¤{°AÑ6Ô6Ð6Øˆr   r6   Úcompute_codesÚdecoder9   )r   r0   rH   rL   s       r   Úhandle_QuantizerrO   ‰   sp   € ð%ð %ð %ðð ð ð*ð ð õ& �9˜gÐ'8Ñ9Ô9Ð9Ý�9˜oÐ/HÑIÔIÐIÝ�9˜hÐ(:Ñ;Ô;Ð;Ð;Ð;r   c                 ó.   — d„ }t          | d|¦  «         d S )Nc                 óJ  — |j         \  }}|| j        k    sJ ‚|j        dk    sJ ‚|j         d         |k    sJ ‚|j         d         }t          j        |d¬¦  «        }t          j        |d¬¦  «        }|                      |t          |¦  «        t          |¦  «        |¦  «         d S )Né   r   é   r%   r&   Úint64)r(   r)   Úndimr   r   Úbuild_cr
   )r+   r,   Úgraphr/   r)   ÚKs         r   Úreplacement_buildz%handle_NSG.<locals>.replacement_buildÇ   s¡   € ØŒw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ØŒz˜QŠˆˆˆØŒ{˜1Œ~ Ò"Ð"Ð"Ð"ØŒK˜ŒNˆÝÔ  ¨)Ð4Ñ4Ô4ˆÝÔ$ U°'Ð:Ñ:Ô:ˆØ�Š�Q� ™œ¥X¨e¡_¤_°aÑ8Ô8Ð8Ð8Ð8r   Úbuildr9   )r   rY   s     r   Ú
handle_NSGr[   Å   s,   € ð9ð 9ð 9õ �9˜gÐ'8Ñ9Ô9Ð9Ð9Ð9r   c                 ó†  — d„ }d„ }d2d„}d„ }d d d dœd„}d d d d dœd„}d	d d d d d
œd„}d„ }d2d„}	d2d„}
d3d„}d„ }d dœd„}d d d dœd„}d dœd„}d2d„}d2d„}d2d„}d„ }t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d |¦  «         t          | d!|	¦  «         t          | d"|
¦  «         t          | d#|¦  «         t          | d$|¦  «         t          | d%|d&¬'¦  «         t          | d(|d&¬'¦  «         t          | d)|d&¬'¦  «         t          | d*|d&¬'¦  «         t          | d+|d&¬'¦  «         t          | d,|¦  «         t          | d-|¦  «         t          | d.|¦  «         t          | d/|d&¬'¦  «         d0„ }d1„ }|| _        || _        d S )4Nc                 ó¦   — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|                      |t          |¦  «        ¦  «         dS )aÅ  Adds vectors to the index.
        The index must be trained before vectors can be added to it.
        The vectors are implicitly numbered in sequence. When `n` vectors are
        added to the index, they are given ids `ntotal`, `ntotal + 1`, ..., `ntotal + n - 1`.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        r%   r&   N)r(   r)   r   r   Úadd_cr
   r>   s       r   Úreplacement_addz%handle_Index.<locals>.replacement_addÖ   sS   € ð Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�
Š
�1•h˜q‘k”kÑ"Ô"Ð"Ð"Ð"r   c                 ó  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }t          j        |d¬¦  «        }|j         |fk    s
J d¦   «         ‚|                      |t          |¦  «        t          |¦  «        ¦  «         dS )aW  Adds vectors with arbitrary ids to the index (not all indexes support this).
        The index must be trained before vectors can be added to it.
        Vector `i` is stored in `x[i]` and has id `ids[i]`.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        ids : array_like
            Array if ids of size n. The ids must be of type `int64`. Note that `-1` is reserved
            in result lists to mean "not found" so it's better to not use it as an id.
        r%   r&   rT   únot same nb of vectors as idsN)r(   r)   r   r   Úadd_with_ids_cr
   ©r+   r,   Úidsr/   r)   s        r   Úreplacement_add_with_idsz.handle_Index.<locals>.replacement_add_with_idsè   s�   € ð Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆÝÔ" 3¨gÐ6Ñ6Ô6ˆØŒy˜Q˜EÒ!Ð!Ð!Ð#BÑ!Ô!Ð!Ø×Ò˜A�x¨™{œ{­H°S©M¬MÑ:Ô:Ð:Ð:Ð:r   c                 ó,  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|                      |t          |¦  «        t          |¦  «        |¦  «         |S )a”  Find the k nearest neighbors of the set of vectors x in the index.
        This is the same as the `search` method, but discards the distances.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        k : int
            Number of nearest neighbors.
        labels : array_like, optional
            Labels array to store the results.

        Returns
        -------
        labels: array_like
            Labels of the nearest neighbors, shape (n, k).
            When not enough results are found, the label is set to -1
        r%   r&   )r(   r)   r   r   rE   rT   Úassign_cr
   ©r+   r,   ÚkÚlabelsr/   r)   s         r   Úreplacement_assignz(handle_Index.<locals>.replacement_assigný   s–   € ð( Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆàˆ>Ý”X˜q !˜f­B¬HÐ5Ñ5Ô5ˆFˆFà”< A q 6Ò)Ð)Ð)Ð)à�Š�a� !™œ¥h¨vÑ&6Ô&6¸Ñ:Ô:Ð:Øˆr   c                 ó¦   — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|                      |t          |¦  «        ¦  «         dS )a3  Trains the index on a representative set of vectors.
        The index must be trained before vectors can be added to it.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        r%   r&   N)r(   r)   r   r   r*   r
   r>   s       r   r0   z'handle_Index.<locals>.replacement_train  sS   € ð Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�Š�Q� ™œÑ$Ô$Ð$Ð$Ð$r   )ÚparamsÚDÚIc          	      óÆ  — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚|dk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|                      |t          |¦  «        |t          |¦  «        t          |¦  «        |¦  «         ||fS )a­  Find the k nearest neighbors of the set of vectors x in the index.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        k : int
            Number of nearest neighbors.
        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)
        D : array_like, optional
            Distance array to store the result.
        I : array_like, optional
            Labels array to store the results.

        Returns
        -------
        D : array_like
            Distances of the nearest neighbors, shape (n, k). When not enough results are found
            the label is set to +Inf or -Inf.
        I : array_like
            Labels of the nearest neighbors, shape (n, k).
            When not enough results are found, the label is set to -1
        r%   r&   r   )	r(   r   r   r)   rE   r%   rT   Úsearch_cr
   )r+   r,   ri   rm   rn   ro   r/   r)   s           r   Úreplacement_searchz(handle_Index.<locals>.replacement_search,  sç   € ð6 Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{à�1Šuˆuˆuˆuàˆ9Ý”˜!˜Q˜¥r¤zÐ2Ñ2Ô2ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$àˆ9Ý”˜!˜Q˜¥r¤xÐ0Ñ0Ô0ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$à�Š�a� !™œ a­°!©¬µh¸q±k´kÀ6ÑJÔJÐJØ�!ˆtˆr   )rm   rn   ro   ÚRc          
      óP  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|dk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|€$t          j        |||ft          j        ¬¦  «        }n|j         |||fk    sJ ‚|                      |t          |¦  «        |t          |¦  «        t          |¦  «        t          |¦  «        |¦  «         |||fS )a—  Find the k nearest neighbors of the set of vectors x in the index,
        and return an approximation of these vectors.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        k : int
            Number of nearest neighbors.
        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)
        D : array_like, optional
            Distance array to store the result.
        I : array_like, optional
            Labels array to store the result.
        R : array_like, optional
            reconstruction array to store

        Returns
        -------
        D : array_like
            Distances of the nearest neighbors, shape (n, k). When not enough results are found
            the label is set to +Inf or -Inf.
        I : array_like
            Labels of the nearest neighbors, shape (n, k). When not enough results are found,
            the label is set to -1
        R : array_like
            Approximate (reconstructed) nearest neighbor vectors, shape (n, k, d).
        r%   r&   r   )	r(   r)   r   r   rE   r%   rT   Úsearch_and_reconstruct_cr
   )	r+   r,   ri   rm   rn   ro   rs   r/   r)   s	            r   Ú"replacement_search_and_reconstructz8handle_Index.<locals>.replacement_search_and_reconstructZ  s:  € ð> Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆà�1Šuˆuˆuˆuàˆ9Ý”˜!˜Q˜¥r¤zÐ2Ñ2Ô2ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$àˆ9Ý”˜!˜Q˜¥r¤xÐ0Ñ0Ô0ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$àˆ9Ý”˜!˜Q ˜­"¬*Ð5Ñ5Ô5ˆAˆAà”7˜q ! Q˜iÒ'Ð'Ð'Ð'à×%Ò%Ø�x˜‰{Œ{Ø�x˜‰{Œ{Ý�Q‰KŒK� !™œ fñ	
ô 	
ð 	
ð
 �!�Qˆwˆr   F)Úinclude_listnosrm   rn   ro   r   c          
      ó’  — |j         \  }}	|	| j        k    sJ ‚t          j        |d¬¦  «        }|dk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚| j        }
|r|
|                      ¦   «         z  }
|€$t          j        |||
ft          j	        ¬¦  «        }n|j         |||
fk    sJ ‚|  
                    |t          |¦  «        |t          |¦  «        t          |¦  «        t          |¦  «        ||¦  «         |||fS )a  Find the k nearest neighbors of the set of vectors x in the index,
        and return the codes stored for these vectors

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        k : int
            Number of nearest neighbors.
        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)
        include_listnos : bool, optional
            whether to include the list ids in the first bytes of each code
        D : array_like, optional
            Distance array to store the result.
        I : array_like, optional
            Labels array to store the result.
        codes : array_like, optional
            codes array to store

        Returns
        -------
        D : array_like
            Distances of the nearest neighbors, shape (n, k). When not enough results are found
            the label is set to +Inf or -Inf.
        I : array_like
            Labels of the nearest neighbors, shape (n, k). When not enough results are found,
            the label is set to -1
        R : array_like
            Approximate (reconstructed) nearest neighbor vectors, shape (n, k, d).
        r%   r&   r   )r(   r)   r   r   rE   r%   rT   rF   Úcoarse_code_sizer   Úsearch_and_return_codes_cr
   )r+   r,   ri   rw   rm   rn   ro   r   r/   r)   Úcode_size_1s              r   Ú#replacement_search_and_return_codesz9handle_Index.<locals>.replacement_search_and_return_codes•  sf  € ðF Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆà�1Šuˆuˆuˆuàˆ9Ý”˜!˜Q˜¥r¤zÐ2Ñ2Ô2ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$àˆ9Ý”˜!˜Q˜¥r¤xÐ0Ñ0Ô0ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$à”nˆØð 	3Ø˜4×0Ò0Ñ2Ô2Ñ2ˆKàˆ=Ý”H˜a  KÐ0½¼ÐAÑAÔAˆEˆEà”; 1 a¨Ð"5Ò5Ð5Ð5Ð5à×&Ò&Ø�x˜‰{Œ{Ø�x˜‰{Œ{Ý�Q‰KŒK� %™œ¨/Øñ		
ô 	
ð 	
ð �!�Uˆ{Ðr   c                 ó‚  — t          |t          ¦  «        r|}n“|j        dk    sJ ‚t          | ¦  «        }t	          j        |d¬¦  «        }|r=|j        j        t          j	        k    r#t          |j        t          |¦  «        ¦  «        }n"t          |j        t          |¦  «        ¦  «        }|                      |¦  «        S )aó  Remove some ids from the index.
        This is a O(ntotal) operation by default, so could be expensive.

        Parameters
        ----------
        x : array_like or faiss.IDSelector
            Either an IDSelector that returns True for vectors to remove, or a
            list of ids to reomove (1D array of int64). When `x` is a list,
            it is wrapped into an IDSelector.

        Returns
        -------
        n_remove: int
            number of vectors that were removed
        rS   rT   r&   )Ú
isinstancer   rU   r   r   r   Ú
direct_mapÚtyper   Ú	Hashtabler   Úsizer
   r   Úremove_ids_c)r+   r,   ÚselÚ	index_ivfs       r   Úreplacement_remove_idsz,handle_Index.<locals>.replacement_remove_idsÙ  s­   € õ  �a�Ñ$Ô$ð 		;ØˆCˆCà”6˜Q’;�;�;�;Ý-¨dÑ3Ô3ˆIÝÔ$ Q¨gÐ6Ñ6Ô6ˆAØð ;˜YÔ1Ô6½)Ô:MÒMÐMÝ% a¤f­h°q©k¬kÑ:Ô:��å% a¤f­h°q©k¬kÑ:Ô:�Ø× Ò  Ñ%Ô%Ð%r   c                 óÂ   — |€&t          j        | j        t           j        ¬¦  «        }n|j        | j        fk    sJ ‚|                      |t          |¦  «        ¦  «         |S )ai  Approximate reconstruction of one vector from the index.

        Parameters
        ----------
        key : int
            Id of the vector to reconstruct
        x : array_like, optional
            pre-allocated array to store the results

        Returns
        -------
        x : array_like reconstructed vector, size `self.d`, `dtype`=float32
        Nr&   )r   rE   r)   r%   r(   Úreconstruct_cr
   ©r+   Úkeyr,   s      r   Úreplacement_reconstructz-handle_Index.<locals>.replacement_reconstructõ  s[   € ð ˆ9Ý”˜œ¥r¤zÐ2Ñ2Ô2ˆAˆAà”7˜tœv˜jÒ(Ð(Ð(Ð(à×Ò˜3¥¨¡¤Ñ,Ô,Ð,Øˆr   c                 ó"  — t          j        |d¬¦  «        }|j        \  }|€(t          j        || j        ft           j        ¬¦  «        }n|j        || j        fk    sJ ‚|                      |t          |¦  «        t          |¦  «        ¦  «         |S )a€  Approximate reconstruction of several vectors from the index.

        Parameters
        ----------
        key : array of ints
            Ids of the vectors to reconstruct
        x : array_like, optional
            pre-allocated array to store the results

        Returns
        -------
        x : array_like
            reconstrcuted vectors, size `len(key), self.d`
        rT   r&   )r   r   r(   rE   r)   r%   Úreconstruct_batch_cr
   )r+   rŠ   r,   r/   s       r   Úreplacement_reconstruct_batchz3handle_Index.<locals>.replacement_reconstruct_batch  s‡   € õ Ô" 3¨gÐ6Ñ6Ô6ˆØŒY‰ˆØˆ9Ý”˜!˜TœV˜­B¬JÐ7Ñ7Ô7ˆAˆAà”7˜q $¤&˜kÒ)Ð)Ð)Ð)Ø× Ò  ¥H¨S¡M¤Mµ8¸A±;´;Ñ?Ô?Ð?Øˆr   r   éÿÿÿÿc                 óê   — |dk    r
| j         |z
  }|€(t          j        || j        ft          j        ¬¦  «        }n|j        || j        fk    sJ ‚|                      ||t          |¦  «        ¦  «         |S )a'  Approximate reconstruction of vectors `n0` ... `n0 + ni - 1` from the index.
        Missing vectors trigger an exception.

        Parameters
        ----------
        n0 : int
            Id of the first vector to reconstruct (default 0)
        ni : int
            Number of vectors to reconstruct (-1 = default = ntotal)
        x : array_like, optional
            pre-allocated array to store the results

        Returns
        -------
        x : array_like
            Reconstructed vectors, size (`ni`, `self.d`), `dtype`=float32
        r�   Nr&   )Úntotalr   rE   r)   r%   r(   Úreconstruct_n_cr
   ©r+   Ún0Únir,   s       r   Úreplacement_reconstruct_nz/handle_Index.<locals>.replacement_reconstruct_n#  sx   € ð$ �Š8ˆ8Ø”˜rÑ!ˆBØˆ9Ý”˜"˜dœf˜­R¬ZÐ8Ñ8Ô8ˆAˆAà”7˜r 4¤6˜lÒ*Ð*Ð*Ð*à×Ò˜R ¥X¨a¡[¤[Ñ1Ô1Ð1Øˆr   c                 ó  — |j         }|j        |fk    sJ ‚|j        || j        fk    sJ ‚t          j        |d¬¦  «        }t          j        |d¬¦  «        }|                      |t          |¦  «        t          |¦  «        ¦  «         d S )Nr%   r&   rT   )r‚   r(   r)   r   r   Úupdate_vectors_cr
   )r+   Úkeysr,   r/   s       r   Úreplacement_update_vectorsz0handle_Index.<locals>.replacement_update_vectors?  s‹   € ØŒIˆØŒz˜a˜UÒ"Ð"Ð"Ð"ØŒw˜1˜dœf˜+Ò%Ð%Ð%Ð%ÝÔ  ¨)Ð4Ñ4Ô4ˆÝÔ# D°Ð8Ñ8Ô8ˆØ×Ò˜a¥¨$¡¤µ¸!±´Ñ=Ô=Ð=Ð=Ð=r   ©rm   c                ó  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }t	          |¦  «        }t          |¦  «        }|                      |t          |¦  «        |||¦  «         t          |j	        |dz   ¦  «         
                    ¦   «         }t          |d         ¦  «        }t          |j        |¦  «         
                    ¦   «         }	t          |j        |¦  «         
                    ¦   «         }
||	|
fS )a  Search vectors that are within a distance of the query vectors.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        thresh : float
            Threshold to select neighbors. All elements within this radius are returned,
            except for maximum inner product indexes, where the elements above the
            threshold are returned
        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)


        Returns
        -------
        lims: array_like
            Starting index of the results for each query vector, size n+1.
        D : array_like
            Distances of the nearest neighbors, shape `lims[n]`. The distances for
            query i are in `D[lims[i]:lims[i+1]]`.
        I : array_like
            Labels of nearest neighbors, shape `lims[n]`. The labels for query i
            are in `I[lims[i]:lims[i+1]]`.

        r%   r&   rS   r�   )r(   r)   r   r   Úfloatr   Úrange_search_cr
   r	   ÚlimsÚcopyÚintÚ	distancesrj   )r+   r,   Úthreshrm   r/   r)   ÚresrŸ   Úndrn   ro   s              r   Úreplacement_range_searchz.handle_Index.<locals>.replacement_range_searchH  sã   € ð8 Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆÝ�v‘”ˆå Ñ"Ô"ˆØ×Ò˜A�x¨™{œ{¨F°C¸Ñ@Ô@Ð@å˜CœH a¨!¡eÑ,Ô,×1Ò1Ñ3Ô3ˆÝ��b”‰]Œ]ˆÝ˜œ¨Ñ+Ô+×0Ò0Ñ2Ô2ˆÝ˜œ RÑ(Ô(×-Ò-Ñ/Ô/ˆØ�Q˜ˆzÐr   c                ó¾  — |j         \  }}	t          j        |d¬¦  «        }|	| j        k    sJ ‚|dk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚t          j        |d¬¦  «        }|�
J d¦   «         ‚|j         || j        fk    sJ ‚|�(t          j        |d¬¦  «        }|j         |j         k    sJ ‚|                      |t          |¦  «        |t          |¦  «        t          |¦  «        t          |¦  «        t          |¦  «        d¦  «         ||fS )až  Find the k nearest neighbors of the set of vectors x in an IVF index,
        with precalculated coarse quantization assignment.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        k : int
            Number of nearest neighbors.
        Dq : array_like, optional
            Distance array to the centroids, size (n, nprobe)
        Iq : array_like, optional
            Nearest centroids, size (n, nprobe)

        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)
        D : array_like, optional
            Distance array to store the result.
        I : array_like, optional
            Labels array to store the results.

        Returns
        -------
        D : array_like
            Distances of the nearest neighbors, shape (n, k). When not enough results are found
            the label is set to +Inf or -Inf.
        I : array_like
            Labels of the nearest neighbors, shape (n, k).
            When not enough results are found, the label is set to -1
        r%   r&   r   NrT   úparams not supportedF)
r(   r   r   r)   rE   r%   rT   ÚnprobeÚsearch_preassigned_cr
   )
r+   r,   ri   ÚIqÚDqrm   rn   ro   r/   r)   s
             r   Úreplacement_search_preassignedz4handle_Index.<locals>.replacement_search_preassignedr  su  € ð@ Œw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”FŠ{ˆ{ˆ{ˆ{Ø�1Šuˆuˆuˆuàˆ9Ý”˜!˜Q˜¥r¤zÐ2Ñ2Ô2ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$àˆ9Ý”˜!˜Q˜¥r¤xÐ0Ñ0Ô0ˆAˆAà”7˜q !˜fÒ$Ð$Ð$Ð$åÔ! "¨GÐ4Ñ4Ô4ˆØˆ~ˆ~Ð5‰~Œ~ˆ~ØŒx˜A˜tœ{Ð+Ò+Ð+Ð+Ð+àˆ>ÝÔ% b°	Ð:Ñ:Ô:ˆBØ”8˜rœxÒ'Ð'Ð'Ð'à×!Ò!Ø�x˜‰{Œ{ØÝ�R‰LŒL�( 2™,œ,Ý�Q‰KŒK� !™œØñ	
ô 	
ð 	
ð �!ˆtˆr   c          	      óþ  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }t          j        |d¬¦  «        }|�
J d¦   «         ‚|j         || j        fk    sJ ‚|�(t          j        |d¬¦  «        }|j         |j         k    sJ ‚t          |¦  «        }t          |¦  «        }|                      |t          |¦  «        |t          |¦  «        t          |¦  «        |¦  «         t          |j
        |dz   ¦  «                             ¦   «         }	t          |	d         ¦  «        }
t          |j        |
¦  «                             ¦   «         }t          |j        |
¦  «                             ¦   «         }|	||fS )aÁ  Search vectors that are within a distance of the query vectors.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        thresh : float
            Threshold to select neighbors. All elements within this radius are returned,
            except for maximum inner product indexes, where the elements above the
            threshold are returned
        Iq : array_like, optional
            Nearest centroids, size (n, nprobe)
        Dq : array_like, optional
            Distance array to the centroids, size (n, nprobe)
        params : SearchParameters
            Search parameters of the current search (overrides the class-level params)


        Returns
        -------
        lims: array_like
            Starting index of the results for each query vector, size n+1.
        D : array_like
            Distances of the nearest neighbors, shape `lims[n]`. The distances for
            query i are in `D[lims[i]:lims[i+1]]`.
        I : array_like
            Labels of nearest neighbors, shape `lims[n]`. The labels for query i
            are in `I[lims[i]:lims[i+1]]`.

        r%   r&   rT   Nr¨   rS   r�   )r(   r)   r   r   r©   r�   r   Úrange_search_preassigned_cr
   r	   rŸ   r    r¡   r¢   rj   ©r+   r,   r£   r«   r¬   rm   r/   r)   r¤   rŸ   r¥   rn   ro   s                r   Ú$replacement_range_search_preassignedz:handle_Index.<locals>.replacement_range_search_preassigned²  sk  € ð@ Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆåÔ! "¨GÐ4Ñ4Ô4ˆØˆ~ˆ~Ð5‰~Œ~ˆ~ØŒx˜A˜tœ{Ð+Ò+Ð+Ð+Ð+àˆ>ÝÔ% b°	Ð:Ñ:Ô:ˆBØ”8˜rœxÒ'Ð'Ð'Ð'å�v‘”ˆÝ Ñ"Ô"ˆØ×'Ò'Ø�x˜‰{Œ{˜FÝ�R‰LŒL�( 2™,œ,Øñ	
ô 	
ð 	
õ ˜CœH a¨!¡eÑ,Ô,×1Ò1Ñ3Ô3ˆÝ��b”‰]Œ]ˆÝ˜œ¨Ñ+Ô+×0Ò0Ñ2Ô2ˆÝ˜œ RÑ(Ô(×-Ò-Ñ/Ô/ˆØ�Q˜ˆzÐr   c                 ór  — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|€5t          j        ||                      ¦   «         ft          j        ¬¦  «        }n!|j         ||                      ¦   «         fk    sJ ‚|                      |t          |¦  «        t          |¦  «        ¦  «         |S ©Nr%   r&   )	r(   r)   r   r   rE   r2   r   Úsa_encode_cr
   )r+   r,   r   r/   r)   s        r   Úreplacement_sa_encodez+handle_Index.<locals>.replacement_sa_encodeì  s¬   € ØŒw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆàˆ=Ý”H˜a ×!2Ò!2Ñ!4Ô!4Ð5½R¼XÐFÑFÔFˆEˆEà”; 1 d×&7Ò&7Ñ&9Ô&9Ð":Ò:Ð:Ð:Ð:à×Ò˜�H Q™KœK­°%©¬Ñ9Ô9Ð9Øˆr   c                 óJ  — |j         \  }}||                      ¦   «         k    sJ ‚t          |¦  «        }|€(t          j        || j        ft          j        ¬¦  «        }n|j         || j        fk    sJ ‚|                      |t          |¦  «        t          |¦  «        ¦  «         |S ©Nr&   )	r(   r2   r   r   rE   r)   r%   Úsa_decode_cr
   )r+   r   r,   r/   rK   s        r   Úreplacement_sa_decodez+handle_Index.<locals>.replacement_sa_decodeù  sœ   € Ø”‰ˆˆ2Ø�T×&Ò&Ñ(Ô(Ò(Ð(Ð(Ð(Ý" 5Ñ)Ô)ˆàˆ9Ý”˜!˜TœV˜­B¬JÐ7Ñ7Ô7ˆAˆAà”7˜q $¤&˜kÒ)Ð)Ð)Ð)à×Ò˜�H U™OœO­X°a©[¬[Ñ9Ô9Ð9Øˆr   c                 óò   — |j         \  }}||                      ¦   «         k    sJ ‚t          |¦  «        }|�|j         |fk    sJ ‚t          |¦  «        }|                      |t          |¦  «        |¦  «         d S r8   )r(   r2   r   r
   Úadd_sa_codes_c)r+   r   rd   r/   rK   s        r   Úreplacement_add_sa_codesz.handle_Index.<locals>.replacement_add_sa_codes  s€   € Ø”‰ˆˆ2Ø�T×&Ò&Ñ(Ô(Ò(Ð(Ð(Ð(Ý" 5Ñ)Ô)ˆàˆ?Ø”9  Ò$Ð$Ð$Ð$Ý˜3‘-”-ˆCØ×Ò˜A�x¨™œ°Ñ4Ô4Ð4Ð4Ð4r   c                 ó¬   — |j         \  }|| j        k    sJ ‚t          j        |d¬¦  «        }|                      t          j        |¦  «        ¦  «         d S ©NrT   r&   )r(   r‘   r   r   Úpermute_entries_cÚfaissr
   )r+   Úpermr/   s      r   Úreplacement_permute_entriesz1handle_Index.<locals>.replacement_permute_entries  sW   € ØŒZ‰ˆØ�D”KÒÐÐÐÝÔ# D°Ð8Ñ8Ô8ˆØ×Ò�uœ~¨dÑ3Ô3Ñ4Ô4Ð4Ð4Ð4r   ÚaddÚadd_with_idsÚassignr6   ÚsearchÚ
remove_idsÚreconstructÚreconstruct_batchÚreconstruct_nÚrange_searchÚupdate_vectorsT©r    Úsearch_and_reconstructÚsearch_and_return_codesÚsearch_preassignedÚrange_search_preassignedÚ	sa_encodeÚ	sa_decodeÚadd_sa_codesÚpermute_entriesc                 óR   — dt          j        | ¦  «                             ¦   «         iS )NÚthis)rÀ   Úserialize_indexÚtobytes©r+   s    r   Úindex_getstatez$handle_Index.<locals>.index_getstate7  s$   € Ø�Ô-¨dÑ3Ô3×;Ò;Ñ=Ô=Ð>Ð>r   c                 óz   — t          j        t          j        |d         d¬¦  «        ¦  «        }|j        | _        d S )Nr×   r   r&   )rÀ   Údeserialize_indexr   Ú
frombufferr×   )r+   ÚstÚindex2s      r   Úindex_setstatez$handle_Index.<locals>.index_setstate:  s2   € ÝÔ(­¬°r¸&´zÈÐ)QÑ)QÔ)QÑRÔRˆØ”KˆŒ	ˆ	ˆ	r   r8   ©r   r�   N)r"   Ú__getstate__Ú__setstate__)r   r_   re   rk   r0   rr   rv   r|   r†   r‹   rŽ   r–   rš   r¦   r­   r±   rµ   r¹   r¼   rÂ   rÛ   rá   s                         r   Úhandle_Indexrå   Ô   s×  € ð#ð #ð #ð$;ð ;ð ;ð*ð ð ð ð@%ð %ð %ð 26¸Àð ,ð ,ð ,ð ,ð ,ð\ BFÈÐQUÐY]ð 9ð 9ð 9ð 9ð 9ðz "¨$°$¸$ÀdðBð Bð Bð Bð BðH&ð &ð &ð8ð ð ð ð,ð ð ð ð0ð ð ð ð8>ð >ð >ð =Að (ð (ð (ð (ð (ðT FJÈTÐUYð >ð >ð >ð >ð >ð@ QUð 8ð 8ð 8ð 8ð 8ðtð ð ð ðð ð ð ð5ð 5ð 5ð 5ð5ð 5ð 5õ �9˜e _Ñ5Ô5Ð5Ý�9˜nÐ.FÑGÔGÐGÝ�9˜hÐ(:Ñ;Ô;Ð;Ý�9˜gÐ'8Ñ9Ô9Ð9Ý�9˜hÐ(:Ñ;Ô;Ð;Ý�9˜lÐ,BÑCÔCÐCÝ�9˜mÐ-DÑEÔEÐEÝ�9Ð1Ø0ñ2ô 2ð 2å�9˜oÐ/HÑIÔIÐIÝ�9˜nÐ.FÑGÔGÐGÝ�9Ð.Ð0JØ"&ð(ñ (ô (ð (å�9Ð6Ø5ÀdðLñ Lô Lð Lå�9Ð7Ø6ÀtðMñ Mô Mð Mõ �9Ð2Ø1À$ðHñ Hô Hð Hå�9Ð8Ø7ÈðNñ Nô Nð Nå�9˜kÐ+@ÑAÔAÐAÝ�9˜kÐ+@ÑAÔAÐAÝ�9˜nÐ.FÑGÔGÐGÝ�9Ð/Ð1LØ"&ð(ñ (ô (ð (ð?ð ?ð ?ð ð  ð  ð ,€IÔØ+€IÔÐÐr   c                 óÐ  — d„ }d„ }d„ }d„ }dd„}d„ }d	„ }d
„ }d dœd„}	d„ }
dd„}t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|¦  «         t          | d|
¦  «         t          | d|d¬¦  «         t          | d|	d¬¦  «         d S )Nc                 ó˜   — |j         \  }}t          |¦  «        }|| j        k    sJ ‚|                      |t	          |¦  «        ¦  «         d S r8   )r(   r   rF   r^   r
   r>   s       r   r_   z+handle_IndexBinary.<locals>.replacement_addD  sM   € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"Ø�
Š
�1•h˜q‘k”kÑ"Ô"Ð"Ð"Ð"r   c                 ó  — |j         \  }}t          |¦  «        }t          j        |d¬¦  «        }|| j        k    sJ ‚|j         |fk    s
J d¦   «         ‚|                      |t          |¦  «        t          |¦  «        ¦  «         d S )NrT   r&   ra   )r(   r   r   r   rF   rb   r
   rc   s        r   re   z4handle_IndexBinary.<locals>.replacement_add_with_idsJ  sŠ   € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆÝÔ" 3¨gÐ6Ñ6Ô6ˆØ�D”NÒ"Ð"Ð"Ð"ØŒy˜Q˜EÒ!Ð!Ð!Ð#BÑ!Ô!Ð!Ø×Ò˜A�x¨™{œ{­H°S©M¬MÑ:Ô:Ð:Ð:Ð:r   c                 ó˜   — |j         \  }}t          |¦  «        }|| j        k    sJ ‚|                      |t	          |¦  «        ¦  «         d S r8   )r(   r   rF   r*   r
   r>   s       r   r0   z-handle_IndexBinary.<locals>.replacement_trainR  sM   € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"Ø�Š�Q� ™œÑ$Ô$Ð$Ð$Ð$r   c                 ó–   — t          j        | j        t           j        ¬¦  «        }|                      |t          |¦  «        ¦  «         |S r·   )r   rE   rF   r   rˆ   r
   r‰   s      r   r‹   z3handle_IndexBinary.<locals>.replacement_reconstructX  s;   € ÝŒH�T”^­2¬8Ð4Ñ4Ô4ˆØ×Ò˜3¥¨¡¤Ñ,Ô,Ð,Øˆr   r   r�   c                 óê   — |dk    r
| j         |z
  }|€(t          j        || j        ft          j        ¬¦  «        }n|j        || j        fk    sJ ‚|                      ||t          |¦  «        ¦  «         |S )Nr�   r&   )r‘   r   rE   rF   r   r(   r’   r
   r“   s       r   r–   z5handle_IndexBinary.<locals>.replacement_reconstruct_n]  sx   € Ø�Š8ˆ8Ø”˜rÑ!ˆBØˆ9Ý”˜"˜dœnÐ-µR´XÐ>Ñ>Ô>ˆAˆAà”7˜r 4¤>Ð2Ò2Ð2Ð2Ð2à×Ò˜R ¥X¨a¡[¤[Ñ1Ô1Ð1Øˆr   c           	      ón  — t          |¦  «        }|j        \  }}|| j        k    sJ ‚|dk    sJ ‚t          j        ||ft          j        ¬¦  «        }t          j        ||ft          j        ¬¦  «        }|                      |t          |¦  «        |t          |¦  «        t          |¦  «        ¦  «         ||fS )Nr   r&   )	r   r(   rF   r   rE   Úint32rT   rq   r
   )r+   r,   ri   r/   r)   r¢   rj   s          r   rr   z.handle_IndexBinary.<locals>.replacement_searchh  s³   € Ý˜qÑ!Ô!ˆØŒw‰ˆˆ1Ø�D”NÒ"Ð"Ð"Ð"Ø�1ŠuˆuˆuˆuÝ”H˜a ˜V­2¬8Ð4Ñ4Ô4ˆ	Ý”˜1˜a˜&­¬Ð1Ñ1Ô1ˆØ�Š�a� !™œØ� )Ñ,Ô,Ý˜vÑ&Ô&ñ	(ô 	(ð 	(ð ˜&Ð Ð r   c                 óP  — |j         \  }}t          |¦  «        }|| j        k    sJ ‚|dk    sJ ‚t          j        ||ft          j        ¬¦  «        }t          j        ||ft          j        ¬¦  «        }t          j        |d¬¦  «        }|j         || j        fk    sJ ‚|�(t          j        |d¬¦  «        }|j         |j         k    sJ ‚|  	                    |t          |¦  «        |t          |¦  «        t          |¦  «        t          |¦  «        t          |¦  «        d¦  «         ||fS )Nr   r&   rT   rí   F)r(   r   rF   r   rE   rí   rT   r   r©   rª   r
   )	r+   r,   ri   r«   r¬   r/   r)   rn   ro   s	            r   r­   z:handle_IndexBinary.<locals>.replacement_search_preassignedt  s"  € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"Ø�1ŠuˆuˆuˆuåŒH�a˜�V¥2¤8Ð,Ñ,Ô,ˆÝŒH�a˜�V¥2¤8Ð,Ñ,Ô,ˆåÔ! "¨GÐ4Ñ4Ô4ˆØŒx˜A˜tœ{Ð+Ò+Ð+Ð+Ð+àˆ>ÝÔ% b°Ð8Ñ8Ô8ˆBØ”8˜rœxÒ'Ð'Ð'Ð'à×!Ò!Ø�x˜‰{Œ{ØÝ�R‰LŒL�( 2™,œ,Ý�Q‰KŒK� !™œØñ	
ô 	
ð 	
ð �!ˆtˆr   c                 óÚ  — |j         \  }}t          |¦  «        }|| j        k    sJ ‚t          |¦  «        }|                      |t          |¦  «        ||¦  «         t          |j        |dz   ¦  «                             ¦   «         }t          |d         ¦  «        }t          |j
        |¦  «                             ¦   «         }t          |j        |¦  «                             ¦   «         }	|||	fS )NrS   r�   )r(   r   rF   r   rž   r
   r	   rŸ   r    r¡   r¢   rj   )
r+   r,   r£   r/   r)   r¤   rŸ   r¥   rn   ro   s
             r   r¦   z4handle_IndexBinary.<locals>.replacement_range_search�  sÐ   € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"Ý Ñ"Ô"ˆØ×Ò˜A�x¨™{œ{¨F°CÑ8Ô8Ð8å˜CœH a¨!¡eÑ,Ô,×1Ò1Ñ3Ô3ˆÝ��b”‰]Œ]ˆÝ˜œ¨Ñ+Ô+×0Ò0Ñ2Ô2ˆÝ˜œ RÑ(Ô(×-Ò-Ñ/Ô/ˆØ�Q˜ˆzÐr   r›   c          	      óð  — |j         \  }}t          |¦  «        }|| j        k    sJ ‚t          j        |d¬¦  «        }|�
J d¦   «         ‚|j         || j        fk    sJ ‚|�(t          j        |d¬¦  «        }|j         |j         k    sJ ‚t          |¦  «        }t          |¦  «        }|                      |t          |¦  «        |t          |¦  «        t          |¦  «        |¦  «         t          |j        |dz   ¦  «                             ¦   «         }	t          |	d         ¦  «        }
t          |j        |
¦  «                             ¦   «         }t          |j        |
¦  «                             ¦   «         }|	||fS )NrT   r&   r¨   rí   rS   r�   )r(   r   rF   r   r   r©   r¡   r   r¯   r
   r	   rŸ   r    r¢   rj   r°   s                r   r±   z@handle_IndexBinary.<locals>.replacement_range_search_preassignedš  sd  € ØŒw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"åÔ! "¨GÐ4Ñ4Ô4ˆØˆ~ˆ~Ð5‰~Œ~ˆ~ØŒx˜A˜tœ{Ð+Ò+Ð+Ð+Ð+àˆ>ÝÔ% b°Ð8Ñ8Ô8ˆBØ”8˜rœxÒ'Ð'Ð'Ð'å�V‘”ˆÝ Ñ"Ô"ˆØ×'Ò'Ø�x˜‰{Œ{˜FÝ�R‰LŒL�( 2™,œ,Øñ	
ô 	
ð 	
õ ˜CœH a¨!¡eÑ,Ô,×1Ò1Ñ3Ô3ˆÝ��b”‰]Œ]ˆÝ˜œ¨Ñ+Ô+×0Ò0Ñ2Ô2ˆÝ˜œ RÑ(Ô(×-Ò-Ñ/Ô/ˆØ�Q˜ˆzÐr   c                 óæ   — t          |t          ¦  «        r|}nE|j        dk    sJ ‚t          j        |d¬¦  «        }t          |j        t          |¦  «        ¦  «        }|                      |¦  «        S ©NrS   rT   r&   )	r~   r   rU   r   r   r   r‚   r
   rƒ   )r+   r,   r„   s      r   r†   z2handle_IndexBinary.<locals>.replacement_remove_idsµ  sj   € Ý�a�Ñ$Ô$ð 	7ØˆCˆCà”6˜Q’;�;�;�;ÝÔ$ Q¨gÐ6Ñ6Ô6ˆAÝ! !¤&­(°1©+¬+Ñ6Ô6ˆCØ× Ò  Ñ%Ô%Ð%r   c                 ó.  — |j         \  }}t          |¦  «        }|| j        k    sJ ‚|dk    sJ ‚|€#t          j        ||ft          j        ¬¦  «        }n|j         ||fk    sJ ‚|                      |t          |¦  «        t          |¦  «        |¦  «         |S )a’  Find the k nearest neighbors of the set of vectors x in the index.
        This is the same as the `search` method, but discards the distances.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be uint8.
        k : int
            Number of nearest neighbors.
        labels : array_like, optional
            Labels array to store the results.

        Returns
        -------
        labels: array_like
            Labels of the nearest neighbors, shape (n, k).
            When not enough results are found, the label is set to -1
        r   Nr&   )r(   r   rF   r   rE   rT   rg   r
   rh   s         r   rk   z.handle_IndexBinary.<locals>.replacement_assign¾  sŸ   € ð( Œw‰ˆˆ1Ý˜qÑ!Ô!ˆØ�D”NÒ"Ð"Ð"Ð"Ø�1Šuˆuˆuˆuàˆ>Ý”X˜q !˜f­B¬HÐ5Ñ5Ô5ˆFˆFà”< A q 6Ò)Ð)Ð)Ð)à�Š�a� !™œ¥h¨vÑ&6Ô&6¸Ñ:Ô:Ð:Øˆr   rÃ   rÄ   r6   rÆ   rÅ   rË   rÈ   rÊ   rÇ   rÐ   TrÍ   rÑ   râ   r8   r9   )r   r_   re   r0   r‹   r–   rr   r­   r¦   r±   r†   rk   s               r   Úhandle_IndexBinaryrô   B  sÅ  € ð#ð #ð #ð;ð ;ð ;ð%ð %ð %ðð ð ð
	ð 	ð 	ð 	ð
!ð 
!ð 
!ðð ð ð2ð ð ð QUð ð ð ð ð ð6&ð &ð &ðð ð ð õB �9˜e _Ñ5Ô5Ð5Ý�9˜nÐ.FÑGÔGÐGÝ�9˜gÐ'8Ñ9Ô9Ð9Ý�9˜hÐ(:Ñ;Ô;Ð;Ý�9˜hÐ(:Ñ;Ô;Ð;Ý�9˜nÐ.FÑGÔGÐGÝ�9˜mÐ-DÑEÔEÐEÝ�9˜oÐ/HÑIÔIÐIÝ�9˜lÐ,BÑCÔCÐCÝ�9Ð2Ø1À$ðHñ Hô Hð Hå�9Ð8Ø7ÈðNñ Nô Nð Nð Nð Nr   c                 óx   — d„ }d„ }d„ }t          | d|¦  «         || _        || _        t          | d|¦  «         d S )Nc                 ó  — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚t          j        || j        ft          j        ¬¦  «        }|                      |t          |¦  «        t          |¦  «        ¦  «         |S r³   )	r(   r   r   Úd_inrE   Úd_outr%   Úapply_noallocr
   ©r+   r,   r/   r)   Úys        r   Úapply_methodz,handle_VectorTransform.<locals>.apply_methodð  sv   € ØŒw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”IŠ~ˆ~ˆ~ˆ~ÝŒH�a˜œ�_­B¬JÐ7Ñ7Ô7ˆØ×Ò˜1�h q™kœk­8°A©;¬;Ñ7Ô7Ð7Øˆr   c                 ó  — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚t          j        || j        ft          j        ¬¦  «        }|                      |t          |¦  «        t          |¦  «        ¦  «         |S r³   )	r(   r   r   rø   rE   r÷   r%   Úreverse_transform_cr
   rú   s        r   Úreplacement_reverse_transformz=handle_VectorTransform.<locals>.replacement_reverse_transformø  sv   € ØŒw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”JŠˆˆˆÝŒH�a˜œ�^­2¬:Ð6Ñ6Ô6ˆØ× Ò  ¥H¨Q¡K¤Kµ¸!±´Ñ=Ô=Ð=Øˆr   c                 ó¦   — |j         \  }}t          j        |d¬¦  «        }|| j        k    sJ ‚|                      |t          |¦  «        ¦  «         d S r³   )r(   r   r   r÷   r*   r
   r>   s       r   Úreplacement_vt_trainz4handle_VectorTransform.<locals>.replacement_vt_train   sQ   € ØŒw‰ˆˆ1ÝÔ  ¨)Ð4Ñ4Ô4ˆØ�D”IŠ~ˆ~ˆ~ˆ~Ø�Š�Q� ™œÑ$Ô$Ð$Ð$Ð$r   r6   Úreverse_transform)r"   Úapply_pyÚapply)r   rü   rÿ   r  s       r   Úhandle_VectorTransformr  î  sw   € ðð ð ðð ð ð%ð %ð %õ �9˜gÐ';Ñ<Ô<Ð<à%€IÔØ"€I„OÝ�9Ð1Ø0ñ2ô 2ð 2ð 2ð 2r   c                 óV   — d„ }d„ }t          | d|¦  «         t          | d|¦  «         d S )Nc                 óÊ   — |r|j         |j         k    sJ ‚|j         \  | _        | _        |                      | j        |rt	          |¦  «        nd t	          |¦  «        ¦  «         d S r8   )r(   ÚnqÚgt_nnnÚset_groundtruth_cr
   ©r+   rn   ro   s      r   Úreplacement_set_groundtruthz=handle_AutoTuneCriterion.<locals>.replacement_set_groundtruth  st   € Øð 	&Ø”7˜aœgÒ%Ð%Ð%Ð%Ø œwÑˆŒ�”Ø×ÒØŒK¨Ð3� !™œ˜¨tµX¸a±[´[ñ	Bô 	Bð 	Bð 	Bð 	Br   c                 ó¸   — |j         |j         k    sJ ‚|j         | j        | j        fk    sJ ‚|                      t	          |¦  «        t	          |¦  «        ¦  «        S r8   )r(   r  ÚnnnÚ
evaluate_cr
   r  s      r   Úreplacement_evaluatez6handle_AutoTuneCriterion.<locals>.replacement_evaluate  sS   € ØŒw˜!œ'Ò!Ð!Ð!Ð!ØŒw˜4œ7 D¤HÐ-Ò-Ð-Ð-Ð-Ø�Š�x¨™{œ{­H°Q©K¬KÑ8Ô8Ð8r   Úset_groundtruthÚevaluater9   )r   r  r  s      r   Úhandle_AutoTuneCriterionr    sR   € ðBð Bð Bð9ð 9ð 9õ
 �9Ð/Ð1LÑMÔMÐMÝ�9˜jÐ*>Ñ?Ô?Ð?Ð?Ð?r   c                 ó.   — d„ }t          | d|¦  «         d S )Nc                 óÖ   — |j         |j        |j        fk    sJ ‚t          j        |d¬¦  «        }t          ¦   «         }|                      ||j        t          |¦  «        ||¦  «         |S r³   )r(   r  r)   r   r   r   Ú	explore_cr
   )r+   r-   ÚxqÚcritÚopss        r   Úreplacement_explorez2handle_ParameterSpace.<locals>.replacement_explore   sl   € ØŒx˜DœG U¤WÐ-Ò-Ð-Ð-Ð-ÝÔ! "¨IÐ6Ñ6Ô6ˆÝÑÔˆØ�Š�u˜dœg¥x°¡|¤|Ø˜Sñ	"ô 	"ð 	"àˆ
r   Úexplorer9   )r   r  s     r   Úhandle_ParameterSpacer    s,   € ðð ð õ �9˜iÐ)<Ñ=Ô=Ð=Ð=Ð=r   c                 ó.   ‡— | j         Šˆfd„}|| _         d S )Nc                 óÊ   •— t          |j        ¦  «        dk    sJ ‚t          j        |d¬¦  «        } ‰| |j        d         |j        d         t	          |¦  «        ¦  «         d S )NrR   r%   r&   r   rS   )Úlenr(   r   r   r
   )r+   ÚmÚoriginal_inits     €r   Úreplacement_initz,handle_MatrixStats.<locals>.replacement_init-  s_   ø€ Ý�1”7‰|Œ|˜qÒ Ð Ð Ð ÝÔ  ¨)Ð4Ñ4Ô4ˆØˆ�d˜AœG AœJ¨¬°¬
µH¸Q±K´KÑ@Ô@Ð@Ð@Ð@r   )Ú__init__)r   r"  r!  s     @r   Úhandle_MatrixStatsr$  *  s9   ø€ ØÔ&€MðAð Að Að Að Að
 *€IÔÐÐr   c                 ó   — d„ }|| _         dS )z add a write_bytes method c                 óP   —  | t          |¦  «        dt          |¦  «        ¦  «        S ©NrS   )r
   r  )r+   Úbs     r   Úwrite_bytesz$handle_IOWriter.<locals>.write_bytes7  s"   € Øˆt•H˜Q‘K”K ¥C¨¡F¤FÑ+Ô+Ð+r   N)r)  )r   r)  s     r   Úhandle_IOWriterr*  5  s!   € ð,ð ,ð ,ð (€IÔÐÐr   c                 ó   — d„ }|| _         dS )z add a read_bytes method c                 óœ   — t          |¦  «        } | t          |¦  «        dt          |¦  «        ¦  «        }t          |d |…         ¦  «        S r'  )Ú	bytearrayr
   r  Úbytes)r+   ÚtotszÚbufÚwas_reads       r   Ú
read_bytesz#handle_IOReader.<locals>.read_bytes@  sD   € Ý˜ÑÔˆØ�4� ™œ q­#¨c©(¬(Ñ3Ô3ˆÝ�S˜˜(˜”^Ñ$Ô$Ð$r   N)r2  )r   r2  s     r   Úhandle_IOReaderr3  =  s!   € ð%ð %ð %ð
 &€IÔÐÐr   c                 ó.   — d„ }t          | d|¦  «         d S )Nc                 ó¦   — |j         \  }}|| j        k    sJ ‚t          j        |d¬¦  «        }|                      |t          |¦  «        ¦  «         dS )a¼  Trains the index on a representative set of vectors inplace.
        The index must be trained before vectors can be added to it.

        This call WILL change the values in the input array, because
        of two scaling proceduces being performed inplace.

        Parameters
        ----------
        x : array_like
            Query vectors, shape (n, d) where d is appropriate for the index.
            `dtype` must be float32.
        r%   r&   N)r(   r)   r   r   Útrain_inplace_cr
   r>   s       r   Úreplacement_train_inplacez<handle_IndexRowwiseMinMax.<locals>.replacement_train_inplaceI  sU   € ð Œw‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ  ¨)Ð4Ñ4Ô4ˆØ×Ò˜Q¥¨¡¤Ñ,Ô,Ð,Ð,Ð,r   Útrain_inplacer9   )r   r7  s     r   Úhandle_IndexRowwiseMinMaxr9  H  s,   € ð-ð -ð -õ$ �9˜oÐ/HÑIÔIÐIÐIÐIr   c                 óV   — d„ }d„ }t          | d|¦  «         t          | d|¦  «         d S )Nc                 óø   — |j         | j        fk    sJ ‚|j         \  }}|| j        k    sJ ‚d|cxk    r|| j        z  k     sn J ‚|                      t          |¦  «        |t          j        |¦  «        ¦  «         d S )Nr   )r(   rF   Ú
block_sizeÚnvecÚpack_1_cr
   rÀ   )r+   r,   ÚoffsetÚblockÚnblockr<  s         r   Úreplacement_pack_1z-handle_CodePacker.<locals>.replacement_pack_1`  s‘   € ØŒw˜4œ>Ð+Ò+Ð+Ð+Ð+Ø"œ[Ñˆ�
Ø˜Tœ_Ò,Ð,Ð,Ð,Ø�FÐ3Ð3Ò3Ð3˜Z¨$¬)Ñ3Ò3Ð3Ð3Ð3Ð3Ð3Ø�Š•h˜q‘k”k 6­5¬>¸%Ñ+@Ô+@ÑAÔAÐAÐAÐAr   c                 ó  — |j         \  }}|| j        k    sJ ‚d|cxk    r|| j        z  k     sn J ‚t          j        | j        d¬¦  «        }|                      t          j        |¦  «        |t          |¦  «        ¦  «         |S )Nr   r   r&   )	r(   r<  r=  r   ÚzerosrF   Ú
unpack_1_crÀ   r
   )r+   r@  r?  rA  r<  r,   s         r   Úreplacement_unpack_1z/handle_CodePacker.<locals>.replacement_unpack_1g  sŽ   € Ø"œ[Ñˆ�
Ø˜Tœ_Ò,Ð,Ð,Ð,Ø�FÐ3Ð3Ò3Ð3˜Z¨$¬)Ñ3Ò3Ð3Ð3Ð3Ð3Ð3ÝŒH�T”^¨7Ð3Ñ3Ô3ˆØ�Š�œ uÑ-Ô-¨vµxÀ±{´{ÑCÔCÐCØˆr   Úpack_1Úunpack_1r9   )r   rB  rF  s      r   Úhandle_CodePackerrI  ^  sQ   € ðBð Bð Bðð ð õ �9˜hÐ(:Ñ;Ô;Ð;Ý�9˜jÐ*>Ñ?Ô?Ð?Ð?Ð?r   c                 óV   — d„ }d„ }t          | d|¦  «         t          | d|¦  «         d S )Nc                 ó–   — |j         \  }|f|j         k    sJ ‚|                      |t          |¦  «        t          |¦  «        ¦  «         d S r8   )r(   r^   r
   )r+   r™   Úvalsr/   s       r   Úreplacement_map_addz0handle_MapLong2Long.<locals>.replacement_map_addy  sH   € ØŒZ‰ˆØˆt�t”zÒ!Ð!Ð!Ð!Ø�
Š
�1•h˜t‘n”n¥h¨t¡n¤nÑ5Ô5Ð5Ð5Ð5r   c                 ó¦   — |j         \  }t          j        |d¬¦  «        }|                      |t	          |¦  «        t	          |¦  «        ¦  «         |S r¾   )r(   r   rE   Úsearch_multiple_cr
   )r+   r™   r/   rL  s       r   Úreplacement_map_search_multiplez<handle_MapLong2Long.<locals>.replacement_map_search_multiple~  sH   € ØŒZ‰ˆÝŒx˜ Ð)Ñ)Ô)ˆØ×Ò˜q¥(¨4¡.¤.µ(¸4±.´.ÑAÔAÐAØˆr   rÃ   Úsearch_multipler9   )r   rM  rP  s      r   Úhandle_MapLong2LongrR  w  sY   € ð6ð 6ð 6ð
ð ð õ �9˜eÐ%8Ñ9Ô9Ð9Ý�9Ð/Ø2ñ4ô 4ð 4ð 4ð 4r   c                 ón   — t          | d¦  «        s
|g| _        d S | j                             |¦  «         d S )NÚreferenced_objects)ÚhasattrrT  Úappend)r+   Úrefs     r   Úadd_to_referenced_objectsrX  Ž  sB   € Ý�4Ð-Ñ.Ô.ð ,Ø#& %ˆÔÐÐàÔ×&Ò& sÑ+Ô+Ð+Ð+Ð+r   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚRememberSwigOwnershipaJ  
    SWIG's seattr transfers ownership of SWIG wrapped objects to the class
    (btw this seems to contradict https://www.swig.org/Doc1.3/Python.html#Python_nn22
    31.4.2)
    This interferes with how we manage ownership: with the referenced_objects
    table. Therefore, we reset the thisown field in this context manager.
    c                 ó   — || _         d S r8   )Úobj)r+   r\  s     r   r#  zRememberSwigOwnership.__init__�  s   € ØˆŒˆˆr   c                 ód   — t          | j        d¦  «        r| j        j        | _        d S d | _        d S )NÚthisown)rU  r\  r^  Úold_thisownrÚ   s    r   Ú	__enter__zRememberSwigOwnership.__enter__   s7   € Ý�4”8˜YÑ'Ô'ð 	$Ø#œxÔ/ˆDÔÐÐà#ˆDÔÐÐr   c                 ó:   — | j         �| j         | j        _        d S d S r8   )r_  r\  r^  )r+   Úignoreds     r   Ú__exit__zRememberSwigOwnership.__exit__¦  s&   € ØÔÐ'Ø#Ô/ˆDŒHÔÐÐð (Ð'r   N)r   Ú
__module__Ú__qualname__Ú__doc__r#  r`  rc  © r   r   rZ  rZ  ”  sK   € € € € € ðð ðð ð ð$ð $ð $ð0ð 0ð 0ð 0ð 0r   rZ  c                 ó2   — | j         | _        d„ }|| _         dS )a   this wrapper is to enable initializations of the form
    SearchParametersXX(a=3, b=SearchParamsYY)
    This also requires the enclosing class to keep a reference on the
    sub-object, since the C++ code assumes the object ownwership is
    handled externally.
    c                 óh  — |                       ¦   «          |                     ¦   «         D ]ˆ\  }}t          | |¦  «        sJ ‚t          |¦  «        5  t	          | ||¦  «         d d d ¦  «         n# 1 swxY w Y   t          |¦  «        t          t          t          t          fvrt          | |¦  «         Œ‰d S r8   )r!  ÚitemsrU  rZ  r   r€   r¡   r�   ÚboolÚstrrX  )r+   Úargsri   Úvs       r   r"  z1handle_SearchParameters.<locals>.replacement_init´  sï   € Ø×ÒÑÔÐØ—J’J‘L”Lð 	3ð 	3‰DˆAˆqÝ˜4 Ñ#Ô#Ð#Ð#Ð#Ý& qÑ)Ô)ð $ð $Ý˜˜a Ñ#Ô#Ð#ð$ð $ð $ñ $ô $ð $ð $ð $ð $ð $ð $øøøð $ð $ð $ð $å�A‰wŒw�s¥E­4µÐ5Ð5Ð5Ý)¨$°Ñ2Ô2Ð2øð	3ð 	3s   ÁA-Á-A1	Á4A1	N©r#  r!  )r   r"  s     r   Úhandle_SearchParametersrp  «  s.   € ð (Ô0€IÔð3ð 3ð 3ð *€IÔÐÐr   Tc                 ó<   ‡‡— | j         | _        ˆˆfd„}|| _         d S )Nc                 óä   •— t          |¦  «        dk    rQ|\  }‰rt          j        |d¬¦  «        }t          |¦  «        t          j        |¦  «        f}‰st          | |¦  «          | j        |Ž  d S rò   )r  r   r   rÀ   r
   rX  r!  )r+   rm  ÚsubsetÚ
class_ownsÚforce_int64s      €€r   r"  z1handle_IDSelectorSubset.<locals>.replacement_initÃ  s   ø€ Ýˆt‰9Œ9˜Š>ˆ>à‰GˆFØð EÝÔ-¨f¸GÐDÑDÔD�Ý˜‘K”K¥¤°Ñ!7Ô!7Ð8ˆDØð 8Ý)¨$°Ñ7Ô7Ð7ØˆÔ˜DÐ!Ð!Ð!Ð!r   ro  )r   rt  ru  r"  s    `` r   Úhandle_IDSelectorSubsetrv  À  s=   øø€ Ø'Ô0€IÔð	"ð 	"ð 	"ð 	"ð 	"ð 	"ð *€IÔÐÐr   c                 ó0   — dd„}t          | d|¦  «         d S )Nc                 ó.  — |j         \  }}|| j        k    sJ ‚t          j        |t          j        ¬¦  «        }|€t          j        |t          ¬¦  «        }n|j         |fk    sJ ‚|                      |t          |¦  «        t          |¦  «        ¦  «         |S r·   )	r(   r)   r   r   r   rE   rk  Úinsert_cr
   )r+   r   Úinsertedr/   r)   s        r   Úreplacement_insertz*handle_CodeSet.<locals>.replacement_insertÓ  s�   € ØŒ{‰ˆˆ1Ø�D”FŠ{ˆ{ˆ{ˆ{ÝÔ$ Uµ"´(Ð;Ñ;Ô;ˆàÐÝ”x ­Ð.Ñ.Ô.ˆHˆHà”> a UÒ*Ð*Ð*Ð*à�Š�a� %™œ­(°8Ñ*<Ô*<Ñ=Ô=Ð=Øˆr   Úinsertr8   r9   )r   r{  s     r   Úhandle_CodeSetr}  Ñ  s1   € ðð ð ð õ �9˜hÐ(:Ñ;Ô;Ð;Ð;Ð;r   c                 óF   — | j         | _        d„ }d„ }|| _         || _        d S )Nc                 ó  — t          |¦  «        dk    rd|\  }|j        \  }}|                      ||¦  «         t          j        t          j        |¦  «                             ¦   «         | j        ¦  «         d S  | j        |Ž  d S r'  )	r  r(   r!  rÀ   Úcopy_array_to_vectorr   r   Úravelrn  )r+   rm  Úarrayr/   r)   s        r   r"  z)handle_Tensor2D.<locals>.replacement_initê  sŽ   € Ýˆt‰9Œ9˜Š>ˆ>Ø‰FˆEØ”;‰DˆAˆqØ×Ò˜q !Ñ$Ô$Ð$ÝÔ&ÝÔ$ UÑ+Ô+×1Ò1Ñ3Ô3°T´Vñ=ô =ð =ð =ð =ð ˆDÔ Ð%Ð%Ð%Ð%r   c                 ó  — t          j        dt           j        ¬¦  «        }t          j        t          j        |¦  «        | j        |j        ¦  «         t          j        | j	        ¦  «         
                    |d         |d         ¦  «        S )NrR   r&   r   rS   )r   rD  rT   rÀ   Úmemcpyr
   r(   ÚnbytesÚvector_to_arrayrn  Úreshape)r+   r(   s     r   Únumpyzhandle_Tensor2D.<locals>.numpyô  se   € Ý”˜¥"¤(Ð+Ñ+Ô+ˆÝŒ•U”^ EÑ*Ô*¨D¬J¸¼ÑEÔEÐEÝÔ$ T¤VÑ,Ô,×4Ò4°U¸1´X¸uÀQ¼xÑHÔHÐHr   )r#  r!  rˆ  )r   r"  rˆ  s      r   Úhandle_Tensor2Dr‰  ç  sC   € Ø'Ô0€IÔð&ð &ð &ðIð Ið Ið
 *€IÔØ€I„O€O€Or   c                 ó`   ‡ — ‰ j         ‰ _        ˆ fd„}d„ }d„ }|‰ _        |‰ _        |‰ _         d S )Nc                 óâ   •— t          |¦  «        dk    s|d         j        ‰k    r | j        |Ž  d S |d         }|                      |j        |j        ¦  «         |                      |¦  «         d S ©NrS   r   )r  Ú	__class__r!  Únum_embeddingsÚembedding_dimÚ
from_torch)r+   rm  Úembr   s      €r   r"  z*handle_Embedding.<locals>.replacement_init   su   ø€ Ýˆt‰9Œ9˜Š>ˆ>˜T !œWÔ.°)Ò;Ð;ØˆDÔ Ð%Ð%ØˆFà�1ŒgˆØ×Ò˜3Ô-¨sÔ/@ÑAÔAÐAØ�Š˜ÑÔÐÐÐr   c                 óÒ   — |j         j        | j        | j        fk    sJ ‚t	          j        t          j        |j         j        ¦  «         	                    ¦   «         | j         ¦  «         dS )z# copy weights from torch.Embedding N)
Úweightr(   rŽ  r�  rÀ   r€  r   r   Údatar�  )r+   r‘  s     r   r�  z$handle_Embedding.<locals>.from_torch	  si   € àŒzÔ DÔ$7¸Ô9KÐ#LÒLÐLÐLÐLÝÔ"ÝÔ  ¤¤Ñ1Ô1×7Ò7Ñ9Ô9¸4¼;ñ	Hô 	Hð 	Hð 	Hð 	Hr   c                 ó´   — |j         | j        | j        fk    sJ ‚t          j        t          j        |¦  «                             ¦   «         | j        ¦  «         dS ©z copy weights from numpy array N)	r(   rŽ  r�  rÀ   r€  r   r   r�  r“  )r+   r‚  s     r   Ú
from_arrayz$handle_Embedding.<locals>.from_array  s]   € àŒ{˜tÔ2°DÔ4FÐGÒGÐGÐGÐGÝÔ"ÝÔ  Ñ'Ô'×-Ò-Ñ/Ô/°´ñ	>ô 	>ð 	>ð 	>ð 	>r   ©r#  r!  r—  r�  ©r   r"  r�  r—  s   `   r   Úhandle_Embeddingrš  ý  sh   ø€ Ø'Ô0€IÔðð ð ð ð ðHð Hð Hð>ð >ð >ð &€IÔØ%€IÔØ)€IÔÐÐr   c                 ób   ‡ — ‰ j         ‰ _        ˆ fd„}d„ }dd„}|‰ _         |‰ _        |‰ _        d S )Nc                 óö   •— t          |¦  «        dk    s|d         j        ‰k    r | j        |Ž  d S |d         }|j        d u}|                      |j        |j        |¦  «         |                      |¦  «         d S rŒ  )r  r�  r!  ÚbiasÚin_featuresÚout_featuresr�  )r+   rm  Úlinearr�  r   s       €r   r"  z'handle_Linear.<locals>.replacement_init  sƒ   ø€ Ýˆt‰9Œ9˜Š>ˆ>˜T !œWÔ.°)Ò;Ð;ØˆDÔ Ð%Ð%ØˆFà�a”ˆØŒ{ $Ð&ˆØ×Ò˜6Ô-¨vÔ/BÀDÑIÔIÐIØ�Š˜ÑÔÐÐÐr   c                 ó€  — |j         j        | j        | j        fk    sJ ‚t	          j        |j         j                             ¦   «                              ¦   «         | j         ¦  «         |j	        �P|j	        j        | j        fk    sJ ‚t	          j        |j	        j                             ¦   «         | j	        ¦  «         dS dS )z  copy weights from torch.Linear N)
r“  r(   rŸ  rž  rÀ   r€  r”  rˆ  r�  r�  )r+   r   s     r   r�  z!handle_Linear.<locals>.from_torch'  s´   € àŒ}Ô" tÔ'8¸$Ô:JÐ&KÒKÐKÐKÐKÝÔ"ØŒMÔ×$Ò$Ñ&Ô&×,Ò,Ñ.Ô.°´ñ	=ô 	=ð 	=àŒ;Ð"Ø”;Ô$¨Ô):Ð(<Ò<Ð<Ð<Ð<ÝÔ& v¤{Ô'7×'=Ò'=Ñ'?Ô'?ÀÄÑKÔKÐKÐKÐKð #Ð"r   c                 ó  — |j         | j        | j        fk    sJ ‚t          j        t          j        |¦  «                             ¦   «         | j        ¦  «         |�/|j         | j        fk    sJ ‚t          j        || j	        ¦  «         dS dS r–  )
r(   rŸ  rž  rÀ   r€  r   r   r�  r“  r�  )r+   r‚  r�  s      r   r—  z!handle_Linear.<locals>.from_array0  s•   € àŒ{˜tÔ0°$Ô2BÐCÒCÐCÐCÐCÝÔ"ÝÔ  Ñ'Ô'×-Ò-Ñ/Ô/°´ñ	>ô 	>ð 	>àÐØ”: $Ô"3Ð!5Ò5Ð5Ð5Ð5ÝÔ& t¨T¬YÑ7Ô7Ð7Ð7Ð7ð Ðr   r8   r˜  r™  s   `   r   Úhandle_Linearr£    sm   ø€ Ø'Ô0€IÔð ð  ð  ð  ð  ðLð Lð Lð8ð 8ð 8ð 8ð *€IÔØ%€IÔØ%€IÔÐÐr   c                 óL   ‡ — ‰ j         ‰ _        ˆ fd„}d„ }|‰ _         |‰ _        d S )Nc                 óú   •— t          |¦  «        dk    s|d         j        ‰k    r | j        |Ž  d S |d         }|                      |j        |j        |j        |j        ¦  «         |                      |¦  «         d S rŒ  )r  r�  r!  r)   rX   ÚLÚhr�  )r+   rm  Ústepr   s      €r   r"  z*handle_QINCoStep.<locals>.replacement_initD  s{   ø€ Ýˆt‰9Œ9˜Š>ˆ>˜T !œWÔ.°)Ò;Ð;ØˆDÔ Ð%Ð%ØˆFØ�AŒwˆà×Ò˜4œ6 4¤6¨4¬6°4´6Ñ:Ô:Ð:Ø�Š˜ÑÔÐÐÐr   c                 óä  — |j         |j        |j        |j        f| j         | j        | j        | j        fk    sJ ‚| j                             |j        ¦  «         | j                             |j        ¦  «         t          |j        ¦  «        D ]d}|j        |         }|  	                    |¦  «        }|j
                             |d         ¦  «         |j                             |d         ¦  «         ŒedS )z# copy weights from torch.QINCoStep r   rR   N)r)   rX   r¦  r§  Úcodebookr�  Ú	MLPconcatÚrangeÚresidual_blocksÚget_residual_blockÚlinear1Úlinear2)r+   r¨  ÚlÚsrcÚdests        r   r�  z$handle_QINCoStep.<locals>.from_torchM  sÝ   € à”˜œ ¤¨¬Ð/°D´F¸D¼FÀDÄFÈDÌFÐ3SÒSÐSÐSÐSØŒ× Ò  ¤Ñ/Ô/Ð/ØŒ×!Ò! $¤.Ñ1Ô1Ð1å�t”v‘”ð 	,ð 	,ˆAØÔ& qÔ)ˆCØ×*Ò*¨1Ñ-Ô-ˆDØŒL×#Ò# C¨¤FÑ+Ô+Ð+ØŒL×#Ò# C¨¤FÑ+Ô+Ð+Ð+ð		,ð 	,r   ©r#  r!  r�  ©r   r"  r�  s   `  r   Úhandle_QINCoStepr¶  A  sN   ø€ Ø'Ô0€IÔðð ð ð ð ð
,ð 
,ð 
,ð *€IÔØ%€IÔÐÐr   c                 óL   ‡ — ‰ j         ‰ _        ˆ fd„}d„ }|‰ _         |‰ _        d S )Nc                 ó  •— t          |¦  «        dk    s|d         j        ‰k    r | j        |Ž  d S |d         }|                      |j        |j        |j        |j        |j        ¦  «         |                      |¦  «         d S rŒ  )	r  r�  r!  r)   rX   r¦  ÚMr§  r�  )r+   rm  Úqincor   s      €r   r"  z&handle_QINCo.<locals>.replacement_init`  s�   ø€ Ýˆt‰9Œ9˜Š>ˆ>˜T !œWÔ.°)Ò;Ð;ØˆDÔ Ð%Ð%ØˆFð �Q”ˆØ×Ò˜5œ7 E¤G¨U¬W°e´g¸u¼wÑGÔGÐGØ�Š˜ÑÔÐÐÐr   c                 óf  — |j         |j        |j        |j        |j        f| j         | j        | j        | j        | j        fk    sJ ‚| j                             |j        ¦  «         t          |j        dz
  ¦  «        D ]5}|                      |¦  «                             |j	        |         ¦  «         Œ6dS )z copy weights from torch.QINCo rS   N)
r)   rX   r¦  r¹  r§  Ú	codebook0r�  r¬  Úget_stepÚsteps)r+   rº  r   s      r   r�  z handle_QINCo.<locals>.from_torchj  s²   € ð ŒW�e”g˜uœw¨¬°´Ð9ØŒV�T”V˜TœV T¤V¨T¬VÐ4ò5ð 5ð 5ð 5ð 	Œ×!Ò! %¤/Ñ2Ô2Ð2Ý�u”w ‘{Ñ#Ô#ð 	8ð 	8ˆAØ�MŠM˜!ÑÔ×'Ò'¨¬°A¬Ñ7Ô7Ð7Ð7ð	8ð 	8r   r´  rµ  s   `  r   Úhandle_QINCor¿  ]  sN   ø€ Ø'Ô0€IÔðð ð ð ð ð8ð 8ð 8ð *€IÔØ%€IÔÐÐr   )F)T))ÚinspectrÀ   rˆ  r   Úfaiss.loaderr   r   r   r   r   r   r	   r
   r   r   r"   r:   rA   rO   r[   rå   rô   r  r  r  r$  r*  r3  r9  rI  rR  rX  rZ  rp  rv  r}  r‰  rš  r£  r¶  r¿  rg  r   r   ú<module>rÂ     ss  ðð €€€à €€€Ø Ð Ð Ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð8'ð 'ð 'ð*ð *ð *ð *ð 6Jð 6Jð 6JðrFð Fð Fð$9<ð 9<ð 9<ðx:ð :ð :ðk	,ð k	,ð k	,ð\iNð iNð iNðX2ð 2ð 2ð@@ð @ð @ð">ð >ð >ð*ð *ð *ð(ð (ð (ð&ð &ð &ðJð Jð Jð,@ð @ð @ð24ð 4ð 4ð.,ð ,ð ,ð0ð 0ð 0ð 0ð 0ñ 0ô 0ð 0ð.*ð *ð *ð**ð *ð *ð *ð"<ð <ð <ð,ð ð ð,*ð *ð *ð:!&ð !&ð !&ðN&ð &ð &ð8&ð &ð &ð &ð &r   