ó
    ö<ðhì#  ã                   ó\   • S SK rS SK7  S
S jrSS jrSS jrSS\SSS S 4S jrS\S4S	 jrg)é    N)Ú*c                 ó  • Uc  [        [        U 5      5      n[        5       n[        5       n[	        X05       H'  u  pgUR                  U5        UR                  U5        M)     [        U[        5      (       a  [        XEX5      $ [        XEX5      $ )z„builds the C++ vectors for the GPU indices and the
resources. Handles the case where the resources are assigned to
the list of GPUs )
ÚrangeÚlenÚGpuResourcesVectorÚInt32VectorÚzipÚ	push_backÚ
isinstanceÚIndexBinaryÚ index_binary_cpu_to_gpu_multipleÚindex_cpu_to_gpu_multiple)Ú	resourcesÚindexÚcoÚgpusÚvresÚvdevÚiÚress           ÚL/home/james-whalen/.local/lib/python3.13/site-packages/faiss/gpu_wrappers.pyÚindex_cpu_to_gpu_multiple_pyr      sx   € ð |Ü”S˜“^Ó$ˆÜÓ€DÜ‹=€DÜdÖ&‰ˆØ‰qÔØ‰sÖñ 'ô %œ×%Ñ%Ü/°¸EÓFÐFä(¨°UÓ?Ð?ó    éÿÿÿÿc                 ó   • [        XS US9nU$ )N)r   r   Úngpu)Úindex_cpu_to_gpus_list)r   r   r   Ú	index_gpus       r   Úindex_cpu_to_all_gpusr   &   s   € Ü& u¸$ÀTÑJ€IØÐr   c                 ó¾   • Uc  US:X  a  [        [        5       5      nOUc  US:w  a  [        U5      nU Vs/ s H  n[        5       PM     nn[        XPX5      nU$ s  snf )z‹Here we can pass list of GPU ids as a parameter or ngpu to
use first n GPU's. gpus mut be a list or None.
co is a GpuMultipleClonerOptions
r   )r   Úget_num_gpusÚStandardGpuResourcesr   )r   r   r   r   Ú_r   r   s          r   r   r   +   s^   € ð
 	‰˜4 2›:Ü”\“^Ó$‰Ø
‰,˜T R›ZÜT‹{ˆÙ+/Ó
0ª4 aÔÖ!©4€CÐ
0Ü,¨S¸ÓB€IØÐùò 1s   ¶AFc                 ó¼  • UR                   u  p¼UR                  R                  (       a  SnOAUR                  R                  (       a  UR                  nSnO[
        R                  " USS9nSn[        U5      nUR                  [
        R                  :X  a  [        nO0UR                  [
        R                  :X  a  [        nO[        S5      eUR                   u  nnUU:X  d   eUR                  R                  (       a  SnOAUR                  R                  (       a  UR                  nSnO[
        R                  " USS9nSn[        U5      nUR                  [
        R                  :X  a  [        nO0UR                  [
        R                  :X  a  [        nO[        S5      eUc%  [
        R                  " X³4[
        R                  S9nO3UR                   X³4:X  d   eUR                  [
        R                  :X  d   e[        U5      nUc%  [
        R                  " X³4[
        R                  S9nOUR                   X³4:X  d   e[        U5      nUR                  [
        R                  :X  a  [         nODUR                  UR                  s=:X  a  [
        R"                  :X  a
  O  O[$        nO[        S5      e['        5       nUUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl        UUl         UUl!        UUl"        UUl#        U	S:”  d  U
S:”  a  [I        U UXš5        XE4$ [K        U U5        XE4$ )	ac  
Compute the k nearest neighbors of a vector on one GPU without constructing an index

Parameters
----------
res : StandardGpuResources
    GPU resources to use during computation
xq : array_like
    Query vectors, shape (nq, d) where d is appropriate for the index.
    `dtype` must be float32.
xb : array_like
    Database vectors, shape (nb, d) where d is appropriate for the index.
    `dtype` must be float32.
k : int
    Number of nearest neighbors.
D : array_like, optional
    Output array for distances of the nearest neighbors, shape (nq, k)
I : array_like, optional
    Output array for the nearest neighbors, shape (nq, k)
metric : MetricType, optional
    Distance measure to use (either METRIC_L2 or METRIC_INNER_PRODUCT)
device: int, optional
    Which CUDA device in the system to run the search on. -1 indicates that
    the current thread-local device state (via cudaGetDevice) should be used
    (can also be set via torch.cuda.set_device in PyTorch)
    Otherwise, an integer 0 <= device < numDevices indicates the GPU on which
    the computation should be run
vectorsMemoryLimit: int, optional
queriesMemoryLimit: int, optional
    Memory limits for vectors and queries.
    If not 0, the GPU will use at most this amount of memory
    for vectors and queries respectively.
    Vectors are broken up into chunks of size vectorsMemoryLimit,
    and queries are broken up into chunks of size queriesMemoryLimit,
    including the memory required for the results.

Returns
-------
D : array_like
    Distances of the nearest neighbors, shape (nq, k)
I : array_like
    Labels of the nearest neighbors, shape (nq, k)
TFÚfloat32©Údtypezxq must be f32 or f16úxb must be float32 or float16zI must be i64 or i32r   )&ÚshapeÚflagsÚc_contiguousÚf_contiguousÚTÚnpÚascontiguousarrayÚswig_ptrr'   r%   ÚDistanceDataType_F32Úfloat16ÚDistanceDataType_F16Ú	TypeErrorÚemptyÚint64ÚIndicesDataType_I64Úint32ÚIndicesDataType_I32ÚGpuDistanceParamsÚmetricÚkÚdimsÚvectorsÚvectorsRowMajorÚ
vectorTypeÚ
numVectorsÚqueriesÚqueriesRowMajorÚ	queryTypeÚ
numQueriesÚoutDistancesÚ
outIndicesÚoutIndicesTypeÚdeviceÚuse_cuvsÚbfKnn_tilingÚbfKnn)r   ÚxqÚxbr<   ÚDÚIr;   rI   rJ   ÚvectorsMemoryLimitÚqueriesMemoryLimitÚnqÚdÚxq_row_majorÚxq_ptrÚxq_typeÚnbÚd2Úxb_row_majorÚxb_ptrÚxb_typeÚD_ptrÚI_ptrÚI_typeÚargss                            r   Úknn_gpura   ;   sª  € ðX H‰HE€BØ	‡xx××Ø‰Ø	‰×	×	ØT‰TˆØ‰ä×!Ò! "¨IÑ6ˆØˆäb‹\€Fà	‡xx”2—:‘:ÓÜ&‰Ø	‰”R—Z‘ZÓ	Ü&‰äÐ/Ó0Ð0àX‰XF€BˆØ‹7€Nˆ7Ø	‡xx××Ø‰Ø	‰×	×	ØT‰TˆØ‰ä×!Ò! "¨IÑ6ˆØˆäb‹\€Fà	‡xx”2—:‘:ÓÜ&‰Ø	‰”R—Z‘ZÓ	Ü&‰äÐ7Ó8Ð8àyÜHŠHbW¤B§J¡JÑ/‰àw‰w˜2˜'Ó!Ð!Ð!àw‰wœ"Ÿ*™*Ó$Ð$Ð$äQ‹K€EàyÜHŠHbW¤B§H¡HÑ-‰àw‰w˜2˜'Ó!Ð!Ð!äQ‹K€Eà‡ww”"—(‘(ÓÜ$‰Ø	
‰A—G‘GÕ	'œrŸx™xÖ	'Ü$‰äÐ.Ó/Ð/äÓ€DØ€D„KØ€D„FØ€D„IØ€D„LØ'€DÔØ€D„OØ€D„OØ€D„LØ'€DÔØ€D„NØ€D„OØ€DÔØ€D„OØ €DÔØ€D„KØ€D„Mð ˜AÓÐ!3°aÓ!7ÜS˜$Ð 2ÔGð ˆ4€Kô 	ˆc4Ôàˆ4€Kr   c                 óö  • UR                   u  pgUR                  R                  (       a  SnO5UR                  R                  (       a  UR                  nSnO[        S5      e[        U5      n	UR                  [        R                  :X  a  [        n
O<UR                  [        R                  :X  a  [        n
O[        R                  " USS9nSnUR                   u  p¼XÇ:X  d   eUR                  R                  (       a  SnOAUR                  R                  (       a  UR                  nSnO[        R                  " USS9nSn[        U5      nUR                  [        R                  :X  a  [        nO0UR                  [        R                  :X  a  [        nO[        S5      eUc%  [        R                  " Xk4[        R                  S9nO3UR                   Xk4:X  d   eUR                  [        R                  :X  d   e[        U5      n[        5       nUUl        SUl        UUl        UUl        UUl        UUl        UUl        U	Ul        UUl        W
Ul        UUl        UUl        UUl        [;        U U5        U$ )a  
Compute all pairwise distances between xq and xb on one GPU without constructing an index

Parameters
----------
res : StandardGpuResources
    GPU resources to use during computation
xq : array_like
    Query vectors, shape (nq, d) where d is appropriate for the index.
    `dtype` must be float32.
xb : array_like
    Database vectors, shape (nb, d) where d is appropriate for the index.
    `dtype` must be float32.
D : array_like, optional
    Output array for all pairwise distances, shape (nq, nb)
metric : MetricType, optional
    Distance measure to use (either METRIC_L2 or METRIC_INNER_PRODUCT)
device: int, optional
    Which CUDA device in the system to run the search on. -1 indicates that
    the current thread-local device state (via cudaGetDevice) should be used
    (can also be set via torch.cuda.set_device in PyTorch)
    Otherwise, an integer 0 <= device < numDevices indicates the GPU on which
    the computation should be run

Returns
-------
D : array_like
    All pairwise distances, shape (nq, nb)
TFz5xq matrix should be row (C) or column-major (Fortran)r%   r&   r(   r   )r)   r*   r+   r,   r-   r4   r0   r'   r.   r%   r1   r2   r3   r/   r5   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rI   rL   )r   rM   rN   rO   r;   rI   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r`   s                     r   Úpairwise_distance_gpurc   Ã   sö  € ð< H‰HE€BØ	‡xx××Ø‰Ø	‰×	×	ØT‰TˆØ‰äØCóEð 	Eô b‹\€Fà	‡xx”2—:‘:ÓÜ&‰Ø	‰”R—Z‘ZÓ	Ü&‰ä×!Ò! "¨IÑ6ˆØˆàX‰XF€BØ‹7€Nˆ7Ø	‡xx××Ø‰Ø	‰×	×	ØT‰TˆØ‰ä×!Ò! "¨IÑ6ˆØˆäb‹\€Fà	‡xx”2—:‘:ÓÜ&‰Ø	‰”R—Z‘ZÓ	Ü&‰äÐ7Ó8Ð8àyÜHŠHbX¤R§Z¡ZÑ0‰àw‰w˜2˜(Ó"Ð"Ð"àw‰wœ"Ÿ*™*Ó$Ð$Ð$äQ‹K€EäÓ€DØ€D„KØ€D„FØ€D„IØ€D„LØ'€DÔØ€D„OØ€D„OØ€D„LØ'€DÔØ€D„NØ€D„OØ€DÔØ€D„Kô 
ˆ#ˆtÔà€Hr   )NN)Nr   )NNr   )	Únumpyr.   Úfaiss.loaderr   r   r   Ú	METRIC_L2ra   rc   © r   r   Ú<module>rh      sK   ðó ä ô@ô"ô
ð  # d°9ÀRÐRWÐlmð  CDô CðP *.°iÈõ br   