§
    ÏÁ³gì#  ã                   óR   — d dl Zd dlT d
d„Zdd„Zdd„Zddeddd d fd„Zdedfd	„ZdS )é    N)Ú*c                 óh  — |€t          t          | ¦  «        ¦  «        }t          ¦   «         }t          ¦   «         }t	          || ¦  «        D ]/\  }}|                     |¦  «         |                     |¦  «         Œ0t          |t          ¦  «        rt          ||||¦  «        S t          ||||¦  «        S )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           úP/var/www/html/mpstechhub/venv/lib/python3.11/site-packages/faiss/gpu_wrappers.pyÚindex_cpu_to_gpu_multiple_pyr      s¯   € ð €|Ý•S˜‘^”^Ñ$Ô$ˆÝÑÔ€DÝ‰=Œ=€DÝ�d˜IÑ&Ô&ð ð ‰ˆˆ3Ø�Š�qÑÔÐØ�Š�sÑÔÐÐÝ�%�Ñ%Ô%ð @Ý/°°d¸EÀ2ÑFÔFÐFå(¨¨t°U¸BÑ?Ô?Ð?ó    éÿÿÿÿc                 ó,   — t          | |d |¬¦  «        }|S )N)r   r   Úngpu)Úindex_cpu_to_gpus_list)r   r   r   Ú	index_gpus       r   Úindex_cpu_to_all_gpusr   &   s   € Ý& u°¸$ÀTÐJÑJÔJ€IØÐr   c                 ó¸   — |€"|dk    rt          t          ¦   «         ¦  «        }n|€|dk    rt          |¦  «        }d„ |D ¦   «         }t          || ||¦  «        }|S )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
    Nr   c                 ó*   — g | ]}t          ¦   «         ‘ŒS © )ÚStandardGpuResources)Ú.0Ú_s     r   ú
<listcomp>z*index_cpu_to_gpus_list.<locals>.<listcomp>4   s   € Ð
0Ð
0Ð
0 aÕÑ!Ô!Ð
0Ð
0Ð
0r   )r   Úget_num_gpusr   )r   r   r   r   r   r   s         r   r   r   +   sh   € ð
 	ˆ˜4 2š:˜:Ý•\‘^”^Ñ$Ô$ˆˆØ
ˆ,˜T RšZ˜ZÝ�T‰{Œ{ˆØ
0Ð
0¨4Ð
0Ñ
0Ô
0€CÝ,¨S°%¸¸TÑBÔB€IØÐr   Fc                 óÚ  — |j         \  }}|j        j        rd}n.|j        j        r
|j        }d}nt          j        |d¬¦  «        }d}t          |¦  «        }|j        t
          j	        k    rt          }n,|j        t
          j        k    rt          }nt          d¦  «        ‚|j         \  }}||k    sJ ‚|j        j        rd}n.|j        j        r
|j        }d}nt          j        |d¬¦  «        }d}t          |¦  «        }|j        t
          j	        k    rt          }n,|j        t
          j        k    rt          }nt          d¦  «        ‚|€#t          j        ||ft
          j	        ¬¦  «        }n&|j         ||fk    sJ ‚|j        t
          j	        k    sJ ‚t          |¦  «        }|€#t          j        ||ft
          j        ¬¦  «        }n|j         ||fk    sJ ‚t          |¦  «        }|j        t
          j        k    rt           }n;|j        |j        cxk    rt
          j        k    rn nt$          }nt          d¦  «        ‚t'          ¦   «         }||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_         ||_!        ||_"        ||_#        |	d	k    s|
d	k    rtI          | ||	|
¦  «         ntK          | |¦  «         ||fS )
a  
    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 float16Nz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?   rM   rN   Ú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_gpure   ;   sþ  € ðX ŒH�E€BˆØ	„xÔð ØˆˆØ	ŒÔ	ð ØŒTˆØˆˆåÔ! "¨IÐ6Ñ6Ô6ˆØˆå�b‰\Œ\€Fà	„x•2”:ÒÐÝ&ˆˆØ	Œ•R”ZÒ	Ð	Ý&ˆˆåÐ/Ñ0Ô0Ð0àŒX�F€BˆØ�Š7ˆ7ˆ7ˆ7Ø	„xÔð ØˆˆØ	ŒÔ	ð ØŒTˆØˆˆåÔ! "¨IÐ6Ñ6Ô6ˆØˆå�b‰\Œ\€Fà	„x•2”:ÒÐÝ&ˆˆØ	Œ•R”ZÒ	Ð	Ý&ˆˆåÐ7Ñ8Ô8Ð8à€yÝŒH�b˜!�W¥B¤JÐ/Ñ/Ô/ˆˆàŒw˜2˜q˜'Ò!Ð!Ð!Ð!àŒw�"œ*Ò$Ð$Ð$Ð$å�Q‰KŒK€Eà€yÝŒH�b˜!�W¥B¤HÐ-Ñ-Ô-ˆˆàŒw˜2˜q˜'Ò!Ð!Ð!Ð!å�Q‰KŒK€Eà„w•"”(ÒÐÝ$ˆˆØ	
Œ�A”GÐ	'Ð	'Ò	'Ð	'�rœ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Ð!7Ý�S˜$Ð 2Ð4FÑGÔGÐGÐGåˆc�4ÑÔÐàˆaˆ4€Kr   c                 ó8  — |j         \  }}|j        j        rd}n%|j        j        r
|j        }d}nt          d¦  «        ‚t          |¦  «        }	|j        t          j	        k    rt          }
n5|j        t          j        k    rt          }
nt          j        |d¬¦  «        }d}|j         \  }}||k    sJ ‚|j        j        rd}n.|j        j        r
|j        }d}nt          j        |d¬¦  «        }d}t          |¦  «        }|j        t          j	        k    rt          }n,|j        t          j        k    rt          }nt          d¦  «        ‚|€#t          j        ||ft          j	        ¬¦  «        }n&|j         ||fk    sJ ‚|j        t          j	        k    sJ ‚t          |¦  «        }t          ¦   «         }||_        d|_        ||_        ||_        ||_        ||_        ||_        |	|_        ||_        |
|_        ||_        ||_        ||_        t;          | |¦  «         |S )	ak  
    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,   Nr   )r-   r.   r/   r0   r1   r8   r4   r+   r2   r)   r5   r6   r7   r3   r9   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rM   rP   )r   rQ   rR   rS   r?   rM   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rd   s                     r   Úpairwise_distance_gpurg   Ã   s*  € ð< ŒH�E€BˆØ	„xÔð EØˆˆØ	ŒÔ	ð EØŒTˆØˆˆåØCñEô Eð 	Eõ �b‰\Œ\€Fà	„x•2”:ÒÐÝ&ˆˆØ	Œ•R”ZÒ	Ð	Ý&ˆˆåÔ! "¨IÐ6Ñ6Ô6ˆØˆàŒX�F€BˆØ�Š7ˆ7ˆ7ˆ7Ø	„xÔð ØˆˆØ	ŒÔ	ð ØŒTˆØˆˆåÔ! "¨IÐ6Ñ6Ô6ˆØˆå�b‰\Œ\€Fà	„x•2”:ÒÐÝ&ˆˆØ	Œ•R”ZÒ	Ð	Ý&ˆˆåÐ7Ñ8Ô8Ð8à€yÝŒH�b˜"�X¥R¤ZÐ0Ñ0Ô0ˆˆàŒw˜2˜r˜(Ò"Ð"Ð"Ð"àŒw�"œ*Ò$Ð$Ð$Ð$å�Q‰KŒ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   )	Únumpyr2   Úfaiss.loaderr   r   r   Ú	METRIC_L2re   rg   r"   r   r   ú<module>rk      s½   ðð Ð Ð Ð à Ð Ð Ð ð@ð @ð @ð @ð"ð ð ð ð
ð ð ð ð  # d°9ÀRÐRWÐlmð  CDð Cð Cð Cð CðP *.°iÈð bð bð bð bð bð br   