
    g                     T    d dl Zd dlZd Zd Zd Zd Zd ZddZd Z	d	 Z
d
 Zd ZdS )    Nc                 Z   t          j        |           } |                     |          }t          j        |d          }dx}}	 |                     |          }|dk    r-t          j        t          j        |          ||j                   | 	                    |          }| j
        t           j        j        k    rt          j        || j
        fd          }n5| j        }| j        }||z   dz
  |z  }	t          j        |	||z  |fd          }|dk    r-t          j        t          j        |          ||j                   ||                     ||           ||                     ||           n6# ||                     ||           ||                     ||           w w xY w||fS )zy returns the inverted lists content as a pair of (list_ids, list_codes).
    The codes are reshaped to a proper size
    int64dtypeNr   uint8   )faissdowncast_InvertedLists	list_sizenpzerosget_idsmemcpyswig_ptrnbytes	get_codes	code_sizeInvertedListsINVALID_CODE_SIZEn_per_block
block_sizerelease_idsrelease_codes)
invlistsllslist_idsidscodes
list_codesnpbbsls_rounds
             Y/var/www/html/mpstechhub/venv/lib/python3.11/site-packages/faiss/contrib/inspect_tools.pyget_invlistr%   
   s    +H55H			A		Bx'***HC%-q!!66L113HHH""1%%!4!FFF2x'9":'JJJJJ &C$BS1,H8R3Y"<GLLLJ66L
33UJ<MNNN?  C(((""1e,,, ?  C(((""1e,,,, Zs   C=E3 33F&c                 l     t          j         fdt           j                  D             d          S )z1 return the array of sizes of the inverted lists c                 :    g | ]}                     |          S  )r   ).0ir   s     r$   
<listcomp>z%get_invlist_sizes.<locals>.<listcomp>+   s7        	1      r   r   )r   arrayrangenlist)r   s   `r$   get_invlist_sizesr0   )   sQ    8    x~&&      r,   c           	      h    | j         j        D ]$}t          | dt          | |                      %dS )z3 list values all fields of an object known to SWIG z = N)	__class____swig_getmethods__printgetattr)objnames     r$   print_object_fieldsr8   1   sK     1 0 0..'#t,,..////0 0r,   c                     t          j        | j                  }|                    | j        | j        | j                  S )z% return the PQ centroids as an array )r	   vector_to_array	centroidsreshapeMksubdsub)pqcens     r$   get_pq_centroidsrB   8   s0    


-
-C;;rtRWbg...r,   c                     t          j        | j                  }t          j        | j                                      | j        | j                  }||fS )zo extract matrix + bias from the PCA object
    works for any linear transform (OPQ, random rotation, etc.)
    )r	   r:   bAr<   d_outd_in)pcarD   rE   s      r$   get_LinearTransform_matrixrI   >   sE     	ce$$Ace$$,,SYAAAa4Kr,   c                 0   | j         \  }}||j         |fk    sJ t          j        |||du          }t          j        |                                 |j                   |t          j        ||j                   d|_        |                                 |S )zA make a linear transform from a matrix and a bias term (optional)NT)	shaper	   LinearTransformcopy_array_to_vectorravelrE   rD   
is_trainedset_is_orthonormal)rE   rD   rF   rG   lts        r$   make_LinearTransform_matrixrR   G   s    'KE4}w5)####		tUATM	:	:B	qwwyy"$///}"1bd+++BMIr,   c                     t          j        | j                                      d| j                  t          j        | j                  fdt          | j                  D             S )z. return to codebooks of an additive quantizer c                 B    g | ]}|         |d z                     S )r   r(   )r)   r*   co	codebookss     r$   r+   z4get_additive_quantizer_codebooks.<locals>.<listcomp>Y   s>        	"Q%1q5	/"  r,   )r	   r:   rW   r<   dcodebook_offsetsr.   r=   )aqrV   rW   s    @@r$    get_additive_quantizer_codebooksr[   U   ss    %bl33;;BEEI		r2	3	3B    rt   r,   c                     t          j        | j                                      d          }|                    | j        | j                  S )z1 copy and return the data matrix in an IndexFlat float32)r	   r:   r   viewr<   ntotalrX   )indexxbs     r$   get_flat_datarb   _   s:    		u{	+	+	0	0	;	;B::elEG,,,r,   c                 p    t          j        | j                                      | j        | j                  S )z2 get the codes from an indexFlatCodes as an array )r	   r:   r   r<   r_   r   )
index_flats    r$   get_flat_codesre   e   s3     !122:::/1 1 1r,   c                     |                                  }t          j        |j        |j        fd          }t          j        t          j        |          |j        |j	                   |S )zf get the neighbor list for the vectors stored in the NSG structure, as
    a N-by-K matrix of indices int32r   )
get_final_graphr   r   NKr	   r   r   datar   )nsggraph	neighborss      r$   get_NSG_neighborsro   k   sf     !!E%'57+7;;;I	Ly!!
  
 r,   )N)numpyr   r	   r%   r0   r8   rB   rI   rR   r[   rb   re   ro   r(   r,   r$   <module>rq      s             >  0 0 0/ / /       - - -1 1 1
 
 
 
 
r,   