
    rh                    V   d dl mZ esdev rddlmZ nd dlZ	 d dlZd Z
d Zd Zd	 Z G d
 de      Z G d de      Z ej$                  e       ej&                  Z G d de      Z ej*                  e        G d de      Z ej.                  e        G d de      Z ej2                  e        G d de      Z ej6                  e        G d de      Z ej:                  e        G d de      Z ej>                  e        G d de      Z  ejB                  e         G d de      Z" ejF                  e"        G d de      Z$ ejJ                  e$        G d  d!e      Z& ejN                  e&        G d" d#e      Z( ejR                  e(        G d$ d%e      Z* ejV                  e*        G d& d'e      Z, ejZ                  e,        G d( d)e      Z. ej^                  e.        G d* d+e      Z0 ejb                  e0        G d, d-e      Z2 ejf                  e2        G d. d/e      Z4 ejj                  e4        G d0 d1e      Z6 ejn                  e6        G d2 d3e      Z8 ejr                  e8        G d4 d5e      Z: ejv                  e:        G d6 d7e      Z< ejz                  e<        G d8 d9e      Z> ej~                  e>        G d: d;e      Z@ ej                  e@        G d< d=e      ZB ej                  eB       d> ZDd? ZE G d@ dAe      ZF ej                  eF       dB ZHdC ZIdD ZJdE ZKdF ZL G dG dHe      ZM ej                  eM       ej                  ZO G dI dJe      ZP ej                  eP       dK ZRdL ZSdM ZTd	dNZUd	dOZVdP ZWdQ ZXdR ZYd
dSZZdT Z[dU Z\dV Z]dW Z^dX Z_dY Z`dZ Zad[ Zbd\ Zcd] Zdd^ Zed_ Zfd` Zgda Zhdb Zidc Zjdd ZkddeZldf Zmdg Zndh Zodi Zpdj Zqdk ZrddlZsdm Ztdn Zudo Zvdp Zw G dq dre      Zx ej                  ex       eOj                  Zz G ds dte      Z{ ej                  e{        G du dve      Z} ej                  e}       dw Zdx Zdy Zdz Zd{ Zd| Zdd}Zd~ Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZddZd	dZd	dZd Zd Zd Z G d de      Z ej@                  e        G d de      Z ejD                  e       d Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zejd                  Z	 ejf                  Z	 ejh                  Z	 ejj                  Z	 ejl                  Z	 ejn                  Z	 ejp                  Zejr                  Zejt                  Z	 ejv                  Z	 ejx                  Z	 d Zej|                  Zej~                  Zej                  Zej                  Zej                  Zej                  Zej                  Zej                  Zd Z G d de      Z ej                  eǫ        G d de      Z ej                  eɫ        G d de      Z ej                  e˫        G d de˫      Z ej                  eͫ        G d de˫      Z ej                  eϫ        G d de      Z ej                  eѫ        G d de      Z ej                  eӫ        G d deѫ      Z ej                  eի        G d deӫ      Z ej                  e׫        G d deѫ      Z ej                  e٫        G d deӫ      Z ej                  e۫        G d deѫ      Z ej                  eݫ        G dĄ deӫ      Z ej                  e߫       dƄ ZdǄ ZdȄ Z G dɄ de      Z ej                  e        G d˄ de      Z ej                  e        G d̈́ deѫ      Z ej                  e        G dτ deѫ      Z ej                  e        G dф deɫ      Z ej                  e        G dӄ de      Z ej                  e        G dՄ de      Z ej                  e        G dׄ de      Z ej                  e        G dل de      Z ej                  e        G dۄ de      Z ej                  e        G d݄ de      Z ej                  e        G d߄ de      Z ej                  e        G d de      Z ej                  e        G d de      Z ej                  e        G d de      Z  ej                  e         G d de      Z ej                  e       d ZddZd Zd Z G d de      Z ej                  e        G d de      Z
 ej                  e
        G d de      Z ej                  e        G d de      Z ej                  e        G d de      Z ej"                  e        G d de      Z ej&                  e        G d de      Z ej*                  e        G d de      Z ej.                  e        G d de      Z ej2                  e       d Zd  Z G d de      Z ej:                  e       d Z G d de      Z ej@                  e       d Z! G d de      Z" ejF                  e"       d	 Z$ G d
 de      Z% ejL                  e%       d Z' G d de      Z( ejR                  e(        G d de      Z* ejV                  e*        G d de      Z, ejZ                  e,        G d de      Z. ej^                  e.        G d de      Z0 ejb                  e0        G d de      Z2 ejf                  e2        G d de      Z4 ejj                  e4        G d de4      Z6 ejn                  e6        G d de4      Z8 ejr                  e8        G d d e      Z: ejv                  e:        G d! d"e:      Z< ejz                  e<        G d# d$e      Z> ej~                  e>        G d% d&e>      Z@ ej                  e@        G d' d(e@      ZB ej                  eB        G d) d*e@      ZD ej                  eD        G d+ d,e@      ZF ej                  eF        G d- d.e>      ZH ej                  eH        G d/ d0e@      ZJ ej                  eJ        G d1 d2e>      ZL ej                  eL        G d3 d4e>      ZN ej                  eN        G d5 d6e>      ZP ej                  eP        G d7 d8eǫ      ZR ej                  eR        G d9 d:eɫ      ZT ej                  eT        G d; d<eǫ      ZV ej                  eV        G d= d>eɫ      ZX ej                  eX        G d? d@eX      ZZ ej                  eZ        G dA dBe      Z\ ej                  e\        G dC dDe      Z^ ej                  e^        G dE dFe      Z` ej                  e`        G dG dHe`      Zb ej                  eb        G dI dJe^      Zd ej                  ed        G dK dLe^      Zf ej                  ef        G dM dNe      Zh ej                  eh        G dO dPeǫ      Zj ej                  ej        G dQ dRe      Zl ej                  el        G dS dTeɫ      Zn ej                  en        G dU dVen      Zp ej                  ep        G dW dXe      Zr ej                  er        G dY dZer      Zt ej                  et        G d[ d\er      Zv ej                  ev        G d] d^er      Zx ej                  ex        G d_ d`er      Zz ej                  ez        G da dbeɫ      Z| ej                  e|        G dc ddeǫ      Z~ ej                  e~        G de dfe|      Z ej                  e        G dg dhe|      Z ej                  e        G di dje      Z ej
                  e        G dk dle      Z ej                  e        G dm dne      Z ej                  e        G do dpe      Z ej                  e        G dq dre      Z ej                  e        G ds dte      Z ej                  e        G du dve      Z ej"                  e        G dw dxe      Z ej&                  e        G dy dze      Z ej*                  e        G d{ d|e      Z ej.                  e        G d} d~e      Z ej2                  e       d Zd Zd Z G d de      Z ej<                  e        G d de      Z ej@                  e        G d de      Z ejD                  e        G d deǫ      Z ejH                  e        G d de      Z ejL                  e        G d deɐe      Z ejP                  e        G d de      Z ejT                  e        G d de      Z ejX                  e       d Zd Zd Zd Zd Zd Z G d de      Z ejh                  e       d Zd ZddZddZd ZddZ G d de      Z ejx                  e        G d de      Z ej|                  e       d Zd Z G d de      Z ej                  e        G d de      Z ej                  eë        G d de      Z ej                  eū        G d de      Z ej                  eǫ        G d de      Z ej                  eɫ        G d deɫ      Z ej                  e˫        G d deɫ      Z ej                  eͫ        G d deɫ      Z ej                  eϫ        G d deɫ      Z ej                  eѫ        G d deǫ      Z ej                  eӫ        G d de      Z ej                  eի        G d de      Z ej                  e׫       ddZِd Zڐd ZېddZ G d deɫ      Z ej                  eݫ        G dĄ dŐeݫ      Z ej                  e߫        G dƄ dǐeݫ      Z ej                  e        G dȄ dɐeݫ      Z ej                  e        G dʄ dːeݫ      Z ej                  e        G d̄ d͐eݫ      Z ej                  e       d΄ Zdτ Z G dЄ de      Z ej                  e        G d҄ de      Z ej                  e        G dԄ de      Z ej                  e        G dք deɫ      Z ej                  e        G d؄ dِe      Z ej                  e        G dڄ dېe      Z ej                  e        G d܄ dݐe      Z ej                  e       dބ Z G d߄ de      Z ej                  e        G d de      Z ej                  e        G d deɫ      Z ej                  e        G d de      Z  ej                  e         G d de      Z ej                  e        G d de      Z ej
                  e        G d de      Z ej                  e        G d de      Z ej                  e        G d de      Z
 ej                  e
        G d de      Z ej                  e        G d de      Z ej                  e        G d de      Z ej"                  e        G d de
e      Z ej&                  e        G d de      Z ej*                  e        G d de      Z ej.                  e        G d de      Z ej2                  e        G d d e      Z ej6                  e        G d de      Z ej:                  e       d Z G d de      Z ej@                  e        G d de      Z! ejD                  e!        G d d	e      Z# ejH                  e#        G d
 deɫ      Z% ejL                  e%        G d de      Z' ejP                  e'        G d de%      Z) ejT                  e)        G d de)      Z+ ejX                  e+        G d de)      Z- ej\                  e-        G d de)      Z/ ej`                  e/        G d de)      Z1 ejd                  e1        G d de%      Z3 ejh                  e3        G d de      Z5 ejl                  e5        G d de      Z7 ejp                  e7        G d de7      Z9 ejt                  e9        G d  d!e7      Z; ejx                  e;        G d" d#e7      Z= ej|                  e=        G d$ d%e      Z? ej                  e?        G d& d'e      ZA ej                  eA        G d( d)e?      ZC ej                  eC        G d* d+eC      ZE ej                  eE        G d, d-eC      ZG ej                  eG        G d. d/eC      ZI ej                  eI        G d0 d1eC      ZK ej                  eK        G d2 d3eɫ      ZM ej                  eM        G d4 d5e?      ZO ej                  eO       dd6ZQdd7ZRdd8ZSd9 ZTd: ZU G d; d<e      ZV ej                  eV        G d= d>eV      ZX ej                  eX        G d? d@eV      ZZ ej                  eZ        G dA dBe      Z\ ej                  e\        G dC dDeV      Z^ ej                  e^        G dE dFeV      Z` ej                  e`        G dG dHe`      Zb ej                  eb        G dI dJeV      Zd ej                  ed        G dK dLe      Zf ej                  ef        G dM dNeV      Zh ej                  eh        G dO dPeɫ      Zj ej                  ej        G dQ dReV      Zl ej                  el        G dS dTej      Zn ej                  en        G dU dVel      Zp ej                  ep        G dW dXene      Zr ej                  er        G dY dZej      Zt ej                  et        G d[ d\el      Zv ej                  ev        G d] d^eɫ      Zx ej                  ex        G d_ d`eɫ      Zz ej                  ez        G da dbeɫ      Z| ej                  e|        G dc dde|      Z~ ej                  e~        G de dfe|      Z ej                  e        G dg dhe      Z ej                  e        G di dje      Z ej
                  e        G dk dle      Z ej                  e        G dm dne      Z ej                  e        G do dpe      Z ej                  e        G dq dre      Z ej                  e        G ds dte      Z ej                  e        G du dve      Z ej"                  e        G dw dxe      Z ej&                  e        G dy dze      Z ej*                  e        G d{ d|e      Z ej.                  e        G d} d~eǫ      Z ej2                  e        G d de      Z ej6                  e        G d de      Z ej:                  e        G d de      Z ej>                  e        G d de      Z ejB                  e        G d de      Z ejF                  e        G d de      Z ejJ                  e        G d de      Z ejN                  e        G d de      Z ejR                  e        G d de      Z ejV                  e        G d de      Z ejZ                  e        G d de      Z ej^                  e        G d de      Z ejb                  e        G d de      Z ejf                  e        G d de      Z ejj                  e        G d de      Z ejn                  e        G d de      Z ejr                  e        G d de      Z ejv                  e        G d de      Z ejz                  e        G d de      Z ej~                  e        G d de      Z ej                  e        G d de      Z ej                  e«        G d deɫ      Z ej                  eī        G d deV      Z ej                  eƫ        G d deī      Z ej                  eȫ        G d deƫ      Z ej                  eʫ       ej                  Zej                  Zej                  Zej                  Zej                  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dZd Z G d de      Z ej                  e       eOj                  ZeOj                  ZeOj                  ZeOj                  ZeOj                  ZeOj                  ZeOj                  ZeOj                  ZdĄ Zdń Z G dƄ de      Z ej                  e        G dȄ dɐe      Z ej                  e        G dʄ dːe      Z ej                  e        G d̄ de      Z ej                  e        G d΄ de      Z ej                  e        G dЄ de      Z ej                  e        G d҄ de      Z ej                  e       dԄ ZddՄZ G dք de      Z ej                  e        G d؄ deӫ      Z  ej                  e         G dڄ deѫ      Z ej                  e        G d܄ dݐe      Z ej
                  e        G dބ dߐe      Z ej                  e        G d de      Z ej                  e        G d de      Z
 ej                  e
        G d de      Z ej                  e        G d de      Z ej                  e       d Zd Z G d de      Z ej&                  e        G d de      Z ej*                  e        G d de      Z ej.                  e        G d de      Z ej2                  e        G d de      Z ej6                  e        G d de      Z ej:                  e       d Zd Zd Z d Z! G d de      Z" ejF                  e"       d Z$d Z%d Z& G d d e      Z' ejP                  e'       d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0y# e	$ r d dlZY +Uw xY w(      )version_info.   )_swigfaiss_avx2Nc                     	 d| j                   j                         z   }d| j                  j
                  d| j                  j                  d|dS # t        j                  $ r d}Y Kw xY w)Nz	proxy of  <r   z; z >)this__repr____builtin__	Exception	__class__
__module____name__)selfstrthiss     g/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/faiss/swigfaiss_avx2.py
_swig_reprr      s_    		 2 2 44 "^^668O8OQXZZ    s   A A+*A+c                       fd}|S )Nc                     |dk(  r | ||       y |dk(  r| j                   j                  |       y t        | |      r.t        t	        t        |       |      t              r | ||       y t        d| z        )Nr
   thisownz(You cannot add instance attributes to %s)r
   ownhasattr
isinstancegetattrtypepropertyAttributeError)r   namevaluesets      r   set_instance_attrzE_swig_setattr_nondynamic_instance_variable.<locals>.set_instance_attr   si    6>dE"YIIMM% T4 ZT
D0I8%TdE" !Kd!RSS     )r!   r"   s   ` r   *_swig_setattr_nondynamic_instance_variabler%      s    T r#   c                       fd}|S )Nc                     t        | |      r%t        t        | |      t              s | ||       y t	        d| z        )Nz%You cannot add class attributes to %s)r   r   r   r   r   )clsr   r    r!   s      r   set_class_attrz?_swig_setattr_nondynamic_class_variable.<locals>.set_class_attr)   s:    3jd1CX&NT5! !H3!NOOr#   r$   )r!   r)   s   ` r   '_swig_setattr_nondynamic_class_variabler*   (   s    P
 r#   c                       fd}|S )zlClass decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclassc                 p     | j                   | j                  | j                  j                               S N)r   	__bases____dict__copy)r(   	metaclasss    r   wrapperz$_swig_add_metaclass.<locals>.wrapper3   s'    s}}cll6G6G6IJJr#   r$   )r1   r2   s   ` r   _swig_add_metaclassr3   1   s    KNr#   c                   4    e Zd ZdZ eej                        Zy)_SwigNonDynamicMetazKMeta class to enforce nondynamic attributes (no new attributes) for a classN)r   r   __qualname____doc__r*   r   __setattr__r$   r#   r   r5   r5   8   s    U9$:J:JKKr#   r5   c                       e Zd Z ed d d      Zd ZeZej                  Z
d Zd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y)SwigPyIteratorc                 6    | j                   j                         S r-   r
   r   xs    r   <lambda>zSwigPyIterator.<lambda>>        r#   c                 8    | j                   j                  |      S r-   r<   r>   vs     r   r?   zSwigPyIterator.<lambda>>       AFFJJqM r#   The membership flagdocc                     t        d      Nz*No constructor defined - class is abstractr   r   argskwargss      r   __init__zSwigPyIterator.__init__@       IJJr#   c                 ,    t        j                  |       S r-   )r   SwigPyIterator_valuer   s    r   r    zSwigPyIterator.valueE       33D99r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator_incrr   ns     r   incrzSwigPyIterator.incrH       224;;r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator_decrrV   s     r   decrzSwigPyIterator.decrK   rY   r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator_distancer   r>   s     r   distancezSwigPyIterator.distanceN       66tQ??r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator_equalr_   s     r   equalzSwigPyIterator.equalQ       33D!<<r#   c                 ,    t        j                  |       S r-   )r   SwigPyIterator_copyrR   s    r   r0   zSwigPyIterator.copyT       22488r#   c                 ,    t        j                  |       S r-   )r   SwigPyIterator_nextrR   s    r   nextzSwigPyIterator.nextW   rh   r#   c                 ,    t        j                  |       S r-   )r   SwigPyIterator___next__rR   s    r   __next__zSwigPyIterator.__next__Z       66t<<r#   c                 ,    t        j                  |       S r-   )r   SwigPyIterator_previousrR   s    r   previouszSwigPyIterator.previous]   ro   r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator_advancerV   s     r   advancezSwigPyIterator.advance`       55dA>>r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator___eq__r_   s     r   __eq__zSwigPyIterator.__eq__c       44T1==r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator___ne__r_   s     r   __ne__zSwigPyIterator.__ne__f   rz   r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator___iadd__rV   s     r   __iadd__zSwigPyIterator.__iadd__i   ra   r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator___isub__rV   s     r   __isub__zSwigPyIterator.__isub__l   ra   r#   c                 .    t        j                  | |      S r-   )r   SwigPyIterator___add__rV   s     r   __add__zSwigPyIterator.__add__o   rv   r#   c                 .    t        j                  | g| S r-   )r   SwigPyIterator___sub__r   rL   s     r   __sub__zSwigPyIterator.__sub__r       55dBTBBr#   c                     | S r-   r$   rR   s    r   __iter__zSwigPyIterator.__iter__t   s    r#   Nr   )r   r   r6   r   r   rN   r   r   r   delete_SwigPyIterator__swig_destroy__r    rX   r\   r`   rd   r0   rk   rn   rr   ru   ry   r}   r   r   r   r   r   r$   r#   r   r:   r:   =   s    -/IOdeGKH&<<:<<@=99==?>>@@?Cr#   r:   c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Float32Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFloat32Vector.<lambda>{   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFloat32Vector.<lambda>{   rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Float32Vector_swiginitnew_Float32VectorrR   s    r   rN   zFloat32Vector.__init__~       ..t_5V5V5XYr#   c                 .    t        j                  | |      S r-   )r   Float32Vector_push_backr   arg2s     r   	push_backzFloat32Vector.push_back       66tTBBr#   c                 ,    t        j                  |       S r-   )r   Float32Vector_clearrR   s    r   clearzFloat32Vector.clear   rh   r#   c                 ,    t        j                  |       S r-   )r   Float32Vector_datarR   s    r   datazFloat32Vector.data       11$77r#   c                 ,    t        j                  |       S r-   )r   Float32Vector_sizerR   s    r   sizezFloat32Vector.size   r   r#   c                 .    t        j                  | |      S r-   )r   Float32Vector_atrV   s     r   atzFloat32Vector.at       //a88r#   c                 .    t        j                  | |      S r-   )r   Float32Vector_resizerV   s     r   resizezFloat32Vector.resize   re   r#   c                 .    t        j                  | |      S r-   )r   Float32Vector_swapr   others     r   swapzFloat32Vector.swap       11$>>r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Float32Vectorr   r$   r#   r   r   r   z   N    -/IOdeGHZC9889=?&;;r#   r   c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Float64Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFloat64Vector.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFloat64Vector.<lambda>   rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Float64Vector_swiginitnew_Float64VectorrR   s    r   rN   zFloat64Vector.__init__   r   r#   c                 .    t        j                  | |      S r-   )r   Float64Vector_push_backr   s     r   r   zFloat64Vector.push_back   r   r#   c                 ,    t        j                  |       S r-   )r   Float64Vector_clearrR   s    r   r   zFloat64Vector.clear   rh   r#   c                 ,    t        j                  |       S r-   )r   Float64Vector_datarR   s    r   r   zFloat64Vector.data   r   r#   c                 ,    t        j                  |       S r-   )r   Float64Vector_sizerR   s    r   r   zFloat64Vector.size   r   r#   c                 .    t        j                  | |      S r-   )r   Float64Vector_atrV   s     r   r   zFloat64Vector.at   r   r#   c                 .    t        j                  | |      S r-   )r   Float64Vector_resizerV   s     r   r   zFloat64Vector.resize   re   r#   c                 .    t        j                  | |      S r-   )r   Float64Vector_swapr   s     r   r   zFloat64Vector.swap   r   r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Float64Vectorr   r$   r#   r   r   r      r   r#   r   c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)
Int8Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt8Vector.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt8Vector.<lambda>   rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int8Vector_swiginitnew_Int8VectorrR   s    r   rN   zInt8Vector.__init__   s    ++D/2P2P2RSr#   c                 .    t        j                  | |      S r-   )r   Int8Vector_push_backr   s     r   r   zInt8Vector.push_back       33D$??r#   c                 ,    t        j                  |       S r-   )r   Int8Vector_clearrR   s    r   r   zInt8Vector.clear       //55r#   c                 ,    t        j                  |       S r-   )r   Int8Vector_datarR   s    r   r   zInt8Vector.data       ..t44r#   c                 ,    t        j                  |       S r-   )r   Int8Vector_sizerR   s    r   r   zInt8Vector.size   r   r#   c                 .    t        j                  | |      S r-   )r   Int8Vector_atrV   s     r   r   zInt8Vector.at   s    ,,T155r#   c                 .    t        j                  | |      S r-   )r   Int8Vector_resizerV   s     r   r   zInt8Vector.resize       00q99r#   c                 .    t        j                  | |      S r-   )r   Int8Vector_swapr   s     r   r   zInt8Vector.swap       ..tU;;r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int8Vectorr   r$   r#   r   r   r      sN    -/IOdeGHT@6556:<&88r#   r   c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Int16Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt16Vector.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt16Vector.<lambda>   rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int16Vector_swiginitnew_Int16VectorrR   s    r   rN   zInt16Vector.__init__       ,,T?3R3R3TUr#   c                 .    t        j                  | |      S r-   )r   Int16Vector_push_backr   s     r   r   zInt16Vector.push_back       44T4@@r#   c                 ,    t        j                  |       S r-   )r   Int16Vector_clearrR   s    r   r   zInt16Vector.clear       0066r#   c                 ,    t        j                  |       S r-   )r   Int16Vector_datarR   s    r   r   zInt16Vector.data   r   r#   c                 ,    t        j                  |       S r-   )r   Int16Vector_sizerR   s    r   r   zInt16Vector.size   r   r#   c                 .    t        j                  | |      S r-   )r   Int16Vector_atrV   s     r   r   zInt16Vector.at       --dA66r#   c                 .    t        j                  | |      S r-   )r   Int16Vector_resizerV   s     r   r   zInt16Vector.resize       11$::r#   c                 .    t        j                  | |      S r-   )r   Int16Vector_swapr   s     r   r   zInt16Vector.swap       //e<<r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int16Vectorr   r$   r#   r   r   r      N    -/IOdeGHVA7667;=&99r#   r   c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Int32Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt32Vector.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt32Vector.<lambda>   rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int32Vector_swiginitnew_Int32VectorrR   s    r   rN   zInt32Vector.__init__   r   r#   c                 .    t        j                  | |      S r-   )r   Int32Vector_push_backr   s     r   r   zInt32Vector.push_back   r   r#   c                 ,    t        j                  |       S r-   )r   Int32Vector_clearrR   s    r   r   zInt32Vector.clear   r   r#   c                 ,    t        j                  |       S r-   )r   Int32Vector_datarR   s    r   r   zInt32Vector.data  r   r#   c                 ,    t        j                  |       S r-   )r   Int32Vector_sizerR   s    r   r   zInt32Vector.size  r   r#   c                 .    t        j                  | |      S r-   )r   Int32Vector_atrV   s     r   r   zInt32Vector.at	  r   r#   c                 .    t        j                  | |      S r-   )r   Int32Vector_resizerV   s     r   r   zInt32Vector.resize  r   r#   c                 .    t        j                  | |      S r-   )r   Int32Vector_swapr   s     r   r   zInt32Vector.swap  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int32Vectorr   r$   r#   r   r  r     r  r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Int64Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt64Vector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt64Vector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int64Vector_swiginitnew_Int64VectorrR   s    r   rN   zInt64Vector.__init__  r   r#   c                 .    t        j                  | |      S r-   )r   Int64Vector_push_backr   s     r   r   zInt64Vector.push_back  r   r#   c                 ,    t        j                  |       S r-   )r   Int64Vector_clearrR   s    r   r   zInt64Vector.clear  r   r#   c                 ,    t        j                  |       S r-   )r   Int64Vector_datarR   s    r   r   zInt64Vector.data"  r   r#   c                 ,    t        j                  |       S r-   )r   Int64Vector_sizerR   s    r   r   zInt64Vector.size%  r   r#   c                 .    t        j                  | |      S r-   )r   Int64Vector_atrV   s     r   r   zInt64Vector.at(  r   r#   c                 .    t        j                  | |      S r-   )r   Int64Vector_resizerV   s     r   r   zInt64Vector.resize+  r   r#   c                 .    t        j                  | |      S r-   )r   Int64Vector_swapr   s     r   r   zInt64Vector.swap.  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int64Vectorr   r$   r#   r   r  r    r  r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)UInt8Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zUInt8Vector.<lambda>5  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zUInt8Vector.<lambda>5  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   UInt8Vector_swiginitnew_UInt8VectorrR   s    r   rN   zUInt8Vector.__init__8  r   r#   c                 .    t        j                  | |      S r-   )r   UInt8Vector_push_backr   s     r   r   zUInt8Vector.push_back;  r   r#   c                 ,    t        j                  |       S r-   )r   UInt8Vector_clearrR   s    r   r   zUInt8Vector.clear>  r   r#   c                 ,    t        j                  |       S r-   )r   UInt8Vector_datarR   s    r   r   zUInt8Vector.dataA  r   r#   c                 ,    t        j                  |       S r-   )r   UInt8Vector_sizerR   s    r   r   zUInt8Vector.sizeD  r   r#   c                 .    t        j                  | |      S r-   )r   UInt8Vector_atrV   s     r   r   zUInt8Vector.atG  r   r#   c                 .    t        j                  | |      S r-   )r   UInt8Vector_resizerV   s     r   r   zUInt8Vector.resizeJ  r   r#   c                 .    t        j                  | |      S r-   )r   UInt8Vector_swapr   s     r   r   zUInt8Vector.swapM  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_UInt8Vectorr   r$   r#   r   r3  r3  4  r  r#   r3  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)UInt16Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zUInt16Vector.<lambda>T  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zUInt16Vector.<lambda>T  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   UInt16Vector_swiginitnew_UInt16VectorrR   s    r   rN   zUInt16Vector.__init__W      --dO4T4T4VWr#   c                 .    t        j                  | |      S r-   )r   UInt16Vector_push_backr   s     r   r   zUInt16Vector.push_backZ      55dDAAr#   c                 ,    t        j                  |       S r-   )r   UInt16Vector_clearrR   s    r   r   zUInt16Vector.clear]  r   r#   c                 ,    t        j                  |       S r-   )r   UInt16Vector_datarR   s    r   r   zUInt16Vector.data`  r   r#   c                 ,    t        j                  |       S r-   )r   UInt16Vector_sizerR   s    r   r   zUInt16Vector.sizec  r   r#   c                 .    t        j                  | |      S r-   )r   UInt16Vector_atrV   s     r   r   zUInt16Vector.atf      ..tQ77r#   c                 .    t        j                  | |      S r-   )r   UInt16Vector_resizerV   s     r   r   zUInt16Vector.resizei  rY   r#   c                 .    t        j                  | |      S r-   )r   UInt16Vector_swapr   s     r   r   zUInt16Vector.swapl      00u==r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_UInt16Vectorr   r$   r#   r   rI  rI  S  N    -/IOdeGHXB8778<>&::r#   rI  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)UInt32Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zUInt32Vector.<lambda>s  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zUInt32Vector.<lambda>s  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   UInt32Vector_swiginitnew_UInt32VectorrR   s    r   rN   zUInt32Vector.__init__v  rO  r#   c                 .    t        j                  | |      S r-   )r   UInt32Vector_push_backr   s     r   r   zUInt32Vector.push_backy  rR  r#   c                 ,    t        j                  |       S r-   )r   UInt32Vector_clearrR   s    r   r   zUInt32Vector.clear|  r   r#   c                 ,    t        j                  |       S r-   )r   UInt32Vector_datarR   s    r   r   zUInt32Vector.data  r   r#   c                 ,    t        j                  |       S r-   )r   UInt32Vector_sizerR   s    r   r   zUInt32Vector.size  r   r#   c                 .    t        j                  | |      S r-   )r   UInt32Vector_atrV   s     r   r   zUInt32Vector.at  r[  r#   c                 .    t        j                  | |      S r-   )r   UInt32Vector_resizerV   s     r   r   zUInt32Vector.resize  rY   r#   c                 .    t        j                  | |      S r-   )r   UInt32Vector_swapr   s     r   r   zUInt32Vector.swap  r`  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_UInt32Vectorr   r$   r#   r   rd  rd  r  rb  r#   rd  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)UInt64Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zUInt64Vector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zUInt64Vector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   UInt64Vector_swiginitnew_UInt64VectorrR   s    r   rN   zUInt64Vector.__init__  rO  r#   c                 .    t        j                  | |      S r-   )r   UInt64Vector_push_backr   s     r   r   zUInt64Vector.push_back  rR  r#   c                 ,    t        j                  |       S r-   )r   UInt64Vector_clearrR   s    r   r   zUInt64Vector.clear  r   r#   c                 ,    t        j                  |       S r-   )r   UInt64Vector_datarR   s    r   r   zUInt64Vector.data  r   r#   c                 ,    t        j                  |       S r-   )r   UInt64Vector_sizerR   s    r   r   zUInt64Vector.size  r   r#   c                 .    t        j                  | |      S r-   )r   UInt64Vector_atrV   s     r   r   zUInt64Vector.at  r[  r#   c                 .    t        j                  | |      S r-   )r   UInt64Vector_resizerV   s     r   r   zUInt64Vector.resize  rY   r#   c                 .    t        j                  | |      S r-   )r   UInt64Vector_swapr   s     r   r   zUInt64Vector.swap  r`  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_UInt64Vectorr   r$   r#   r   rz  rz    rb  r#   rz  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Float32VectorVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFloat32VectorVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFloat32VectorVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Float32VectorVector_swiginitnew_Float32VectorVectorrR   s    r   rN   zFloat32VectorVector.__init__      44T?;b;b;der#   c                 .    t        j                  | |      S r-   )r   Float32VectorVector_push_backr   s     r   r   zFloat32VectorVector.push_back      <<T4HHr#   c                 ,    t        j                  |       S r-   )r   Float32VectorVector_clearrR   s    r   r   zFloat32VectorVector.clear      88>>r#   c                 ,    t        j                  |       S r-   )r   Float32VectorVector_datarR   s    r   r   zFloat32VectorVector.data      77==r#   c                 ,    t        j                  |       S r-   )r   Float32VectorVector_sizerR   s    r   r   zFloat32VectorVector.size  r  r#   c                 .    t        j                  | |      S r-   )r   Float32VectorVector_atrV   s     r   r   zFloat32VectorVector.at  rv   r#   c                 .    t        j                  | |      S r-   )r   Float32VectorVector_resizerV   s     r   r   zFloat32VectorVector.resize      99$BBr#   c                 .    t        j                  | |      S r-   )r   Float32VectorVector_swapr   s     r   r   zFloat32VectorVector.swap      77eDDr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Float32VectorVectorr   r$   r#   r   r  r    P    -/IOdeGHfI?>>?CE&AAr#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)UInt8VectorVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zUInt8VectorVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zUInt8VectorVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   UInt8VectorVector_swiginitnew_UInt8VectorVectorrR   s    r   rN   zUInt8VectorVector.__init__      2249^9^9`ar#   c                 .    t        j                  | |      S r-   )r   UInt8VectorVector_push_backr   s     r   r   zUInt8VectorVector.push_back      ::4FFr#   c                 ,    t        j                  |       S r-   )r   UInt8VectorVector_clearrR   s    r   r   zUInt8VectorVector.clear  ro   r#   c                 ,    t        j                  |       S r-   )r   UInt8VectorVector_datarR   s    r   r   zUInt8VectorVector.data      55d;;r#   c                 ,    t        j                  |       S r-   )r   UInt8VectorVector_sizerR   s    r   r   zUInt8VectorVector.size  r  r#   c                 .    t        j                  | |      S r-   )r   UInt8VectorVector_atrV   s     r   r   zUInt8VectorVector.at  re   r#   c                 .    t        j                  | |      S r-   )r   UInt8VectorVector_resizerV   s     r   r   zUInt8VectorVector.resize      77a@@r#   c                 .    t        j                  | |      S r-   )r   UInt8VectorVector_swapr   s     r   r   zUInt8VectorVector.swap      55dEBBr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_UInt8VectorVectorr   r$   r#   r   r  r    P    -/IOdeGHbG=<<=AC&??r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Int32VectorVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt32VectorVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt32VectorVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int32VectorVector_swiginitnew_Int32VectorVectorrR   s    r   rN   zInt32VectorVector.__init__  r  r#   c                 .    t        j                  | |      S r-   )r   Int32VectorVector_push_backr   s     r   r   zInt32VectorVector.push_back  r  r#   c                 ,    t        j                  |       S r-   )r   Int32VectorVector_clearrR   s    r   r   zInt32VectorVector.clear  ro   r#   c                 ,    t        j                  |       S r-   )r   Int32VectorVector_datarR   s    r   r   zInt32VectorVector.data  r  r#   c                 ,    t        j                  |       S r-   )r   Int32VectorVector_sizerR   s    r   r   zInt32VectorVector.size  r  r#   c                 .    t        j                  | |      S r-   )r   Int32VectorVector_atrV   s     r   r   zInt32VectorVector.at  re   r#   c                 .    t        j                  | |      S r-   )r   Int32VectorVector_resizerV   s     r   r   zInt32VectorVector.resize  r  r#   c                 .    t        j                  | |      S r-   )r   Int32VectorVector_swapr   s     r   r   zInt32VectorVector.swap  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int32VectorVectorr   r$   r#   r   r  r    r  r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)Int64VectorVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt64VectorVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt64VectorVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Int64VectorVector_swiginitnew_Int64VectorVectorrR   s    r   rN   zInt64VectorVector.__init__  r  r#   c                 .    t        j                  | |      S r-   )r   Int64VectorVector_push_backr   s     r   r   zInt64VectorVector.push_back  r  r#   c                 ,    t        j                  |       S r-   )r   Int64VectorVector_clearrR   s    r   r   zInt64VectorVector.clear  ro   r#   c                 ,    t        j                  |       S r-   )r   Int64VectorVector_datarR   s    r   r   zInt64VectorVector.data  r  r#   c                 ,    t        j                  |       S r-   )r   Int64VectorVector_sizerR   s    r   r   zInt64VectorVector.size  r  r#   c                 .    t        j                  | |      S r-   )r   Int64VectorVector_atrV   s     r   r   zInt64VectorVector.at   re   r#   c                 .    t        j                  | |      S r-   )r   Int64VectorVector_resizerV   s     r   r   zInt64VectorVector.resize#  r  r#   c                 .    t        j                  | |      S r-   )r   Int64VectorVector_swapr   s     r   r   zInt64VectorVector.swap&  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_Int64VectorVectorr   r$   r#   r   r  r    r  r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)VectorTransformVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVectorTransformVector.<lambda>-  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVectorTransformVector.<lambda>-  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   VectorTransformVector_swiginitnew_VectorTransformVectorrR   s    r   rN   zVectorTransformVector.__init__0      66t_=f=f=hir#   c                 .    t        j                  | |      S r-   )r   VectorTransformVector_push_backr   s     r   r   zVectorTransformVector.push_back3      >>tTJJr#   c                 ,    t        j                  |       S r-   )r   VectorTransformVector_clearrR   s    r   r   zVectorTransformVector.clear6      ::4@@r#   c                 ,    t        j                  |       S r-   )r   VectorTransformVector_datarR   s    r   r   zVectorTransformVector.data9      99$??r#   c                 ,    t        j                  |       S r-   )r   VectorTransformVector_sizerR   s    r   r   zVectorTransformVector.size<  r  r#   c                 .    t        j                  | |      S r-   )r   VectorTransformVector_atrV   s     r   r   zVectorTransformVector.at?  r  r#   c                 .    t        j                  | |      S r-   )r   VectorTransformVector_resizerV   s     r   r   zVectorTransformVector.resizeB      ;;D!DDr#   c                 .    t        j                  | |      S r-   )r   VectorTransformVector_swapr   s     r   r   zVectorTransformVector.swapE      99$FFr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_VectorTransformVectorr   r$   r#   r   r  r  ,  sT    -/IOdeGHjKA@@AEG&CCr#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)OperatingPointVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOperatingPointVector.<lambda>L  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOperatingPointVector.<lambda>L  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   OperatingPointVector_swiginitnew_OperatingPointVectorrR   s    r   rN   zOperatingPointVector.__init__O      55dO<d<d<fgr#   c                 .    t        j                  | |      S r-   )r   OperatingPointVector_push_backr   s     r   r   zOperatingPointVector.push_backR      ==dDIIr#   c                 ,    t        j                  |       S r-   )r   OperatingPointVector_clearrR   s    r   r   zOperatingPointVector.clearU  r  r#   c                 ,    t        j                  |       S r-   )r   OperatingPointVector_datarR   s    r   r   zOperatingPointVector.dataX  r  r#   c                 ,    t        j                  |       S r-   )r   OperatingPointVector_sizerR   s    r   r   zOperatingPointVector.size[  r  r#   c                 .    t        j                  | |      S r-   )r   OperatingPointVector_atrV   s     r   r   zOperatingPointVector.at^  ra   r#   c                 .    t        j                  | |      S r-   )r   OperatingPointVector_resizerV   s     r   r   zOperatingPointVector.resizea      ::4CCr#   c                 .    t        j                  | |      S r-   )r   OperatingPointVector_swapr   s     r   r   zOperatingPointVector.swapd      88uEEr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_OperatingPointVectorr   r$   r#   r   r  r  K  R    -/IOdeGHhJ@??@DF&BBr#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)InvertedListsPtrVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInvertedListsPtrVector.<lambda>k  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInvertedListsPtrVector.<lambda>k  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   InvertedListsPtrVector_swiginitnew_InvertedListsPtrVectorrR   s    r   rN   zInvertedListsPtrVector.__init__n      77o>h>h>jkr#   c                 .    t        j                  | |      S r-   )r    InvertedListsPtrVector_push_backr   s     r   r   z InvertedListsPtrVector.push_backq  s    ??dKKr#   c                 ,    t        j                  |       S r-   )r   InvertedListsPtrVector_clearrR   s    r   r   zInvertedListsPtrVector.cleart      ;;DAAr#   c                 ,    t        j                  |       S r-   )r   InvertedListsPtrVector_datarR   s    r   r   zInvertedListsPtrVector.dataw  r  r#   c                 ,    t        j                  |       S r-   )r   InvertedListsPtrVector_sizerR   s    r   r   zInvertedListsPtrVector.sizez  r  r#   c                 .    t        j                  | |      S r-   )r   InvertedListsPtrVector_atrV   s     r   r   zInvertedListsPtrVector.at}      88qAAr#   c                 .    t        j                  | |      S r-   )r   InvertedListsPtrVector_resizerV   s     r   r   zInvertedListsPtrVector.resize  s    <<T1EEr#   c                 .    t        j                  | |      S r-   )r   InvertedListsPtrVector_swapr   s     r   r   zInvertedListsPtrVector.swap  s    ::4GGr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_InvertedListsPtrVectorr   r$   r#   r   r,  r,  j  sT    -/IOdeGHlLBAABFH&DDr#   r,  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)RepeatVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRepeatVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRepeatVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   RepeatVector_swiginitnew_RepeatVectorrR   s    r   rN   zRepeatVector.__init__  rO  r#   c                 .    t        j                  | |      S r-   )r   RepeatVector_push_backr   s     r   r   zRepeatVector.push_back  rR  r#   c                 ,    t        j                  |       S r-   )r   RepeatVector_clearrR   s    r   r   zRepeatVector.clear  r   r#   c                 ,    t        j                  |       S r-   )r   RepeatVector_datarR   s    r   r   zRepeatVector.data  r   r#   c                 ,    t        j                  |       S r-   )r   RepeatVector_sizerR   s    r   r   zRepeatVector.size  r   r#   c                 .    t        j                  | |      S r-   )r   RepeatVector_atrV   s     r   r   zRepeatVector.at  r[  r#   c                 .    t        j                  | |      S r-   )r   RepeatVector_resizerV   s     r   r   zRepeatVector.resize  rY   r#   c                 .    t        j                  | |      S r-   )r   RepeatVector_swapr   s     r   r   zRepeatVector.swap  r`  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_RepeatVectorr   r$   r#   r   rE  rE    rb  r#   rE  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)ClusteringIterationStatsVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z'ClusteringIterationStatsVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z'ClusteringIterationStatsVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   'ClusteringIterationStatsVector_swiginit"new_ClusteringIterationStatsVectorrR   s    r   rN   z'ClusteringIterationStatsVector.__init__  s    ??oFxFxFz{r#   c                 .    t        j                  | |      S r-   )r   (ClusteringIterationStatsVector_push_backr   s     r   r   z(ClusteringIterationStatsVector.push_back      GGdSSr#   c                 ,    t        j                  |       S r-   )r   $ClusteringIterationStatsVector_clearrR   s    r   r   z$ClusteringIterationStatsVector.clear      CCDIIr#   c                 ,    t        j                  |       S r-   )r   #ClusteringIterationStatsVector_datarR   s    r   r   z#ClusteringIterationStatsVector.data      BB4HHr#   c                 ,    t        j                  |       S r-   )r   #ClusteringIterationStatsVector_sizerR   s    r   r   z#ClusteringIterationStatsVector.size  ri  r#   c                 .    t        j                  | |      S r-   )r   !ClusteringIterationStatsVector_atrV   s     r   r   z!ClusteringIterationStatsVector.at      @@qIIr#   c                 .    t        j                  | |      S r-   )r   %ClusteringIterationStatsVector_resizerV   s     r   r   z%ClusteringIterationStatsVector.resize  s    DDT1MMr#   c                 .    t        j                  | |      S r-   )r   #ClusteringIterationStatsVector_swapr   s     r   r   z#ClusteringIterationStatsVector.swap  s    BB4OOr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   %delete_ClusteringIterationStatsVectorr   r$   r#   r   r[  r[    sT    -/IOdeGH|TJIIJNP&LLr#   r[  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)ParameterRangeVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zParameterRangeVector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zParameterRangeVector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   ParameterRangeVector_swiginitnew_ParameterRangeVectorrR   s    r   rN   zParameterRangeVector.__init__  r  r#   c                 .    t        j                  | |      S r-   )r   ParameterRangeVector_push_backr   s     r   r   zParameterRangeVector.push_back  r  r#   c                 ,    t        j                  |       S r-   )r   ParameterRangeVector_clearrR   s    r   r   zParameterRangeVector.clear  r  r#   c                 ,    t        j                  |       S r-   )r   ParameterRangeVector_datarR   s    r   r   zParameterRangeVector.data  r  r#   c                 ,    t        j                  |       S r-   )r   ParameterRangeVector_sizerR   s    r   r   zParameterRangeVector.size  r  r#   c                 .    t        j                  | |      S r-   )r   ParameterRangeVector_atrV   s     r   r   zParameterRangeVector.at  ra   r#   c                 .    t        j                  | |      S r-   )r   ParameterRangeVector_resizerV   s     r   r   zParameterRangeVector.resize  r%  r#   c                 .    t        j                  | |      S r-   )r   ParameterRangeVector_swapr   s     r   r   zParameterRangeVector.swap  r(  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_ParameterRangeVectorr   r$   r#   r   ru  ru    r*  r#   ru  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)MaybeOwnedVectorUInt8Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$MaybeOwnedVectorUInt8Vector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$MaybeOwnedVectorUInt8Vector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   $MaybeOwnedVectorUInt8Vector_swiginitnew_MaybeOwnedVectorUInt8VectorrR   s    r   rN   z$MaybeOwnedVectorUInt8Vector.__init__      <<T?CrCrCtur#   c                 .    t        j                  | |      S r-   )r   %MaybeOwnedVectorUInt8Vector_push_backr   s     r   r   z%MaybeOwnedVectorUInt8Vector.push_back      DDT4PPr#   c                 ,    t        j                  |       S r-   )r   !MaybeOwnedVectorUInt8Vector_clearrR   s    r   r   z!MaybeOwnedVectorUInt8Vector.clear      @@FFr#   c                 ,    t        j                  |       S r-   )r    MaybeOwnedVectorUInt8Vector_datarR   s    r   r   z MaybeOwnedVectorUInt8Vector.data      ??EEr#   c                 ,    t        j                  |       S r-   )r    MaybeOwnedVectorUInt8Vector_sizerR   s    r   r   z MaybeOwnedVectorUInt8Vector.size  r  r#   c                 .    t        j                  | |      S r-   )r   MaybeOwnedVectorUInt8Vector_atrV   s     r   r   zMaybeOwnedVectorUInt8Vector.at      ==dAFFr#   c                 .    t        j                  | |      S r-   )r   "MaybeOwnedVectorUInt8Vector_resizerV   s     r   r   z"MaybeOwnedVectorUInt8Vector.resize      AA$JJr#   c                 .    t        j                  | |      S r-   )r    MaybeOwnedVectorUInt8Vector_swapr   s     r   r   z MaybeOwnedVectorUInt8Vector.swap      ??eLLr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   "delete_MaybeOwnedVectorUInt8Vectorr   r$   r#   r   r  r    T    -/IOdeGHvQGFFGKM&IIr#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)MaybeOwnedVectorInt32Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$MaybeOwnedVectorInt32Vector.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$MaybeOwnedVectorInt32Vector.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   $MaybeOwnedVectorInt32Vector_swiginitnew_MaybeOwnedVectorInt32VectorrR   s    r   rN   z$MaybeOwnedVectorInt32Vector.__init__	  r  r#   c                 .    t        j                  | |      S r-   )r   %MaybeOwnedVectorInt32Vector_push_backr   s     r   r   z%MaybeOwnedVectorInt32Vector.push_back  r  r#   c                 ,    t        j                  |       S r-   )r   !MaybeOwnedVectorInt32Vector_clearrR   s    r   r   z!MaybeOwnedVectorInt32Vector.clear  r  r#   c                 ,    t        j                  |       S r-   )r    MaybeOwnedVectorInt32Vector_datarR   s    r   r   z MaybeOwnedVectorInt32Vector.data  r  r#   c                 ,    t        j                  |       S r-   )r    MaybeOwnedVectorInt32Vector_sizerR   s    r   r   z MaybeOwnedVectorInt32Vector.size  r  r#   c                 .    t        j                  | |      S r-   )r   MaybeOwnedVectorInt32Vector_atrV   s     r   r   zMaybeOwnedVectorInt32Vector.at  r  r#   c                 .    t        j                  | |      S r-   )r   "MaybeOwnedVectorInt32Vector_resizerV   s     r   r   z"MaybeOwnedVectorInt32Vector.resize  r  r#   c                 .    t        j                  | |      S r-   )r    MaybeOwnedVectorInt32Vector_swapr   s     r   r   z MaybeOwnedVectorInt32Vector.swap  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   "delete_MaybeOwnedVectorInt32Vectorr   r$   r#   r   r  r    r  r#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)MaybeOwnedVectorFloat32Vectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z&MaybeOwnedVectorFloat32Vector.<lambda>%  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z&MaybeOwnedVectorFloat32Vector.<lambda>%  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   &MaybeOwnedVectorFloat32Vector_swiginit!new_MaybeOwnedVectorFloat32VectorrR   s    r   rN   z&MaybeOwnedVectorFloat32Vector.__init__(  s    >>t_EvEvExyr#   c                 .    t        j                  | |      S r-   )r   'MaybeOwnedVectorFloat32Vector_push_backr   s     r   r   z'MaybeOwnedVectorFloat32Vector.push_back+  s    FFtTRRr#   c                 ,    t        j                  |       S r-   )r   #MaybeOwnedVectorFloat32Vector_clearrR   s    r   r   z#MaybeOwnedVectorFloat32Vector.clear.  ri  r#   c                 ,    t        j                  |       S r-   )r   "MaybeOwnedVectorFloat32Vector_datarR   s    r   r   z"MaybeOwnedVectorFloat32Vector.data1      AA$GGr#   c                 ,    t        j                  |       S r-   )r   "MaybeOwnedVectorFloat32Vector_sizerR   s    r   r   z"MaybeOwnedVectorFloat32Vector.size4  r  r#   c                 .    t        j                  | |      S r-   )r    MaybeOwnedVectorFloat32Vector_atrV   s     r   r   z MaybeOwnedVectorFloat32Vector.at7      ??aHHr#   c                 .    t        j                  | |      S r-   )r   $MaybeOwnedVectorFloat32Vector_resizerV   s     r   r   z$MaybeOwnedVectorFloat32Vector.resize:  s    CCD!LLr#   c                 .    t        j                  | |      S r-   )r   "MaybeOwnedVectorFloat32Vector_swapr   s     r   r   z"MaybeOwnedVectorFloat32Vector.swap=      AA$NNr#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   $delete_MaybeOwnedVectorFloat32Vectorr   r$   r#   r   r  r  $  sT    -/IOdeGHzSIHHIMO&KKr#   r  c                   r    e Zd Z ed d d      ZeZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   Zy)OnDiskOneListVectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOnDiskOneListVector.<lambda>D  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOnDiskOneListVector.<lambda>D  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   OnDiskOneListVector_swiginitnew_OnDiskOneListVectorrR   s    r   rN   zOnDiskOneListVector.__init__G  r  r#   c                 .    t        j                  | |      S r-   )r   OnDiskOneListVector_push_backr   s     r   r   zOnDiskOneListVector.push_backJ  r  r#   c                 ,    t        j                  |       S r-   )r   OnDiskOneListVector_clearrR   s    r   r   zOnDiskOneListVector.clearM  r  r#   c                 ,    t        j                  |       S r-   )r   OnDiskOneListVector_datarR   s    r   r   zOnDiskOneListVector.dataP  r  r#   c                 ,    t        j                  |       S r-   )r   OnDiskOneListVector_sizerR   s    r   r   zOnDiskOneListVector.sizeS  r  r#   c                 .    t        j                  | |      S r-   )r   OnDiskOneListVector_atrV   s     r   r   zOnDiskOneListVector.atV  rv   r#   c                 .    t        j                  | |      S r-   )r   OnDiskOneListVector_resizerV   s     r   r   zOnDiskOneListVector.resizeY  r  r#   c                 .    t        j                  | |      S r-   )r   OnDiskOneListVector_swapr   s     r   r   zOnDiskOneListVector.swap\  r  r#   N)r   r   r6   r   r   r   r   rN   r   r   r   r   r   r   r   r   delete_OnDiskOneListVectorr   r$   r#   r   r  r  C  r  r#   r  c                 4    t        j                  | ||||      S )z
     low level SIMD histogramming functions  8-bin histogram of (x - min) >> shift
    values outside the range are ignored.
    the data table should be aligned on 32 bytes
    )r   simd_histogram_8r   rW   minshifthists        r   r  r  c  s     ++D!S%FFr#   c                 4    t        j                  | ||||      S )zsame for 16-bin histogram)r   simd_histogram_16r  s        r   r  r  k  s    ,,T1c5$GGr#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zej                   Zy)PartitionStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPartitionStats.<lambda>o  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPartitionStats.<lambda>o  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   PartitionStats_swiginitnew_PartitionStatsrR   s    r   rN   zPartitionStats.__init__t      //o6X6X6Z[r#   c                 ,    t        j                  |       S r-   )r   PartitionStats_resetrR   s    r   resetzPartitionStats.resetw  rS   r#   N)r   r   r6   r   r   r   r   r   !PartitionStats_bissect_cycles_get!PartitionStats_bissect_cycles_setbissect_cycles"PartitionStats_compress_cycles_get"PartitionStats_compress_cycles_setcompress_cyclesrN   r  delete_PartitionStatsr   r$   r#   r   r  r  n  sw    -/IOdeGHoOOQ`  RC  RC  DNQQSb  TF  TF  GO\:&<<r#   r  c                 .    t        j                  | |      S r-   )r   bitvec_print)bds     r   r  r  ~  s    ''1--r#   c                 2    t        j                  | |||      S r-   )r   fvecs2bitvecs)r>   r	  r
  rW   s       r   r  r        ((Aq!44r#   c                 2    t        j                  | |||      S r-   )r   bitvecs2fvecs)r	  r>   r
  rW   s       r   r  r    r  r#   c                 0    t        j                  | ||      S r-   )r   fvec2bitvec)r>   r	  r
  s      r   r  r    s    &&q!Q//r#   c                 6    t        j                  | |||||      S )z/Shuffle the bits from b(i, j) := a(i, order[j]))r   bitvec_shuffle)rW   dadborderar	  s         r   r  r    s    ))!RUAqAAr#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zd Zej&                  Zy)BitstringWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBitstringWriter.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBitstringWriter.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   BitstringWriter_swiginitnew_BitstringWriterr   code	code_sizes      r   rN   zBitstringWriter.__init__  !    007Z7Z[_aj7klr#   c                 0    t        j                  | ||      S r-   )r   BitstringWriter_write)r   r>   nbits      r   writezBitstringWriter.write  s    44T1dCCr#   N)r   r   r6   r   r   r   r   r   BitstringWriter_code_getBitstringWriter_code_setr   BitstringWriter_code_size_getBitstringWriter_code_size_setr!  BitstringWriter_i_getBitstringWriter_i_setirN   r&  delete_BitstringWriterr   r$   r#   r   r  r    sx    -/IOdeGHO<<o>f>fgDFFHuHuvI668]8]^AmD&==r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zd Zej&                  Zy)BitstringReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBitstringReader.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBitstringReader.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   BitstringReader_swiginitnew_BitstringReaderr  s      r   rN   zBitstringReader.__init__  r"  r#   c                 .    t        j                  | |      S r-   )r   BitstringReader_read)r   r%  s     r   readzBitstringReader.read  r   r#   N)r   r   r6   r   r   r   r   r   BitstringReader_code_getBitstringReader_code_setr   BitstringReader_code_size_getBitstringReader_code_size_setr!  BitstringReader_i_getBitstringReader_i_setr-  rN   r8  delete_BitstringReaderr   r$   r#   r   r0  r0    sx    -/IOdeGHO<<o>f>fgDFFHuHuvI668]8]^Am@&==r#   r0  c                 6    t        j                  | |||||      S )ax  
     Compute a set of Hamming distances between na and nb binary vectors

    :type a: uint8_t
    :param a:             size na * nbytespercode
    :type b: uint8_t
    :param b:             size nb * nbytespercode
    :type nbytespercode: int
    :param nbytespercode: should be multiple of 8
    :type dis: int
    :param dis:           output distances, size na * nb
    )r   hammings)r  r	  nanbnbytespercodediss         r   rA  rA    s     ##Aq"b-EEr#   c                  &    t        j                  |  S )a  
     Return the k smallest Hamming distances for a set of binary query vectors,
    using a max heap.
    :type a: uint8_t
    :param a:       queries, size ha->nh * ncodes
    :type b: uint8_t
    :param b:       database, size nb * ncodes
    :type nb: int
    :param nb:      number of database vectors
    :type ncodes: int
    :param ncodes:  size of the binary codes (bytes)
    :type ordered: int
    :param ordered: if != 0: order the results by decreasing distance
                       (may be bottleneck for k/n > 0.01)
    :type approx_topk_mode: int, optional
    :param approx_topk_mode: allows to use approximate top-k facilities
                                to speedup heap
    )r   hammings_knn_hcrL   s    r   rG  rG    s    & **D11r#   c                 6    t        j                  | |||||      S r-   )r   hammings_knn)har  r	  rC  ncodesordereds         r   rJ  rJ    s    ''Aq"fgFFr#   c	                 <    t        j                  | ||||||||	      S )a  
     Return the k smallest Hamming distances for a set of binary query vectors,
    using counting max.
    :type a: uint8_t
    :param a:       queries, size na * ncodes
    :type b: uint8_t
    :param b:       database, size nb * ncodes
    :type na: int
    :param na:      number of query vectors
    :type nb: int
    :param nb:      number of database vectors
    :type k: int
    :param k:       number of vectors/distances to return
    :type ncodes: int
    :param ncodes:  size of the binary codes (bytes)
    :type distances: int
    :param distances: output distances from each query vector to its k nearest
                       neighbors
    :type labels: int
    :param labels:  output ids of the k nearest neighbors to each query vector
    )r   hammings_knn_mc)	r  r	  rB  rC  krL  	distanceslabelssels	            r   rO  rO    s&    , **1aRFIvWZ[[r#   c           
      :    t        j                  | |||||||      S )zCsame as hammings_knn except we are doing a range search with radius)r   hamming_range_search)r  r	  rB  rC  radiusrL  resultrS  s           r   rU  rU    s"    //1b"fffVYZZr#   c           	      8    t        j                  | ||||||      S r-   )r   hamming_count_thres)bs1bs2n1n2htrL  nptrs          r   rY  rY    s    ..sCRVTRRr#   c           
      :    t        j                  | |||||||      S r-   )r   match_hamming_thres)rZ  r[  r\  r]  r^  rL  idxrE  s           r   ra  ra    s"    ..sCRVSRUVVr#   c                 4    t        j                  | ||||      S r-   )r   crosshamming_count_thres)dbsrW   r^  rL  r_  s        r   rd  rd    s    33CBMMr#   c                 6    t        j                  | |||||      S )z_
    generalized Hamming distances (= count number of code bytes that
       are the same)
    )r   generalized_hammings_knn_hc)rK  r  r	  rC  r!  rM  s         r   rg  rg    s     
 66r1aYPWXXr#   c                  &    t        j                  |  S )a  
    *Overload 1:*
     Pack a set of n codes of size M * nbit

    :type n: int
    :param n:           number of codes to pack
    :type M: int
    :param M:           number of elementary codes per code
    :type nbit: int
    :param nbit:        number of bits per elementary code
    :type unpacked: int
    :param unpacked:    input unpacked codes, size (n, M)
    :type packed: uint8_t
    :param packed:      output packed codes, size (n, code_size)
    :type code_size: int
    :param code_size:   should be >= ceil(M * nbit / 8)

    |

    *Overload 2:*
     Pack a set of n codes of variable sizes

    :param nbit:       number of bits per entry (size M)
    )r   pack_bitstringsrH  s    r   ri  ri    s    2 **D11r#   c                  &    t        j                  |  S )a  
    *Overload 1:*
     Unpack a set of n codes of size M * nbit

    :type n: int
    :param n:           number of codes to pack
    :type M: int
    :param M:           number of elementary codes per code
    :type nbit: int
    :param nbit:        number of bits per elementary code
    :type unpacked: int
    :param unpacked:    input unpacked codes, size (n, M)
    :type packed: uint8_t
    :param packed:      output packed codes, size (n, code_size)
    :type code_size: int
    :param code_size:   should be >= ceil(M * nbit / 8)

    |

    *Overload 2:*
     Unpack a set of n codes of variable sizes

    :param nbit:       number of bits per entry (size M)
    )r   unpack_bitstringsrH  s    r   rk  rk    s    2 ,,d33r#   c                 ,    t        j                  |       S r-   )r   
popcount32r=   s    r   rm  rm  9      %%a((r#   c                 ,    t        j                  |       S r-   )r   
popcount64r=   s    r   rp  rp  <  rn  r#   c                  *    t        j                         S r-   )r   get_num_gpusr$   r#   r   rr  rr  ?      ''))r#   c                  *    t        j                         S r-   )r   gpu_profiler_startr$   r#   r   ru  ru  B  s    --//r#   c                  *    t        j                         S r-   )r   gpu_profiler_stopr$   r#   r   rw  rw  E  s    ,,..r#   c                  *    t        j                         S r-   )r   gpu_sync_all_devicesr$   r#   r   ry  ry  H  s    //11r#   c                  *    t        j                         S )zget compile options)r   get_compile_optionsr$   r#   r   r{  r{  K  s    ..00r#   c                  *    t        j                         S r-   )r   get_versionr$   r#   r   r}  r}  O  s    &&((r#   c                  *    t        j                         S )z%ms elapsed since some arbitrary epoch)r   getmillisecsr$   r#   r   r  r  R      ''))r#   c                  *    t        j                         S )zget current RSS usage in kB)r   get_mem_usage_kbr$   r#   r   r  r  V  s    ++--r#   c                  *    t        j                         S r-   )r   
get_cyclesr$   r#   r   r  r  Z  s    %%''r#   c                 4    t        j                  | ||||      S r-   )r   
reflection)ur>   rW   r
  nus        r   r  r  ]  s    %%aAq"55r#   c                 0    t        j                  | ||      S )z
     compute the Q of the QR decomposition for m > n
    :type a: float
    :param a:   size n * m: input matrix and output Q
    )r   	matrix_qr)mrW   r  s      r   r  r  `  s     $$Q1--r#   c                 0    t        j                  | ||      S )zEdistances are supposed to be sorted. Sorts indices with same distance)r   ranklist_handle_ties)rP  rb  rE  s      r   r  r  h  s    //3<<r#   c                 2    t        j                  | |||      S )z
     count the number of common elements between v1 and v2
    algorithm = sorting + bissection to avoid double-counting duplicates
    )r   ranklist_intersection_size)k1v1k2v2s       r   r  r  l  s    
 55b"b"EEr#   c           
      :    t        j                  | |||||||      S )a  
     merge a result table into another one

    :type I0: int
    :param I0:, D0       first result table, size (n, k)
    :type I1: int
    :param I1:, D1       second result table, size (n, k)
    :type keep_min: boolean, optional
    :param keep_min:     if true, keep min values, otherwise keep max
    :type translation: int, optional
    :param translation:  add this value to all I1's indexes
    :rtype: int
    :return: nb of values that were taken from the second table
    )r   merge_result_table_with)rW   rP  I0D0I1D1keep_mintranslations           r   r  r  s  s$     221aRRS^__r#   c                  &    t        j                  |  S )z
    *Overload 1:*
    a balanced assignment has a IF of 1, a completely unbalanced assignment has
    an IF = k.

    |

    *Overload 2:*
    same, takes a histogram as input
    )r   imbalance_factorrH  s    r   r  r    s     ++T22r#   c                 2    t        j                  | |||      S )zcompute histogram on v)r   	ivec_hist)rW   rC   vmaxr  s       r   r  r    s    $$Q466r#   c                 2    t        j                  | |||      S )z
     Compute histogram of bits on a code array

    :type codes: uint8_t
    :param codes:   size(n, nbits / 8)
    :type hist: int
    :param hist:    size(nbits): nb of 1s in the array of codes
    )r   bincode_hist)rW   nbitscodesr  s       r   r  r    s     ''5%>>r#   c                 .    t        j                  | |      S zcompute a checksum on a table.)r   ivec_checksumrW   r  s     r   r  r        ((A..r#   c                 .    t        j                  | |      S r  )r   bvec_checksumr  s     r   r  r    r  r#   c                 2    t        j                  | |||      S )a  
     compute checksums for the rows of a matrix

    :type n: int
    :param n:   number of rows
    :type d: int
    :param d:   size per row
    :type a: uint8_t
    :param a:   matrix to handle, size n * d
    :type cs: int
    :param cs:  output checksums, size n
    )r   bvecs_checksum)rW   r
  r  css       r   r  r    s     ))!Q266r#   c                 6    t        j                  | |||||      S )a  
     random subsamples a set of vectors if there are too many of them

    :type d: int
    :param d:      dimension of the vectors
    :type n: int
    :param n:      on input: nb of input vectors, output: nb of output vectors
    :type nmax: int
    :param nmax:   max nb of vectors to keep
    :type x: float
    :param x:      input array, size *n-by-d
    :type seed: int, optional
    :param seed:   random seed to use for sampling
    :rtype: float
    :return: x or an array allocated with new [] with *n vectors
    )r   fvecs_maybe_subsample)r
  rW   nmaxr>   verboseseeds         r   r  r    s    " 00AtQNNr#   c                 0    t        j                  | ||      S )a>  
     Convert binary vector to +1/-1 valued float vector.

    :type d: int
    :param d:      dimension of the vector (multiple of 8)
    :type x_in: uint8_t
    :param x_in:   input binary vector (uint8_t table of size d / 8)
    :type x_out: float
    :param x_out:  output float vector (float table of size d)
    )r   binary_to_realr
  x_inx_outs      r   r  r    s     ))!T599r#   c                 0    t        j                  | ||      S )ae  
     Convert float vector to binary vector. Components > 0 are converted to 1,
    others to 0.

    :type d: int
    :param d:      dimension of the vector (multiple of 8)
    :type x_in: float
    :param x_in:   input float vector (float table of size d)
    :type x_out: uint8_t
    :param x_out:  output binary vector (uint8_t table of size d / 8)
    )r   real_to_binaryr  s      r   r  r    s     ))!T599r#   c                 .    t        j                  | |      S )zA reasonable hashing function)r   
hash_bytes)bytesrW   s     r   r  r    s    %%eQ//r#   c                  *    t        j                         S )z*Whether OpenMP annotations were respected.)r   check_openmpr$   r#   r   r  r    r  r#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zej                   Zy)CodeSetc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCodeSet.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCodeSet.<lambda>  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   CodeSet_swiginitnew_CodeSetr   r
  s     r   rN   zCodeSet.__init__  s    ((/J/J1/MNr#   c                 2    t        j                  | |||      S r-   )r   CodeSet_insert)r   rW   r  inserteds       r   insertzCodeSet.insert  s    --dAuhGGr#   N)r   r   r6   r   r   r   r   r   CodeSet_d_getCodeSet_d_setr
  CodeSet_s_getCodeSet_s_setsrN   r  delete_CodeSetr   r$   r#   r   r  r    s`    -/IOdeGH..0M0MNA..0M0MNAOH&55r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d      Zd	 Z eej,                  ej.                  d
      Z eej2                  ej4                  d      Z eej8                  ej:                  d      Z eej>                  ej@                  d      Z! eejD                  ejF                  d      Z$ eejJ                  ejL                  d      Z' eejP                  ejR                  d      Z*d Z+d Z,ejZ                  Z.y)CombinerRangeKNNfloatw
     This class is used to combine range and knn search results
    in contrib.exhaustive_search.range_search_gpu
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCombinerRangeKNNfloat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCombinerRangeKNNfloat.<lambda>  rD   r#   rE   rF   nb of queries+number of neighbors for the knn search partrange search radiusc           	      \    t        j                  | t        j                  ||||             yz*whether to keep max values instead of min.N)r   CombinerRangeKNNfloat_swiginitnew_CombinerRangeKNNfloatr   nqrP  r2keep_maxs        r   rN   zCombinerRangeKNNfloat.__init__
  '    66t_=f=fgiklnprz={|r#   Knn search resultssize nq * kR
    size nq * k
    optional: range search results (ignored if mask is NULL)
    -mask for where knn results are valid, size nqsize nrange + 1size lim_remain[nrange]c                 .    t        j                  | |      S zsize nq + 1)r   #CombinerRangeKNNfloat_compute_sizesr   L_ress     r   compute_sizesz#CombinerRangeKNNfloat.compute_sizes      BB4OOr#   c                 0    t        j                  | ||      S zu
        Phase 2: caller allocates D_res and I_res (size L_res[nq])
        Phase 3: fill in D_res and I_res
        )r   "CombinerRangeKNNfloat_write_resultr   D_resI_ress      r   write_resultz"CombinerRangeKNNfloat.write_result      
 AA$uUUr#   N)/r   r   r6   r7   r   r   r   r   r   CombinerRangeKNNfloat_nq_getCombinerRangeKNNfloat_nq_setr  CombinerRangeKNNfloat_k_getCombinerRangeKNNfloat_k_setrP  CombinerRangeKNNfloat_r2_getCombinerRangeKNNfloat_r2_setr  "CombinerRangeKNNfloat_keep_max_get"CombinerRangeKNNfloat_keep_max_setr  rN   CombinerRangeKNNfloat_I_getCombinerRangeKNNfloat_I_setICombinerRangeKNNfloat_D_getCombinerRangeKNNfloat_D_setDCombinerRangeKNNfloat_mask_getCombinerRangeKNNfloat_mask_setmask$CombinerRangeKNNfloat_lim_remain_get$CombinerRangeKNNfloat_lim_remain_set
lim_remain"CombinerRangeKNNfloat_D_remain_get"CombinerRangeKNNfloat_D_remain_setD_remain"CombinerRangeKNNfloat_I_remain_get"CombinerRangeKNNfloat_I_remain_setI_remainCombinerRangeKNNfloat_L_res_getCombinerRangeKNNfloat_L_res_setr  r  r  delete_CombinerRangeKNNfloatr   r$   r#   r   r  r       
 -/IOdeGH	/>>@l@l	mB<<o>i>i  pD  	EA	/>>@l@l  se  
fBJJOL~L~  E_  `H} 	<<o>i>i  pI  	JA<<o>i>i  pB  	CAOBBODrDr y 	D /NNP_  QE  QE  K  @JJJOL~L~  E[  \HJJOL~L~  Ec  dH_DDoFuFu  |Z  [EPV 'CCr#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d      Zd	 Z eej,                  ej.                  d
      Z eej2                  ej4                  d      Z eej8                  ej:                  d      Z eej>                  ej@                  d      Z! eejD                  ejF                  d      Z$ eejJ                  ejL                  d      Z' eejP                  ejR                  d      Z*d Z+d Z,ejZ                  Z.y)CombinerRangeKNNint16r  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCombinerRangeKNNint16.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCombinerRangeKNNint16.<lambda>,  rD   r#   rE   rF   r  r  r  c           	      \    t        j                  | t        j                  ||||             yr  )r   CombinerRangeKNNint16_swiginitnew_CombinerRangeKNNint16r  s        r   rN   zCombinerRangeKNNint16.__init__3  r  r#   r  r  r  r  r  r  c                 .    t        j                  | |      S r  )r   #CombinerRangeKNNint16_compute_sizesr  s     r   r  z#CombinerRangeKNNint16.compute_sizesA  r  r#   c                 0    t        j                  | ||      S r  )r   "CombinerRangeKNNint16_write_resultr  s      r   r  z"CombinerRangeKNNint16.write_resultE  r  r#   N)/r   r   r6   r7   r   r   r   r   r   CombinerRangeKNNint16_nq_getCombinerRangeKNNint16_nq_setr  CombinerRangeKNNint16_k_getCombinerRangeKNNint16_k_setrP  CombinerRangeKNNint16_r2_getCombinerRangeKNNint16_r2_setr  "CombinerRangeKNNint16_keep_max_get"CombinerRangeKNNint16_keep_max_setr  rN   CombinerRangeKNNint16_I_getCombinerRangeKNNint16_I_setr  CombinerRangeKNNint16_D_getCombinerRangeKNNint16_D_setr  CombinerRangeKNNint16_mask_getCombinerRangeKNNint16_mask_setr  $CombinerRangeKNNint16_lim_remain_get$CombinerRangeKNNint16_lim_remain_setr  "CombinerRangeKNNint16_D_remain_get"CombinerRangeKNNint16_D_remain_setr  "CombinerRangeKNNint16_I_remain_get"CombinerRangeKNNint16_I_remain_setr  CombinerRangeKNNint16_L_res_getCombinerRangeKNNint16_L_res_setr  r  r  delete_CombinerRangeKNNint16r   r$   r#   r   r  r  &  r  r#   r  c                 0    t        j                  | ||      S )z'Squared L2 distance between two vectors)r   
fvec_L2sqrr>   yr
  s      r   r9  r9  P  s    %%aA..r#   c                 0    t        j                  | ||      S )zinner product)r   fvec_inner_productr:  s      r   r=  r=  T  s    --aA66r#   c                 0    t        j                  | ||      S )zL1 distance)r   fvec_L1r:  s      r   r?  r?  X  s    ""1a++r#   c                 0    t        j                  | ||      S )zinfinity distance)r   	fvec_Linfr:  s      r   rA  rA  \  s    $$Q1--r#   c
                 >    t        j                  | |||||||||	
      S )zy
    Special version of inner product that computes 4 distances
    between x and yi, which is performance oriented.
    )r   fvec_inner_product_batch_4
r>   y0y1y2y3r
  dis0dis1dis2dis3s
             r   rC  rC  `  s*    
 55aRRDRVX\^bccr#   c
                 >    t        j                  | |||||||||	
      S )zq
    Special version of L2sqr that computes 4 distances
    between x and yi, which is performance oriented.
    )r   fvec_L2sqr_batch_4rD  s
             r   rN  rN  g  s)    
 --aRRD$PTVZ[[r#   c	                 <    t        j                  | ||||||||	      S )a  
     Compute pairwise distances between sets of vectors

    :type d: int
    :param d:     dimension of the vectors
    :type nq: int
    :param nq:    nb of query vectors
    :type nb: int
    :param nb:    nb of database vectors
    :type xq: float
    :param xq:    query vectors (size nq * d)
    :type xb: float
    :param xb:    database vectors (size nb * d)
    :type dis: float
    :param dis:   output distances (size nq * nb)
    :param ldq,ldb:, ldd strides for the matrices
    )r   pairwise_L2sqr)	r
  r  xqrC  xbrE  ldqldbldds	            r   rP  rP  n  s%    $ ))!RRS#sCPPr#   c                 4    t        j                  | ||||      S r-   )r   fvec_inner_products_ny)ipr>   r;  r
  nys        r   rW  rW    s    11"aArBBr#   c                 4    t        j                  | ||||      S r-   )r   fvec_L2sqr_ny)rE  r>   r;  r
  rY  s        r   r[  r[    s    ((aAr::r#   c           	      8    t        j                  | ||||||      S r-   )r   fvec_L2sqr_ny_transposed)rE  r>   r;  y_sqlenr
  d_offsetrY  s          r   r]  r]    s     33CAw8UWXXr#   c                 4    t        j                  | ||||      S r-   )r   fvec_L2sqr_ny_nearest)distances_tmp_bufferr>   r;  r
  rY  s        r   ra  ra    s    001Eq!QPRSSr#   c           	      8    t        j                  | ||||||      S r-   )r   "fvec_L2sqr_ny_nearest_y_transposed)rb  r>   r;  r^  r
  r_  rY  s          r   rd  rd    s&    ==>RTUWXZacdfnprssr#   c                 .    t        j                  | |      S )zsquared norm of a vector)r   fvec_norm_L2sqr)r>   r
  s     r   rf  rf    s    **1a00r#   c                 2    t        j                  | |||      S )z
     compute the L2 norms for a set of vectors

    :type norms: float
    :param norms:    output norms, size nx
    :type x: float
    :param x:        set of vectors, size nx * d
    )r   fvec_norms_L2normsr>   r
  nxs       r   rh  rh    s     ((1b99r#   c                 2    t        j                  | |||      S )z1same as fvec_norms_L2, but computes squared norms)r   fvec_norms_L2sqrri  s       r   rm  rm    s    ++E1a<<r#   c                 0    t        j                  | ||      S r-   )r   fvec_renorm_L2)r
  rk  r>   s      r   ro  ro    s    ))!R33r#   c                 4    t        j                  | ||||      S r-   )r   inner_product_to_L2sqr)rE  nr1nr2r\  r]  s        r   rq  rq    s    11#sCRHHr#   c                  &    t        j                  |  S )a  
    *Overload 1:*
     compute c := a + b for vectors

    c and a can overlap, c and b can overlap

    :type a: float
    :param a: size d
    :type b: float
    :param b: size d
    :type c: float
    :param c: size d

    |

    *Overload 2:*
     compute c := a + b for a, c vectors and b a scalar

    c and a can overlap

    :type a: float
    :param a: size d
    :type c: float
    :param c: size d
    )r   fvec_addrH  s    r   ru  ru    s    4 ##T**r#   c                 2    t        j                  | |||      S )z
     compute c := a - b for vectors

    c and a can overlap, c and b can overlap

    :type a: float
    :param a: size d
    :type b: float
    :param b: size d
    :type c: float
    :param c: size d
    )r   fvec_sub)r
  r  r	  cs       r   rw  rw    s     ##Aq!Q//r#   c           	      8    t        j                  | ||||||      S )a  
     compute the inner product between x and a subset y of ny vectors defined by
    ids

    ip(i, j) = inner_product(x(i, :), y(ids(i, j), :))

    :type ip: float
    :param ip:    output array, size nx * ny
    :type x: float
    :param x:     first-term vector, size nx * d
    :type y: float
    :param y:     second-term vector, size (max(ids) + 1) * d
    :type ids: int
    :param ids:   ids to sample from y, size nx * ny
    )r   fvec_inner_products_by_idx)rX  r>   r;  idsr
  rk  rY  s          r   rz  rz    s!      55b!QQBOOr#   c           	      8    t        j                  | ||||||      S )a  
     compute the squared L2 distances between x and a subset y of ny vectors
    defined by ids

    dis(i, j) = inner_product(x(i, :), y(ids(i, j), :))

    :type dis: float
    :param dis:   output array, size nx * ny
    :type x: float
    :param x:     first-term vector, size nx * d
    :type y: float
    :param y:     second-term vector, size (max(ids) + 1) * d
    :type ids: int
    :param ids:   ids to sample from y, size nx * ny
    )r   fvec_L2sqr_by_idx)rE  r>   r;  r{  r
  rk  rY  s          r   r}  r}    s!      ,,S!QQBGGr#   c           	      8    t        j                  | ||||||      S )a2  
     compute dis[j] = L2sqr(x[ix[j]], y[iy[j]]) forall j=0..n-1

    :type x: float
    :param x:  size (max(ix) + 1, d)
    :type y: float
    :param y:  size (max(iy) + 1, d)
    :type ix: int
    :param ix: size n
    :type iy: int
    :param iy: size n
    :type dis: float
    :param dis: size n
    )r   pairwise_indexed_L2sqrr
  rW   r>   ixr;  iyrE  s          r   r  r    s!     11!Q2q"cJJr#   c           	      8    t        j                  | ||||||      S )a:  
     compute dis[j] = inner_product(x[ix[j]], y[iy[j]]) forall j=0..n-1

    :type x: float
    :param x:  size (max(ix) + 1, d)
    :type y: float
    :param y:  size (max(iy) + 1, d)
    :type ix: int
    :param ix: size n
    :type iy: int
    :param iy: size n
    :type dis: float
    :param dis: size n
    )r   pairwise_indexed_inner_productr  s          r   r  r  
  s!     99!Q2q"cRRr#   c                  &    t        j                  |  S )a  
    *Overload 1:*
     Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, w.r.t to max inner product.

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type res: :py:class:`float_minheap_array_t`
    :param res:  result heap structure, which also provides k. Sorted on output

    |

    *Overload 2:*
      Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the inner product metric.

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type distances: float
    :param distances:  output distances, size nq * k
    :type indexes: int
    :param indexes:    output vector ids, size nq * k

    |

    *Overload 3:*
      Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the inner product metric.

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type distances: float
    :param distances:  output distances, size nq * k
    :type indexes: int
    :param indexes:    output vector ids, size nq * k
    )r   knn_inner_productrH  s    r   r  r    s    V ,,d33r#   c                  &    t        j                  |  S )aS	  
    *Overload 1:*
     Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the L2 distance
    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type res: :py:class:`float_maxheap_array_t`
    :param res:  result heap strcture, which also provides k. Sorted on output
    :type y_norm2: float, optional
    :param y_norm2:    (optional) norms for the y vectors (nullptr or size ny)
    :type sel: :py:class:`IDSelector`, optional
    :param sel:  search in this subset of vectors

    |

    *Overload 2:*
      Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the L2 distance

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type distances: float
    :param distances:  output distances, size nq * k
    :type indexes: int
    :param indexes:    output vector ids, size nq * k
    :type y_norm2: float, optional
    :param y_norm2:    (optional) norms for the y vectors (nullptr or size ny)
    :type sel: :py:class:`IDSelector`, optional
    :param sel:  search in this subset of vectors

    |

    *Overload 3:*
      Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the L2 distance

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type distances: float
    :param distances:  output distances, size nq * k
    :type indexes: int
    :param indexes:    output vector ids, size nq * k
    :type y_norm2: float, optional
    :param y_norm2:    (optional) norms for the y vectors (nullptr or size ny)
    :param sel:  search in this subset of vectors

    |

    *Overload 4:*
      Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, for the L2 distance

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size ny * d
    :type distances: float
    :param distances:  output distances, size nq * k
    :type indexes: int
    :param indexes:    output vector ids, size nq * k
    :param y_norm2:    (optional) norms for the y vectors (nullptr or size ny)
    :param sel:  search in this subset of vectors
    )r   	knn_L2sqrrH  s    r   r  r  H  s    L $$d++r#   c                 @    t        j                  | |||||||||	|
      S )a=  
     Find the max inner product neighbors for nx queries in a set of ny vectors
    indexed by ids. May be useful for re-ranking a pre-selected vector list

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size (max(ids) + 1) * d
    :type ids: int
    :param ids:  subset of database vectors to consider, size (nx, nsubset)
    :param res:  result structure
    :type ld_ids: int, optional
    :param ld_ids: stride for the ids array. -1: use nsubset, 0: all queries
        process the same subset
    )r   knn_inner_products_by_idx)r>   r;  subsetr
  rk  rY  nsubsetrP  valsr{  ld_idss              r   r  r    s-      44Q61b"gWXZ^`cekllr#   c                 @    t        j                  | |||||||||	|
      S )aC  
     Find the nearest neighbors for nx queries in a set of ny vectors
    indexed by ids. May be useful for re-ranking a pre-selected vector list

    :type x: float
    :param x:    query vectors, size nx * d
    :type y: float
    :param y:    database vectors, size (max(ids) + 1) * d
    :type subset: int
    :param subset: subset of database vectors to consider, size (nx, nsubset)
    :param res:  rIDesult structure
    :type ld_subset: int, optional
    :param ld_subset: stride for the subset array. -1: use nsubset, 0: all queries
        process the same subset
    )r   knn_L2sqr_by_idx)r>   r;  r  r
  rk  rY  r  rP  r  r{  	ld_subsets              r   r  r    s,      ++Aq&!RWaQUWZ\effr#   c           
      :    t        j                  | |||||||      S )a  
     Return the k nearest neighbors of each of the nx vectors x among the ny
     vector y, w.r.t to max inner product

    :type x: float
    :param x:      query vectors, size nx * d
    :type y: float
    :param y:      database vectors, size ny * d
    :type radius: float
    :param radius: search radius around the x vectors
    :type result: :py:class:`RangeSearchResult`
    :param result: result structure
    )r   range_search_L2sqrr>   r;  r
  rk  rY  rV  rW  rS  s           r   r  r    s#     --aAr2vvsSSr#   c           
      :    t        j                  | |||||||      S )z;same as range_search_L2sqr for the inner product similarity)r   range_search_inner_productr  s           r   r  r    s"    55aAr2vvWZ[[r#   c           	      8    t        j                  | ||||||      S )zspecialized function for PQ2)r   compute_PQ_dis_tables_dsub2)r
  ksub	centroidsrk  r>   is_inner_product
dis_tabless          r   r  r    s!    66q$	2qRbdnoor#   c                 4    t        j                  | ||||      S )z
     compute c := a + bf * b for a, b and c tables

    :type n: int
    :param n:   size of the tables
    :type a: float
    :param a:   size n
    :type b: float
    :param b:   size n
    :type c: float
    :param c:   result table, size n
    )r   	fvec_maddrW   r  bfr	  rx  s        r   r  r    s     $$Q2q!44r#   c                 4    t        j                  | ||||      S )z
     same as fvec_madd, also return index of the min of the result table
    :rtype: int
    :return: index of the min of table c
    )r   fvec_madd_and_argminr  s        r   r  r    s     //1b!Q??r#   c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zdd
Zej"                  Zy)RandomGeneratorz;random generator that can be used in multithreaded contextsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRandomGenerator.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRandomGenerator.<lambda>  rD   r#   rE   rF   c                 ,    t        j                  |       S zrandom int64_t)r   RandomGenerator_rand_int64rR   s    r   
rand_int64zRandomGenerator.rand_int64      99$??r#   c                 .    t        j                  | g| S z
        *Overload 1:*
        random positive integer

        |

        *Overload 2:*
        generate random integer between 0 and max-1
        )r   RandomGenerator_rand_intr   s     r   rand_intzRandomGenerator.rand_int  s     77DtDDr#   c                 ,    t        j                  |       S zbetween 0 and 1)r   RandomGenerator_rand_floatrR   s    r   
rand_floatzRandomGenerator.rand_float  r  r#   c                 ,    t        j                  |       S r-   )r   RandomGenerator_rand_doublerR   s    r   rand_doublezRandomGenerator.rand_double  r  r#   c                 V    t        j                  | t        j                  |             y r-   )r   RandomGenerator_swiginitnew_RandomGeneratorr   r  s     r   rN   zRandomGenerator.__init__   s    007Z7Z[_7`ar#   N  )r   r   r6   r7   r   r   r   r   r   RandomGenerator_mt_getRandomGenerator_mt_setmtr  r  r  r  rN   delete_RandomGeneratorr   r$   r#   r   r  r    s]    F-/IOdeGH	/88/:`:`	aB@
E@Ab&==r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zdd
Zd Zej$                  Zy)SplitMix64RandomGeneratorzu
    fast random generator that cannot be used in multithreaded contexts.
    based on https://prng.di.unimi.it/
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"SplitMix64RandomGenerator.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"SplitMix64RandomGenerator.<lambda>  rD   r#   rE   rF   c                 ,    t        j                  |       S r  )r   $SplitMix64RandomGenerator_rand_int64rR   s    r   r  z$SplitMix64RandomGenerator.rand_int64      CCDIIr#   c                 .    t        j                  | g| S r  )r   "SplitMix64RandomGenerator_rand_intr   s     r   r  z"SplitMix64RandomGenerator.rand_int  s     AA$NNNr#   c                 ,    t        j                  |       S r  )r   $SplitMix64RandomGenerator_rand_floatrR   s    r   r  z$SplitMix64RandomGenerator.rand_float   r  r#   c                 ,    t        j                  |       S r-   )r   %SplitMix64RandomGenerator_rand_doublerR   s    r   r  z%SplitMix64RandomGenerator.rand_double$      DDTJJr#   c                 V    t        j                  | t        j                  |             y r-   )r   "SplitMix64RandomGenerator_swiginitnew_SplitMix64RandomGeneratorr  s     r   rN   z"SplitMix64RandomGenerator.__init__'  s    ::4AnAnosAtur#   c                 ,    t        j                  |       S r-   )r   SplitMix64RandomGenerator_nextrR   s    r   rk   zSplitMix64RandomGenerator.next*      ==dCCr#   Nr  )r   r   r6   r7   r   r   r   r   r   #SplitMix64RandomGenerator_state_get#SplitMix64RandomGenerator_state_setstater  r  r  r  rN   rk    delete_SplitMix64RandomGeneratorr   r$   r#   r   r  r    sg    
 -/IOdeGH_HH/J}J}~EJ
OJKvD&GGr#   r  c                 0    t        j                  | ||      S r-   )r   
float_randr>   rW   r  s      r   r  r  1      %%aD11r#   c                 0    t        j                  | ||      S r-   )r   float_randnr  s      r   r  r  4  s    &&q!T22r#   c                 0    t        j                  | ||      S r-   )r   
int64_randr  s      r   r  r  7  r  r#   c                 0    t        j                  | ||      S r-   )r   	byte_randr  s      r   r  r  :  s    $$Q400r#   c                 2    t        j                  | |||      S r-   )r   int64_rand_max)r>   rW   maxr  s       r   r  r  =  s    ))!QT::r#   c                 0    t        j                  | ||      S r-   )r   	rand_permpermrW   r  s      r   r  r  @  s    $$T1d33r#   c                 0    t        j                  | ||      S r-   )r   rand_perm_splitmix64r  s      r   r  r  C  s    //a>>r#   c                 2    t        j                  | |||      S r-   )r   rand_smooth_vectors)rW   r
  r>   r  s       r   r  r  F  s    ..q!Q==r#   c                 0    t        j                  | ||      S )a)  
     Indirect sort of a floating-point array

    :type n: int
    :param n:     size of the array
    :type vals: float
    :param vals:  array to sort, size n
    :type perm: int
    :param perm:  output: permutation of [0..n-1], st.
                     vals[perm[i + 1]] >= vals[perm[i]]
    )r   fvec_argsortrW   r  r  s      r   r  r  I  s     ''466r#   c                 0    t        j                  | ||      S )z"Same as fvec_argsort, parallelized)r   fvec_argsort_parallelr  s      r   r  r  W  s    00D$??r#   c                 6    t        j                  | |||||      S )a  
     Bucket sort of a list of values

    :type vals: int
    :param vals:     values to sort, size nval, max value nbucket - 1
    :type lims: int
    :param lims:     output limits of buckets, size nbucket + 1
    :type perm: int
    :param perm:     output buckets, the elements of bucket
                        i are in perm[lims[i]:lims[i + 1]]
    :type nt: int, optional
    :param nt:       number of threads (0 = pure sequential code)
    )r   bucket_sort)nvalr  nbucketlimsr  nts         r   r  r  [  s     &&tT7D$KKr#   c                  &    t        j                  |  S )a_  
    *Overload 1:*
     in-place bucket sort (with attention to memory=>int32)
    on input the values are in a nrow * col matrix
    we want to store the row numbers in the output.

    :type vals: int
    :param vals:     positive values to sort, size nrow * ncol,
                        max value nbucket - 1
    :type lims: int
    :param lims:     output limits of buckets, size nbucket + 1
    :type nt: int, optional
    :param nt:       number of threads (0 = pure sequential code)

    |

    *Overload 2:*
     same with int64 elements

    |

    *Overload 3:*
     same with int64 elements
    )r   matrix_bucket_sort_inplacerH  s    r   r  r  k  s    2 55t<<r#   c                 .    t        j                  | |      S )a  
     Hashtable implementation for int64 -> int64 with external storage
    implemented for fast batch add and lookup.

    tab is of size  2 * (1 << log2_capacity)
    n is the number of elements to add or search

    adding several values in a same batch: an arbitrary one gets added
    in different batches: the newer batch overwrites.
    raises an exception if capacity is exhausted.
    )r   hashtable_int64_to_int64_init)log2_capacitytabs     r   r  r    s     88LLr#   c                 4    t        j                  | ||||      S r-   )r   hashtable_int64_to_int64_addr  r  rW   keysr  s        r   r   r     s    77sAtUYZZr#   c                 4    t        j                  | ||||      S r-   )r   hashtable_int64_to_int64_lookupr  s        r   r  r    s    ::=#qRVX\]]r#   c                 ,    t        j                  |       S )z
    this function is used to distinguish between min and max indexes since
    we need to support similarity and dis-similarity metrics in a flexible way
    )r   is_similarity_metric)metric_types    r   r  r    s    
 //<<r#   c                 ,    t        j                  |       S r-   )r   get_numeric_type_size)numeric_types    r   r	  r	    s    00>>r#   c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zej                  Zd Zy)	SearchParametersz
     Parent class for the optional search paramenters.

    Sub-classes with additional search parameters should inherit this class.
    Ownership of the object fields is always to the caller.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSearchParameters.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSearchParameters.<lambda>  rD   r#   rE   rF   z=if non-null, only these IDs will be considered during search.c                 T    t        j                  | t        j                                y r-   )r   SearchParameters_swiginitnew_SearchParametersrR   s    r   rN   zSearchParameters.__init__      11$8\8\8^_r#   N)r   r   r6   r7   r   r   r   r   r   SearchParameters_sel_getSearchParameters_sel_setrS  delete_SearchParametersr   rN   r$   r#   r   r  r    sS     -/IOdeGH
?;;_=e=e  lp  qC&>>`r#   r  c                   b   e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Z ee	j&                  e	j(                  d
      Z ee	j,                  e	j.                  d      Z ee	j2                  e	j4                  d      Ze	j8                  Zd Zd Zd Z d Z!d Z"d Z#d'dZ$d'dZ%d'dZ&d(dZ'd Z(d Z)d Z*d Z+d Z,d'dZ-d Z.d Z/d  Z0d! Z1d" Z2d# Z3d)d$Z4d% Z5d& Z6y)*Indexz
     Abstract structure for an index, supports adding vectors and searching
    them.

    All vectors provided at add or search time are 32-bit float arrays,
    although the internal representation may vary.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndex.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndex.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndex.__init__  rO   r#   vector dimensiontotal nb of indexed vectorsverbosity levelzX
    set if the Index does not require training, or if training is
    done already
    )type of metric this index uses for searchzargument of the metric typec                 0    t        j                  | ||      S )z
         Perform training on a representative set of vectors

        :type n: int
        :param n:      nb of training vectors
        :type x: float
        :param x:      training vecors, size n * d
        )r   Index_trainr   rW   r>   s      r   trainzIndex.train  s     **4A66r#   c                 2    t        j                  | |||      S r-   )r   Index_trainExr   rW   r>   r
  s       r   trainExzIndex.trainEx  s    ,,T1aFFr#   c                 0    t        j                  | ||      S )a{  
         Add n vectors of dimension d to the index.

        Vectors are implicitly assigned labels ntotal .. ntotal + n - 1
        This function slices the input vectors in chunks smaller than
        blocksize_add and calls add_core.
        :type n: int
        :param n:      number of vectors
        :type x: float
        :param x:      input matrix, size n * d
        )r   	Index_addr!  s      r   addz	Index.add  s     ((q!44r#   c                 2    t        j                  | |||      S r-   )r   Index_addExr%  s       r   addExzIndex.addEx  s    **4A|DDr#   c                 2    t        j                  | |||      S )a  
         Same as add, but stores xids instead of sequential ids.

        The default implementation fails with an assertion, as it is
        not supported by all indexes.

        :type n: int
        :param n:         number of vectors
        :type x: float
        :param x:         input vectors, size n * d
        :type xids: int
        :param xids:      if non-null, ids to store for the vectors (size n)
        )r   Index_add_with_idsr   rW   r>   xidss       r   add_with_idszIndex.add_with_ids  s     11$1dCCr#   c                 4    t        j                  | ||||      S r-   )r   Index_add_with_idsExr   rW   r>   r
  r0  s        r   add_with_idsExzIndex.add_with_idsEx  s    33D!QdSSr#   Nc           	      8    t        j                  | ||||||      S )a\  
         query n vectors of dimension d to the index.

        return at most k vectors. If there are not enough results for a
        query, the result array is padded with -1s.

        :type n: int
        :param n:           number of vectors
        :type x: float
        :param x:           input vectors to search, size n * d
        :type k: int
        :param k:           number of extracted vectors
        :type distances: float
        :param distances:   output pairwise distances, size n*k
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        )r   Index_searchr   rW   r>   rP  rQ  rR  paramss          r   searchzIndex.search"  s!    $ ++D!Q9ffUUr#   c           
      :    t        j                  | |||||||      S r-   )r   Index_searchExr   rW   r>   r
  rP  rQ  rR  r9  s           r   searchExzIndex.searchEx6  s#    --dAq,9V\^deer#   c                 6    t        j                  | |||||      S )a  
         query n vectors of dimension d to the index.

        return all vectors with distance < radius. Note that many
        indexes do not implement the range_search (only the k-NN search
        is mandatory).

        :type n: int
        :param n:           number of vectors
        :type x: float
        :param x:           input vectors to search, size n * d
        :type radius: float
        :param radius:      search radius
        :type result: :py:class:`RangeSearchResult`
        :param result:      result table
        )r   Index_range_searchr   rW   r>   rV  rW  r9  s         r   range_searchzIndex.range_search9  s    " 11$1fffUUr#   c                 4    t        j                  | ||||      S )a  
         return the indexes of the k vectors closest to the query x.

        This function is identical as search but only return labels of
        neighbors.
        :type n: int
        :param n:           number of vectors
        :type x: float
        :param x:           input vectors to search, size n * d
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        :type k: int, optional
        :param k:           number of nearest neighbours
        )r   Index_assignr   rW   r>   rR  rP  s        r   assignzIndex.assignL  s     ++D!QBBr#   c                 ,    t        j                  |       S )z'removes all elements from the database.)r   Index_resetrR   s    r   r  zIndex.reset]  s    **400r#   c                 .    t        j                  | |      S )z|
         removes IDs from the index. Not supported by all
        indexes. Returns the number of elements removed.
        )r   Index_remove_idsr   rS  s     r   
remove_idszIndex.remove_idsa  s    
 //c::r#   c                 0    t        j                  | ||      S )a7  
         Reconstruct a stored vector (or an approximation if lossy coding)

        this function may not be defined for some indexes
        :type key: int
        :param key:         id of the vector to reconstruct
        :type recons: float
        :param recons:      reconstucted vector (size d)
        )r   Index_reconstructr   keyreconss      r   reconstructzIndex.reconstructh  s     00sFCCr#   c                 2    t        j                  | |||      S )a  
         Reconstruct several stored vectors (or an approximation if lossy
        coding)

        this function may not be defined for some indexes
        :type n: int
        :param n:           number of vectors to reconstruct
        :type keys: int
        :param keys:        ids of the vectors to reconstruct (size n)
        :type recons: float
        :param recons:      reconstucted vector (size n * d)
        )r   Index_reconstruct_batch)r   rW   r  rQ  s       r   reconstruct_batchzIndex.reconstruct_batcht  s     66tQfMMr#   c                 2    t        j                  | |||      S )a}  
         Reconstruct vectors i0 to i0 + ni - 1

        this function may not be defined for some indexes
        :type i0: int
        :param i0:          index of the first vector in the sequence
        :type ni: int
        :param ni:          number of vectors in the sequence
        :type recons: float
        :param recons:      reconstucted vector (size ni * d)
        )r   Index_reconstruct_nr   i0nirQ  s       r   reconstruct_nzIndex.reconstruct_n  s     224RHHr#   c           
      :    t        j                  | |||||||      S )a  
         Similar to search, but also reconstructs the stored vectors (or an
        approximation in the case of lossy coding) for the search results.

        If there are not enough results for a query, the resulting arrays
        is padded with -1s.

        :type n: int
        :param n:           number of vectors
        :type x: float
        :param x:           input vectors to search, size n * d
        :type k: int
        :param k:           number of extracted vectors
        :type distances: float
        :param distances:   output pairwise distances, size n*k
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        :type recons: float
        :param recons:      reconstructed vectors size (n, k, d)
        )r   Index_search_and_reconstructr   rW   r>   rP  rQ  rR  rQ  r9  s           r   search_and_reconstructzIndex.search_and_reconstruct  s&    * ;;D!Q9V\^dflmmr#   c                 2    t        j                  | |||      S )aK  
         Computes a residual vector after indexing encoding.

        The residual vector is the difference between a vector and the
        reconstruction that can be decoded from its representation in
        the index. The residual can be used for multiple-stage indexing
        methods, like IndexIVF's methods.

        :type x: float
        :param x:           input vector, size d
        :type residual: float
        :param residual:    output residual vector, size d
        :type key: int
        :param key:         encoded index, as returned by search and assign
        )r   Index_compute_residual)r   r>   residualrP  s       r   compute_residualzIndex.compute_residual  s      55dAxMMr#   c                 4    t        j                  | ||||      S )a  
         Computes a residual vector after indexing encoding (batch form).
        Equivalent to calling compute_residual for each vector.

        The residual vector is the difference between a vector and the
        reconstruction that can be decoded from its representation in
        the index. The residual can be used for multiple-stage indexing
        methods, like IndexIVF's methods.

        :type n: int
        :param n:           number of vectors
        :type xs: float
        :param xs:          input vectors, size (n x d)
        :type residuals: float
        :param residuals:   output residual vectors, size (n x d)
        :type keys: int
        :param keys:        encoded index, as returned by search and assign
        )r   Index_compute_residual_n)r   rW   xs	residualsr  s        r   compute_residual_nzIndex.compute_residual_n  s    & 77aYPTUUr#   c                 ,    t        j                  |       S )z
         Get a DistanceComputer (defined in AuxIndexStructures) object
        for this kind of index.

        DistanceComputer is implemented for indexes that support random
        access of their vectors.
        )r   Index_get_distance_computerrR   s    r   get_distance_computerzIndex.get_distance_computer  s     ::4@@r#   c                 ,    t        j                  |       S z#size of the produced codes in bytes)r   Index_sa_code_sizerR   s    r   sa_code_sizezIndex.sa_code_size  s    11$77r#   c                 2    t        j                  | |||      S )a  
         encode a set of vectors

        :type n: int
        :param n:       number of vectors
        :type x: float
        :param x:       input vectors, size n * d
        :type bytes: uint8_t
        :param bytes:   output encoded vectors, size n * sa_code_size()
        )r   Index_sa_encoder   rW   r>   r  s       r   	sa_encodezIndex.sa_encode  s     ..tQ5AAr#   c                 2    t        j                  | |||      S )a  
         decode a set of vectors

        :type n: int
        :param n:       number of vectors
        :type bytes: uint8_t
        :param bytes:   input encoded vectors, size n * sa_code_size()
        :type x: float
        :param x:       output vectors, size n * d
        )r   Index_sa_decoder   rW   r  r>   s       r   	sa_decodezIndex.sa_decode  s     ..tQqAAr#   c                 0    t        j                  | ||      S z
         moves the entries from another dataset to self.
        On output, other is empty.
        add_id is added to all moved ids
        (for sequential ids, this would be this->ntotal)
        )r   Index_merge_fromr   
otherIndexadd_ids      r   
merge_fromzIndex.merge_from  s     //j&IIr#   c                 .    t        j                  | |      S z
         check that the two indexes are compatible (ie, they are
        trained in the same way and have the same
        parameters). Otherwise throw.
        )r    Index_check_compatible_for_merger   r|  s     r   check_compatible_for_mergez Index.check_compatible_for_merge 	  s     ??jQQr#   c                 2    t        j                  | |||      S z
         Add vectors that are computed with the standalone codec

        :type codes: uint8_t
        :param codes:  codes to add size n * sa_code_size()
        :type xids: int
        :param xids:   corresponding ids, size n
        )r   Index_add_sa_codesr   rW   r  r0  s       r   add_sa_codeszIndex.add_sa_codes	  s     11$5$GGr#   r-   r   r   )7r   r   r6   r7   r   r   rN   r   r   r   Index_d_getIndex_d_setr
  Index_ntotal_getIndex_ntotal_setntotalIndex_verbose_getIndex_verbose_setr  Index_is_trained_getIndex_is_trained_set
is_trainedIndex_metric_type_getIndex_metric_type_setr  Index_metric_arg_getIndex_metric_arg_set
metric_argdelete_Indexr   r"  r&  r)  r,  r1  r5  r:  r>  rB  rF  r  rL  rR  rU  r[  r_  rc  rh  rk  ro  rs  rw  r~  r  r  r$   r#   r   r  r    s    -/IOdeGKH,,o.I.IOfgAo668X8X  _A  BF88/:[:[awxG/>>@d@d k 	J ?@@/BgBg  n^  _K/>>@d@d  kM  NJ&33	7G5ED TV(fV&C"1;
DNIn.N$V*A8BBJR	Hr#   r  c                   `    e Zd Z ed d d      Zd ZeZd Zd Z	d Z
d	 Zej                  Zy
)DistanceComputerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zDistanceComputer.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zDistanceComputer.<lambda>	  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zDistanceComputer.__init__	  rO   r#   c                 .    t        j                  | |      S )zv
        called before computing distances. Pointer x should remain valid
        while operator () is called
        )r   DistanceComputer_set_queryr_   s     r   	set_queryzDistanceComputer.set_query	  s    
 99$BBr#   c                 .    t        j                  | |      S z-compute distance of vector i to current query)r   DistanceComputer___call__r   r-  s     r   __call__zDistanceComputer.__call__#	  s    88qAAr#   c	                 <    t        j                  | ||||||||	      S )z
        compute distances of current query to 4 stored vectors.
        certain DistanceComputer implementations may benefit
        heavily from this.
        )r   "DistanceComputer_distances_batch_4	r   idx0idx1idx2idx3rI  rJ  rK  rL  s	            r   distances_batch_4z"DistanceComputer.distances_batch_4'	  s+     AA$dTXZ^`dfjlprvwwr#   c                 0    t        j                  | ||      S z+compute distance between two stored vectors)r   DistanceComputer_symmetric_disr   r-  js      r   symmetric_diszDistanceComputer.symmetric_dis/	      ==dAqIIr#   N)r   r   r6   r   r   rN   r   r   r  r  r  r  r   delete_DistanceComputerr   r$   r#   r   r  r  	  sD    -/IOdeGKHCBxJ '>>r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
d Zd Zd Zd	 Zd
 Zej                   Zy)NegativeDistanceComputerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!NegativeDistanceComputer.<lambda>7	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!NegativeDistanceComputer.<lambda>7	  rD   r#   rE   rF   zowned by thisc                 V    t        j                  | t        j                  |             y r-   )r   !NegativeDistanceComputer_swiginitnew_NegativeDistanceComputer)r   basediss     r   rN   z!NegativeDistanceComputer.__init__;	  s    99$@l@lmt@uvr#   c                 .    t        j                  | |      S r-   )r   "NegativeDistanceComputer_set_queryr_   s     r   r  z"NegativeDistanceComputer.set_query>	  r  r#   c                 .    t        j                  | |      S r  )r   !NegativeDistanceComputer___call__r  s     r   r  z!NegativeDistanceComputer.__call__A	  s    @@qIIr#   c	                 <    t        j                  | ||||||||	      S r-   )r   *NegativeDistanceComputer_distances_batch_4r  s	            r   r  z*NegativeDistanceComputer.distances_batch_4E	  s+    II$PTVZ\`bfhlnrtxz~r#   c                 0    t        j                  | ||      S r  )r   &NegativeDistanceComputer_symmetric_disr  s      r   r  z&NegativeDistanceComputer.symmetric_disH	  s    EEdAqQQr#   N)r   r   r6   r   r   r   r   r   $NegativeDistanceComputer_basedis_get$NegativeDistanceComputer_basedis_setr  rN   r  r  r  r  delete_NegativeDistanceComputerr   r$   r#   r   r  r  6	  sn    -/IOdeGHKK_  NB  NB  H\  ]GwKJ@R 'FFr#   r  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	FlatCodesDistanceComputerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"FlatCodesDistanceComputer.<lambda>P	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"FlatCodesDistanceComputer.<lambda>P	  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   z"FlatCodesDistanceComputer.__init__R	  rO   r#   c                 .    t        j                  | |      S r-   )r   "FlatCodesDistanceComputer___call__r  s     r   r  z"FlatCodesDistanceComputer.__call__X	  r  r#   c                 .    t        j                  | |      S )z6compute distance of current query to an encoded vector)r   *FlatCodesDistanceComputer_distance_to_coder   r   s     r   distance_to_codez*FlatCodesDistanceComputer.distance_to_code[	      II$PTUUr#   N)r   r   r6   r   r   rN   r   r   r   #FlatCodesDistanceComputer_codes_get#FlatCodesDistanceComputer_codes_setr  'FlatCodesDistanceComputer_code_size_get'FlatCodesDistanceComputer_code_size_setr!  r  r   delete_FlatCodesDistanceComputerr   r$   r#   r   r  r  O	  st    -/IOdeGKH_HH/J}J}~EPPRa  SJ  SJ  KIKV 'GGr#   r  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                        Zd Zd Zej                  Zy)	IOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIOReader.<lambda>c	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIOReader.<lambda>c	  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIOReader.__init__e	  rO   r#   c                 2    t        j                  | |||      S r-   )r   IOReader___call__r   ptrr   nitemss       r   r  zIOReader.__call__j	      00sD&IIr#   c                 ,    t        j                  |       S r-   )r   IOReader_filedescriptorrR   s    r   filedescriptorzIOReader.filedescriptorm	  ro   r#   N)r   r   r6   r   r   rN   r   r   r   IOReader_name_getIOReader_name_setr   r  r  delete_IOReaderr   r$   r#   r   r  r  b	  M    -/IOdeGKHO557X7XYDJ=&66r#   r  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                        Zd Zd Zej                  Zy)	IOWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIOWriter.<lambda>t	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIOWriter.<lambda>t	  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIOWriter.__init__v	  rO   r#   c                 2    t        j                  | |||      S r-   )r   IOWriter___call__r  s       r   r  zIOWriter.__call__{	  r  r#   c                 ,    t        j                  |       S r-   )r   IOWriter_filedescriptorrR   s    r   r  zIOWriter.filedescriptor~	  ro   r#   N)r   r   r6   r   r   rN   r   r   r   IOWriter_name_getIOWriter_name_setr   r  r  delete_IOWriterr   r$   r#   r   r  r  s	  r  r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zej                   Zy)VectorIOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVectorIOReader.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVectorIOReader.<lambda>	  rD   r#   rE   rF   c                 2    t        j                  | |||      S r-   )r   VectorIOReader___call__r  s       r   r  zVectorIOReader.__call__	      66tS$OOr#   c                 T    t        j                  | t        j                                y r-   )r   VectorIOReader_swiginitnew_VectorIOReaderrR   s    r   rN   zVectorIOReader.__init__	  r  r#   N)r   r   r6   r   r   r   r   r   VectorIOReader_data_getVectorIOReader_data_setr   VectorIOReader_rp_getVectorIOReader_rp_setrpr  rN   delete_VectorIOReaderr   r$   r#   r   r  r  	  s`    -/IOdeGHO;;_=d=deD	/779^9^	_BP\&<<r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)VectorIOWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVectorIOWriter.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVectorIOWriter.<lambda>	  rD   r#   rE   rF   c                 2    t        j                  | |||      S r-   )r   VectorIOWriter___call__r  s       r   r  zVectorIOWriter.__call__	  r  r#   c                 T    t        j                  | t        j                                y r-   )r   VectorIOWriter_swiginitnew_VectorIOWriterrR   s    r   rN   zVectorIOWriter.__init__	  r  r#   N)r   r   r6   r   r   r   r   r   VectorIOWriter_data_getVectorIOWriter_data_setr   r  rN   delete_VectorIOWriterr   r$   r#   r   r
  r
  	  sH    -/IOdeGHO;;_=d=deDP\&<<r#   r
  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zej                  Zd Zd Zy)	FileIOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFileIOReader.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFileIOReader.<lambda>	  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   FileIOReader_swiginitnew_FileIOReaderr   s     r   rN   zFileIOReader.__init__	      --dO4T4TVZ4[\r#   c                 2    t        j                  | |||      S r-   )r   FileIOReader___call__r  s       r   r  zFileIOReader.__call__	      44T3fMMr#   c                 ,    t        j                  |       S r-   )r   FileIOReader_filedescriptorrR   s    r   r  zFileIOReader.filedescriptor	  r  r#   N)r   r   r6   r   r   r   r   r   FileIOReader_f_getFileIOReader_f_setfFileIOReader_need_close_getFileIOReader_need_close_set
need_closerN   delete_FileIOReaderr   r  r  r$   r#   r   r  r  	  f    -/IOdeGH33_5W5WXA/EEGrGrsJ]&::NAr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zej                  Zd Zd Zy)	FileIOWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFileIOWriter.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFileIOWriter.<lambda>	  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   FileIOWriter_swiginitnew_FileIOWriterr   s     r   rN   zFileIOWriter.__init__	  r  r#   c                 2    t        j                  | |||      S r-   )r   FileIOWriter___call__r  s       r   r  zFileIOWriter.__call__	  r  r#   c                 ,    t        j                  |       S r-   )r   FileIOWriter_filedescriptorrR   s    r   r  zFileIOWriter.filedescriptor	  r  r#   N)r   r   r6   r   r   r   r   r   FileIOWriter_f_getFileIOWriter_f_setr$  FileIOWriter_need_close_getFileIOWriter_need_close_setr'  rN   delete_FileIOWriterr   r  r  r$   r#   r   r+  r+  	  r)  r#   r+  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                   d      Z eej$                  ej&                  d      Z eej*                  ej,                  d      Z eej0                  ej2                        Z eej6                  ej8                        Zd	 Zd
 Zej@                  Z!y)BufferedIOReaderzAwraps an ioreader to make buffered reads to avoid too small readsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBufferedIOReader.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBufferedIOReader.<lambda>	  rD   r#   rE   rF   zoffset in input streamz"number of bytes returned to callerz&range of available bytes in the bufferc                 P    t        j                  | t        j                  |        y)z
        :type bsz: int, optional
        :param bsz:    buffer size (bytes). Reads will be done by batched of
                          this size
        N)r   BufferedIOReader_swiginitnew_BufferedIOReaderr   s     r   rN   zBufferedIOReader.__init__	  s      	11$8\8\^b8cdr#   c                 2    t        j                  | |||      S r-   )r   BufferedIOReader___call__r  s       r   r  zBufferedIOReader.__call__	      88sD&QQr#   N)"r   r   r6   r7   r   r   r   r   r   BufferedIOReader_reader_getBufferedIOReader_reader_setreaderBufferedIOReader_bsz_getBufferedIOReader_bsz_setbszBufferedIOReader_ofs_getBufferedIOReader_ofs_setofsBufferedIOReader_ofs2_getBufferedIOReader_ofs2_setofs2BufferedIOReader_b0_getBufferedIOReader_b0_setb0BufferedIOReader_b1_getBufferedIOReader_b1_setb1BufferedIOReader_buffer_getBufferedIOReader_buffer_setbufferrN   r  delete_BufferedIOReaderr   r$   r#   r   r;  r;  	  s    L-/IOdeGHoAA?CnCnoF
?;;_=e=e
fC
?;;_=e=e  lI  JCO==?h?h  oX  YD	/99?;b;b  iV  
WB	/99?;b;b	cBoAA?CnCnoFeR&>>r#   r;  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                  d      Z eej(                  ej*                  d      Z eej.                  ej0                        Zd Zd Zej8                  Zy	)
BufferedIOWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBufferedIOWriter.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBufferedIOWriter.<lambda>	  rD   r#   rE   rF   z$number of bytes received from callerzamount of data in bufferc                 P    t        j                  | t        j                  |        y r-   )r   BufferedIOWriter_swiginitnew_BufferedIOWriterr   s     r   rN   zBufferedIOWriter.__init__	      11$8\8\^b8cdr#   c                 2    t        j                  | |||      S r-   )r   BufferedIOWriter___call__r  s       r   r  zBufferedIOWriter.__call__	  rC  r#   N)r   r   r6   r   r   r   r   r   BufferedIOWriter_writer_getBufferedIOWriter_writer_setwriterBufferedIOWriter_bsz_getBufferedIOWriter_bsz_setrI  BufferedIOWriter_ofs_getBufferedIOWriter_ofs_setrL  BufferedIOWriter_ofs2_getBufferedIOWriter_ofs2_setrO  BufferedIOWriter_b0_getBufferedIOWriter_b0_setrR  BufferedIOWriter_buffer_getBufferedIOWriter_buffer_setrX  rN   r  delete_BufferedIOWriterr   r$   r#   r   r[  r[  	  s    -/IOdeGHoAA?CnCnoF
?;;_=e=e
fC
?;;_=e=e
fCO==?h?h  oZ  [D	/99?;b;b  iH  
IBoAA?CnCnoFeR&>>r#   r[  c                  &    t        j                  |  S )zKcast a 4-character string to a uint32_t that can be written and read easily)r   fourccrH  s    r   rs  rs  	  s    !!4((r#   c                  &    t        j                  |  S r-   )r   
fourcc_invrH  s    r   ru  ru  	      %%t,,r#   c                 ,    t        j                  |       S r-   )r   fourcc_inv_printabler=   s    r   rx  rx  	  s    //22r#   c                   H    e Zd Z ed d d      ZeZej                  Z	d Z
y)MaybeOwnedVectorOwnerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMaybeOwnedVectorOwner.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMaybeOwnedVectorOwner.<lambda>	  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   MaybeOwnedVectorOwner_swiginitnew_MaybeOwnedVectorOwnerrR   s    r   rN   zMaybeOwnedVectorOwner.__init__
  r  r#   N)r   r   r6   r   r   r   r   r   delete_MaybeOwnedVectorOwnerr   rN   r$   r#   r   rz  rz  	  s*    -/IOdeGH&CCjr#   rz  c                   T    e Zd Z ed d d      ZeZd Zej                  Z
d Zd Zy)	MmappedFileMappingOwnerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z MmappedFileMappingOwner.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z MmappedFileMappingOwner.<lambda>
  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r    MmappedFileMappingOwner_swiginitnew_MmappedFileMappingOwnerr   s     r   rN   z MmappedFileMappingOwner.__init__
      88?j?jlp?qrr#   c                 ,    t        j                  |       S r-   )r   MmappedFileMappingOwner_datarR   s    r   r   zMmappedFileMappingOwner.data
  r7  r#   c                 ,    t        j                  |       S r-   )r   MmappedFileMappingOwner_sizerR   s    r   r   zMmappedFileMappingOwner.size
  r7  r#   N)r   r   r6   r   r   r   r   rN   r   delete_MmappedFileMappingOwnerr   r   r   r$   r#   r   r  r  
  s6    -/IOdeGHs&EEBBr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zd Zd Zej$                  Zy	)
MappedFileIOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMappedFileIOReader.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMappedFileIOReader.<lambda>
  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   MappedFileIOReader_swiginitnew_MappedFileIOReader)r   owners     r   rN   zMappedFileIOReader.__init__
  s    33D/:`:`af:ghr#   c                 2    t        j                  | |||      S r-   )r   MappedFileIOReader___call__r  s       r   r  zMappedFileIOReader.__call__ 
  s    ::4dFSSr#   c                 2    t        j                  | |||      S r-   )r   MappedFileIOReader_mmapr  s       r   mmapzMappedFileIOReader.mmap#
  r  r#   c                 ,    t        j                  |       S r-   )r   !MappedFileIOReader_filedescriptorrR   s    r   r  z!MappedFileIOReader.filedescriptor&
  r  r#   N)r   r   r6   r   r   r   r   r   !MappedFileIOReader_mmap_owner_get!MappedFileIOReader_mmap_owner_set
mmap_ownerMappedFileIOReader_pos_getMappedFileIOReader_pos_setposrN   r  r  r  delete_MappedFileIOReaderr   r$   r#   r   r  r  
  sl    -/IOdeGH/KK_M~M~J
?==?i?i
jCiTPG&@@r#   r  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zej$                  Zd Zd Zd Zd	 Zy
)ZeroCopyIOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zZeroCopyIOReader.<lambda>-
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zZeroCopyIOReader.<lambda>-
  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   ZeroCopyIOReader_swiginitnew_ZeroCopyIOReader)r   r   r   s      r   rN   zZeroCopyIOReader.__init__3
  s!    11$8\8\]acg8hir#   c                 ,    t        j                  |       S r-   )r   ZeroCopyIOReader_resetrR   s    r   r  zZeroCopyIOReader.reset7
  r  r#   c                 2    t        j                  | |||      S r-   )r   ZeroCopyIOReader_get_data_viewr  s       r   get_data_viewzZeroCopyIOReader.get_data_view:
  s    ==dCvVVr#   c                 2    t        j                  | |||      S r-   )r   ZeroCopyIOReader___call__r  s       r   r  zZeroCopyIOReader.__call__=
  rC  r#   c                 ,    t        j                  |       S r-   )r   ZeroCopyIOReader_filedescriptorrR   s    r   r  zZeroCopyIOReader.filedescriptor@
      >>tDDr#   N)r   r   r6   r   r   r   r   r   ZeroCopyIOReader_data__getZeroCopyIOReader_data__setdata_ZeroCopyIOReader_rp__getZeroCopyIOReader_rp__setrp_ZeroCopyIOReader_total__getZeroCopyIOReader_total__settotal_rN   delete_ZeroCopyIOReaderr   r  r  r  r  r$   r#   r   r  r  ,
  s    -/IOdeGH_??AkAklE
?;;_=e=e
fCoAA?CnCnoFj&>><WREr#   r  c                   $   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZddZddZd Zd ZddZd Zd Zej>                  Z y)IndexFlatCodeszr
     Index that encodes all vectors as fixed-size codes (size code_size). Storage
    is in the codes vector
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFlatCodes.<lambda>K
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFlatCodes.<lambda>K
  rD   r#   rE   rF   z(encoded dataset, size ntotal * code_sizec                 P    t        j                  | t        j                  |        y r-   )r   IndexFlatCodes_swiginitnew_IndexFlatCodesr   s     r   rN   zIndexFlatCodes.__init__P
      //o6X6XZ^6_`r#   c                 0    t        j                  | ||      S )zdefault add uses sa_encode)r   IndexFlatCodes_addr!  s      r   r)  zIndexFlatCodes.addS
  s    11$1==r#   c                 ,    t        j                  |       S r-   )r   IndexFlatCodes_resetrR   s    r   r  zIndexFlatCodes.resetW
  rS   r#   c                 2    t        j                  | |||      S r-   )r   IndexFlatCodes_reconstruct_nrX  s       r   r[  zIndexFlatCodes.reconstruct_nZ
  s    ;;D"b&QQr#   c                 0    t        j                  | ||      S r-   )r   IndexFlatCodes_reconstructrO  s      r   rR  zIndexFlatCodes.reconstruct]
      99$VLLr#   c                 ,    t        j                  |       S r-   )r   IndexFlatCodes_sa_code_sizerR   s    r   ro  zIndexFlatCodes.sa_code_size`
  r  r#   c                 .    t        j                  | |      S )z
         remove some ids. NB that because of the structure of the
        index, the semantics of this operation are
        different from the usual ones: the new ids are shifted
        )r   IndexFlatCodes_remove_idsrK  s     r   rL  zIndexFlatCodes.remove_idsc
  s     88sCCr#   c                 ,    t        j                  |       S )z
         a FlatCodesDistanceComputer offers a distance_to_code method

        The default implementation explicitly decodes the vector with sa_decode.
        )r   ,IndexFlatCodes_get_FlatCodesDistanceComputerrR   s    r   get_FlatCodesDistanceComputerz,IndexFlatCodes.get_FlatCodesDistanceComputerk
  s     KKDQQr#   c                 ,    t        j                  |       S r-   )r   $IndexFlatCodes_get_distance_computerrR   s    r   rk  z$IndexFlatCodes.get_distance_computers
  rf  r#   Nc           	      8    t        j                  | ||||||      S )zSearch implemented by decoding)r   IndexFlatCodes_searchr8  s          r   r:  zIndexFlatCodes.searchv
       44T1aIvW]^^r#   c                 6    t        j                  | |||||      S r-   )r   IndexFlatCodes_range_searchrA  s         r   rB  zIndexFlatCodes.range_searchz
      ::4AvvW]^^r#   c                 ,    t        j                  |       S r-   )r   IndexFlatCodes_get_CodePackerrR   s    r   get_CodePackerzIndexFlatCodes.get_CodePacker}
      <<TBBr#   c                 .    t        j                  | |      S r-   )r   )IndexFlatCodes_check_compatible_for_merger  s     r   r  z)IndexFlatCodes.check_compatible_for_merge
      HHzZZr#   c                 0    t        j                  | ||      S r-   )r   IndexFlatCodes_merge_fromr{  s      r   r~  zIndexFlatCodes.merge_from
  s    88z6RRr#   c                 2    t        j                  | |||      S r-   )r   IndexFlatCodes_add_sa_codesr/  s       r   r  zIndexFlatCodes.add_sa_codes
      ::4AtLLr#   c                 .    t        j                  | |      S r-   )r   IndexFlatCodes_permute_entriesr   r  s     r   permute_entrieszIndexFlatCodes.permute_entries
  r  r#   r-   r  )!r   r   r6   r7   r   r   r   r   r   IndexFlatCodes_code_size_getIndexFlatCodes_code_size_setr!  IndexFlatCodes_codes_getIndexFlatCodes_codes_setr  rN   r)  r  r[  rR  ro  rL  r  rk  r:  rB  r  r  r~  r  r  delete_IndexFlatCodesr   r$   r#   r   r  r  E
  s    
 -/IOdeGHEEGsGstI_==?g?g  n]  ^Ea>:RMADRJ__C[SMJ&<<r#   r  c                       e Zd ZdZ ed d d      ZeZddZddZ	d	 Z
d
 Zd Zd Zd Zd Zd Zej$                  Zy)	IndexFlatzAIndex that stores the full vectors and performs exhaustive searchc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFlat.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFlat.<lambda>
  rD   r#   rE   rF   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexFlat_searchr8  s          r   r:  zIndexFlat.search
  s     //aAy&RXYYr#   c                 6    t        j                  | |||||      S r-   )r   IndexFlat_range_searchrA  s         r   rB  zIndexFlat.range_search
      55dAq&&RXYYr#   c                 0    t        j                  | ||      S r-   )r   IndexFlat_reconstructrO  s      r   rR  zIndexFlat.reconstruct
      44T3GGr#   c                 6    t        j                  | |||||      S )a  
         compute distance with a subset of vectors

        :type x: float
        :param x:       query vectors, size n * d
        :type labels: int
        :param labels:  indices of the vectors that should be compared
                           for each query vector, size n * k
        :type distances: float
        :param distances:
                           corresponding output distances, size n * k
        )r   !IndexFlat_compute_distance_subset)r   rW   r>   rP  rQ  rR  s         r   compute_distance_subsetz!IndexFlat.compute_distance_subset
  s!     @@q!QPY[abbr#   c                 .    t        j                  | g| S r-   )r   IndexFlat_get_xbr   s     r   get_xbzIndexFlat.get_xb
      //<t<<r#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexFlat_swiginitnew_IndexFlatr   s     r   rN   zIndexFlat.__init__
      **41N1NPT1UVr#   c                 ,    t        j                  |       S r-   )r   'IndexFlat_get_FlatCodesDistanceComputerrR   s    r   r  z'IndexFlat.get_FlatCodesDistanceComputer
      FFtLLr#   c                 2    t        j                  | |||      S r-   )r   IndexFlat_sa_encoderr  s       r   rs  zIndexFlat.sa_encode
  s    224AuEEr#   c                 2    t        j                  | |||      S r-   )r   IndexFlat_sa_decoderv  s       r   rw  zIndexFlat.sa_decode
  s    224E1EEr#   r-   )r   r   r6   r7   r   r   r   r   r:  rB  rR  r  r  rN   r  rs  rw  r   delete_IndexFlatr   r$   r#   r   r  r  
  s\    L-/IOdeGHZZHc=WMFF&77r#   r  c                   H    e Zd Z ed d d      ZeZd Zej                  Z
y)IndexFlatIPc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFlatIP.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFlatIP.<lambda>
  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexFlatIP_swiginitnew_IndexFlatIPr   s     r   rN   zIndexFlatIP.__init__
      ,,T?3R3RTX3YZr#   N)r   r   r6   r   r   r   r   rN   r   delete_IndexFlatIPr   r$   r#   r   r  r  
  s*    -/IOdeGH[&99r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zd Zd Zej                  Zy	)
IndexFlatL2c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFlatL2.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFlatL2.<lambda>
  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)zT
        :type d: int
        :param d: dimensionality of the input vectors
        N)r   IndexFlatL2_swiginitnew_IndexFlatL2r   s     r   rN   zIndexFlatL2.__init__
  s     
 	,,T?3R3RTX3YZr#   c                 ,    t        j                  |       S r-   )r   )IndexFlatL2_get_FlatCodesDistanceComputerrR   s    r   r  z)IndexFlatL2.get_FlatCodesDistanceComputer
      HHNNr#   c                 ,    t        j                  |       S r-   )r   IndexFlatL2_sync_l2normsrR   s    r   sync_l2normszIndexFlatL2.sync_l2norms
  r  r#   c                 ,    t        j                  |       S r-   )r   IndexFlatL2_clear_l2normsrR   s    r   clear_l2normszIndexFlatL2.clear_l2norms
  r  r#   N)r   r   r6   r   r   r   r   r   IndexFlatL2_cached_l2norms_getIndexFlatL2_cached_l2norms_setcached_l2normsrN   r  r(  r+  delete_IndexFlatL2r   r$   r#   r   r  r  
  sR    -/IOdeGHoLLoN|N|}N[O>?&99r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      ZddZd	 Zd
 Zd ZddZej(                  Zy)IndexFlat1Dz#optimized version for 1D "vectors".c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFlat1D.<lambda>
  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFlat1D.<lambda>
  rD   r#   rE   rF   z(is the permutation updated continuously?zsorted database indicesc                 V    t        j                  | t        j                  |             y r-   )r   IndexFlat1D_swiginitnew_IndexFlat1D)r   continuous_updates     r   rN   zIndexFlat1D.__init__
  s    ,,T?3R3RSd3efr#   c                 ,    t        j                  |       S )zg
        if not continuous_update, call this between the last add and
        the first search
        )r   IndexFlat1D_update_permutationrR   s    r   update_permutationzIndexFlat1D.update_permutation
      
 ==dCCr#   c                 0    t        j                  | ||      S r-   )r   IndexFlat1D_addr!  s      r   r)  zIndexFlat1D.add
      ..tQ::r#   c                 ,    t        j                  |       S r-   )r   IndexFlat1D_resetrR   s    r   r  zIndexFlat1D.reset
  r   r#   Nc           	      8    t        j                  | ||||||      S )z*Warn: the distances returned are L1 not L2)r   IndexFlat1D_searchr8  s          r   r:  zIndexFlat1D.search
       11$1aFTZ[[r#   Tr-   )r   r   r6   r7   r   r   r   r   r   !IndexFlat1D_continuous_update_get!IndexFlat1D_continuous_update_setr7  IndexFlat1D_perm_getIndexFlat1D_perm_setr  rN   r:  r)  r  r:  delete_IndexFlat1Dr   r$   r#   r   r1  r1  
  s    .-/IOdeGH !R!RTc  UF  UF  L{  |O88/:^:^  eC  DDgD;7\ '99r#   r1  c                   n   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                  d	      Z eej0                  ej2                  d
      Z eej6                  ej8                  d      Z eej<                  ej>                  d      Z  eejB                  ejD                  d      Z# eejH                  ejJ                  d      Z& eejN                  ejP                  d      Z) eejT                  ejV                  d      Z, eejZ                  ej\                  d      Z/d Z0ejb                  Z2y)ClusteringParameterszn
     Class for the clustering parameters. Can be passed to the
    constructor of the Clustering object.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zClusteringParameters.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zClusteringParameters.<lambda>  rD   r#   rE   rF   znumber of clustering iterationsz[
    redo clustering this many times and keep the clusters with the best
    objective
    zg
    whether to normalize centroids after each iteration (useful for inner
    product clustering)
    z<round centroids coordinates to integer after each iteration?z$re-train index after each iteration?zd
    Use the subset of centroids provided as input and do not change them
    during iterations
    z
    If fewer than this number of training vectors per centroid are provided,
    writes a warning. Note that fewer than 1 point per centroid raises an
    exception.
    zBto limit size of dataset, otherwise the training set is subsampledz
    seed for the random number generator.
    negative values lead to seeding an internal rng with
    std::high_resolution_clock.
    zAwhen the training set is encoded, batch size of the codec decoderz*whether to check for NaNs in an input dataz
    Whether to use splitmix64-based random number generator for subsampling,
    which is faster, but may pick duplicate points.
    c                 T    t        j                  | t        j                                y r-   )r   ClusteringParameters_swiginitnew_ClusteringParametersrR   s    r   rN   zClusteringParameters.__init__*  r  r#   N)3r   r   r6   r7   r   r   r   r   r   ClusteringParameters_niter_getClusteringParameters_niter_setniterClusteringParameters_nredo_getClusteringParameters_nredo_setnredo ClusteringParameters_verbose_get ClusteringParameters_verbose_setr  "ClusteringParameters_spherical_get"ClusteringParameters_spherical_set	spherical&ClusteringParameters_int_centroids_get&ClusteringParameters_int_centroids_setint_centroids%ClusteringParameters_update_index_get%ClusteringParameters_update_index_setupdate_index)ClusteringParameters_frozen_centroids_get)ClusteringParameters_frozen_centroids_setfrozen_centroids0ClusteringParameters_min_points_per_centroid_get0ClusteringParameters_min_points_per_centroid_setmin_points_per_centroid0ClusteringParameters_max_points_per_centroid_get0ClusteringParameters_max_points_per_centroid_setmax_points_per_centroidClusteringParameters_seed_getClusteringParameters_seed_setr  *ClusteringParameters_decode_block_size_get*ClusteringParameters_decode_block_size_setdecode_block_size2ClusteringParameters_check_input_data_for_NaNs_get2ClusteringParameters_check_input_data_for_NaNs_setcheck_input_data_for_NaNs/ClusteringParameters_use_faster_subsampling_get/ClusteringParameters_use_faster_subsampling_setuse_faster_subsamplingrN   delete_ClusteringParametersr   r$   r#   r   rK  rK     s-   
 -/IOdeGH_CC_EsEs  z`  aE_CC_EsEs z 	E GGIyIyzGKK_MM F 	I _SSUd  VL  VL  RU  VMOQQSb  TI  TI  Oz  {L Y Y[j  \U  \U [ 	 ''g'gix  jj  jj p 	
 ''g'gix  jj  jj  py  zOAA?CpCp w 	D
 !![![]l  ^X  ^X  ^f  g ()k)km|  np  np  vg  !h%o&e&egv  hg  hg m 	
h&BBr#   rK  c                   ~   e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Z eej                  ej                  d      Z eej"                  ej$                  d      Z eej(                  ej*                  d	      Zd
 Zej0                  Zy)ClusteringIterationStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!ClusteringIterationStats.<lambda>1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!ClusteringIterationStats.<lambda>1  rD   r#   rE   rF   z5objective values (sum of distances reported by index)zseconds for iterationzseconds for just searchzimbalance factor of iterationznumber of cluster splitsc                 T    t        j                  | t        j                                y r-   )r   !ClusteringIterationStats_swiginitnew_ClusteringIterationStatsrR   s    r   rN   z!ClusteringIterationStats.__init__9  s    99$@l@l@nor#   N)r   r   r6   r   r   r   r   r    ClusteringIterationStats_obj_get ClusteringIterationStats_obj_setobj!ClusteringIterationStats_time_get!ClusteringIterationStats_time_settime(ClusteringIterationStats_time_search_get(ClusteringIterationStats_time_search_settime_search-ClusteringIterationStats_imbalance_factor_get-ClusteringIterationStats_imbalance_factor_setr  #ClusteringIterationStats_nsplit_get#ClusteringIterationStats_nsplit_setnsplitrN   delete_ClusteringIterationStatsr   r$   r#   r   rx  rx  0  s    -/IOdeGH
?CC_EuEu  |x  yCOEEGxGx  [  \D?SSUd  VN  VN  Tr  sK ] ]_n  `]  `]  cG  HoII?K~K~  Ed  eFp&FFr#   rx  c                   Z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 ZddZddZd Zej2                  Zy)
Clusteringa  
     K-means clustering based on assignment - centroid update iterations

    The clustering is based on an Index object that assigns training
    points to the centroids. Therefore, at each iteration the centroids
    are added to the index.

    On output, the centoids table is set to the latest version
    of the centroids and they are also added to the index. If the
    centroids table it is not empty on input, it is also used for
    initialization.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zClustering.<lambda>M  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zClustering.<lambda>M  rD   r#   rE   rF   dimension of the vectorsnb of centroidszp
     centroids (k * d)
    if centroids are set on input to train, they will be used as
    initialization
    &stats at every iteration of clusteringc                 P    t        j                  | t        j                  |        y r-   )r   Clustering_swiginitnew_Clusteringr   s     r   rN   zClustering.__init__X      ++D/2P2PRV2WXr#   Nc                 4    t        j                  | ||||      S )aH  
         run k-means training

        :type x: float
        :param x:          training vectors, size n * d
        :type index: :py:class:`Index`
        :param index:      index used for assignment
        :type x_weights: float, optional
        :param x_weights:  weight associated to each vector: NULL or size n
        )r   Clustering_train)r   rW   r>   index	x_weightss        r   r"  zClustering.train[  s     //aE9MMr#   c                 6    t        j                  | |||||      S )aB  
         run with encoded vectors

        win addition to train()'s parameters takes a codec as parameter
        to decode the input vectors.

        :type codec: :py:class:`Index`
        :param codec:      codec used to decode the vectors (nullptr =
                              vectors are in fact floats)
        )r   Clustering_train_encoded)r   rk  r  codecr  weightss         r   train_encodedzClustering.train_encodedh  s      77b$uV]^^r#   c                 ,    t        j                  |       S )z
        Post-process the centroids after each centroid update.
        includes optional L2 normalization and nearest integer rounding
        )r   !Clustering_post_process_centroidsrR   s    r   post_process_centroidsz!Clustering.post_process_centroidsu  s    
 @@FFr#   r-   )r   r   r6   r7   r   r   r   r   r   Clustering_d_getClustering_d_setr
  Clustering_k_getClustering_k_setrP  Clustering_centroids_getClustering_centroids_setr  Clustering_iteration_stats_getClustering_iteration_stats_setiteration_statsrN   r"  r  r  delete_Clusteringr   r$   r#   r   r  r  ?  s     -/IOdeGH11?3S3SYxyA11?3S3SYopAAA?CkCk r 	I
 MMO}O}  Dq  rOYN_G '88r#   r  c                   R    e Zd ZdZ ed d d      ZeZd Zd Z	e
j                  Zy)	Clustering1Dzw
     Exact 1D clustering algorithm

    Since it does not use an index, it does not overload the train() function
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zClustering1D.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zClustering1D.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   Clustering1D_swiginitnew_Clustering1Dr   s     r   rN   zClustering1D.__init__  r  r#   c                 0    t        j                  | ||      S r-   )r   Clustering1D_train_exactr!  s      r   train_exactzClustering1D.train_exact      77aCCr#   N)r   r   r6   r7   r   r   r   r   rN   r  r   delete_Clustering1Dr   r$   r#   r   r  r    s7     -/IOdeGH]D&::r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Zd Zej                  Zy)	"ProgressiveDimClusteringParametersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z+ProgressiveDimClusteringParameters.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z+ProgressiveDimClusteringParameters.<lambda>  rD   r#   rE   rF   znumber of incremental stepszapply PCA on inputc                 T    t        j                  | t        j                                y r-   )r   +ProgressiveDimClusteringParameters_swiginit&new_ProgressiveDimClusteringParametersrR   s    r   rN   z+ProgressiveDimClusteringParameters.__init__  s*    CCD/  KA  KA  KC  	Dr#   N)r   r   r6   r   r   r   r   r   <ProgressiveDimClusteringParameters_progressive_dim_steps_get<ProgressiveDimClusteringParameters_progressive_dim_steps_setprogressive_dim_steps0ProgressiveDimClusteringParameters_apply_pca_get0ProgressiveDimClusteringParameters_apply_pca_set	apply_pcarN   )delete_ProgressiveDimClusteringParametersr   r$   r#   r   r  r    s    -/IOdeGH$_%q%q  tC  t@  t@  Fh  iYY[j  \\  \\  b{  |ID&PPr#   r  c                   R    e Zd ZdZ ed d d      ZeZd Ze	j                  Zd Zy)	ProgressiveDimIndexFactoryz6generates an index suitable for clustering when calledc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z#ProgressiveDimIndexFactory.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z#ProgressiveDimIndexFactory.<lambda>  rD   r#   rE   rF   c                 .    t        j                  | |      S )zownership transferred to caller)r   #ProgressiveDimIndexFactory___call__)r   dims     r   r  z#ProgressiveDimIndexFactory.__call__      BB4MMr#   c                 T    t        j                  | t        j                                y r-   )r   #ProgressiveDimIndexFactory_swiginitnew_ProgressiveDimIndexFactoryrR   s    r   rN   z#ProgressiveDimIndexFactory.__init__  s    ;;D/BpBpBrsr#   N)r   r   r6   r7   r   r   r   r   r  r   !delete_ProgressiveDimIndexFactoryr   rN   r$   r#   r   r  r    s5    A-/IOdeGHN 'HHtr#   r  c                   J   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zej.                  Zy)ProgressiveDimClusteringa  
     K-means clustering with progressive dimensions used

    The clustering first happens in dim 1, then with exponentially increasing
    dimension until d (I steps). This is typically applied after a PCA
    transformation (optional). Reference:

    "Improved Residual Vector Quantization for High-dimensional Approximate
    Nearest Neighbor Search"

    Shicong Liu, Hongtao Lu, Junru Shao, AAAI'15

    https://arxiv.org/abs/1509.05195
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!ProgressiveDimClustering.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!ProgressiveDimClustering.<lambda>  rD   r#   rE   rF   r  r  zcentroids (k * d)r  c                 P    t        j                  | t        j                  |        y r-   )r   !ProgressiveDimClustering_swiginitnew_ProgressiveDimClusteringr   s     r   rN   z!ProgressiveDimClustering.__init__  s    99$@l@lnr@str#   c                 2    t        j                  | |||      S r-   )r   ProgressiveDimClustering_train)r   rW   r>   factorys       r   r"  zProgressiveDimClustering.train  s    ==dAq'RRr#   N)r   r   r6   r7   r   r   r   r   r   ProgressiveDimClustering_d_getProgressiveDimClustering_d_setr
  ProgressiveDimClustering_k_getProgressiveDimClustering_k_setrP  &ProgressiveDimClustering_centroids_get&ProgressiveDimClustering_centroids_setr  ,ProgressiveDimClustering_iteration_stats_get,ProgressiveDimClustering_iteration_stats_setr  rN   r"  delete_ProgressiveDimClusteringr   r$   r#   r   r  r    s     -/IOdeGH??AoAo  vU  	VA??AoAo  vL  	MAOOQ`  RH  RH  Nf  gI[[]l  ^Z  ^Z  `M  NOuS&FFr#   r  c                 4    t        j                  | ||||      S )a  
     simplified interface

    :type d: int
    :param d: dimension of the data
    :type n: int
    :param n: nb of training vectors
    :type k: int
    :param k: nb of output centroids
    :type x: float
    :param x: training set (size n * d)
    :type centroids: float
    :param centroids: output centroids (size k * d)
    :rtype: float
    :return: final quantization error
    )r   kmeans_clustering)r
  rW   rP  r>   r  s        r   r  r    s    " ,,Q1aCCr#   c                 @    t        j                  | |||||||||	|
      S r-   )r   pairwise_extra_distances)r
  r  rQ  rC  rR  r  r  rE  rS  rT  rU  s              r   r  r    s+    33Ar2r2r:WZ\_adfijjr#   c
                 >    t        j                  | |||||||||	
      S r-   )r   knn_extra_metrics)
r>   r;  r
  rk  rY  r  r  rP  rQ  indexess
             r   r  r    s'    ,,Q1b"b*aQZ\cddr#   c                 4    t        j                  | ||||      S )zm
    get a DistanceComputer that refers to this type of distance and
    indexes a flat array of size nb
    )r   get_extra_distance_computer)r
  r  r  rC  rR  s        r   r  r    s    
 66q"j"bQQr#   c                       e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Zd	 Zd
 Zd Ze	j&                  Zy)	Quantizerz'General interface for quantizer objectsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zQuantizer.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zQuantizer.__init__  rO   r#   zsize of the input vectorszbytes per indexed vectorc                 0    t        j                  | ||      S )zs
         Train the quantizer

        :type x: float
        :param x:       training vectors, size n * d
        )r   Quantizer_trainr!  s      r   r"  zQuantizer.train  s     ..tQ::r#   c                 2    t        j                  | |||      S )z
         Quantize a set of vectors

        :type x: float
        :param x:        input vectors, size n * d
        :type codes: uint8_t
        :param codes:    output codes, size n * code_size
        )r   Quantizer_compute_codesr   r>   r  rW   s       r   compute_codeszQuantizer.compute_codes  s     66tQqIIr#   c                 2    t        j                  | |||      S )z
         Decode a set of vectors

        :param codes:    input codes, size n * code_size
        :type x: float
        :param x:        output vectors, size n * d
        )r   Quantizer_decoder   r   r>   rW   s       r   decodezQuantizer.decode  s     //dAqAAr#   N)r   r   r6   r7   r   r   rN   r   r   r   Quantizer_d_getQuantizer_d_setr
  Quantizer_code_size_getQuantizer_code_size_setr!  r"  r  r  delete_Quantizerr   r$   r#   r   r  r    s}    2-/IOdeGKH00/2Q2QWwxA@@/BiBi  pO  PI;	JB '77r#   r  c                   (   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Zej0                  Zej4                  Z	 ej8                  Z	 ej<                  Z	 ej@                  Z!	  eejD                  ejF                        Z$ eejJ                  ejL                  d      Z' eejP                  ejR                  d      Z* eejV                  ejX                  d      Z- eej\                  ej^                  d      Z0 eejb                  ejd                  d      Z3d Z4d Z5d Z6d Z7d Z8d Z9d Z:d Z;d Z<d Z=d Z>d Z?d Z@d ZAd&dZBd&dZC eej                  ej                  d       ZFd! ZGd&d"ZHd# ZId$ ZJej                  ZLy%)'ProductQuantizerz
     Product Quantizer.
    PQ is trained using k-means, minimizing the L2 distance to centroids.
    PQ supports L2 and Inner Product search, however the quantization error is
    biased towards L2 distance.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zProductQuantizer.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zProductQuantizer.<lambda>"  rD   r#   rE   rF   znumber of subquantizersz%number of bits per quantization indexz dimensionality of each subvectorz)number of centroids for each subquantizerverbose during training?z!parameters used during clusteringzR
    if non-NULL, use this index for assignment (should be of size
    d / M)
    zK
    Centroid table, size M * ksub * dsub.
    Layout: (M, ksub, dsub)
    zV
    Transposed centroid table, size M * ksub * dsub.
    Layout: (dsub, M, ksub)
    zK
    Squared lengths of centroids, size M * ksub
    Layout: (M, ksub)
    c                 0    t        j                  | ||      S )z0return the centroids associated with subvector m)r   ProductQuantizer_get_centroids)r   r  r-  s      r   get_centroidszProductQuantizer.get_centroidsE  r  r#   c                 0    t        j                  | ||      S r-   )r   ProductQuantizer_trainr!  s      r   r"  zProductQuantizer.trainI      55dAqAAr#   c                 P    t        j                  | t        j                  |        y r-   )r   ProductQuantizer_swiginitnew_ProductQuantizerr   s     r   rN   zProductQuantizer.__init__L  ra  r#   c                 ,    t        j                  |       S )z8compute derived values when d, M and nbits have been set)r   #ProductQuantizer_set_derived_valuesrR   s    r   set_derived_valuesz#ProductQuantizer.set_derived_valuesO      BB4HHr#   c                 0    t        j                  | ||      S )z'Define the centroids for subquantizer m)r   ProductQuantizer_set_params)r   r  r  s      r   
set_paramszProductQuantizer.set_paramsS  s    ::4ANNr#   c                 0    t        j                  | ||      S )z.Quantize one vector with the product quantizer)r   ProductQuantizer_compute_code)r   r>   r   s      r   compute_codezProductQuantizer.compute_codeW  s    <<T1dKKr#   c                 2    t        j                  | |||      S )z(same as compute_code for several vectors)r   ProductQuantizer_compute_codesr  s       r   r  zProductQuantizer.compute_codes[  s    ==dAuaPPr#   c                 2    t        j                  | |||      S )zn
        speed up code assignment using assign_index
        (non-const because the index is changed)
        )r   0ProductQuantizer_compute_codes_with_assign_indexr  s       r   compute_codes_with_assign_indexz0ProductQuantizer.compute_codes_with_assign_index_  s    
 OOPTVWY^`abbr#   c                 .    t        j                  | g| S )zBdecode a vector from a given code (or n vectors if third argument))r   ProductQuantizer_decoder   s     r   r  zProductQuantizer.decodef  s    66tCdCCr#   c                 0    t        j                  | ||      S )z|
        If we happen to have the distance tables precomputed, this is
        more efficient to compute the codes.
        )r   1ProductQuantizer_compute_code_from_distance_table)r   r  r   s      r    compute_code_from_distance_tablez1ProductQuantizer.compute_code_from_distance_tablej  s    
 PPQUWZ\`aar#   c                 0    t        j                  | ||      S )a  
         Compute distance table for one vector.

        The distance table for x = [x_0 x_1 .. x_(M-1)] is a M * ksub
        matrix that contains

          dis_table (m, j) = || x_m - c_(m, j)||^2
          for m = 0..M-1 and j = 0 .. ksub - 1

        where c_(m, j) is the centroid no j of sub-quantizer m.

        :type x: float
        :param x:         input vector size d
        :type dis_table: float
        :param dis_table: output table, size M * ksub
        )r   'ProductQuantizer_compute_distance_tabler   r>   	dis_tables      r   compute_distance_tablez'ProductQuantizer.compute_distance_tableq  s    " FFtQPYZZr#   c                 0    t        j                  | ||      S r-   )r   )ProductQuantizer_compute_inner_prod_tabler(  s      r   compute_inner_prod_tablez)ProductQuantizer.compute_inner_prod_table  s    HHqR[\\r#   c                 2    t        j                  | |||      S )a  
         compute distance table for several vectors
        :type nx: int
        :param nx:        nb of input vectors
        :type x: float
        :param x:         input vector size nx * d
        :param dis_table: output table, size nx * M * ksub
        )r   (ProductQuantizer_compute_distance_tablesr   rk  r>   r  s       r   compute_distance_tablesz(ProductQuantizer.compute_distance_tables  s     GGbRSU_``r#   c                 2    t        j                  | |||      S r-   )r   *ProductQuantizer_compute_inner_prod_tablesr0  s       r   compute_inner_prod_tablesz*ProductQuantizer.compute_inner_prod_tables  s    II$PRTUWabbr#   c           	      8    t        j                  | ||||||      S )aS  
         perform a search (L2 distance)
        :type x: float
        :param x:        query vectors, size nx * d
        :type nx: int
        :param nx:       nb of queries
        :type codes: uint8_t
        :param codes:    database codes, size ncodes * code_size
        :type ncodes: int
        :param ncodes:   nb of nb vectors
        :type res: :py:class:`float_maxheap_array_t`
        :param res:      heap array to store results (nh == nx)
        :type init_finalize_heap: boolean, optional
        :param init_finalize_heap:  initialize heap (input) and sort (output)?
        )r   ProductQuantizer_searchr   r>   rk  r  rL  resinit_finalize_heaps          r   r:  zProductQuantizer.search  s#      66tQE6SVXjkkr#   c           	      8    t        j                  | ||||||      S )z1same as search, but with inner product similarity)r   ProductQuantizer_search_ipr7  s          r   	search_ipzProductQuantizer.search_ip  s!    99$2ufVY[mnnr#   zSymmetric Distance Tablec                 ,    t        j                  |       S r-   )r   "ProductQuantizer_compute_sdc_tablerR   s    r   compute_sdc_tablez"ProductQuantizer.compute_sdc_table  r  r#   c           	      8    t        j                  | ||||||      S r-   )r   ProductQuantizer_search_sdc)r   qcodesr  bcodesrL  r8  r9  s          r   
search_sdczProductQuantizer.search_sdc  s"    ::4VU[]`btuur#   c                 ,    t        j                  |       S )z
        Sync transposed centroids with regular centroids. This call
        is needed if centroids were edited directly.
        )r   *ProductQuantizer_sync_transposed_centroidsrR   s    r   sync_transposed_centroidsz*ProductQuantizer.sync_transposed_centroids  s    
 II$OOr#   c                 ,    t        j                  |       S )z<Clear transposed centroids table so ones are no longer used.)r   +ProductQuantizer_clear_transposed_centroidsrR   s    r   clear_transposed_centroidsz+ProductQuantizer.clear_transposed_centroids  s    JJ4PPr#   NrD  )Mr   r   r6   r7   r   r   r   r   r   ProductQuantizer_M_getProductQuantizer_M_setMProductQuantizer_nbits_getProductQuantizer_nbits_setr  ProductQuantizer_dsub_getProductQuantizer_dsub_setdsubProductQuantizer_ksub_getProductQuantizer_ksub_setr  ProductQuantizer_verbose_getProductQuantizer_verbose_setr  ProductQuantizer_Train_defaultTrain_default ProductQuantizer_Train_hot_startTrain_hot_startProductQuantizer_Train_sharedTrain_shared ProductQuantizer_Train_hypercubeTrain_hypercube$ProductQuantizer_Train_hypercube_pcaTrain_hypercube_pcaProductQuantizer_train_type_getProductQuantizer_train_type_set
train_typeProductQuantizer_cp_getProductQuantizer_cp_setcp!ProductQuantizer_assign_index_get!ProductQuantizer_assign_index_setassign_indexProductQuantizer_centroids_getProductQuantizer_centroids_setr  )ProductQuantizer_transposed_centroids_get)ProductQuantizer_transposed_centroids_settransposed_centroids)ProductQuantizer_centroids_sq_lengths_get)ProductQuantizer_centroids_sq_lengths_setcentroids_sq_lengthsr  r"  rN   r  r  r  r  r   r  r%  r*  r-  r1  r4  r:  r<  ProductQuantizer_sdc_table_getProductQuantizer_sdc_table_set	sdc_tabler?  rD  rG  rJ  delete_ProductQuantizerr   r$   r#   r   r  r    s    -/IOdeGH779_9_  fD  	EA_??AkAk  r^  _EO==?h?h  oV  WDO==?h?h  o_  `DCC_EqEq  xW  XG#BBM%FFO0"@@L.%FFO6)NN6/II?KzKz{J	/99?;b;b  iQ  
RBOMM  PA  PA G 	L GGIwIw ~ 	I $O$]$]_n  `Y  `Y _ 	 $O$]$]_n  `Y  `Y _ 	
JBeIOLQcDb[&]	acl$o GGIwIw  ~]  ^IHvPQ '>>r#   r  c                   *   e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                        Z eej                  d      Z eej                   ej"                        Zd
dZd Zej*                  Zy	)PQEncoderGenericc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQEncoderGeneric.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQEncoderGeneric.<lambda>  rD   r#   rE   rF   zcode for this vectorz%number of bits per subquantizer indexc                 Z    t        j                  | t        j                  |||             y r-   )r   PQEncoderGeneric_swiginitnew_PQEncoderGeneric)r   r   r  offsets       r   rN   zPQEncoderGeneric.__init__  s$    11$8\8\]achjp8qrr#   c                 .    t        j                  | |      S r-   )r   PQEncoderGeneric_encoder_   s     r   encodezPQEncoderGeneric.encode  ra   r#   Nr  )r   r   r6   r   r   r   r   r   PQEncoderGeneric_code_getPQEncoderGeneric_code_setr   PQEncoderGeneric_offset_getPQEncoderGeneric_offset_setr}  PQEncoderGeneric_nbits_getr  PQEncoderGeneric_reg_getPQEncoderGeneric_reg_setregrN   r  delete_PQEncoderGenericr   r$   r#   r   rw  rw    s    -/IOdeGHO==?h?h  oJ  KDoAA?CnCnoF_??EqrE
?;;_=e=e
fCs@&>>r#   rw  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)
PQEncoder8c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQEncoder8.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQEncoder8.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   PQEncoder8_swiginitnew_PQEncoder8r   r   r  s      r   rN   zPQEncoder8.__init__  !    ++D/2P2PQUW\2]^r#   c                 .    t        j                  | |      S r-   )r   PQEncoder8_encoder_   s     r   r  zPQEncoder8.encode  r   r#   N)r   r   r6   r   r   r   r   r   PQEncoder8_code_getPQEncoder8_code_setr   rN   r  delete_PQEncoder8r   r$   r#   r   r  r    sG    -/IOdeGHO779\9\]D_:&88r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)PQEncoder16c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQEncoder16.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQEncoder16.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   PQEncoder16_swiginitnew_PQEncoder16r  s      r   rN   zPQEncoder16.__init__  !    ,,T?3R3RSWY^3_`r#   c                 .    t        j                  | |      S r-   )r   PQEncoder16_encoder_   s     r   r  zPQEncoder16.encode  r   r#   N)r   r   r6   r   r   r   r   r   PQEncoder16_code_getPQEncoder16_code_setr   rN   r  delete_PQEncoder16r   r$   r#   r   r  r    sG    -/IOdeGHO88/:^:^_Da;&99r#   r  c                   D   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                        Z eej                         Z eej$                  ej&                        Zd Zd Zej.                  Zy)PQDecoderGenericc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQDecoderGeneric.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQDecoderGeneric.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   PQDecoderGeneric_swiginitnew_PQDecoderGenericr  s      r   rN   zPQDecoderGeneric.__init__  s!    11$8\8\]ach8ijr#   c                 ,    t        j                  |       S r-   )r   PQDecoderGeneric_decoderR   s    r   r  zPQDecoderGeneric.decode  ro   r#   N)r   r   r6   r   r   r   r   r   PQDecoderGeneric_code_getPQDecoderGeneric_code_setr   PQDecoderGeneric_offset_getPQDecoderGeneric_offset_setr}  PQDecoderGeneric_nbits_getr  PQDecoderGeneric_mask_getr  PQDecoderGeneric_reg_getPQDecoderGeneric_reg_setr  rN   r  delete_PQDecoderGenericr   r$   r#   r   r  r    s    -/IOdeGHO==?h?hiDoAA?CnCnoF_??@EO==>D
?;;_=e=e
fCk=&>>r#   r  c                       e Zd Z ed d d      ZeZej                  Z	 eej                  ej                        Zd Zd Zej                  Zy)
PQDecoder8c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQDecoder8.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQDecoder8.<lambda>   rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   PQDecoder8_swiginitnew_PQDecoder8r  s      r   rN   zPQDecoder8.__init__  r  r#   c                 ,    t        j                  |       S r-   )r   PQDecoder8_decoderR   s    r   r  zPQDecoder8.decode  r   r#   N)r   r   r6   r   r   r   r   r   PQDecoder8_nbitsr  PQDecoder8_code_getPQDecoder8_code_setr   rN   r  delete_PQDecoder8r   r$   r#   r   r  r    sR    -/IOdeGH,,EO779\9\]D_7&88r#   r  c                       e Zd Z ed d d      ZeZej                  Z	 eej                  ej                        Zd Zd Zej                  Zy)PQDecoder16c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPQDecoder16.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPQDecoder16.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   PQDecoder16_swiginitnew_PQDecoder16r  s      r   rN   zPQDecoder16.__init__  r  r#   c                 ,    t        j                  |       S r-   )r   PQDecoder16_decoderR   s    r   r  zPQDecoder16.decode  r   r#   N)r   r   r6   r   r   r   r   r   PQDecoder16_nbitsr  PQDecoder16_code_getPQDecoder16_code_setr   rN   r  delete_PQDecoder16r   r$   r#   r   r  r    sR    -/IOdeGH--EO88/:^:^_Da8&99r#   r  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Z ee	j&                  e	j(                  d
      Z ee	j,                  e	j.                  d      Z ee	j2                  e	j4                  d      Z ee	j8                  e	j:                  d      Z ee	j>                  e	j@                  d      Z! ee	jD                  e	jF                  d      Z$ ee	jJ                  e	jL                  d      Z' ee	jP                  e	jR                  d      Z* ee	jV                  e	jX                  d      Z-d Z. ee	j^                  e	j`                  d      Z1 ee	jd                  e	jf                  d      Z4 ee	jj                  e	jl                  d      Z7d Z8d Z9d Z:e	jv                  Z<	 e	jz                  Z>	 e	j~                  Z@	 e	j                  ZB	 e	j                  ZD	 e	j                  ZFe	j                  ZH	 e	j                  ZJe	j                  ZL	 e	j                  ZN	 d ZOd ZPd ZQd)dZRd*dZSd  ZTd+d!ZU ee	j                  e	j                  d"      ZX ee	j                  e	j                  d#      Z[ ee	j                  e	j                        Z^d$ Z_d,d%Z`d& Zad' Zbd( Zce	j                  Zey)-AdditiveQuantizerz
     Abstract structure for additive quantizers

    Different from the product quantizer in which the decoded vector is the
    concatenation of M sub-vectors, additive quantizers sum M sub-vectors
    to get the decoded vector.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zAdditiveQuantizer.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zAdditiveQuantizer.<lambda>&  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zAdditiveQuantizer.__init__(  rO   r#   znumber of codebookszbits for each step	codebooksz
    codebook #1 is stored in rows codebook_offsets[i]:codebook_offsets[i+1]
    in the codebooks table of size total_codebook_size by d
    z&total number of bits (indexes + norms)zbits allocated for the normszsize of the codebook in vectorsz&are all nbits = 8 (use faster decoder)r  zis trained or notzt
    auxiliary data for ST_norm_lsq2x4 and ST_norm_rq2x4
    store norms of codebook entries for 4-bit fastscan
    zstore and search normsc                 ,    t        j                  |       S r-   )r   )AdditiveQuantizer_compute_codebook_tablesrR   s    r   compute_codebook_tablesz)AdditiveQuantizer.compute_codebook_tables>  r%  r#   z8norms of all codebook entries (size total_codebook_size)z
    dot products of all codebook entries with the previous codebooks
    size sum(codebook_offsets[m] * 2^nbits[m], m=0..M-1)
    z
    norms and distance matrixes with beam search can get large, so use this
    to control for the amount of memory that can be allocated
    c                 .    t        j                  | |      S )z!encode a norm into norm_bits bits)r   AdditiveQuantizer_encode_norm)r   norms     r   encode_normzAdditiveQuantizer.encode_normJ  s    <<T4HHr#   c                 .    t        j                  | |      S )z.encode norm by non-uniform scalar quantization)r   AdditiveQuantizer_encode_qcintr_   s     r   encode_qcintzAdditiveQuantizer.encode_qcintN      ==dAFFr#   c                 .    t        j                  | |      S )z.decode norm by non-uniform scalar quantization)r   AdditiveQuantizer_decode_qcintr   rx  s     r   decode_qcintzAdditiveQuantizer.decode_qcintR  r  r#   c                 ,    t        j                  |       S )zTrain the norm quantizer)r   $AdditiveQuantizer_set_derived_valuesrR   s    r   r  z$AdditiveQuantizer.set_derived_valuesq  r  r#   c                 0    t        j                  | ||      S r-   )r   AdditiveQuantizer_train_norm)r   rW   rj  s      r   
train_normzAdditiveQuantizer.train_normu  s    ;;D!UKKr#   c                 2    t        j                  | |||      S r-   )r   AdditiveQuantizer_compute_codesr  s       r   r  zAdditiveQuantizer.compute_codesx  s    >>tQqQQr#   Nc                 4    t        j                  | ||||      S a7  
         Encode a set of vectors

        :type x: float
        :param x:      vectors to encode, size n * d
        :type codes: uint8_t
        :param codes:  output codes, size n * code_size
        :type centroids: float, optional
        :param centroids:  centroids to be added to x, size n * d
        )r   -AdditiveQuantizer_compute_codes_add_centroidsr   r>   r  rW   r  s        r   compute_codes_add_centroidsz-AdditiveQuantizer.compute_codes_add_centroids{  !     LLTSTV[]^`ijjr#   c           	      8    t        j                  | ||||||      S )an  
         pack a series of code to bit-compact format

        :type codes: int
        :param codes:        codes to be packed, size n * code_size
        :type packed_codes: uint8_t
        :param packed_codes: output bit-compact codes
        :type ld_codes: int, optional
        :param ld_codes:     leading dimension of codes
        :type norms: float, optional
        :param norms:        norms of the vectors (size n). Will be computed if
                                needed but not provided
        :type centroids: float, optional
        :param centroids:    centroids to be added to x, size n * d
        )r   AdditiveQuantizer_pack_codes)r   rW   r  packed_codesld_codesrj  r  s          r   
pack_codeszAdditiveQuantizer.pack_codes  s$      ;;D!ULZbdiktuur#   c                 2    t        j                  | |||      S z
         Decode a set of vectors

        :type codes: uint8_t
        :param codes:  codes to decode, size n * code_size
        :type x: float
        :param x:      output vectors, size n * d
        )r   AdditiveQuantizer_decoder   r  r>   rW   s       r   r  zAdditiveQuantizer.decode  s     77eQJJr#   c                 4    t        j                  | ||||      S z
         Decode a set of vectors in non-packed format

        :type codes: int
        :param codes:  codes to decode, size n * ld_codes
        :type x: float
        :param x:      output vectors, size n * d
        )r   !AdditiveQuantizer_decode_unpackedr   r  r>   rW   r  s        r   decode_unpackedz!AdditiveQuantizer.decode_unpacked  s     @@uaQRT\]]r#   z#Also determines what's in the codesz!min/max for quantization of normsc                 0    t        j                  | ||      S )z-decoding function for a code in a 64-bit word)r   AdditiveQuantizer_decode_64bitr!  s      r   decode_64bitzAdditiveQuantizer.decode_64bit  r  r#   c                 6    t        j                  | |||||      S )a  
         Compute inner-product look-up tables. Used in the centroid search
        functions.

        :type xq: float
        :param xq:     query vector, size (n, d)
        :type LUT: float
        :param LUT:    look-up table, size (n, total_codebook_size)
        :type alpha: float, optional
        :param alpha:  compute alpha * inner-product
        :type ld_lut: int, optional
        :param ld_lut:  leading dimension of LUT
        )r   AdditiveQuantizer_compute_LUTr   rW   rQ  LUTalphald_luts         r   compute_LUTzAdditiveQuantizer.compute_LUT  s      <<T1b#uV\]]r#   c                 6    t        j                  | |||||      S )zexact IP search)r   -AdditiveQuantizer_knn_centroids_inner_product)r   rW   rQ  rP  rQ  rR  s         r   knn_centroids_inner_productz-AdditiveQuantizer.knn_centroids_inner_product  s"    LLTSTVXZ[]fhnoor#   c                 .    t        j                  | |      S )z
         For L2 search we need the L2 norms of the centroids

        :type norms: float
        :param norms:    output norms table, size total_codebook_size
        )r   (AdditiveQuantizer_compute_centroid_normsr   rj  s     r   compute_centroid_normsz(AdditiveQuantizer.compute_centroid_norms  s     GGeTTr#   c           	      8    t        j                  | ||||||      S )z'Exact L2 search, with precomputed norms)r   "AdditiveQuantizer_knn_centroids_L2)r   rW   rQ  rP  rQ  rR  centroid_normss          r   knn_centroids_L2z"AdditiveQuantizer.knn_centroids_L2  s"    AA$2qR[]cesttr#   r-   )NNr	  g      ?r	  )fr   r   r6   r7   r   r   rN   r   r   r   AdditiveQuantizer_M_getAdditiveQuantizer_M_setrM  AdditiveQuantizer_nbits_getAdditiveQuantizer_nbits_setr  AdditiveQuantizer_codebooks_getAdditiveQuantizer_codebooks_setr  &AdditiveQuantizer_codebook_offsets_get&AdditiveQuantizer_codebook_offsets_setcodebook_offsetsAdditiveQuantizer_tot_bits_getAdditiveQuantizer_tot_bits_settot_bitsAdditiveQuantizer_norm_bits_getAdditiveQuantizer_norm_bits_set	norm_bits)AdditiveQuantizer_total_codebook_size_get)AdditiveQuantizer_total_codebook_size_settotal_codebook_sizeAdditiveQuantizer_only_8bit_getAdditiveQuantizer_only_8bit_set	only_8bitAdditiveQuantizer_verbose_getAdditiveQuantizer_verbose_setr   AdditiveQuantizer_is_trained_get AdditiveQuantizer_is_trained_setr  AdditiveQuantizer_norm_tabs_getAdditiveQuantizer_norm_tabs_set	norm_tabsAdditiveQuantizer_qnorm_getAdditiveQuantizer_qnorm_setqnormr  $AdditiveQuantizer_centroid_norms_get$AdditiveQuantizer_centroid_norms_setr	  -AdditiveQuantizer_codebook_cross_products_get-AdditiveQuantizer_codebook_cross_products_setcodebook_cross_products'AdditiveQuantizer_max_mem_distances_get'AdditiveQuantizer_max_mem_distances_setmax_mem_distancesr  r  r  AdditiveQuantizer_ST_decompressST_decompressAdditiveQuantizer_ST_LUT_nonormST_LUT_nonorm"AdditiveQuantizer_ST_norm_from_LUTST_norm_from_LUTAdditiveQuantizer_ST_norm_floatST_norm_floatAdditiveQuantizer_ST_norm_qint8ST_norm_qint8AdditiveQuantizer_ST_norm_qint4ST_norm_qint4 AdditiveQuantizer_ST_norm_cqint8ST_norm_cqint8 AdditiveQuantizer_ST_norm_cqint4ST_norm_cqint4 AdditiveQuantizer_ST_norm_lsq2x4ST_norm_lsq2x4AdditiveQuantizer_ST_norm_rq2x4ST_norm_rq2x4r  r  r  r  r  r  r 	  !AdditiveQuantizer_search_type_get!AdditiveQuantizer_search_type_setsearch_typeAdditiveQuantizer_norm_min_getAdditiveQuantizer_norm_min_setnorm_minAdditiveQuantizer_norm_max_getAdditiveQuantizer_norm_max_setnorm_maxr	  r
	  r	  r	  r	  delete_AdditiveQuantizerr   r$   r#   r   r  r    s    -/IOdeGKH88/:a:a  hB  	CA_@@/BmBm  tM  NEHH/JyJy  @P  QI V VXg  YO  YO U 	 FFHvHv  }j  kHHH/JyJy  @c  dI"?#\#\^m  _X  _X  ^D  EHH/JyJy  @m  nIDDoFsFs  zY  ZG/JJOL|L|  C[  \JHH/JyJy @ 	I _@@/BmBm  tQ  REOoRRTc  UI  UI  ON  ON&'d'dfu  gd  gd j 	 !!X!XZi  [R  [R X 	
IGG $CCM%#CCM 'II $CCM=#CCM3#CCM$EEN:$EEN$EEN $CCM>JLRkv$	K	^ ?LLoNN  Fp  qKFFHvHv  }e  fHFFHvHvwHJ^ pUu '??r#   r  c                  &    t        j                  |  S )a  
     Encode a residual by sampling from a centroid table.

    This is a single encoding step the residual quantizer.
    It allows low-level access to the encoding function, exposed mainly for unit
    tests.

    :type n: int
    :param n:              number of vectors to handle
    :type residuals: float
    :param residuals:      vectors to encode, size (n, beam_size, d)
    :type cent: float
    :param cent:           centroids, size (K, d)
    :type beam_size: int
    :param beam_size:      input beam size
    :type m: int
    :param m:              size of the codes for the previous encoding steps
    :type codes: int
    :param codes:          code array for the previous steps of the beam (n,
        beam_size, m)
    :type new_beam_size: int
    :param new_beam_size:  output beam size (should be <= K * beam_size)
    :type new_codes: int
    :param new_codes:      output codes, size (n, new_beam_size, m + 1)
    :type new_residuals: float
    :param new_residuals:  output residuals, size (n, new_beam_size, d)
    :type new_distances: float
    :param new_distances:  output distances, size (n, new_beam_size)
    :type assign_index: :py:class:`Index`, optional
    :param assign_index:   if non-NULL, will be used to perform assignment
    )r   beam_search_encode_steprH  s    r   r_	  r_	    s    @ 22D99r#   c                  &    t        j                  |  S )a  
     Encode a set of vectors using their dot products with the codebooks

    :type K: int
    :param K:           number of vectors in the codebook
    :type n: int
    :param n:           nb of vectors to encode
    :type beam_size: int
    :param beam_size:   input beam size
    :type codebook_cross_norms: float
    :param codebook_cross_norms: inner product of this codebook with the m
                                    previously encoded codebooks
    :type codebook_offsets: int
    :param codebook_offsets:     offsets into codebook_cross_norms for each
                                    previous codebook
    :type query_cp: float
    :param query_cp:    dot products of query vectors with ???
    :type cent_norms_i: float
    :param cent_norms_i:  norms of centroids
    )r   beam_search_encode_step_tabrH  s    r   ra	  ra	    s    * 66==r#   c                   j   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Zd Zej0                  Zy)RefineBeamMemoryPoolc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRefineBeamMemoryPool.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRefineBeamMemoryPool.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   RefineBeamMemoryPool_swiginitnew_RefineBeamMemoryPoolrR   s    r   rN   zRefineBeamMemoryPool.__init__  r  r#   N)r   r   r6   r   r   r   r   r   "RefineBeamMemoryPool_new_codes_get"RefineBeamMemoryPool_new_codes_set	new_codes&RefineBeamMemoryPool_new_residuals_get&RefineBeamMemoryPool_new_residuals_setnew_residuals"RefineBeamMemoryPool_residuals_get"RefineBeamMemoryPool_residuals_setrg  RefineBeamMemoryPool_codes_getRefineBeamMemoryPool_codes_setr  "RefineBeamMemoryPool_distances_get"RefineBeamMemoryPool_distances_setrQ  rN   delete_RefineBeamMemoryPoolr   r$   r#   r   rc	  rc	    s    -/IOdeGHKK_MM  AI_SSUd  VL  VL  MMKK_MM  AI_CC_EsEstEKK_MM  AIh&BBr#   rc	  c	                 <    t        j                  | ||||||||	      S r-   )r   refine_beam_mp)	rqrW   	beam_sizer>   out_beam_size	out_codesout_residualsout_distancespools	            r   rw	  rw	  $  s&    ))"aA}iYfhuw{||r#   c                   0   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Zd Zej*                  Zy)RefineBeamLUTMemoryPoolc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z RefineBeamLUTMemoryPool.<lambda>'  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z RefineBeamLUTMemoryPool.<lambda>'  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r    RefineBeamLUTMemoryPool_swiginitnew_RefineBeamLUTMemoryPoolrR   s    r   rN   z RefineBeamLUTMemoryPool.__init__.      88?j?j?lmr#   N)r   r   r6   r   r   r   r   r   %RefineBeamLUTMemoryPool_new_codes_get%RefineBeamLUTMemoryPool_new_codes_setrk	  )RefineBeamLUTMemoryPool_new_distances_get)RefineBeamLUTMemoryPool_new_distances_setnew_distances!RefineBeamLUTMemoryPool_codes_get!RefineBeamLUTMemoryPool_codes_setr  %RefineBeamLUTMemoryPool_distances_get%RefineBeamLUTMemoryPool_distances_setrQ  rN   delete_RefineBeamLUTMemoryPoolr   r$   r#   r   r	  r	  &  s    -/IOdeGHNNP_  QF  QF  GI_VVXg  YR  YR  SM_FFHyHyzENNP_  QF  QF  GIn&EEr#   r	  c           
      :    t        j                  | |||||||      S r-   )r   refine_beam_LUT_mp)rx	  rW   query_normsquery_cprz	  r{	  r}	  r~	  s           r   r	  r	  5  s$    --b![(M[dfsuyzzr#   c                   j   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Zd Zej0                  Zy)&ComputeCodesAddCentroidsLUT0MemoryPoolc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z/ComputeCodesAddCentroidsLUT0MemoryPool.<lambda>8  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z/ComputeCodesAddCentroidsLUT0MemoryPool.<lambda>8  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   /ComputeCodesAddCentroidsLUT0MemoryPool_swiginit*new_ComputeCodesAddCentroidsLUT0MemoryPoolrR   s    r   rN   z/ComputeCodesAddCentroidsLUT0MemoryPool.__init__@  *    GGo  OI  OI  OK  	Lr#   N)r   r   r6   r   r   r   r   r   0ComputeCodesAddCentroidsLUT0MemoryPool_codes_get0ComputeCodesAddCentroidsLUT0MemoryPool_codes_setr  0ComputeCodesAddCentroidsLUT0MemoryPool_norms_get0ComputeCodesAddCentroidsLUT0MemoryPool_norms_setrj  4ComputeCodesAddCentroidsLUT0MemoryPool_distances_get4ComputeCodesAddCentroidsLUT0MemoryPool_distances_setrQ  4ComputeCodesAddCentroidsLUT0MemoryPool_residuals_get4ComputeCodesAddCentroidsLUT0MemoryPool_residuals_setrg  ;ComputeCodesAddCentroidsLUT0MemoryPool_refine_beam_pool_get;ComputeCodesAddCentroidsLUT0MemoryPool_refine_beam_pool_setrefine_beam_poolrN   -delete_ComputeCodesAddCentroidsLUT0MemoryPoolr   r$   r#   r   r	  r	  7  s    -/IOdeGH_UUWf  XX  XX  YE_UUWf  XX  XX  YE]]_n  `d  `d  eI]]_n  `d  `d  eI k km|  ny  ny  zL&TTr#   r	  c                 6    t        j                  | |||||      S r-   )r   #compute_codes_add_centroids_mp_lut0rx	  r>   	codes_outrW   r  r~	  s         r   r	  r	  G       >>r1iQRT]_cddr#   c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Zd Zej6                  Zy)&ComputeCodesAddCentroidsLUT1MemoryPoolc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z/ComputeCodesAddCentroidsLUT1MemoryPool.<lambda>J  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z/ComputeCodesAddCentroidsLUT1MemoryPool.<lambda>J  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   /ComputeCodesAddCentroidsLUT1MemoryPool_swiginit*new_ComputeCodesAddCentroidsLUT1MemoryPoolrR   s    r   rN   z/ComputeCodesAddCentroidsLUT1MemoryPool.__init__S  r	  r#   N)r   r   r6   r   r   r   r   r   0ComputeCodesAddCentroidsLUT1MemoryPool_codes_get0ComputeCodesAddCentroidsLUT1MemoryPool_codes_setr  4ComputeCodesAddCentroidsLUT1MemoryPool_distances_get4ComputeCodesAddCentroidsLUT1MemoryPool_distances_setrQ  6ComputeCodesAddCentroidsLUT1MemoryPool_query_norms_get6ComputeCodesAddCentroidsLUT1MemoryPool_query_norms_setr	  3ComputeCodesAddCentroidsLUT1MemoryPool_query_cp_get3ComputeCodesAddCentroidsLUT1MemoryPool_query_cp_setr	  4ComputeCodesAddCentroidsLUT1MemoryPool_residuals_get4ComputeCodesAddCentroidsLUT1MemoryPool_residuals_setrg  ?ComputeCodesAddCentroidsLUT1MemoryPool_refine_beam_lut_pool_get?ComputeCodesAddCentroidsLUT1MemoryPool_refine_beam_lut_pool_setrefine_beam_lut_poolrN   -delete_ComputeCodesAddCentroidsLUT1MemoryPoolr   r$   r#   r   r	  r	  I  s   -/IOdeGH_UUWf  XX  XX  YE]]_n  `d  `d  eI?aacr  dj  dj  kK[[]l  ^a  ^a  bH]]_n  `d  `d  eI#O$s$s  vE  vE  vE  FL&TTr#   r	  c                 6    t        j                  | |||||      S r-   )r   #compute_codes_add_centroids_mp_lut1r	  s         r   r	  r	  Z  r	  r#   c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zej                  Z	 ej                  Z	 ej                   Z	  eej$                  ej&                  d      Zej*                  Z	 ej.                  Z	  eej2                  ej4                  d      Z eej8                  ej:                  d	      Z eej>                  ej@                  d
      Z! eejD                  ejF                  d      Z$ eejJ                  ejL                  d      Z'd Z(d Z)ddZ*d Z+ddZ,ddZ-ddZ.ddZ/ej`                  Z1y)ResidualQuantizera  
     Residual quantizer with variable number of bits per sub-quantizer

    The residual centroids are stored in a big cumulative centroid table.
    The codes are represented either as a non-compact table of size (n, M) or
    as the compact output (n, code_size).
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zResidualQuantizer.<lambda>e  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zResidualQuantizer.<lambda>e  rD   r#   rE   rF   z$Binary or of the Train_* flags belowz-number of iterations for codebook refinement.z,beam size used for training and for encodingzuse LUT for beam searchza
    Currently used mode of approximate min-k computations.
    Default value is EXACT_TOPK.
    zclustering parametersz*if non-NULL, use this index for assignmentc                 P    t        j                  | t        j                  |        y r-   )r   ResidualQuantizer_swiginitnew_ResidualQuantizerr   s     r   rN   zResidualQuantizer.__init__      2249^9^`d9efr#   c                 0    t        j                  | ||      S )zTrain the residual quantizer)r   ResidualQuantizer_trainr!  s      r   r"  zResidualQuantizer.train      66tQBBr#   c                 0    t        j                  | ||      S )z;Copy the M codebook levels from other, starting from skip_M)r   !ResidualQuantizer_initialize_from)r   r   skip_Ms      r   initialize_fromz!ResidualQuantizer.initialize_from  s    @@ufUUr#   c                 0    t        j                  | ||      S )a  
         Encode the vectors and compute codebook that minimizes the quantization
        error on these codes

        :type x: float
        :param x:      training vectors, size n * d
        :type n: int
        :param n:      nb of training vectors, n >= total_codebook_size
        :rtype: float
        :return: returns quantization error for the new codebook with old
            codes
        )r   %ResidualQuantizer_retrain_AQ_codebookr!  s      r   retrain_AQ_codebookz%ResidualQuantizer.retrain_AQ_codebook  s     DDT1aPPr#   Nc                 4    t        j                  | ||||      S r  )r   -ResidualQuantizer_compute_codes_add_centroidsr  s        r   r  z-ResidualQuantizer.compute_codes_add_centroids  r  r#   c           
      :    t        j                  | |||||||      S )a  
         lower-level encode function

        :type n: int
        :param n:              number of vectors to handle
        :type residuals: float
        :param residuals:      vectors to encode, size (n, beam_size, d)
        :type beam_size: int
        :param beam_size:      input beam size
        :type new_beam_size: int
        :param new_beam_size:  output beam size (should be <= K * beam_size)
        :type new_codes: int
        :param new_codes:      output codes, size (n, new_beam_size, m + 1)
        :type new_residuals: float, optional
        :param new_residuals:  output residuals, size (n, new_beam_size, d)
        :type new_distances: float, optional
        :param new_distances:  output distances, size (n, new_beam_size)
        )r   ResidualQuantizer_refine_beam)r   rW   ry	  rg  new_beam_sizerk	  rn	  r	  s           r   refine_beamzResidualQuantizer.refine_beam  s6    & <<T1iQZ\ikt  wD  FS  T  	Tr#   c           	      8    t        j                  | ||||||      S r-   )r   !ResidualQuantizer_refine_beam_LUT)r   rW   r	  r	  r	  rk	  r	  s          r   refine_beam_LUTz!ResidualQuantizer.refine_beam_LUT  s-    @@q+W_anpy  |I  J  	Jr#   c                 .    t        j                  | |      S )z
         Beam search can consume a lot of memory. This function estimates the
        amount of mem used by refine_beam to adjust the batch size

        :type beam_size: int, optional
        :param beam_size:  if != -1, override the beam size
        )r   "ResidualQuantizer_memory_per_point)r   ry	  s     r   memory_per_pointz"ResidualQuantizer.memory_per_point  s     AA$	RRr#   r  r-   NNr	  )2r   r   r6   r7   r   r   r   r   r    ResidualQuantizer_train_type_get ResidualQuantizer_train_type_setrc  ResidualQuantizer_Train_defaultrX  'ResidualQuantizer_Train_progressive_dimTrain_progressive_dim'ResidualQuantizer_Train_refine_codebookTrain_refine_codebook+ResidualQuantizer_niter_codebook_refine_get+ResidualQuantizer_niter_codebook_refine_setniter_codebook_refine ResidualQuantizer_Train_top_beamTrain_top_beam&ResidualQuantizer_Skip_codebook_tablesSkip_codebook_tables#ResidualQuantizer_max_beam_size_get#ResidualQuantizer_max_beam_size_setmax_beam_size"ResidualQuantizer_use_beam_LUT_get"ResidualQuantizer_use_beam_LUT_setuse_beam_LUT&ResidualQuantizer_approx_topk_mode_get&ResidualQuantizer_approx_topk_mode_setapprox_topk_modeResidualQuantizer_cp_getResidualQuantizer_cp_setrf  *ResidualQuantizer_assign_index_factory_get*ResidualQuantizer_assign_index_factory_setassign_index_factoryrN   r"  r	  r	  r  r	  r	  r	  delete_ResidualQuantizerr   r$   r#   r   r	  r	  \  s    -/IOdeGH/JJOL|L|  Cn  oJ#CCM:+SS6+SSR$_%`%`bq  c^  c^  dX  Y$EEN +QQ _PPRa  SF  SF  L  @MONNP_  QC  QC  Ig  hL V VXg  YO  YO U 	 
/::O<d<d  kG  
HB#O$^$^`o  a[  a[  aR  SgCVQkT*JS '??r#   r	  c                   r   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                  d      Z eej6                  ej8                  d      Z eej<                  ej>                  d      Z  eejB                  ejD                  d      Z# eejH                  ejJ                  d      Z& eejN                  ejP                        Z) eejT                  ejV                        Z,d Z-ej\                  Z/d Z0ddZ1d Z2d Z3d Z4d Z5d Z6d Z7d Z8d Z9ddZ:y)LocalSearchQuantizeraK  
     Implementation of LSQ/LSQ++ described in the following two papers:

    Revisiting additive quantization
    Julieta Martinez, et al. ECCV 2016

    LSQ++: Lower running time and higher recall in multi-codebook quantization
    Julieta Martinez, et al. ECCV 2018

    This implementation is mostly translated from the Julia implementations
    by Julieta Martinez:
    (https://github.com/una-dinosauria/local-search-quantization,
     https://github.com/una-dinosauria/Rayuela.jl)

    The trained codes are stored in `codebooks` which is called
    `centroids` in PQ and RQ.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLocalSearchQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLocalSearchQuantizer.<lambda>  rD   r#   rE   rF   znumber of codes per codebookz number of iterations in trainingz&iterations of local search in encodingz&iterations of local search in trainingznumber of iterations in icmztemperature factorzregularization factorz!nb of vectors to encode at a timezseed for random generatorzo
    number of perturbation in each code
    if non-NULL, use this encoder to encode (owned by the object)
    c                 P    t        j                  | t        j                  |        y r-   )r   LocalSearchQuantizer_swiginitnew_LocalSearchQuantizerr   s     r   rN   zLocalSearchQuantizer.__init__      55dO<d<dfj<klr#   c                 0    t        j                  | ||      S r-   )r   LocalSearchQuantizer_trainr!  s      r   r"  zLocalSearchQuantizer.train      99$1EEr#   Nc                 4    t        j                  | ||||      S )au  
         Encode a set of vectors

        :type x: float
        :param x:      vectors to encode, size n * d
        :type codes: uint8_t
        :param codes:  output codes, size n * code_size
        :type n: int
        :param n:      number of vectors
        :type centroids: float, optional
        :param centroids:  centroids to be added to x, size n * d
        )r   0LocalSearchQuantizer_compute_codes_add_centroidsr  s        r   r  z0LocalSearchQuantizer.compute_codes_add_centroids  s"     OOPTVWY^`aclmmr#   c                 2    t        j                  | |||      S )a  
         Update codebooks given encodings

        :type x: float
        :param x:      training vectors, size n * d
        :type codes: int
        :param codes:  encoded training vectors, size n * M
        :type n: int
        :param n:      number of vectors
        )r   %LocalSearchQuantizer_update_codebooksr  s       r   update_codebooksz%LocalSearchQuantizer.update_codebooks	  s     DDT1eUVWWr#   c                 6    t        j                  | |||||      S )a  
         Encode vectors given codebooks using iterative conditional mode (icm).

        :type codes: int
        :param codes:     output codes, size n * M
        :type x: float
        :param x:         vectors to encode, size n * d
        :type n: int
        :param n:         number of vectors
        :type ils_iters: int
        :param ils_iters: number of iterations of iterative local search
        )r   LocalSearchQuantizer_icm_encode)r   r  r>   rW   	ils_itersgens         r   
icm_encodezLocalSearchQuantizer.icm_encode  s!     >>tUAqR[]`aar#   c           
      :    t        j                  | |||||||      S r-   )r   $LocalSearchQuantizer_icm_encode_impl)r   r  r>   unariesr
  rW   r
  r  s           r   icm_encode_implz$LocalSearchQuantizer.icm_encode_impl%  s'    CCD%QRT[]`bcenpwxxr#   c                 6    t        j                  | |||||      S r-   )r   $LocalSearchQuantizer_icm_encode_step)r   r  r
  binariesrW   n_iterss         r   icm_encode_stepz$LocalSearchQuantizer.icm_encode_step(  s!    CCD%QXZbdegnoor#   c                 2    t        j                  | |||      S )z
         Add some perturbation to codes

        :type codes: int
        :param codes: codes to be perturbed, size n * M
        :type n: int
        :param n:     number of vectors
        )r   "LocalSearchQuantizer_perturb_codes)r   r  rW   r
  s       r   perturb_codesz"LocalSearchQuantizer.perturb_codes+  s     AA$qRUVVr#   c                 2    t        j                  | |||      S )a  
         Add some perturbation to codebooks

        :type T: float
        :param T:         temperature of simulated annealing
        :type stddev: std::vector< float >
        :param stddev:    standard derivations of each dimension in training data
        )r   &LocalSearchQuantizer_perturb_codebooks)r   Tstddevr
  s       r   perturb_codebooksz&LocalSearchQuantizer.perturb_codebooks6  s     EEdAvWZ[[r#   c                 .    t        j                  | |      S )z
         Compute binary terms

        :type binaries: float
        :param binaries: binary terms, size M * M * K * K
        )r   )LocalSearchQuantizer_compute_binary_terms)r   r
  s     r   compute_binary_termsz)LocalSearchQuantizer.compute_binary_termsA  s     HHxXXr#   c                 2    t        j                  | |||      S )a  
         Compute unary terms

        :type n: int
        :param n:       number of vectors
        :type x: float
        :param x:       vectors to encode, size n * d
        :type unaries: float
        :param unaries: unary terms, size n * M * K
        )r   (LocalSearchQuantizer_compute_unary_terms)r   r>   r
  rW   s       r   compute_unary_termsz(LocalSearchQuantizer.compute_unary_termsJ  s     GGaQXZ[\\r#   c                 4    t        j                  | ||||      S )a  
         Helper function to compute reconstruction error

        :type codes: int
        :param codes: encoded codes, size n * M
        :type x: float
        :param x:     vectors to encode, size n * d
        :type n: int
        :param n:     number of vectors
        :type objs: float, optional
        :param objs:  if it is not null, store reconstruction
                                error of each vector into it, size n
        )r   LocalSearchQuantizer_evaluate)r   r  r>   rW   objss        r   evaluatezLocalSearchQuantizer.evaluateW  s     <<T5!QPTUUr#   r-   );r   r   r6   r7   r   r   r   r   r   LocalSearchQuantizer_K_getLocalSearchQuantizer_K_setK$LocalSearchQuantizer_train_iters_get$LocalSearchQuantizer_train_iters_settrain_iters)LocalSearchQuantizer_encode_ils_iters_get)LocalSearchQuantizer_encode_ils_iters_setencode_ils_iters(LocalSearchQuantizer_train_ils_iters_get(LocalSearchQuantizer_train_ils_iters_settrain_ils_iters"LocalSearchQuantizer_icm_iters_get"LocalSearchQuantizer_icm_iters_set	icm_itersLocalSearchQuantizer_p_getLocalSearchQuantizer_p_setpLocalSearchQuantizer_lambd_getLocalSearchQuantizer_lambd_setlambd#LocalSearchQuantizer_chunk_size_get#LocalSearchQuantizer_chunk_size_set
chunk_size$LocalSearchQuantizer_random_seed_get$LocalSearchQuantizer_random_seed_setrandom_seedLocalSearchQuantizer_nperts_getLocalSearchQuantizer_nperts_setnperts,LocalSearchQuantizer_icm_encoder_factory_get,LocalSearchQuantizer_icm_encoder_factory_seticm_encoder_factory5LocalSearchQuantizer_update_codebooks_with_double_get5LocalSearchQuantizer_update_codebooks_with_double_setupdate_codebooks_with_doublerN   delete_LocalSearchQuantizerr   r"  r  r
  r
  r
  r
  r!
  r&
  r)
  r,
  r0
  r$   r#   r   r
  r
    sB   $ -/IOdeGH;;_=g=g  nQ  	RA?OOQ`  RF  RF  Ls  tK Y Y[j  \U  \U  [H  IWWYh  ZR  ZR  XE  FOKK_MM  Fh  iI;;_=g=g  nG  	HA_CC_EsEs  zV  WE/MM  PC  PC  Iq  rJ?OOQ`  RF  RF  Ll  mKoEEGvGv } 	F #?#_#_ap  b^  b^  _#+O,q,q  tC  ty  ty  $z m&BBFnXbyp	W	\Y]Vr#   r
  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zej$                  Zd Zd Zy)	
IcmEncoderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIcmEncoder.<lambda>j  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIcmEncoder.<lambda>j  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   IcmEncoder_swiginitnew_IcmEncoderr   lsqs     r   rN   zIcmEncoder.__init__p  s    ++D/2P2PQT2UVr#   c                 ,    t        j                  |       S r-   )r   IcmEncoder_set_binary_termrR   s    r   set_binary_termzIcmEncoder.set_binary_termt  r  r#   c                 6    t        j                  | |||||      S )a  
         Encode vectors given codebooks

        :type codes: int
        :param codes:     output codes, size n * M
        :type x: float
        :param x:         vectors to encode, size n * d
        :type gen: std::mt19937
        :param gen:       random generator
        :type n: int
        :param n:         number of vectors
        :type ils_iters: int
        :param ils_iters: number of iterations of iterative local search
        )r   IcmEncoder_encode)r   r  r>   r
  rW   r
  s         r   r  zIcmEncoder.encodew  s     00uaaSSr#   N)r   r   r6   r   r   r   r   r   IcmEncoder_binaries_getIcmEncoder_binaries_setr
  IcmEncoder_verbose_getIcmEncoder_verbose_setr  IcmEncoder_lsq_getIcmEncoder_lsq_setr^
  rN   delete_IcmEncoderr   ra
  r  r$   r#   r   rW
  rW
  i  s~    -/IOdeGH??AhAhiH==?e?efG
?557Y7Y
ZCW&88@Tr#   rW
  c                   N    e Zd Z ed d d      ZeZd Zej                  Z
d Zy)IcmEncoderFactoryc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIcmEncoderFactory.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIcmEncoderFactory.<lambda>  rD   r#   rE   rF   c                 .    t        j                  | |      S r-   )r   IcmEncoderFactory_getr]
  s     r   getzIcmEncoderFactory.get  s    44T3??r#   c                 T    t        j                  | t        j                                y r-   )r   IcmEncoderFactory_swiginitnew_IcmEncoderFactoryrR   s    r   rN   zIcmEncoderFactory.__init__  r  r#   N)r   r   r6   r   r   r   r   rq
  r   delete_IcmEncoderFactoryr   rN   r$   r#   r   rl
  rl
    s0    -/IOdeGH@&??br#   rl
  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zej                   Zy
)LSQTimerz]
    A helper struct to count consuming time during training.
    It is NOT thread-safe.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLSQTimer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLSQTimer.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   LSQTimer_swiginitnew_LSQTimerrR   s    r   rN   zLSQTimer.__init__  s    ))$0L0L0NOr#   c                 .    t        j                  | |      S r-   )r   LSQTimer_getr   r   s     r   rq
  zLSQTimer.get  s    ++D$77r#   c                 0    t        j                  | ||      S r-   )r   LSQTimer_add)r   r   deltas      r   r)  zLSQTimer.add  s    ++D$>>r#   c                 ,    t        j                  |       S r-   )r   LSQTimer_resetrR   s    r   r  zLSQTimer.reset      --d33r#   N)r   r   r6   r7   r   r   r   r   r   LSQTimer_t_getLSQTimer_t_settrN   rq
  r)  r  delete_LSQTimerr   r$   r#   r   rw
  rw
    sX    
 -/IOdeGH//1O1OPAP8?4&66r#   rw
  c                   6   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Zd Zd Zej,                  Zy)LSQTimerScopec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLSQTimerScope.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLSQTimerScope.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   LSQTimerScope_swiginitnew_LSQTimerScope)r   timerr   s      r   rN   zLSQTimerScope.__init__  s!    ..t_5V5VW\^b5cdr#   c                 ,    t        j                  |       S r-   )r   LSQTimerScope_finishrR   s    r   finishzLSQTimerScope.finish  rS   r#   N)r   r   r6   r   r   r   r   r   LSQTimerScope_t0_getLSQTimerScope_t0_sett0LSQTimerScope_timer_getLSQTimerScope_timer_setr
  LSQTimerScope_name_getLSQTimerScope_name_setr   LSQTimerScope_finished_getLSQTimerScope_finished_setfinishedrN   r
  delete_LSQTimerScoper   r$   r#   r   r
  r
    s    -/IOdeGH	/668\8\	]B_<<o>e>efEO::O<b<bcDBBODnDnoHe:&;;r#   r
  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                        Zd Zej                   Zd Zd	 Zd
 ZddZddZddZd ZddZy)ProductAdditiveQuantizera  
     Product Additive Quantizers

    The product additive quantizer is a variant of AQ and PQ.
    It first splits the vector space into multiple orthogonal sub-spaces
    just like PQ does. And then it quantizes each sub-space by an independent
    additive quantizer.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!ProductAdditiveQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!ProductAdditiveQuantizer.<lambda>  rD   r#   rE   rF   z,number of sub-vectors we split a vector intoc                 P    t        j                  | t        j                  |        y)a  
         Construct a product additive quantizer.

        The additive quantizers passed in will be cloned into the
        ProductAdditiveQuantizer object.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type aqs: std::vector< faiss::AdditiveQuantizer * >
        :param aqs:    sub-additive quantizers
        :type search_type: int, optional
        :param search_type:  AQ search type
        N)r   !ProductAdditiveQuantizer_swiginitnew_ProductAdditiveQuantizerr   s     r   rN   z!ProductAdditiveQuantizer.__init__        	99$@l@lnr@str#   c                 2    t        j                  | |||      S r-   )r   ProductAdditiveQuantizer_init)r   r
  aqsrV	  s       r   initzProductAdditiveQuantizer.init  s    <<T1c;WWr#   c                 .    t        j                  | |      S )z$Train the product additive quantizer)r   %ProductAdditiveQuantizer_subquantizer)r   r  s     r   subquantizerz%ProductAdditiveQuantizer.subquantizer  s    DDT1MMr#   c                 0    t        j                  | ||      S r-   )r   ProductAdditiveQuantizer_trainr!  s      r   r"  zProductAdditiveQuantizer.train      ==dAqIIr#   Nc                 4    t        j                  | ||||      S r  )r   4ProductAdditiveQuantizer_compute_codes_add_centroidsr  s        r   r  z4ProductAdditiveQuantizer.compute_codes_add_centroids  s"     SSTXZ[]bdegpqqr#   c                 4    t        j                  | ||||      S r-   )r   /ProductAdditiveQuantizer_compute_unpacked_codesr  s        r   compute_unpacked_codesz/ProductAdditiveQuantizer.compute_unpacked_codes  s    NNtUVX]_`bkllr#   c                 4    t        j                  | ||||      S r  )r   (ProductAdditiveQuantizer_decode_unpackedr  s        r   r 	  z(ProductAdditiveQuantizer.decode_unpacked  s      GGeUVXY[cddr#   c                 2    t        j                  | |||      S r  )r   ProductAdditiveQuantizer_decoder  s       r   r  zProductAdditiveQuantizer.decode  s     >>tUAqQQr#   c                 6    t        j                  | |||||      S )a  
         Compute inner-product look-up tables. Used in the search functions.

        :type xq: float
        :param xq:     query vector, size (n, d)
        :type LUT: float
        :param LUT:    look-up table, size (n, total_codebook_size)
        :type alpha: float, optional
        :param alpha:  compute alpha * inner-product
        :type ld_lut: int, optional
        :param ld_lut:  leading dimension of LUT
        )r   $ProductAdditiveQuantizer_compute_LUTr	  s         r   r
	  z$ProductAdditiveQuantizer.compute_LUT  s"     CCD!RQTV[]cddr#   r-   r	  r	  )r   r   r6   r7   r   r   r   r   r   $ProductAdditiveQuantizer_nsplits_get$ProductAdditiveQuantizer_nsplits_setnsplits'ProductAdditiveQuantizer_quantizers_get'ProductAdditiveQuantizer_quantizers_set
quantizersrN   delete_ProductAdditiveQuantizerr   r
  r
  r"  r  r
  r 	  r  r
	  r$   r#   r   r
  r
    s     -/IOdeGHKK_  NB  NB  H{  |G/QQSb  TK  TK  LJu 'FFXNJrm	e	Rer#   r
  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)ProductLocalSearchQuantizerzProduct Local Search Quantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$ProductLocalSearchQuantizer.<lambda>%  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$ProductLocalSearchQuantizer.<lambda>%  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)a  
         Construct a product LSQ object.

        :type d: int
        :param d:   dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of sub-vectors we split a vector into
        :type Msub: int
        :param Msub:     number of codebooks of each LSQ
        :type nbits: int
        :param nbits:    bits for each step
        :type search_type: int, optional
        :param search_type:  AQ search type
        N)r   $ProductLocalSearchQuantizer_swiginitnew_ProductLocalSearchQuantizerr   s     r   rN   z$ProductLocalSearchQuantizer.__init__(  s      	<<T?CrCrtxCyzr#   N)r   r   r6   r7   r   r   r   r   rN   r   "delete_ProductLocalSearchQuantizerr   r$   r#   r   r
  r
  "  s/    )-/IOdeGH{  'IIr#   r
  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)ProductResidualQuantizerzProduct Residual Quantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!ProductResidualQuantizer.<lambda>?  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!ProductResidualQuantizer.<lambda>?  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)a  
         Construct a product RQ object.

        :type d: int
        :param d:   dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of sub-vectors we split a vector into
        :type Msub: int
        :param Msub:     number of codebooks of each RQ
        :type nbits: int
        :param nbits:    bits for each step
        :type search_type: int, optional
        :param search_type:  AQ search type
        N)r   !ProductResidualQuantizer_swiginitnew_ProductResidualQuantizerr   s     r   rN   z!ProductResidualQuantizer.__init__B  s      	99$@l@lnr@str#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_ProductResidualQuantizerr   r$   r#   r   r
  r
  <  s/    %-/IOdeGHu  'FFr#   r
  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Z ee	j                  e	j                        Z ee	j                   e	j"                        Zd Zd Zd	 Zd
 Ze	j.                  Zy)
CodePackera,  
    Packing consists in combining a fixed number of codes of constant size
    (code_size) into a block of data where they may (or may not) be interleaved
    for efficient consumption by distance computation kernels. This exists for
    the "fast_scan" indexes on CPU and for some GPU kernels.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCodePacker.<lambda>^  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCodePacker.<lambda>^  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zCodePacker.__init__`  rO   r#   c                 2    t        j                  | |||      S r-   )r   CodePacker_pack_1r   	flat_coder}  blocks       r   pack_1zCodePacker.pack_1g  s    00y&%PPr#   c                 2    t        j                  | |||      S r-   )r   CodePacker_unpack_1r   r
  r}  r
  s       r   unpack_1zCodePacker.unpack_1j  s    224	RRr#   c                 0    t        j                  | ||      S r-   )r   CodePacker_pack_allr   
flat_codesr
  s      r   pack_allzCodePacker.pack_allm  s    224UKKr#   c                 0    t        j                  | ||      S r-   )r   CodePacker_unpack_allr   r
  r
  s      r   
unpack_allzCodePacker.unpack_allp  s    44T5*MMr#   N)r   r   r6   r7   r   r   rN   r   r   r   CodePacker_code_size_getCodePacker_code_size_setr!  CodePacker_nvec_getCodePacker_nvec_setnvecCodePacker_block_size_getCodePacker_block_size_set
block_sizer
  r
  r
  r
  delete_CodePackerr   r$   r#   r   r
  r
  V  s     -/IOdeGKHAA?CkCklIO779\9\]D/CC_EnEnoJQSLN&88r#   r
  c                   d    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 Zej                  Zy)CodePackerFlatz5Trivial code packer where codes are stored one by onec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCodePackerFlat.<lambda>y  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCodePackerFlat.<lambda>y  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   CodePackerFlat_swiginitnew_CodePackerFlat)r   r!  s     r   rN   zCodePackerFlat.__init__|  s    //o6X6XYb6cdr#   c                 2    t        j                  | |||      S r-   )r   CodePackerFlat_pack_1r
  s       r   r
  zCodePackerFlat.pack_1  s    44T9feTTr#   c                 2    t        j                  | |||      S r-   )r   CodePackerFlat_unpack_1r
  s       r   r
  zCodePackerFlat.unpack_1  s    66tUFIVVr#   c                 0    t        j                  | ||      S r-   )r   CodePackerFlat_pack_allr
  s      r   r
  zCodePackerFlat.pack_all  s    66tZOOr#   c                 0    t        j                  | ||      S r-   )r   CodePackerFlat_unpack_allr
  s      r   r
  zCodePackerFlat.unpack_all  s    88ujQQr#   N)r   r   r6   r7   r   r   r   r   rN   r
  r
  r
  r
  r   delete_CodePackerFlatr   r$   r#   r   r
  r
  v  sE    @-/IOdeGHeUWPR&<<r#   r
  c                       e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d      Zd	 Zd
 Zd Zd Zd Ze	j0                  Zy)VectorTransformz.Any transformation applied on a set of vectorsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVectorTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVectorTransform.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zVectorTransform.__init__  rO   r#   zinput dimensionzb
    set if the VectorTransform does not require training, or if
    training is done already
    c                 0    t        j                  | ||      S )z
         Perform training on a representative set of vectors. Does
        nothing by default.

        :type n: int
        :param n:      nb of training vectors
        :type x: float
        :param x:      training vecors, size n * d
        )r   VectorTransform_trainr!  s      r   r"  zVectorTransform.train       44T1a@@r#   c                 0    t        j                  | ||      S )a+  
         apply the transformation and return the result in an allocated pointer
        :type n: int
        :param n: number of vectors to transform
        :type x: float
        :param x: input vectors, size n * d_in
        :rtype: float
        :return: output vectors, size n * d_out
        )r   VectorTransform_applyr!  s      r   applyzVectorTransform.apply  r  r#   c                 2    t        j                  | |||      S )a,  
         apply the transformation and return the result in a provided matrix
        :type n: int
        :param n: number of vectors to transform
        :type x: float
        :param x: input vectors, size n * d_in
        :type xt: float
        :param xt: output vectors, size n * d_out
        )r   VectorTransform_apply_noallocr   rW   r>   xts       r   apply_noalloczVectorTransform.apply_noalloc  s     <<T1aLLr#   c                 2    t        j                  | |||      S )zi
        reverse transformation. May not be implemented or may return
        approximate result
        )r   !VectorTransform_reverse_transformr   rW   r  r>   s       r   reverse_transformz!VectorTransform.reverse_transform  s    
 @@q"aPPr#   c                 .    t        j                  | |      S r-   )r   VectorTransform_check_identicalr   s     r   check_identicalzVectorTransform.check_identical      >>tUKKr#   N)r   r   r6   r7   r   r   rN   r   r   r   VectorTransform_d_in_getVectorTransform_d_in_setd_inVectorTransform_d_out_getVectorTransform_d_out_setd_outVectorTransform_is_trained_getVectorTransform_is_trained_setr  r"  r  r  r  r  delete_VectorTransformr   r$   r#   r   r  r    s    9-/IOdeGKHO<<o>f>fgD_>>@i@i  pF  GE/HH/JxJx  	J

A
A
MQL&==r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d      Zdd	Zd
 Zd Zd Zd Z eej4                  ej6                        Zd Zd Zej>                  Z y)LinearTransformz\
     Generic linear transformation, with bias term applied on output
    y = A * x + b
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLinearTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLinearTransform.<lambda>  rD   r#   rE   rF   zh
    whether to use the bias term
     check if matrix A is orthonormal (enables reverse_transform)
    z(Transformation matrix, size d_out * d_inzbias vector, size d_outc                 Z    t        j                  | t        j                  |||             yz0both d_in > d_out and d_out < d_in are supportedN)r   LinearTransform_swiginitnew_LinearTransform)r   r  r"  	have_biass       r   rN   zLinearTransform.__init__  s$    007Z7Z[_afhq7rsr#   c                 2    t        j                  | |||      S )z*same as apply, but result is pre-allocated)r   LinearTransform_apply_noallocr  s       r   r  zLinearTransform.apply_noalloc  s    <<T1aLLr#   c                 2    t        j                  | |||      S )zc
        compute x = A^T * (x - b)
        is reverse transform if A has orthonormal lines
        )r   #LinearTransform_transform_transpose)r   rW   r;  r>   s       r   transform_transposez#LinearTransform.transform_transpose  s    
 BB4AqQQr#   c                 2    t        j                  | |||      S )zworks only if is_orthonormal)r   !LinearTransform_reverse_transformr  s       r   r  z!LinearTransform.reverse_transform  s    @@q"aPPr#   c                 ,    t        j                  |       S )z.compute A^T * A to set the is_orthonormal flag)r   "LinearTransform_set_is_orthonormalrR   s    r   set_is_orthonormalz"LinearTransform.set_is_orthonormal  s    AA$GGr#   c                 4    t        j                  | ||||      S r-   )r    LinearTransform_print_if_verbose)r   r   matrW   r
  s        r   print_if_verbosez LinearTransform.print_if_verbose  s    ??dCQRTUVVr#   c                 .    t        j                  | |      S r-   )r   LinearTransform_check_identicalr   s     r   r  zLinearTransform.check_identical  r  r#   Nr   r   F)!r   r   r6   r7   r   r   r   r   r   LinearTransform_have_bias_getLinearTransform_have_bias_setr.  "LinearTransform_is_orthonormal_get"LinearTransform_is_orthonormal_setis_orthonormalLinearTransform_A_getLinearTransform_A_setALinearTransform_b_getLinearTransform_b_setr	  rN   r  r3  r  r8  LinearTransform_verbose_getLinearTransform_verbose_setr  r<  r  delete_LinearTransformr   r$   r#   r   r'  r'    s    
 -/IOdeGHFFHuHuvIoPPRa  SE  SE K 	N 	668]8]  dS  	TA668]8]  dB  	CAtMRQH BBODoDopGWL&==r#   r'  c                   X    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
ej                  Zy	)
RandomRotationMatrixz Randomly rotate a set of vectorsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRandomRotationMatrix.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRandomRotationMatrix.<lambda>  rD   r#   rE   rF   c                 .    t        j                  | |      S )z+must be called before the transform is used)r   RandomRotationMatrix_initr  s     r   r
  zRandomRotationMatrix.init  s    88tDDr#   c                 0    t        j                  | ||      S r-   )r   RandomRotationMatrix_trainr!  s      r   r"  zRandomRotationMatrix.train	  r
  r#   c                 P    t        j                  | t        j                  |        yr+  )r   RandomRotationMatrix_swiginitnew_RandomRotationMatrixr   s     r   rN   zRandomRotationMatrix.__init__  s    55dO<d<dfj<klr#   N)r   r   r6   r7   r   r   r   r   r
  r"  rN   r   delete_RandomRotationMatrixr   r$   r#   r   rN  rN    s;    +-/IOdeGHEFm 'BBr#   rN  c                   P   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                  d      Z eej6                  ej8                  d      Z eej<                  ej>                  d      Z ddZ!d Z"d Z#d Z$ejJ                  Z&y)	PCAMatrixzx
    Applies a principal component analysis on a set of vectors,
    with optionally whitening and random rotation.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPCAMatrix.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPCAMatrix.<lambda>  rD   r#   rE   rF   z
     after transformation the components are multiplied by
    eigenvalues^eigen_power

    =0: no whitening
    =-0.5: full whitening
    z@value added to eigenvalues to avoid division by 0 when whiteningzrandom rotation after PCAz.ratio between # training vectors and dimensionz7try to distribute output eigenvectors in this many binszMean, size d_inz<eigenvalues of covariance matrix (= squared singular values)zPCA matrix, size d_in * d_inc           	      \    t        j                  | t        j                  ||||             y r-   )r   PCAMatrix_swiginitnew_PCAMatrix)r   r  r"  eigen_powerrandom_rotations        r   rN   zPCAMatrix.__init__*  s&    **41N1NtUZ\gix1yzr#   c                 0    t        j                  | ||      S )zo
        train on n vectors. If n < d_in then the eigenvector matrix
        will be completed with 0s
        )r   PCAMatrix_trainr!  s      r   r"  zPCAMatrix.train-  s    
 ..tQ::r#   c                 .    t        j                  | |      S )zcopy pre-trained PCA matrix)r   PCAMatrix_copy_fromr   s     r   	copy_fromzPCAMatrix.copy_from4  s    224??r#   c                 ,    t        j                  |       S )z6called after mean, PCAMat and eigenvalues are computed)r   PCAMatrix_prepare_AbrR   s    r   
prepare_AbzPCAMatrix.prepare_Ab8      33D99r#   N)r   r   r   F)'r   r   r6   r7   r   r   r   r   r   PCAMatrix_eigen_power_getPCAMatrix_eigen_power_setr`  PCAMatrix_epsilon_getPCAMatrix_epsilon_setepsilonPCAMatrix_random_rotation_getPCAMatrix_random_rotation_setra  PCAMatrix_max_points_per_d_getPCAMatrix_max_points_per_d_setmax_points_per_dPCAMatrix_balanced_bins_getPCAMatrix_balanced_bins_setbalanced_binsPCAMatrix_mean_getPCAMatrix_mean_setmeanPCAMatrix_eigenvalues_getPCAMatrix_eigenvalues_seteigenvaluesPCAMatrix_PCAMat_getPCAMatrix_PCAMat_setPCAMatrN   r"  rf  ri  delete_PCAMatrixr   r$   r#   r   rZ  rZ    sN   
 -/IOdeGH?DDoFoFo v 	K <<o>c>c  jq  rGLLoN{N{  Bb  cO N NP_P~P~  Ez  {_HH/JuJu  |z  {MO668Z8Z`vwD?DDoFoFo  vy  zKo::O<`<`  gJ  KF{;@: '77r#   rZ  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd	dZd Zej(                  Zy)
	ITQMatrixz
     ITQ implementation from

        Iterative quantization: A procrustean approach to learning binary codes
        for large-scale image retrieval,

    Yunchao Gong, Svetlana Lazebnik, Albert Gordo, Florent Perronnin,
    PAMI'12.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zITQMatrix.<lambda>J  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zITQMatrix.<lambda>J  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   ITQMatrix_swiginitnew_ITQMatrixr  s     r   rN   zITQMatrix.__init__P  s    **41N1Nq1QRr#   c                 0    t        j                  | ||      S r-   )r   ITQMatrix_trainr!  s      r   r"  zITQMatrix.trainS  r>  r#   Nr  )r   r   r6   r7   r   r   r   r   r   ITQMatrix_max_iter_getITQMatrix_max_iter_setmax_iterITQMatrix_seed_getITQMatrix_seed_setr  ITQMatrix_init_rotation_getITQMatrix_init_rotation_setinit_rotationrN   r"  delete_ITQMatrixr   r$   r#   r   r  r  ?  s~     -/IOdeGH>>@f@fgHO668Z8Z[D_HH/JuJuvMS;&77r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                        ZddZd Zd	 Zd
 Zej8                  Zy)ITQTransformzGThe full ITQ transform, including normalizations and PCA transformationc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zITQTransform.<lambda>\  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zITQTransform.<lambda>\  rD   r#   rE   rF   z!max training points per dimensionc                 Z    t        j                  | t        j                  |||             y r-   )r   ITQTransform_swiginitnew_ITQTransform)r   r  r"  do_pcas       r   rN   zITQTransform.__init__d  s$    --dO4T4TUY[`bh4ijr#   c                 0    t        j                  | ||      S r-   )r   ITQTransform_trainr!  s      r   r"  zITQTransform.traing      11$1==r#   c                 2    t        j                  | |||      S r-   )r   ITQTransform_apply_noallocr  s       r   r  zITQTransform.apply_noallocj  s    99$1bIIr#   c                 .    t        j                  | |      S r-   )r   ITQTransform_check_identicalr   s     r   r  zITQTransform.check_identicalm  s    ;;D%HHr#   Nr?  )r   r   r6   r7   r   r   r   r   r   ITQTransform_mean_getITQTransform_mean_setrz  ITQTransform_do_pca_getITQTransform_do_pca_setr  ITQTransform_itq_getITQTransform_itq_setitq"ITQTransform_max_train_per_dim_get"ITQTransform_max_train_per_dim_setmax_train_per_dimITQTransform_pca_then_itq_getITQTransform_pca_then_itq_setpca_then_itqrN   r"  r  r  delete_ITQTransformr   r$   r#   r   r  r  Y  s    R-/IOdeGHO99?;`;`aDo==?f?fgF
?779]9]
^C !S!SUd  VH  VH  Nv  wOII?KxKxyLk>JI&::r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                        Z eej6                  ej8                  d      ZddZd Zej@                  Z!y)	OPQMatrixa\  
     Applies a rotation to align the dimensions with a PQ to minimize
     the reconstruction error. Can be used before an IndexPQ or an
     IndexIVFPQ. The method is the non-parametric version described in:

    "Optimized Product Quantization for Approximate Nearest Neighbor Search"
    Tiezheng Ge, Kaiming He, Qifa Ke, Jian Sun, CVPR'13
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOPQMatrix.<lambda>}  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOPQMatrix.<lambda>}  rD   r#   rE   rF   znb of subquantizersz#Number of outer training iterationsz(Number of training iterations for the PQz#same, for the first outer iterationz/if there are too many training points, resamplezk
    if non-NULL, use this product quantizer for training
    should be constructed with (d_out, M, _)
    c                 Z    t        j                  | t        j                  |||             y)z-if d2 != -1, output vectors of this dimensionN)r   OPQMatrix_swiginitnew_OPQMatrix)r   r
  rM  d2s       r   rN   zOPQMatrix.__init__  s#    **41N1NqRSUW1XYr#   c                 0    t        j                  | ||      S r-   )r   OPQMatrix_trainr!  s      r   r"  zOPQMatrix.train  r>  r#   N)r   r   r	  )"r   r   r6   r7   r   r   r   r   r   OPQMatrix_M_getOPQMatrix_M_setrM  OPQMatrix_niter_getOPQMatrix_niter_setrS  OPQMatrix_niter_pq_getOPQMatrix_niter_pq_setniter_pqOPQMatrix_niter_pq_0_getOPQMatrix_niter_pq_0_set
niter_pq_0OPQMatrix_max_train_points_getOPQMatrix_max_train_points_setmax_train_pointsOPQMatrix_verbose_getOPQMatrix_verbose_setr  OPQMatrix_pq_getOPQMatrix_pq_setpqrN   r"  delete_OPQMatrixr   r$   r#   r   r  r  s  s    -/IOdeGH00/2Q2QWqrA_88/:]:]  dN  OE>>@f@f  m\  ]H/BBODlDl  s]  ^J N NP_P~P~  E{  |<<o>c>cdG	/22O4T4T [ 
	B
Z;&77r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zd	 Zd
 Zej                   Zy)RemapDimensionsTransformz
     remap dimensions for intput vectors, possibly inserting 0s
    strictly speaking this is also a linear transform but we don't want
    to compute it with matrix multiplies
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!RemapDimensionsTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!RemapDimensionsTransform.<lambda>  rD   r#   rE   rF   zR
    map from output dimension to input, size d_out
    -1 -> set output to 0
    c                 2    t        j                  | |||      S r-   )r   &RemapDimensionsTransform_apply_noallocr  s       r   r  z&RemapDimensionsTransform.apply_noalloc  s    EEdAqRTUUr#   c                 2    t        j                  | |||      S )z@reverse transform correct only when the mapping is a permutation)r   *RemapDimensionsTransform_reverse_transformr  s       r   r  z*RemapDimensionsTransform.reverse_transform  s    II$PQSUWXYYr#   c                 P    t        j                  | t        j                  |        y)a  
        *Overload 1:*
        remap input to output, skipping or inserting dimensions as needed
        if uniform: distribute dimensions uniformly
        otherwise just take the d_out first ones.

        |

        *Overload 2:*
        remap input to output, skipping or inserting dimensions as needed
        if uniform: distribute dimensions uniformly
        otherwise just take the d_out first ones.
        N)r   !RemapDimensionsTransform_swiginitnew_RemapDimensionsTransformr   s     r   rN   z!RemapDimensionsTransform.__init__  r
  r#   c                 .    t        j                  | |      S r-   )r   (RemapDimensionsTransform_check_identicalr   s     r   r  z(RemapDimensionsTransform.check_identical  s    GGeTTr#   N)r   r   r6   r7   r   r   r   r   r    RemapDimensionsTransform_map_get RemapDimensionsTransform_map_setmapr  r  rN   r  delete_RemapDimensionsTransformr   r$   r#   r   r  r    sc     -/IOdeGH
?CC_EuEu | 	C
VZu U&FFr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zej                   Zy
)NormalizationTransformzper-vector normalizationc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNormalizationTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNormalizationTransform.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   NormalizationTransform_swiginitnew_NormalizationTransformr   s     r   rN   zNormalizationTransform.__init__      77o>h>hjn>opr#   c                 2    t        j                  | |||      S r-   )r   $NormalizationTransform_apply_noallocr  s       r   r  z$NormalizationTransform.apply_noalloc  s    CCD!QPRSSr#   c                 2    t        j                  | |||      S )z/Identity transform since norm is not revertible)r   (NormalizationTransform_reverse_transformr  s       r   r  z(NormalizationTransform.reverse_transform  s    GGaQSUVWWr#   c                 .    t        j                  | |      S r-   )r   &NormalizationTransform_check_identicalr   s     r   r  z&NormalizationTransform.check_identical  s    EEdERRr#   N)r   r   r6   r7   r   r   r   r   r   NormalizationTransform_norm_getNormalizationTransform_norm_setr  rN   r  r  r  delete_NormalizationTransformr   r$   r#   r   r  r    sW    #-/IOdeGHOCC_EtEtuDqTXS&DDr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      ZddZd Zd	 Zd
 Zd Zej"                  Zy)CenteringTransformz5Subtract the mean of each component from the vectors.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCenteringTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCenteringTransform.<lambda>  rD   r#   rE   rF   zMean, size d_in = d_outc                 V    t        j                  | t        j                  |             y r-   )r   CenteringTransform_swiginitnew_CenteringTransformr  s     r   rN   zCenteringTransform.__init__  s    33D/:`:`ab:cdr#   c                 0    t        j                  | ||      S )ztrain on n vectors.)r   CenteringTransform_trainr!  s      r   r"  zCenteringTransform.train  s    77aCCr#   c                 2    t        j                  | |||      S )zsubtract the mean)r    CenteringTransform_apply_noallocr  s       r   r  z CenteringTransform.apply_noalloc  s    ??aBOOr#   c                 2    t        j                  | |||      S )zadd the mean)r   $CenteringTransform_reverse_transformr  s       r   r  z$CenteringTransform.reverse_transform  s    CCD!RQRSSr#   c                 .    t        j                  | |      S r-   )r   "CenteringTransform_check_identicalr   s     r   r  z"CenteringTransform.check_identical  r  r#   Nr  )r   r   r6   r7   r   r   r   r   r   CenteringTransform_mean_getCenteringTransform_mean_setrz  rN   r"  r  r  r  delete_CenteringTransformr   r$   r#   r   r  r    sg    @-/IOdeGHO??AlAl  sQ  RDeDPTO&@@r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)SearchParametersPreTransformc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z%SearchParametersPreTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z%SearchParametersPreTransform.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   %SearchParametersPreTransform_swiginit new_SearchParametersPreTransformrR   s    r   rN   z%SearchParametersPreTransform.__init__      ==dODtDtDvwr#   N)r   r   r6   r   r   r   r   r   -SearchParametersPreTransform_index_params_get-SearchParametersPreTransform_index_params_setindex_paramsrN   #delete_SearchParametersPreTransformr   r$   r#   r   r  r    sN    -/IOdeGHOYY[j  \Y  \Y  ZLx&JJr#   r  c                   |   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Zd Zd	 Zd
 Zd Zd Zd Zd ZddZddZd Zd ZddZd Zd Zd Z d Z!d Z"d Z#ddZ$d Z%ejL                  Z'y)IndexPreTransformzo
    Index that applies a LinearTransform transform on vectors before
    handing them over to a sub-index
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexPreTransform.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexPreTransform.<lambda>  rD   r#   rE   rF   zchain of transformsthe sub-indexc                 P    t        j                  | t        j                  |        y)z
        *Overload 1:*
        whether pointers are deleted in destructor

        |

        *Overload 2:*
         ltrans is the last transform before the index
        N)r   IndexPreTransform_swiginitnew_IndexPreTransformr   s     r   rN   zIndexPreTransform.__init__	  s      	2249^9^`d9efr#   c                 .    t        j                  | |      S r-   )r   #IndexPreTransform_prepend_transform)r   ltranss     r   prepend_transformz#IndexPreTransform.prepend_transform  s    BB4PPr#   c                 0    t        j                  | ||      S r-   )r   IndexPreTransform_trainr!  s      r   r"  zIndexPreTransform.train      66tQBBr#   c                 0    t        j                  | ||      S r-   )r   IndexPreTransform_addr!  s      r   r)  zIndexPreTransform.add      44T1a@@r#   c                 2    t        j                  | |||      S r-   )r   IndexPreTransform_add_with_idsr/  s       r   r1  zIndexPreTransform.add_with_ids      ==dAq$OOr#   c                 ,    t        j                  |       S r-   )r   IndexPreTransform_resetrR   s    r   r  zIndexPreTransform.reset!  ro   r#   c                 .    t        j                  | |      S )z9removes IDs from the index. Not supported by all indexes.)r   IndexPreTransform_remove_idsrK  s     r   rL  zIndexPreTransform.remove_ids$  s    ;;D#FFr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexPreTransform_searchr8  s          r   r:  zIndexPreTransform.search(  !    77aAyRXZ`aar#   c                 6    t        j                  | |||||      S r-   )r   IndexPreTransform_range_searchrA  s         r   rB  zIndexPreTransform.range_search+  s    ==dAq&RXZ`aar#   c                 0    t        j                  | ||      S r-   )r   IndexPreTransform_reconstructrO  s      r   rR  zIndexPreTransform.reconstruct.      <<T3OOr#   c                 2    t        j                  | |||      S r-   )r   IndexPreTransform_reconstruct_nrX  s       r   r[  zIndexPreTransform.reconstruct_n1  s    >>tRVTTr#   c           
      :    t        j                  | |||||||      S r-   )r   (IndexPreTransform_search_and_reconstructr^  s           r   r_  z(IndexPreTransform.search_and_reconstruct4  s'    GGaQRTUW`bhjprxyyr#   c                 0    t        j                  | ||      S )z
        apply the transforms in the chain. The returned float * may be
        equal to x, otherwise it should be deallocated.
        )r   IndexPreTransform_apply_chainr!  s      r   apply_chainzIndexPreTransform.apply_chain7  s    
 <<T1aHHr#   c                 2    t        j                  | |||      S )z
        Reverse the transforms in the chain. May not be implemented for
        all transforms in the chain or may return approximate results.
        )r   IndexPreTransform_reverse_chainr  s       r   reverse_chainzIndexPreTransform.reverse_chain>  s    
 >>tQANNr#   c                 ,    t        j                  |       S r-   )r   'IndexPreTransform_get_distance_computerrR   s    r   rk  z'IndexPreTransform.get_distance_computerE  r  r#   c                 ,    t        j                  |       S r-   )r   IndexPreTransform_sa_code_sizerR   s    r   ro  zIndexPreTransform.sa_code_sizeH  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexPreTransform_sa_encoderr  s       r   rs  zIndexPreTransform.sa_encodeK  s    ::4AuMMr#   c                 2    t        j                  | |||      S r-   )r   IndexPreTransform_sa_decoderv  s       r   rw  zIndexPreTransform.sa_decodeN  s    ::4E1MMr#   c                 0    t        j                  | ||      S r-   )r   IndexPreTransform_merge_fromr{  s      r   r~  zIndexPreTransform.merge_fromQ      ;;D*fUUr#   c                 .    t        j                  | |      S r-   )r   ,IndexPreTransform_check_compatible_for_merger  s     r   r  z,IndexPreTransform.check_compatible_for_mergeT  s    KKDR\]]r#   r-   r  )(r   r   r6   r7   r   r   r   r   r   IndexPreTransform_chain_getIndexPreTransform_chain_setchainIndexPreTransform_index_getIndexPreTransform_index_setr   IndexPreTransform_own_fields_get IndexPreTransform_own_fields_set
own_fieldsrN   r  r"  r)  r1  r  rL  r:  rB  rR  r[  r_  r5  r8  rk  ro  rs  rw  r~  r  delete_IndexPreTransformr   r$   r#   r   r  r    s    
 -/IOdeGH_@@/BmBmnE_@@/BmBm  tN  OE/JJOL|L|  CW  XJ
gQCAP=GbbPUzIOMDNNV^&??r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zej                  Zd Zy)IndexRefineSearchParametersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$IndexRefineSearchParameters.<lambda>[  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$IndexRefineSearchParameters.<lambda>[  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   $IndexRefineSearchParameters_swiginitnew_IndexRefineSearchParametersrR   s    r   rN   z$IndexRefineSearchParameters.__init__a  r  r#   N)r   r   r6   r   r   r   r   r   (IndexRefineSearchParameters_k_factor_get(IndexRefineSearchParameters_k_factor_setk_factor1IndexRefineSearchParameters_base_index_params_get1IndexRefineSearchParameters_base_index_params_setbase_index_params"delete_IndexRefineSearchParametersr   rN   r$   r#   r   rP  rP  Z  ss    -/IOdeGHPPRa  SK  SK  LH !b!bds  ef  ef  g&IIvr#   rP  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Zd Zd Zd Zd ZddZddZd Zd Zd Z d Z!ejD                  Z#y)IndexRefinez
    Index that queries in a base_index (a fast one) and refines the
    results with an exact search, hopefully improving the results.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRefine.<lambda>l  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRefine.<lambda>l  rD   r#   rE   rF   z>faster index to pre-select the vectors that should be filteredzrefinement indexz%should the base index be deallocated?zsame with the refinement indexzk
    factor between k requested in search and the k requested from
    the base_index (should be >= 1)
    c                 P    t        j                  | t        j                  |        y)zinitialize from empty indexN)r   IndexRefine_swiginitnew_IndexRefiner   s     r   rN   zIndexRefine.__init__w  s    ,,T?3R3RTX3YZr#   c                 0    t        j                  | ||      S r-   )r   IndexRefine_trainr!  s      r   r"  zIndexRefine.train{      00q!<<r#   c                 0    t        j                  | ||      S r-   )r   IndexRefine_addr!  s      r   r)  zIndexRefine.add~  r>  r#   c                 ,    t        j                  |       S r-   )r   IndexRefine_resetrR   s    r   r  zIndexRefine.reset  r   r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexRefine_searchr8  s          r   r:  zIndexRefine.search       11$1aFTZ[[r#   c                 6    t        j                  | |||||      S r-   )r   IndexRefine_range_searchrA  s         r   rB  zIndexRefine.range_search      77aFFTZ[[r#   c                 0    t        j                  | ||      S r-   )r   IndexRefine_reconstructrO  s      r   rR  zIndexRefine.reconstruct      66tS&IIr#   c                 ,    t        j                  |       S r-   )r   IndexRefine_sa_code_sizerR   s    r   ro  zIndexRefine.sa_code_size  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexRefine_sa_encoderr  s       r   rs  zIndexRefine.sa_encode      44T1aGGr#   c                 2    t        j                  | |||      S )zk
        The sa_decode decodes from the index_refine, which is assumed to be more
        accurate
        )r   IndexRefine_sa_decoderv  s       r   rw  zIndexRefine.sa_decode  s    
 44T1eQGGr#   r-   )$r   r   r6   r7   r   r   r   r   r   IndexRefine_base_index_getIndexRefine_base_index_set
base_indexIndexRefine_refine_index_getIndexRefine_refine_index_setrefine_indexIndexRefine_own_fields_getIndexRefine_own_fields_setrM   IndexRefine_own_refine_index_get IndexRefine_own_refine_index_setown_refine_indexIndexRefine_k_factor_getIndexRefine_k_factor_setrX  rN   r"  r)  r  r:  rB  rR  ro  rs  rw  delete_IndexRefiner   r$   r#   r   r^  r^  f  s   
 -/IOdeGH/DDoFpFp  w|  }JOHH/JvJv  }T  UL/DDoFpFp  wc  dJ P PRa  SC  SC  In  o@@/BjBj q 	H
[=;7\\J>HH '99r#   r^  c                   T    e Zd ZdZ ed d d      ZeZd Zd	dZ	e
j                  Zy)
IndexRefineFlatz
     Version where the refinement index is an IndexFlat. It has one additional
    constructor that takes a table of elements to add to the flat refinement
    index
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRefineFlat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRefineFlat.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexRefineFlat_swiginitnew_IndexRefineFlatr   s     r   rN   zIndexRefineFlat.__init__      007Z7Z\`7abr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexRefineFlat_searchr8  s          r   r:  zIndexRefineFlat.search  !    55dAq!YPVX^__r#   r-   )r   r   r6   r7   r   r   r   r   rN   r:  r   delete_IndexRefineFlatr   r$   r#   r   r  r    s7     -/IOdeGHc`&==r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Zd Zd ZddZd Zej8                  Zd Zd Zd Z y)IndexLSHz>The sign of each vector component is put in a binary signaturec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexLSH.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexLSH.<lambda>  rD   r#   rE   rF   znb of bits per vectorz+whether to apply a random rotation to inputz$whether we train thresholds or use 0zoptional random rotationzthresholds to compare withc                 0    t        j                  | ||      S )aP  
         Preprocesses and resizes the input to the size required to
        binarize the data

        :type x: float
        :param x: input vectors, size n * d
        :rtype: float
        :return: output vectors, size n * bits. May be the same pointer
                    as x, otherwise it should be deleted by the caller
        )r   IndexLSH_apply_preprocessr!  s      r   apply_preprocesszIndexLSH.apply_preprocess  s     88q!DDr#   c                 0    t        j                  | ||      S r-   )r   IndexLSH_trainr!  s      r   r"  zIndexLSH.train  s    --dAq99r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexLSH_searchr8  s          r   r:  zIndexLSH.search  s     ..tQ1iQWXXr#   c                 .    t        j                  | |      S )zh
        transfer the thresholds to a pre-processing stage (and unset
        train_thresholds)
        )r   IndexLSH_transfer_thresholds)r   vts     r   transfer_thresholdszIndexLSH.transfer_thresholds  s    
 ;;D"EEr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexLSH_swiginitnew_IndexLSHr   s     r   rN   zIndexLSH.__init__      ))$0L0Ld0STr#   c                 2    t        j                  | |||      S r-   )r   IndexLSH_sa_encoderr  s       r   rs  zIndexLSH.sa_encode  s    11$1eDDr#   c                 2    t        j                  | |||      S r-   )r   IndexLSH_sa_decoderv  s       r   rw  zIndexLSH.sa_decode  s    11$5!DDr#   r-   )!r   r   r6   r7   r   r   r   r   r   IndexLSH_nbits_getIndexLSH_nbits_setr  IndexLSH_rotate_data_getIndexLSH_rotate_data_setrotate_dataIndexLSH_train_thresholds_getIndexLSH_train_thresholds_settrain_thresholdsIndexLSH_rrot_getIndexLSH_rrot_setrrotIndexLSH_thresholds_getIndexLSH_thresholds_set
thresholdsr  r"  r:  r  delete_IndexLSHr   rN   rs  rw  r$   r#   r   r  r    s    I-/IOdeGH_779[9[a}~E?CC_EmEm  tf  gK M MO|O|  Cn  oO557X7X^}~D/AA?CjCj  qR  SJE:YF '66UEEr#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Z eej0                  ej2                        Z eej6                  ej8                        Z eej<                  ej>                        Z d Z!ejD                  Z#y)SimulatedAnnealingParametersz2parameters used for the simulated annealing methodc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z%SimulatedAnnealingParameters.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z%SimulatedAnnealingParameters.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   %SimulatedAnnealingParameters_swiginit new_SimulatedAnnealingParametersrR   s    r   rN   z%SimulatedAnnealingParameters.__init__  r	  r#   N)$r   r   r6   r7   r   r   r   r   r   1SimulatedAnnealingParameters_init_temperature_get1SimulatedAnnealingParameters_init_temperature_setinit_temperature2SimulatedAnnealingParameters_temperature_decay_get2SimulatedAnnealingParameters_temperature_decay_settemperature_decay'SimulatedAnnealingParameters_n_iter_get'SimulatedAnnealingParameters_n_iter_setn_iter'SimulatedAnnealingParameters_n_redo_get'SimulatedAnnealingParameters_n_redo_setn_redo%SimulatedAnnealingParameters_seed_get%SimulatedAnnealingParameters_seed_setr  (SimulatedAnnealingParameters_verbose_get(SimulatedAnnealingParameters_verbose_setr  /SimulatedAnnealingParameters_only_bit_flips_get/SimulatedAnnealingParameters_only_bit_flips_setonly_bit_flips,SimulatedAnnealingParameters_init_random_get,SimulatedAnnealingParameters_init_random_setinit_randomrN   #delete_SimulatedAnnealingParametersr   r$   r#   r   r  r    sL   =-/IOdeGH a acr  de  de  f !c!cet  fh  fh  ioMM  PG  PG  HFoMM  PG  PG  HFOII?  LA  LA  BDOOQ`  RJ  RJ  KGo]]_n  `_  `_  `N?WWYh  ZV  ZV  WKx&JJr#   r  c                       e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Zd Zd Ze	j                  Zy	)
PermutationObjectivez$abstract class for the loss functionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPermutationObjective.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPermutationObjective.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zPermutationObjective.__init__  rO   r#   c                 .    t        j                  | |      S r-   )r   !PermutationObjective_compute_costr  s     r   compute_costz!PermutationObjective.compute_cost  s    @@tLLr#   c                 2    t        j                  | |||      S r-   )r    PermutationObjective_cost_updater   r  iwjws       r   cost_updatez PermutationObjective.cost_update  s    ??dBPRSSr#   N)r   r   r6   r7   r   r   rN   r   r   r   PermutationObjective_n_getPermutationObjective_n_setrW   r  r  delete_PermutationObjectiver   r$   r#   r   r  r    sQ    /-/IOdeGKH;;_=g=ghAMT&BBr#   r  c                   z   e Zd Z ed d d      ZeZ eej                  ej                        Z
ed        Zd Z eej                  ej                  d      Z eej"                  ej$                  d      Z eej(                  ej*                  d	      Zd
 Zd Zd Zd Zed        Zd Zej:                  Zy)ReproduceDistancesObjectivec                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$ReproduceDistancesObjective.<lambda>	  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$ReproduceDistancesObjective.<lambda>	  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r   ReproduceDistancesObjective_sqrr=   s    r   sqrzReproduceDistancesObjective.sqr  s    >>qAAr#   c                 .    t        j                  | |      S r-   )r   &ReproduceDistancesObjective_dis_weightr_   s     r   
dis_weightz&ReproduceDistancesObjective.dis_weight  s    EEdANNr#   z%"real" corrected distances (size n^2)zwanted distances (size n^2)z$weights for each distance (size n^2)c                 0    t        j                  | ||      S r-   )r   *ReproduceDistancesObjective_get_source_disr  s      r   get_source_disz*ReproduceDistancesObjective.get_source_dis  s    II$PQSTUUr#   c                 .    t        j                  | |      S r-   )r   (ReproduceDistancesObjective_compute_costr  s     r   r  z(ReproduceDistancesObjective.compute_cost  rc  r#   c                 2    t        j                  | |||      S r-   )r   'ReproduceDistancesObjective_cost_updater  s       r   r  z'ReproduceDistancesObjective.cost_update  s    FFtTSUWYZZr#   c           	      \    t        j                  | t        j                  ||||             y r-   )r   $ReproduceDistancesObjective_swiginitnew_ReproduceDistancesObjective)r   rW   source_dis_intarget_dis_indis_weight_factors        r   rN   z$ReproduceDistancesObjective.__init__   s:    <<T?CrCrst  wD  FS  Uf  Dg  	hr#   c                 2    t        j                  | |||      S r-   )r   .ReproduceDistancesObjective_compute_mean_stdev)r  r]  mean_out
stddev_outs       r   compute_mean_stdevz.ReproduceDistancesObjective.compute_mean_stdev#  s    MMcSUW_akllr#   c                 .    t        j                  | |      S r-   )r   1ReproduceDistancesObjective_set_affine_target_dis)r   r  s     r   set_affine_target_disz1ReproduceDistancesObjective.set_affine_target_dis'  s    PPQUWdeer#   N)r   r   r6   r   r   r   r   r   1ReproduceDistancesObjective_dis_weight_factor_get1ReproduceDistancesObjective_dis_weight_factor_setr   staticmethodr  r  *ReproduceDistancesObjective_source_dis_get*ReproduceDistancesObjective_source_dis_set
source_dis*ReproduceDistancesObjective_target_dis_get*ReproduceDistancesObjective_target_dis_set
target_dis'ReproduceDistancesObjective_weights_get'ReproduceDistancesObjective_weights_setr  r  r  r  rN   r  r  "delete_ReproduceDistancesObjectiver   r$   r#   r   r  r    s   -/IOdeGH !b!bds  ef  ef  gB BO/TTVe  WQ  WQ  WC  DJ/TTVe  WQ  WQ  Wy  zJNNP_  QH  QH  Ny  zGVT[h m mf&IIr#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                         Zd Z eej&                  ej(                        Z eej,                  ej.                  d      Zd	 Zd
 Zej6                  Zy)SimulatedAnnealingOptimizerz<Simulated annealing optimization algorithm for permutations.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z$SimulatedAnnealingOptimizer.<lambda>0  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z$SimulatedAnnealingOptimizer.<lambda>0  rD   r#   rE   rF   zsize of the permutationc                 X    t        j                  | t        j                  ||             y)z logs values of the cost functionN)r   $SimulatedAnnealingOptimizer_swiginitnew_SimulatedAnnealingOptimizer)r   r  rB
  s      r   rN   z$SimulatedAnnealingOptimizer.__init__6  s!    <<T?CrCrsvxyCz{r#   z%remember initial cost of optimizationc                 .    t        j                  | |      S r-   )r   $SimulatedAnnealingOptimizer_optimizer  s     r   optimizez$SimulatedAnnealingOptimizer.optimize<  s    CCD$OOr#   c                 .    t        j                  | |      S r-   )r   ,SimulatedAnnealingOptimizer_run_optimization)r   	best_perms     r   run_optimizationz,SimulatedAnnealingOptimizer.run_optimization?  s    KKDR[\\r#   N)r   r   r6   r7   r   r   r   r   r   #SimulatedAnnealingOptimizer_obj_get#SimulatedAnnealingOptimizer_obj_setr  !SimulatedAnnealingOptimizer_n_get!SimulatedAnnealingOptimizer_n_setrW   'SimulatedAnnealingOptimizer_logfile_get'SimulatedAnnealingOptimizer_logfile_setlogfilerN   #SimulatedAnnealingOptimizer_rnd_get#SimulatedAnnealingOptimizer_rnd_setrnd)SimulatedAnnealingOptimizer_init_cost_get)SimulatedAnnealingOptimizer_init_cost_set	init_costr  r"  "delete_SimulatedAnnealingOptimizerr   r$   r#   r   r  r  -  s    G-/IOdeGH
?FFH{H{
|CBBODuDu  |Z  	[ANNP_  QH  QH  IG| ?FFH{H{
|CRRTc  UN  UN  T@  AIP]&IIr#   r  c                      e Zd ZdZ ed d d      ZeZej                  Z
ej                  Z	 ej                  Z	  eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                  d      Z eej0                  ej2                  d      Z eej6                  ej8                        Zd	 Zd
 Zd Z d Z!d Z"ejF                  Z$y)PolysemousTrainingz4optimizes the order of indices in a ProductQuantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPolysemousTraining.<lambda>H  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPolysemousTraining.<lambda>H  rD   r#   rE   rF   z
     use 1/4 of the training points for the optimization, with
    max. ntrain_permutation. If ntrain_permutation == 0: train on
    centroids
    z'decay of exp that weights distance lossz@refuse to train if it would require more than that amount of RAMc                 T    t        j                  | t        j                                y r-   )r   PolysemousTraining_swiginitnew_PolysemousTrainingrR   s    r   rN   zPolysemousTraining.__init__\      33D/:`:`:bcr#   c                 2    t        j                  | |||      S )z
        reorder the centroids so that the Hamming distance becomes a
        good approximation of the SDC distance (called by train)
        )r   *PolysemousTraining_optimize_pq_for_hammingr   r  rW   r>   s       r   optimize_pq_for_hammingz*PolysemousTraining.optimize_pq_for_hamming_  s    
 II$PRTUWXYYr#   c                 2    t        j                  | |||      S z!called by optimize_pq_for_hamming)r   #PolysemousTraining_optimize_rankingr;  s       r   optimize_rankingz#PolysemousTraining.optimize_rankingf  s    BB4QPQRRr#   c                 .    t        j                  | |      S r>  )r   /PolysemousTraining_optimize_reproduce_distancesr   r  s     r   optimize_reproduce_distancesz/PolysemousTraining.optimize_reproduce_distancesj  s    NNtUWXXr#   c                 .    t        j                  | |      S )z%make sure we don't blow up the memory)r   *PolysemousTraining_memory_usage_per_threadrC  s     r   memory_usage_per_threadz*PolysemousTraining.memory_usage_per_threadn  s    II$PRSSr#   N)%r   r   r6   r7   r   r   r   r   r   PolysemousTraining_OT_NoneOT_None/PolysemousTraining_OT_ReproduceDistances_affineOT_ReproduceDistances_affine+PolysemousTraining_OT_Ranking_weighted_diffOT_Ranking_weighted_diff(PolysemousTraining_optimization_type_get(PolysemousTraining_optimization_type_setoptimization_type)PolysemousTraining_ntrain_permutation_get)PolysemousTraining_ntrain_permutation_setntrain_permutation(PolysemousTraining_dis_weight_factor_get(PolysemousTraining_dis_weight_factor_setr   !PolysemousTraining_max_memory_get!PolysemousTraining_max_memory_set
max_memory"PolysemousTraining_log_pattern_get"PolysemousTraining_log_pattern_setlog_patternrN   r<  r@  rD  rG  delete_PolysemousTrainingr   r$   r#   r   r2  r2  E  s6   ?-/IOdeGH88G#2#b#b .ZZ !!Y!Y[j  \T  \T  U!/"["[]l  ^W  ^W ] 	
 !!Y!Y[j  \T  \T  ZH  I/KK_M~M~  EL  MJ?MM  PB  PB  CKdZSYT '@@r#   r2  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zdd
Zd Zd Zd Z eej$                  ej&                  d      Z eej*                  ej,                  d      Zej0                  Z	 ej4                  Z	 ej8                  Z	 ej<                  Z	 ej@                  Z!	 ejD                  Z#	  eejH                  ejJ                        Z& eejN                  ejP                        Z) eejT                  ejV                  d      Z,d Z-d Z.d Z/ej`                  Z1y	)IndexPQz_
     Index based on a product quantizer. Stored vectors are
    approximated by PQ codes.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexPQ.<lambda>{  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexPQ.<lambda>{  rD   r#   rE   rF   z0The product quantizer used to encode the vectorsc                 P    t        j                  | t        j                  |        ya  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type M: int
        :param M:      number of subquantizers
        :type nbits: int
        :param nbits:  number of bit per subvector index
        N)r   IndexPQ_swiginitnew_IndexPQr   s     r   rN   zIndexPQ.__init__  s     	((/J/JD/QRr#   c                 0    t        j                  | ||      S r-   )r   IndexPQ_trainr!  s      r   r"  zIndexPQ.train      ,,T1a88r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexPQ_searchr8  s          r   r:  zIndexPQ.search  s     --dAq!YPVWWr#   c                 2    t        j                  | |||      S r-   )r   IndexPQ_sa_encoderr  s       r   rs  zIndexPQ.sa_encode  s    00q!UCCr#   c                 2    t        j                  | |||      S r-   )r   IndexPQ_sa_decoderv  s       r   rw  zIndexPQ.sa_decode  s    00q%CCr#   c                 ,    t        j                  |       S r-   )r   %IndexPQ_get_FlatCodesDistanceComputerrR   s    r   r  z%IndexPQ.get_FlatCodesDistanceComputer  r  r#   zfalse = standard PQz+parameters used for the polysemous trainingz#Hamming threshold used for polysemyc           
      :    t        j                  | |||||||      S r-   )r   IndexPQ_search_core_polysemous)r   rW   r>   rP  rQ  rR  polysemous_htgeneralized_hammings           r   search_core_polysemouszIndexPQ.search_core_polysemous  s.    ==dAq!YX^`m  pC  D  	Dr#   c                 6    t        j                  | |||||      S )a  
        prepare query for a polysemous search, but instead of
        computing the result, just get the histogram of Hamming
        distances. May be computed on a provided dataset if xb != NULL
        :type dist_histogram: int
        :param dist_histogram: (M * nbits + 1)
        )r   "IndexPQ_hamming_distance_histogram)r   rW   r>   rC  rR  dist_histograms         r   hamming_distance_histogramz"IndexPQ.hamming_distance_histogram  s!     AA$1bRTVdeer#   c                 2    t        j                  | |||      S )a  
         compute pairwise distances between queries and database

        :type n: int
        :param n:    nb of query vectors
        :type x: float
        :param x:    query vector, size n * d
        :type dis: int
        :param dis:  output distances, size n * ntotal
        )r   IndexPQ_hamming_distance_table)r   rW   r>   rE  s       r   hamming_distance_tablezIndexPQ.hamming_distance_table  s     ==dAq#NNr#   r-   )2r   r   r6   r7   r   r   r   r   r   IndexPQ_pq_getIndexPQ_pq_setr  rN   r"  r:  rs  rw  r  "IndexPQ_do_polysemous_training_get"IndexPQ_do_polysemous_training_setdo_polysemous_trainingIndexPQ_polysemous_training_getIndexPQ_polysemous_training_setpolysemous_trainingIndexPQ_ST_PQST_PQIndexPQ_ST_HEST_HEIndexPQ_ST_generalized_HEST_generalized_HEIndexPQ_ST_SDCST_SDCIndexPQ_ST_polysemousST_polysemous IndexPQ_ST_polysemous_generalizeST_polysemous_generalizeIndexPQ_search_type_getIndexPQ_search_type_setrV	  IndexPQ_encode_signs_getIndexPQ_encode_signs_setencode_signsIndexPQ_polysemous_ht_getIndexPQ_polysemous_ht_setrr  rt  rx  r{  delete_IndexPQr   r$   r#   r   r^  r^  u  s   
 -/IOdeGH	/00/2P2P  WN  
OBS9XDDK%o&X&XZi  [M  [M  Sm  n"?#R#RTc  UD  UD  J|  }))E1))E$'AA++F,#99M0.OO(?BBODkDklKODDoFnFnoL_FFHqHq  xb  cMDfO '55r#   r^  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zej                   Zy)SearchParametersPQz)override search parameters from the classc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSearchParametersPQ.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSearchParametersPQ.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   SearchParametersPQ_swiginitnew_SearchParametersPQrR   s    r   rN   zSearchParametersPQ.__init__  r8  r#   N)r   r   r6   r7   r   r   r   r   r   "SearchParametersPQ_search_type_get"SearchParametersPQ_search_type_setrV	  $SearchParametersPQ_polysemous_ht_get$SearchParametersPQ_polysemous_ht_setrr  rN   delete_SearchParametersPQr   r$   r#   r   r  r    st    4-/IOdeGH?MM  PB  PB  CK_QQSb  TH  TH  IMd&@@r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zej(                  Zy)	IndexPQStatszs
    statistics are robust to internal threading, but not if
    IndexPQ::search is called by multiple threads
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexPQStats.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexPQStats.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   IndexPQStats_swiginitnew_IndexPQStatsrR   s    r   rN   zIndexPQStats.__init__  rO  r#   c                 ,    t        j                  |       S r-   )r   IndexPQStats_resetrR   s    r   r  zIndexPQStats.reset  r   r#   N)r   r   r6   r7   r   r   r   r   r   IndexPQStats_nq_getIndexPQStats_nq_setr  IndexPQStats_ncode_getIndexPQStats_ncode_setncodeIndexPQStats_n_hamming_pass_getIndexPQStats_n_hamming_pass_setn_hamming_passrN   r  delete_IndexPQStatsr   r$   r#   r   r  r    s~    
 -/IOdeGH	/557Z7Z	[B_;;_=c=cdEoMMO~O~NX8&::r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd ZddZd	 Zd
 Zd Zd Zej$                  Zy)MultiIndexQuantizerze
    Quantizer where centroids are virtual: they are the Cartesian
    product of sub-centroids.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMultiIndexQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMultiIndexQuantizer.<lambda>  rD   r#   rE   rF   c                 0    t        j                  | ||      S r-   )r   MultiIndexQuantizer_trainr!  s      r   r"  zMultiIndexQuantizer.train      88q!DDr#   Nc           	      8    t        j                  | ||||||      S r-   )r   MultiIndexQuantizer_searchr8  s          r   r:  zMultiIndexQuantizer.search  s!    99$1aTZ\bccr#   c                 0    t        j                  | ||      S )z#add and reset will crash at runtime)r   MultiIndexQuantizer_addr!  s      r   r)  zMultiIndexQuantizer.add  r	  r#   c                 ,    t        j                  |       S r-   )r   MultiIndexQuantizer_resetrR   s    r   r  zMultiIndexQuantizer.reset   r  r#   c                 P    t        j                  | t        j                  |        y)z
         number of bit per subvector index
        :type d: int
        :param d: dimension of the input vectors
        :type M: int
        :param M: number of subquantizers
        N)r   MultiIndexQuantizer_swiginitnew_MultiIndexQuantizerr   s     r   rN   zMultiIndexQuantizer.__init__  s      	44T?;b;bdh;ijr#   c                 0    t        j                  | ||      S r-   )r   MultiIndexQuantizer_reconstructrO  s      r   rR  zMultiIndexQuantizer.reconstruct  s    >>tS&QQr#   r-   )r   r   r6   r7   r   r   r   r   r   MultiIndexQuantizer_pq_getMultiIndexQuantizer_pq_setr  r"  r:  r)  r  rN   rR  delete_MultiIndexQuantizerr   r$   r#   r   r  r    sf    
 -/IOdeGH	/<<o>h>h	iBEdC?kR&AAr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                        Zd Zd Zdd
Zej$                  Zy	)MultiIndexQuantizer2zGMultiIndexQuantizer where the PQ assignmnet is performed by sub-indexesc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMultiIndexQuantizer2.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMultiIndexQuantizer2.<lambda>  rD   r#   rE   rF   zM Indexes on d / M dimensionsc                 P    t        j                  | t        j                  |        y r-   )r   MultiIndexQuantizer2_swiginitnew_MultiIndexQuantizer2r   s     r   rN   zMultiIndexQuantizer2.__init__  r
  r#   c                 0    t        j                  | ||      S r-   )r   MultiIndexQuantizer2_trainr!  s      r   r"  zMultiIndexQuantizer2.train  r
  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   MultiIndexQuantizer2_searchr8  s          r   r:  zMultiIndexQuantizer2.search!  !    ::4Aq)U[]cddr#   r-   )r   r   r6   r7   r   r   r   r   r   'MultiIndexQuantizer2_assign_indexes_get'MultiIndexQuantizer2_assign_indexes_setassign_indexes#MultiIndexQuantizer2_own_fields_get#MultiIndexQuantizer2_own_fields_setrM  rN   r"  r:  delete_MultiIndexQuantizer2r   r$   r#   r   r  r    s    R-/IOdeGHoUUWf  XO  XO  Uy  zN/MM  PC  PC  DJmFe&BBr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd ZddZd	 Zd
 Zd Zej"                  Zy)IndexAdditiveQuantizerzKAbstract class for additive quantizers. The search functions are in common.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexAdditiveQuantizer.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexAdditiveQuantizer.<lambda>*  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexAdditiveQuantizer_swiginitnew_IndexAdditiveQuantizerr   s     r   rN   zIndexAdditiveQuantizer.__init__.  r  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexAdditiveQuantizer_searchr8  s          r   r:  zIndexAdditiveQuantizer.search1  !    <<T1aIW]_effr#   c                 2    t        j                  | |||      S r-   )r    IndexAdditiveQuantizer_sa_encoderr  s       r   rs  z IndexAdditiveQuantizer.sa_encode4      ??aERRr#   c                 2    t        j                  | |||      S r-   )r    IndexAdditiveQuantizer_sa_decoderv  s       r   rw  z IndexAdditiveQuantizer.sa_decode7      ??aPQRRr#   c                 ,    t        j                  |       S r-   )r   4IndexAdditiveQuantizer_get_FlatCodesDistanceComputerrR   s    r   r  z4IndexAdditiveQuantizer.get_FlatCodesDistanceComputer:      SSTXYYr#   r-   )r   r   r6   r7   r   r   r   r   r   IndexAdditiveQuantizer_aq_getIndexAdditiveQuantizer_aq_setaqrN   r:  rs  rw  r  delete_IndexAdditiveQuantizerr   r$   r#   r   r  r  '  s]    V-/IOdeGH	/??AnAn	oBqgSSZ&DDr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zej                  Zy	)
IndexResidualQuantizer
     Index based on a residual quantizer. Stored vectors are
    approximated by residual quantization codes.
    Can also be used as a codec
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexResidualQuantizer.<lambda>G  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexResidualQuantizer.<lambda>G  rD   r#   rE   rF   1The residual quantizer used to encode the vectorsc                 P    t        j                  | t        j                  |        ya  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type M: int
        :param M:      number of subquantizers
        :type nbits: int
        :param nbits:  number of bit per subvector index

        :type d: int
        :param d: dimensionality of the input vectors
        :type M: int
        :param M: number of subquantizers
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   IndexResidualQuantizer_swiginitnew_IndexResidualQuantizerr   s     r   rN   zIndexResidualQuantizer.__init__K  s     $ 	77o>h>hjn>opr#   c                 0    t        j                  | ||      S r-   )r   IndexResidualQuantizer_trainr!  s      r   r"  zIndexResidualQuantizer.train_      ;;D!QGGr#   N)r   r   r6   r7   r   r   r   r   r   IndexResidualQuantizer_rq_getIndexResidualQuantizer_rq_setrx	  rN   r"  delete_IndexResidualQuantizerr   r$   r#   r   r  r  @  sY     -/IOdeGH	/??AnAn  um  
nBq(H&DDr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)IndexLocalSearchQuantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"IndexLocalSearchQuantizer.<lambda>f  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"IndexLocalSearchQuantizer.<lambda>f  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        yr  )r   "IndexLocalSearchQuantizer_swiginitnew_IndexLocalSearchQuantizerr   s     r   rN   z"IndexLocalSearchQuantizer.__init__j  s     $ 	::4AnAnptAuvr#   c                 0    t        j                  | ||      S r-   )r   IndexLocalSearchQuantizer_trainr!  s      r   r"  zIndexLocalSearchQuantizer.train~  s    >>tQJJr#   N)r   r   r6   r   r   r   r   r   !IndexLocalSearchQuantizer_lsq_get!IndexLocalSearchQuantizer_lsq_setr^
  rN   r"   delete_IndexLocalSearchQuantizerr   r$   r#   r   r  r  e  sH    -/IOdeGH
?DDoFwFw
xCw(K&GGr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zej                  Zy	)
IndexProductResidualQuantizerz,Index based on a product residual quantizer.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z&IndexProductResidualQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z&IndexProductResidualQuantizer.<lambda>  rD   r#   rE   rF   9The product residual quantizer used to encode the vectorsc                 P    t        j                  | t        j                  |        y)a  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of residual quantizers
        :type Msub: int
        :param Msub:      number of subquantizers per RQ
        :type nbits: int
        :param nbits:  number of bit per subvector index

        :type d: int
        :param d: dimensionality of the input vectors
        :type nsplits: int
        :param nsplits: number of residual quantizers
        :type Msub: int
        :param Msub: number of subquantizers per RQ
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   &IndexProductResidualQuantizer_swiginit!new_IndexProductResidualQuantizerr   s     r   rN   z&IndexProductResidualQuantizer.__init__  s     , 	>>t_EvEvx|E}~r#   c                 0    t        j                  | ||      S r-   )r   #IndexProductResidualQuantizer_trainr!  s      r   r"  z#IndexProductResidualQuantizer.train  s    BB4ANNr#   N)r   r   r6   r7   r   r   r   r   r   %IndexProductResidualQuantizer_prq_get%IndexProductResidualQuantizer_prq_setprqrN   r"  $delete_IndexProductResidualQuantizerr   r$   r#   r   r  r    sU    7-/IOdeGH
?HH/JJ  FF  GC0O&KKr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zej                  Zy	)
 IndexProductLocalSearchQuantizerz0Index based on a product local search quantizer.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z)IndexProductLocalSearchQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z)IndexProductLocalSearchQuantizer.<lambda>  rD   r#   rE   rF   =The product local search quantizer used to encode the vectorsc                 P    t        j                  | t        j                  |        y)a  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of local search quantizers
        :type Msub: int
        :param Msub:     number of subquantizers per LSQ
        :type nbits: int
        :param nbits:  number of bit per subvector index

        :type d: int
        :param d: dimensionality of the input vectors
        :type nsplits: int
        :param nsplits: number of local search quantizers
        :type Msub: int
        :param Msub: number of subquantizers per LSQ
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   )IndexProductLocalSearchQuantizer_swiginit$new_IndexProductLocalSearchQuantizerr   s     r   rN   z)IndexProductLocalSearchQuantizer.__init__  s+    , 	AA$H|H|  C  ID  	Er#   c                 0    t        j                  | ||      S r-   )r   &IndexProductLocalSearchQuantizer_trainr!  s      r   r"  z&IndexProductLocalSearchQuantizer.train  s    EEdAqQQr#   N)r   r   r6   r7   r   r   r   r   r   )IndexProductLocalSearchQuantizer_plsq_get)IndexProductLocalSearchQuantizer_plsq_setplsqrN   r"  'delete_IndexProductLocalSearchQuantizerr   r$   r#   r   r  r    s]    ;-/IOdeGHOMM  PI  PI  OS  TDE0R&NNr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Z eej                  ej                  d      Zd Zdd
Zd Zd Zd Zej*                  Zy	)AdditiveCoarseQuantizerz
     A "virtual" index where the elements are the residual quantizer centroids.

    Intended for use as a coarse quantizer in an IndexIVF.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z AdditiveCoarseQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z AdditiveCoarseQuantizer.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r    AdditiveCoarseQuantizer_swiginitnew_AdditiveCoarseQuantizerr   s     r   rN   z AdditiveCoarseQuantizer.__init__  r  r#   z)norms of centroids, useful for knn-searchc                 0    t        j                  | ||      S zN/A)r   AdditiveCoarseQuantizer_addr!  s      r   r)  zAdditiveCoarseQuantizer.add  s    ::4AFFr#   Nc           	      8    t        j                  | ||||||      S r-   )r   AdditiveCoarseQuantizer_searchr8  s          r   r:  zAdditiveCoarseQuantizer.search  !    ==dAq!YX^`fggr#   c                 0    t        j                  | ||      S r-   )r   #AdditiveCoarseQuantizer_reconstructrO  s      r   rR  z#AdditiveCoarseQuantizer.reconstruct  s    BB4fUUr#   c                 0    t        j                  | ||      S r-   )r   AdditiveCoarseQuantizer_trainr!  s      r   r"  zAdditiveCoarseQuantizer.train  s    <<T1aHHr#   c                 ,    t        j                  |       S r4  )r   AdditiveCoarseQuantizer_resetrR   s    r   r  zAdditiveCoarseQuantizer.reset      <<TBBr#   r-   )r   r   r6   r7   r   r   r   r   r   AdditiveCoarseQuantizer_aq_getAdditiveCoarseQuantizer_aq_setr  rN   *AdditiveCoarseQuantizer_centroid_norms_get*AdditiveCoarseQuantizer_centroid_norms_setr	  r)  r:  rR  r"  r  delete_AdditiveCoarseQuantizerr   r$   r#   r   r-  r-    s     -/IOdeGH	/@@/BpBp	qBsoXXZi  [U  [U  [K  LNGhVIC 'EEr#   r-  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
ej                  Zd Zy)'SearchParametersResidualCoarseQuantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z0SearchParametersResidualCoarseQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z0SearchParametersResidualCoarseQuantizer.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   0SearchParametersResidualCoarseQuantizer_swiginit+new_SearchParametersResidualCoarseQuantizerrR   s    r   rN   z0SearchParametersResidualCoarseQuantizer.__init__  s*    HH  PK  PK  PM  	Nr#   N)r   r   r6   r   r   r   r   r   7SearchParametersResidualCoarseQuantizer_beam_factor_get7SearchParametersResidualCoarseQuantizer_beam_factor_setbeam_factor.delete_SearchParametersResidualCoarseQuantizerr   rN   r$   r#   r   rF  rF    sN    -/IOdeGH?bbds  el  el  mK&UUNr#   rF  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Zd Zdd
Zd Zd Zej&                  Zy	)ResidualCoarseQuantizerz
     The ResidualCoarseQuantizer is a bit specialized compared to the
    default AdditiveCoarseQuantizer because it can use a beam search
    at search time (slow but may be useful for very large vocabularies)
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z ResidualCoarseQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z ResidualCoarseQuantizer.<lambda>  rD   r#   rE   rF   r  ze
    factor between the beam size and the search k
    if negative, use exact search-to-centroid
    c                 .    t        j                  | |      S )z#computes centroid norms if required)r   'ResidualCoarseQuantizer_set_beam_factor)r   new_beam_factors     r   set_beam_factorz'ResidualCoarseQuantizer.set_beam_factor  s    FFt_]]r#   Nc           	      8    t        j                  | ||||||      S r-   )r   ResidualCoarseQuantizer_searchr8  s          r   r:  zResidualCoarseQuantizer.search  r8  r#   c                 .    t        j                  | |      S )z
         Copy the M first codebook levels from other. Useful to crop a
        ResidualQuantizer to its first M quantizers.
        )r   'ResidualCoarseQuantizer_initialize_fromr   s     r   r	  z'ResidualCoarseQuantizer.initialize_from  s    
 FFtUSSr#   c                 P    t        j                  | t        j                  |        yr  )r    ResidualCoarseQuantizer_swiginitnew_ResidualCoarseQuantizerr   s     r   rN   z ResidualCoarseQuantizer.__init__  s     $ 	88?j?jlp?qrr#   r-   )r   r   r6   r7   r   r   r   r   r   ResidualCoarseQuantizer_rq_getResidualCoarseQuantizer_rq_setrx	  'ResidualCoarseQuantizer_beam_factor_get'ResidualCoarseQuantizer_beam_factor_setrN  rW  r:  r	  rN   delete_ResidualCoarseQuantizerr   r$   r#   r   rQ  rQ    s     -/IOdeGH	/@@/BpBp  wo  
pB?RRTc  UL  UL R 	K
^hTs& 'EEr#   rQ  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
d Zej                  Zy)LocalSearchCoarseQuantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z#LocalSearchCoarseQuantizer.<lambda>1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z#LocalSearchCoarseQuantizer.<lambda>1  rD   r#   rE   rF   r  c                 P    t        j                  | t        j                  |        yr  )r   #LocalSearchCoarseQuantizer_swiginitnew_LocalSearchCoarseQuantizerr   s     r   rN   z#LocalSearchCoarseQuantizer.__init__5  s     $ 	;;D/BpBprvBwxr#   N)r   r   r6   r   r   r   r   r   "LocalSearchCoarseQuantizer_lsq_get"LocalSearchCoarseQuantizer_lsq_setr^
  rN   !delete_LocalSearchCoarseQuantizerr   r$   r#   r   re  re  0  sN    -/IOdeGH
?EEGyGy  @x  yCy& 'HHr#   re  c                   ^    e Zd ZdZ ed d d      Zd ZeZe	j                  Zd Zd Zd	 Zy
)InvertedListsIteratorz_
    Definition of inverted lists + a few common classes that implement
    the interface.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInvertedListsIterator.<lambda>R  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInvertedListsIterator.<lambda>R  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zInvertedListsIterator.__init__T  rO   r#   c                 ,    t        j                  |       S r-   )r   "InvertedListsIterator_is_availablerR   s    r   is_availablez"InvertedListsIterator.is_availableY  r  r#   c                 ,    t        j                  |       S r-   )r   InvertedListsIterator_nextrR   s    r   rk   zInvertedListsIterator.next\  r  r#   c                 ,    t        j                  |       S r-   )r   &InvertedListsIterator_get_id_and_codesrR   s    r   get_id_and_codesz&InvertedListsIterator.get_id_and_codes_      EEdKKr#   N)r   r   r6   r7   r   r   rN   r   r   r   delete_InvertedListsIteratorr   ru  rk   rz  r$   r#   r   ro  ro  L  sC    
 -/IOdeGKH&CCH@Lr#   ro  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Ze	j&                  Ze	j*                  Z	 d
 Zd Zd Zd Zd Zd Zd Zd Zd dZd dZ d dZ!d Z"d Z#d Z$d Z%d Z&d Z'e	jP                  Z)e	jT                  Z+e	jX                  Z-e	j\                  Z/e	j`                  Z1d Z2d Z3d Z4d Z5y)!InvertedListsz
     Table of inverted lists
    multithreading rules:
    - concurrent read accesses are allowed
    - concurrent update accesses are allowed
    - for resize and add_entries, only concurrent access to different lists
      are allowed
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInvertedLists.<lambda>n  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInvertedLists.<lambda>n  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zInvertedLists.__init__p  rO   r#   number of possible key valuescode size per vector in bytesz7request to use iterator rather than get_codes / get_idsc                 .    t        j                  | |      S )zget the size of a list)r   InvertedLists_list_sizer   list_nos     r   	list_sizezInvertedLists.list_size}  s    66tWEEr#   c                 .    t        j                  | |      S )z
         get the codes for an inverted list
        must be released by release_codes

        :rtype: uint8_t
        :return: codes    size list_size * code_size
        )r   InvertedLists_get_codesr  s     r   	get_codeszInvertedLists.get_codes  s     66tWEEr#   c                 .    t        j                  | |      S )z
         get the ids for an inverted list
        must be released by release_ids

        :rtype: int
        :return: ids      size list_size
        )r   InvertedLists_get_idsr  s     r   get_idszInvertedLists.get_ids  s     44T7CCr#   c                 0    t        j                  | ||      S )zBrelease codes returned by get_codes (default implementation is nop)r   InvertedLists_release_codesr   r  r  s      r   release_codeszInvertedLists.release_codes  s    ::4%PPr#   c                 0    t        j                  | ||      S )zrelease ids returned by get_ids)r   InvertedLists_release_idsr   r  r{  s      r   release_idszInvertedLists.release_ids  s    88wLLr#   c                 0    t        j                  | ||      S )zN
        :rtype: int
        :return: a single id in an inverted list
        )r   InvertedLists_get_single_idr   r  r}  s      r   get_single_idzInvertedLists.get_single_id  s    
 ::4&QQr#   c                 0    t        j                  | ||      S )z
        :rtype: uint8_t
        :return: a single code in an inverted list
            (should be deallocated with release_codes)
        )r   InvertedLists_get_single_coder  s      r   get_single_codezInvertedLists.get_single_code  s     <<T7FSSr#   c                 0    t        j                  | ||      S )zs
        prepare the following lists (default does nothing)
        a list can be -1 hence the signed long
        )r   InvertedLists_prefetch_listsr   list_nosnlists      r   prefetch_listszInvertedLists.prefetch_lists  s    
 ;;D(ERRr#   Nc                 0    t        j                  | ||      S )zcheck if the list is empty)r   InvertedLists_is_emptyr   r  inverted_list_contexts      r   is_emptyzInvertedLists.is_empty  s    55dGEZ[[r#   c                 0    t        j                  | ||      S )z(get iterable for lists that use_iterator)r   InvertedLists_get_iteratorr  s      r   get_iteratorzInvertedLists.get_iterator  s    99$I^__r#   c                 4    t        j                  | ||||      S )z!add one entry to an inverted list)r   InvertedLists_add_entry)r   r  theidr   r  s        r   	add_entryzInvertedLists.add_entry  s    66tWeTShiir#   c                 4    t        j                  | ||||      S r-   )r   InvertedLists_add_entriesr   r  n_entryr{  r   s        r   add_entrieszInvertedLists.add_entries  s    88wQTVZ[[r#   c                 4    t        j                  | ||||      S r-   )r   InvertedLists_update_entry)r   r  r}  idr   s        r   update_entryzInvertedLists.update_entry  s    99$QSUYZZr#   c                 6    t        j                  | |||||      S r-   )r   InvertedLists_update_entriesr   r  r}  r  r{  r   s         r   update_entrieszInvertedLists.update_entries  s     ;;D'6SZ\_aeffr#   c                 0    t        j                  | ||      S r-   )r   InvertedLists_resizer   r  new_sizes      r   r   zInvertedLists.resize  s    33D'8LLr#   c                 ,    t        j                  |       S r-   )r   InvertedLists_resetrR   s    r   r  zInvertedLists.reset  rh   r#   c                 0    t        j                  | ||      S )z,move all entries from oivf (empty on output))r   InvertedLists_merge_from)r   oivfr}  s      r   r~  zInvertedLists.merge_from  s    77dFKKr#   c                 4    t        j                  | ||||      S )z
         copy a subset of the entries index to the other index
        :rtype: int
        :return: number of entries copied
        )r   InvertedLists_copy_subset_tor   r   subset_typea1a2s        r   copy_subset_tozInvertedLists.copy_subset_to  s     ;;D%VXZ\]]r#   c                 ,    t        j                  |       S )z%1= perfectly balanced, >1: imbalanced)r   InvertedLists_imbalance_factorrR   s    r   r  zInvertedLists.imbalance_factor  s    ==dCCr#   c                 ,    t        j                  |       S )z+display some stats about the inverted lists)r   InvertedLists_print_statsrR   s    r   print_statszInvertedLists.print_stats      88>>r#   c                 ,    t        j                  |       S )zsum up list sizes)r   InvertedLists_compute_ntotalrR   s    r   compute_ntotalzInvertedLists.compute_ntotal  s    ;;DAAr#   r-   )6r   r   r6   r7   r   r   rN   r   r   r   InvertedLists_nlist_getInvertedLists_nlist_setr  InvertedLists_code_size_getInvertedLists_code_size_setr!  InvertedLists_use_iterator_getInvertedLists_use_iterator_setuse_iteratordelete_InvertedListsr   InvertedLists_INVALID_CODE_SIZEINVALID_CODE_SIZEr  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r~  "InvertedLists_SUBSET_TYPE_ID_RANGESUBSET_TYPE_ID_RANGE InvertedLists_SUBSET_TYPE_ID_MODSUBSET_TYPE_ID_MOD'InvertedLists_SUBSET_TYPE_ELEMENT_RANGESUBSET_TYPE_ELEMENT_RANGE*InvertedLists_SUBSET_TYPE_INVLIST_FRACTIONSUBSET_TYPE_INVLIST_FRACTION!InvertedLists_SUBSET_TYPE_INVLISTSUBSET_TYPE_INVLISTr  r  r  r  r$   r#   r   r~  r~  d  sb    -/IOdeGKH_<<o>e>e  lP  QEDDoFqFq  x\  ]IOJJOLzLz  A  @L&;;'GG
FFDQMRTS\`j\[gM9L +MM(II / W W#2#]#] )KK^D?Br#   r~  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Zd Zd Zd	 Zd
 Zd Zd Zd Zd ZddZej0                  Zy)ArrayInvertedListsz=simple (default) implementation as an array of inverted listsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zArrayInvertedLists.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zArrayInvertedLists.<lambda>  rD   r#   rE   rF   zInverted lists for indexesc                 X    t        j                  | t        j                  ||             y r-   )r   ArrayInvertedLists_swiginitnew_ArrayInvertedLists)r   r  r!  s      r   rN   zArrayInvertedLists.__init__  s!    33D/:`:`afhq:rsr#   c                 .    t        j                  | |      S r-   )r   ArrayInvertedLists_list_sizer  s     r   r  zArrayInvertedLists.list_size      ;;D'JJr#   c                 .    t        j                  | |      S r-   )r   ArrayInvertedLists_get_codesr  s     r   r  zArrayInvertedLists.get_codes  r  r#   c                 .    t        j                  | |      S r-   )r   ArrayInvertedLists_get_idsr  s     r   r  zArrayInvertedLists.get_ids      99$HHr#   c                 4    t        j                  | ||||      S r-   )r   ArrayInvertedLists_add_entriesr  s        r   r  zArrayInvertedLists.add_entries      ==dGWVY[_``r#   c                 6    t        j                  | |||||      S r-   )r   !ArrayInvertedLists_update_entriesr  s         r   r  z!ArrayInvertedLists.update_entries  s!    @@wPVX_adfjkkr#   c                 0    t        j                  | ||      S r-   )r   ArrayInvertedLists_resizer  s      r   r   zArrayInvertedLists.resize      88wQQr#   c                 .    t        j                  | |      S )z5permute the inverted lists, map maps new_id to old_id)r   #ArrayInvertedLists_permute_invlistsr   r  s     r   permute_invlistsz#ArrayInvertedLists.permute_invlists
  r  r#   Nc                 0    t        j                  | ||      S r-   )r   ArrayInvertedLists_is_emptyr  s      r   r  zArrayInvertedLists.is_empty  s    ::4J_``r#   r-   )r   r   r6   r7   r   r   r   r   r   ArrayInvertedLists_codes_getArrayInvertedLists_codes_setr  ArrayInvertedLists_ids_getArrayInvertedLists_ids_setr{  rN   r  r  r  r  r  r   r  r  delete_ArrayInvertedListsr   r$   r#   r   r  r    s    H-/IOdeGH_AA?CoCopE
?==?i?i  pQ  RCtKKIalRNa&@@r#   r  c                   ^    e Zd ZdZ ed d d      Zd ZeZd Z	d Z
d	 Zej                  Zy
)ReadOnlyInvertedListsz*invlists that fail for all write functionsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zReadOnlyInvertedLists.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zReadOnlyInvertedLists.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zReadOnlyInvertedLists.__init__  rO   r#   c                 4    t        j                  | ||||      S r-   )r   !ReadOnlyInvertedLists_add_entriesr  s        r   r  z!ReadOnlyInvertedLists.add_entries  s    @@wPWY\^bccr#   c                 6    t        j                  | |||||      S r-   )r   $ReadOnlyInvertedLists_update_entriesr  s         r   r  z$ReadOnlyInvertedLists.update_entries   s!    CCD'SY[bdgimnnr#   c                 0    t        j                  | ||      S r-   )r   ReadOnlyInvertedLists_resizer  s      r   r   zReadOnlyInvertedLists.resize#  s    ;;D'8TTr#   N)r   r   r6   r7   r   r   rN   r   r   r  r  r   r   delete_ReadOnlyInvertedListsr   r$   r#   r   r  r    s?    5-/IOdeGKHdoU&CCr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zej*                  Zy)HStackInvertedListsz"Horizontal stack of inverted listsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zHStackInvertedLists.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zHStackInvertedLists.<lambda>,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             yz0build InvertedLists by concatenating nil of themN)r   HStackInvertedLists_swiginitnew_HStackInvertedListsr   nililss      r   rN   zHStackInvertedLists.__init__0  !    44T?;b;bcfhk;lmr#   c                 .    t        j                  | |      S r-   )r   HStackInvertedLists_list_sizer  s     r   r  zHStackInvertedLists.list_size4      <<T7KKr#   c                 .    t        j                  | |      S r-   )r   HStackInvertedLists_get_codesr  s     r   r  zHStackInvertedLists.get_codes7  r&  r#   c                 .    t        j                  | |      S r-   )r   HStackInvertedLists_get_idsr  s     r   r  zHStackInvertedLists.get_ids:      ::4IIr#   c                 0    t        j                  | ||      S r-   )r   "HStackInvertedLists_prefetch_listsr  s      r   r  z"HStackInvertedLists.prefetch_lists=      AA$RWXXr#   c                 0    t        j                  | ||      S r-   )r   !HStackInvertedLists_release_codesr  s      r   r  z!HStackInvertedLists.release_codes@      @@wPUVVr#   c                 0    t        j                  | ||      S r-   )r   HStackInvertedLists_release_idsr  s      r   r  zHStackInvertedLists.release_idsC      >>tWcRRr#   c                 0    t        j                  | ||      S r-   )r   !HStackInvertedLists_get_single_idr  s      r   r  z!HStackInvertedLists.get_single_idF      @@wPVWWr#   c                 0    t        j                  | ||      S r-   )r   #HStackInvertedLists_get_single_coder  s      r   r  z#HStackInvertedLists.get_single_codeI      BB4RXYYr#   N)r   r   r6   r7   r   r   r   r   r   HStackInvertedLists_ils_getHStackInvertedLists_ils_setr"  rN   r  r  r  r  r  r  r  r  delete_HStackInvertedListsr   r$   r#   r   r  r  )  su    --/IOdeGH
?>>@k@k
lCnLLJYWSXZ&AAr#   r  c                   *   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zej6                  Zy)SliceInvertedListsz2vertical slice of indexes in another InvertedListsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSliceInvertedLists.<lambda>R  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSliceInvertedLists.<lambda>R  rD   r#   rE   rF   c                 Z    t        j                  | t        j                  |||             y r-   )r   SliceInvertedLists_swiginitnew_SliceInvertedLists)r   ilrY  i1s       r   rN   zSliceInvertedLists.__init__X  s$    33D/:`:`acegik:lmr#   c                 .    t        j                  | |      S r-   )r   SliceInvertedLists_list_sizer  s     r   r  zSliceInvertedLists.list_size[  r  r#   c                 .    t        j                  | |      S r-   )r   SliceInvertedLists_get_codesr  s     r   r  zSliceInvertedLists.get_codes^  r  r#   c                 .    t        j                  | |      S r-   )r   SliceInvertedLists_get_idsr  s     r   r  zSliceInvertedLists.get_idsa  r  r#   c                 0    t        j                  | ||      S r-   )r    SliceInvertedLists_release_codesr  s      r   r  z SliceInvertedLists.release_codesd  s    ??guUUr#   c                 0    t        j                  | ||      S r-   )r   SliceInvertedLists_release_idsr  s      r   r  zSliceInvertedLists.release_idsg  s    ==dGSQQr#   c                 0    t        j                  | ||      S r-   )r    SliceInvertedLists_get_single_idr  s      r   r  z SliceInvertedLists.get_single_idj  s    ??gvVVr#   c                 0    t        j                  | ||      S r-   )r   "SliceInvertedLists_get_single_coder  s      r   r  z"SliceInvertedLists.get_single_codem  s    AA$QWXXr#   c                 0    t        j                  | ||      S r-   )r   !SliceInvertedLists_prefetch_listsr  s      r   r  z!SliceInvertedLists.prefetch_listsp  s    @@xQVWWr#   N)r   r   r6   r7   r   r   r   r   r   SliceInvertedLists_il_getSliceInvertedLists_il_setrE  SliceInvertedLists_i0_getSliceInvertedLists_i0_setrY  SliceInvertedLists_i1_getSliceInvertedLists_i1_setrF  rN   r  r  r  r  r  r  r  r  delete_SliceInvertedListsr   r$   r#   r   r?  r?  O  s    =-/IOdeGH	/;;_=f=f	gB	/;;_=f=f	gB	/;;_=f=f	gBnKKIVRWYX&@@r#   r?  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zej.                  Zy)VStackInvertedListsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVStackInvertedLists.<lambda>w  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVStackInvertedLists.<lambda>w  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             yr  )r   VStackInvertedLists_swiginitnew_VStackInvertedListsr   s      r   rN   zVStackInvertedLists.__init__|  r#  r#   c                 .    t        j                  | |      S r-   )r   VStackInvertedLists_list_sizer  s     r   r  zVStackInvertedLists.list_size  r&  r#   c                 .    t        j                  | |      S r-   )r   VStackInvertedLists_get_codesr  s     r   r  zVStackInvertedLists.get_codes  r&  r#   c                 .    t        j                  | |      S r-   )r   VStackInvertedLists_get_idsr  s     r   r  zVStackInvertedLists.get_ids  r+  r#   c                 0    t        j                  | ||      S r-   )r   !VStackInvertedLists_release_codesr  s      r   r  z!VStackInvertedLists.release_codes  r1  r#   c                 0    t        j                  | ||      S r-   )r   VStackInvertedLists_release_idsr  s      r   r  zVStackInvertedLists.release_ids  r4  r#   c                 0    t        j                  | ||      S r-   )r   !VStackInvertedLists_get_single_idr  s      r   r  z!VStackInvertedLists.get_single_id  r7  r#   c                 0    t        j                  | ||      S r-   )r   #VStackInvertedLists_get_single_coder  s      r   r  z#VStackInvertedLists.get_single_code  r:  r#   c                 0    t        j                  | ||      S r-   )r   "VStackInvertedLists_prefetch_listsr  s      r   r  z"VStackInvertedLists.prefetch_lists  r.  r#   N)r   r   r6   r   r   r   r   r   VStackInvertedLists_ils_getVStackInvertedLists_ils_setr"  VStackInvertedLists_cumsz_getVStackInvertedLists_cumsz_setcumszrN   r  r  r  r  r  r  r  r  delete_VStackInvertedListsr   r$   r#   r   r_  r_  v  s    -/IOdeGH
?>>@k@k
lC_BBODqDqrEnLLJWSXZY&AAr#   r_  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zej0                  Zy)MaskedInvertedListsz
     use the first inverted lists if they are non-empty otherwise use the second

    This is useful if il1 has a few inverted lists that are too long,
    and that il0 has replacement lists for those, with empty lists for
    the others.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMaskedInvertedLists.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMaskedInvertedLists.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   MaskedInvertedLists_swiginitnew_MaskedInvertedLists)r   il0il1s      r   rN   zMaskedInvertedLists.__init__  s!    44T?;b;bcfhk;lmr#   c                 .    t        j                  | |      S r-   )r   MaskedInvertedLists_list_sizer  s     r   r  zMaskedInvertedLists.list_size  r&  r#   c                 .    t        j                  | |      S r-   )r   MaskedInvertedLists_get_codesr  s     r   r  zMaskedInvertedLists.get_codes  r&  r#   c                 .    t        j                  | |      S r-   )r   MaskedInvertedLists_get_idsr  s     r   r  zMaskedInvertedLists.get_ids  r+  r#   c                 0    t        j                  | ||      S r-   )r   !MaskedInvertedLists_release_codesr  s      r   r  z!MaskedInvertedLists.release_codes  r1  r#   c                 0    t        j                  | ||      S r-   )r   MaskedInvertedLists_release_idsr  s      r   r  zMaskedInvertedLists.release_ids  r4  r#   c                 0    t        j                  | ||      S r-   )r   !MaskedInvertedLists_get_single_idr  s      r   r  z!MaskedInvertedLists.get_single_id  r7  r#   c                 0    t        j                  | ||      S r-   )r   #MaskedInvertedLists_get_single_coder  s      r   r  z#MaskedInvertedLists.get_single_code  r:  r#   c                 0    t        j                  | ||      S r-   )r   "MaskedInvertedLists_prefetch_listsr  s      r   r  z"MaskedInvertedLists.prefetch_lists  r.  r#   N)r   r   r6   r7   r   r   r   r   r   MaskedInvertedLists_il0_getMaskedInvertedLists_il0_setr  MaskedInvertedLists_il1_getMaskedInvertedLists_il1_setr  rN   r  r  r  r  r  r  r  r  delete_MaskedInvertedListsr   r$   r#   r   r|  r|    s     -/IOdeGH
?>>@k@k
lC
?>>@k@k
lCnLLJWSXZY&AAr#   r|  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zej0                  Zy)StopWordsInvertedListszr
    if the inverted list in il is smaller than maxsize then return it,
    otherwise return an empty invlist
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zStopWordsInvertedLists.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zStopWordsInvertedLists.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   StopWordsInvertedLists_swiginitnew_StopWordsInvertedLists)r   rE  maxsizes      r   rN   zStopWordsInvertedLists.__init__  s!    77o>h>hikmt>uvr#   c                 .    t        j                  | |      S r-   )r    StopWordsInvertedLists_list_sizer  s     r   r  z StopWordsInvertedLists.list_size      ??gNNr#   c                 .    t        j                  | |      S r-   )r    StopWordsInvertedLists_get_codesr  s     r   r  z StopWordsInvertedLists.get_codes  r  r#   c                 .    t        j                  | |      S r-   )r   StopWordsInvertedLists_get_idsr  s     r   r  zStopWordsInvertedLists.get_ids  s    ==dGLLr#   c                 0    t        j                  | ||      S r-   )r   $StopWordsInvertedLists_release_codesr  s      r   r  z$StopWordsInvertedLists.release_codes  s    CCD'SXYYr#   c                 0    t        j                  | ||      S r-   )r   "StopWordsInvertedLists_release_idsr  s      r   r  z"StopWordsInvertedLists.release_ids  s    AA$QTUUr#   c                 0    t        j                  | ||      S r-   )r   $StopWordsInvertedLists_get_single_idr  s      r   r  z$StopWordsInvertedLists.get_single_id  s    CCD'SYZZr#   c                 0    t        j                  | ||      S r-   )r   &StopWordsInvertedLists_get_single_coder  s      r   r  z&StopWordsInvertedLists.get_single_code  s    EEdGU[\\r#   c                 0    t        j                  | ||      S r-   )r   %StopWordsInvertedLists_prefetch_listsr  s      r   r  z%StopWordsInvertedLists.prefetch_lists  s    DDT8UZ[[r#   N)r   r   r6   r7   r   r   r   r   r   StopWordsInvertedLists_il0_getStopWordsInvertedLists_il0_setr  "StopWordsInvertedLists_maxsize_get"StopWordsInvertedLists_maxsize_setr  rN   r  r  r  r  r  r  r  r  delete_StopWordsInvertedListsr   r$   r#   r   r  r    s    
 -/IOdeGH
?AA?CqCq
rCII?K}K}~GwOOMZV[]\&DDr#   r  c                       e Zd ZdZ ed d d      Zd ZeZ ee	j                  d      Z ee	j                  d      Zd	 Zd
 Zd Ze	j"                  Zed        Zed        Zed        Zed        Zy)InvertedListsIOHooka  
     Callbacks to handle other types of InvertedList objects.

    The callbacks should be registered with add_callback before calling
    read_index or read_InvertedLists. The callbacks for
    OnDiskInvertedLists are registrered by default. The invlist type is
    identified by:

    - the key (a fourcc) at read time
    - the class name (as given by typeid.name) at write time
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInvertedListsIOHook.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInvertedListsIOHook.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zInvertedListsIOHook.__init__  rO   r#   zstring version of the fourccztypeid.namec                 0    t        j                  | ||      S )z6write the index to the IOWriter (including the fourcc))r   InvertedListsIOHook_write)r   r"  r$  s      r   r&  zInvertedListsIOHook.write  s    88sAFFr#   c                 0    t        j                  | ||      S )z2called when the fourcc matches this class's fourcc)r   InvertedListsIOHook_read)r   r$  io_flagss      r   r8  zInvertedListsIOHook.read	  s    77aJJr#   c                 6    t        j                  | |||||      S )a  
         read from a ArrayInvertedLists into this invertedlist type.
        For this to work, the callback has to be enabled and the io_flag has to
        be set to IO_FLAG_SKIP_IVF_DATA | (16 upper bits of the fourcc)

        (default implementation fails)
        )r   +InvertedListsIOHook_read_ArrayInvertedLists)r   r$  r  r  r!  sizess         r   read_ArrayInvertedListsz+InvertedListsIOHook.read_ArrayInvertedLists  s$     JJ4QRT\^cenpuvvr#   c                 ,    t        j                  |       S r-   )r    InvertedListsIOHook_add_callbackarg1s    r   add_callbackz InvertedListsIOHook.add_callback      ??EEr#   c                  *    t        j                         S r-   )r   #InvertedListsIOHook_print_callbacksr$   r#   r   print_callbacksz#InvertedListsIOHook.print_callbacks  s    BBDDr#   c                 ,    t        j                  |       S r-   )r   InvertedListsIOHook_lookup)hs    r   lookupzInvertedListsIOHook.lookup   s    99!<<r#   c                 ,    t        j                  |       S r-   )r   $InvertedListsIOHook_lookup_classname)	classnames    r   lookup_classnamez$InvertedListsIOHook.lookup_classname$  s    CCINNr#   N)r   r   r6   r7   r   r   rN   r   r   r   InvertedListsIOHook_key_getrP  !InvertedListsIOHook_classname_getr  r&  r8  r  delete_InvertedListsIOHookr   r  r  r  r  r  r$   r#   r   r  r    s    
 -/IOdeGKH
?>>Dg
hCJJPbcIGKw 'AAF F E E = = O Or#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zej@                  Z!y)BlockInvertedListsaZ  
     Inverted Lists that are organized by blocks.

    Different from the regular inverted lists, the codes are organized by blocks
    of size block_size bytes that reprsent a set of n_per_block. Therefore, code
    allocations are always rounded up to block_size bytes. The codes are also
    aligned on 32-byte boundaries for use with SIMD.

    To avoid misinterpretations, the code_size is set to (size_t)(-1), even if
    arguably the amount of memory consumed by code is block_size / n_per_block.

    The writing functions add_entries and update_entries operate on block-aligned
    data.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBlockInvertedLists.<lambda>:  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBlockInvertedLists.<lambda>:  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   BlockInvertedLists_swiginitnew_BlockInvertedListsr   s     r   rN   zBlockInvertedLists.__init__B      33D/:`:`bf:ghr#   c                 .    t        j                  | |      S r-   )r   BlockInvertedLists_list_sizer  s     r   r  zBlockInvertedLists.list_sizeE  r  r#   c                 .    t        j                  | |      S r-   )r   BlockInvertedLists_get_codesr  s     r   r  zBlockInvertedLists.get_codesH  r  r#   c                 .    t        j                  | |      S r-   )r   BlockInvertedLists_get_idsr  s     r   r  zBlockInvertedLists.get_idsK  r  r#   c                 .    t        j                  | |      S )z!remove ids from the InvertedLists)r   BlockInvertedLists_remove_idsrK  s     r   rL  zBlockInvertedLists.remove_idsN      <<T3GGr#   c                 4    t        j                  | ||||      S r-   )r   BlockInvertedLists_add_entriesr  s        r   r  zBlockInvertedLists.add_entriesR  r  r#   c                 6    t        j                  | |||||      S znot implemented)r   !BlockInvertedLists_update_entriesr  s         r   r  z!BlockInvertedLists.update_entriesU  s!    @@wPVX_adfjkkr#   c                 0    t        j                  | ||      S r-   )r   BlockInvertedLists_resizer  s      r   r   zBlockInvertedLists.resizeY  r   r#   N)"r   r   r6   r7   r   r   r   r   r   "BlockInvertedLists_n_per_block_get"BlockInvertedLists_n_per_block_setn_per_block!BlockInvertedLists_block_size_get!BlockInvertedLists_block_size_setr
  BlockInvertedLists_packer_getBlockInvertedLists_packer_setpackerBlockInvertedLists_codes_getBlockInvertedLists_codes_setr  BlockInvertedLists_ids_getBlockInvertedLists_ids_setr{  rN   r  r  r  rL  r  r  r   delete_BlockInvertedListsr   r$   r#   r   r  r  *  s     -/IOdeGH?MM  PB  PB  CK/KK_M~M~JoCC_ErErsF_AA?CoCopE
?==?i?i
jCiKKIHalR&@@r#   r  c                 .    t        j                  | |      S r-   )r   lo_build)list_idr}  s     r   r  r  `  s    ##GV44r#   c                 ,    t        j                  |       S r-   )r   	lo_listnolos    r   r  r  c      $$R((r#   c                 ,    t        j                  |       S r-   )r   	lo_offsetr  s    r   r  r  f  r  r#   c                   v   e Zd ZdZ ed d d      ZeZej                  Z
ej                  Zej                  Z eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                        Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Z ejB                  Z"y)	DirectMapz8Direct map: a way to map back from ids to inverted listsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zDirectMap.<lambda>k  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zDirectMap.<lambda>k  rD   r#   rE   rF   zEmap for direct access to the elements. Map ids to LO-encoded entries.c                 T    t        j                  | t        j                                y r-   )r   DirectMap_swiginitnew_DirectMaprR   s    r   rN   zDirectMap.__init__t      **41N1N1PQr#   c                 2    t        j                  | |||      S )zset type and initialize)r   DirectMap_set_type)r   new_typeinvlistsr  s       r   set_typezDirectMap.set_typew  s    11$(FSSr#   c                 .    t        j                  | |      S )zget an entry)r   DirectMap_getr   r  s     r   rq
  zDirectMap.get{  s    ,,T266r#   c                 ,    t        j                  |       S )zfor quick checks)r   DirectMap_norR   s    r   nozDirectMap.no  s    ++D11r#   c                 .    t        j                  | |      S )zT
        update the direct_map

         throw if Array and ids is not NULL
        )r   DirectMap_check_can_add)r   r{  s     r   check_can_addzDirectMap.check_can_add  s     66tSAAr#   c                 2    t        j                  | |||      S )znon thread-safe version)r   DirectMap_add_single_id)r   r  r  r}  s       r   add_single_idzDirectMap.add_single_id  s    66tR&QQr#   c                 ,    t        j                  |       S )zremove all entries)r   DirectMap_clearrR   s    r   r   zDirectMap.clear      ..t44r#   c                 0    t        j                  | ||      S )z
        operations on inverted lists that require translation with a DirectMap

         remove ids from the InvertedLists, possibly using the direct map
        )r   DirectMap_remove_ids)r   rS  r  s      r   rL  zDirectMap.remove_ids  s     33D#xHHr#   c                 6    t        j                  | |||||      S )z$update entries, using the direct map)r   DirectMap_update_codes)r   r  rW   r{  r  r  s         r   update_codeszDirectMap.update_codes  s    55dHahX]^^r#   N)#r   r   r6   r7   r   r   r   r   r   DirectMap_NoMapNoMapDirectMap_ArrayArrayDirectMap_Hashtable	HashtableDirectMap_type_getDirectMap_type_setr   DirectMap_array_getDirectMap_array_setarrayDirectMap_hashtable_getDirectMap_hashtable_set	hashtablerN   r  rq
  r  r  r   r   rL  r(  delete_DirectMapr   r$   r#   r   r	  r	  h  s    C-/IOdeGH++E++E33IO668Z8Z[D_88/:]:]  dp  qE@@/BiBijIRT72BR5I_ '77r#   r	  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Z eej0                  ej2                        Zd Zd Zej:                  Zy)	DirectMapAddz*Thread-safe way of updating the direct_mapc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zDirectMapAdd.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zDirectMapAdd.<lambda>  rD   r#   rE   rF   c                 Z    t        j                  | t        j                  |||             y r-   )r   DirectMapAdd_swiginitnew_DirectMapAdd)r   
direct_maprW   r0  s       r   rN   zDirectMapAdd.__init__  s$    --dO4T4TU_abdh4ijr#   c                 2    t        j                  | |||      S )z4add vector i (with id xids[i]) at list_no and offset)r   DirectMapAdd_add)r   r-  r  r}  s       r   r)  zDirectMapAdd.add  s    //a&IIr#   N)r   r   r6   r7   r   r   r   r   r   DirectMapAdd_direct_map_getDirectMapAdd_direct_map_setr?  DirectMapAdd_type_getDirectMapAdd_type_setr   DirectMapAdd_ntotal_getDirectMapAdd_ntotal_setr  DirectMapAdd_n_getDirectMapAdd_n_setrW   DirectMapAdd_xids_getDirectMapAdd_xids_setr0  DirectMapAdd_all_ofs_getDirectMapAdd_all_ofs_setall_ofsrN   r)  delete_DirectMapAddr   r$   r#   r   r9  r9    s    5-/IOdeGH/EEGrGrsJO99?;`;`aDo==?f?fgF33_5W5WXAO99?;`;`aD??AiAijGkJ '::r#   r9  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                  d      Zd Zd Zd Zd Zd Zej@                  Z!y)Level1Quantizerz
     Encapsulates a quantizer object for the IndexIVF

    The class isolates the fields that are independent of the storage
    of the lists (especially training)
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLevel1Quantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLevel1Quantizer.<lambda>  rD   r#   rE   rF   -quantizer that maps vectors to inverted listsznumber of inverted listsz
    = 0: use the quantizer as index in a kmeans training
    = 1: just pass on the training set to the train() of the quantizer
    = 2: kmeans training on a flat index + add the centroids to the quantizer
    !whether object owns the quantizer%to override default clustering params(to override index used during clusteringc                 4    t        j                  | ||||      S )zETrains the quantizer and calls train_residual to train sub-quantizers)r   Level1Quantizer_train_q1)r   rW   r>   r  r  s        r   train_q1zLevel1Quantizer.train_q1  s    77aG[YYr#   c                 ,    t        j                  |       S )z6compute the number of bytes required to store list ids)r    Level1Quantizer_coarse_code_sizerR   s    r   coarse_code_sizez Level1Quantizer.coarse_code_size  r  r#   c                 0    t        j                  | ||      S r-   )r   Level1Quantizer_encode_listno)r   r  r   s      r   encode_listnozLevel1Quantizer.encode_listno  s    <<T7DQQr#   c                 .    t        j                  | |      S r-   )r   Level1Quantizer_decode_listnor  s     r   decode_listnozLevel1Quantizer.decode_listno  r  r#   c                 P    t        j                  | t        j                  |        y r-   )r   Level1Quantizer_swiginitnew_Level1Quantizerr   s     r   rN   zLevel1Quantizer.__init__  r  r#   N)"r   r   r6   r7   r   r   r   r   r   Level1Quantizer_quantizer_getLevel1Quantizer_quantizer_set	quantizerLevel1Quantizer_nlist_getLevel1Quantizer_nlist_setr  *Level1Quantizer_quantizer_trains_alone_get*Level1Quantizer_quantizer_trains_alone_setquantizer_trains_aloneLevel1Quantizer_own_fields_getLevel1Quantizer_own_fields_setrM  Level1Quantizer_cp_getLevel1Quantizer_cp_setrf  $Level1Quantizer_clustering_index_get$Level1Quantizer_clustering_index_setclustering_indexrZ  r]  r`  rc  rN   delete_Level1Quantizerr   r$   r#   r   rQ  rQ    s)    -/IOdeGHFFHuHu  |p  qI_>>@i@i  pO  PE%o&`&`bq  c]  c] c 	
 /HH/JxJx  g  hJ	/88/:`:`  gS  
TB T TVe  WK  WK  Q@  AZFRIc&==r#   rQ  c                   <   e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Z eej                  ej                        Z eej"                  ej$                  d      Zej(                  Zd Zy	)
SearchParametersIVFc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSearchParametersIVF.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSearchParametersIVF.<lambda>  rD   r#   rE   rF   number of probes at query time&max nb of codes to visit to do a queryz'context object to pass to InvertedListsc                 T    t        j                  | t        j                                y r-   )r   SearchParametersIVF_swiginitnew_SearchParametersIVFrR   s    r   rN   zSearchParametersIVF.__init__  r  r#   N)r   r   r6   r   r   r   r   r   SearchParametersIVF_nprobe_getSearchParametersIVF_nprobe_setnprobe!SearchParametersIVF_max_codes_get!SearchParametersIVF_max_codes_set	max_codes(SearchParametersIVF_quantizer_params_get(SearchParametersIVF_quantizer_params_setquantizer_params-SearchParametersIVF_inverted_list_context_get-SearchParametersIVF_inverted_list_context_setr  delete_SearchParametersIVFr   rN   r$   r#   r   rx  rx    s    -/IOdeGHoDDoFtFt  {`  aFJJOL}L}  Dq  rI X XZi  [S  [S  T$_%b%bds  eb  eb  hV  W&AAfr#   rx  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                  d      Z eej                  ej                  d      Zdd	Zdd
Zej"                  Zy)IndexIVFInterfacec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFInterface.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFInterface.<lambda>  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexIVFInterface.__init__  rO   r#   r{  r|  Nc                 @    t        j                  | |||||||||	|
      S )a  
         search a set of vectors, that are pre-quantized by the IVF
         quantizer. Fill in the corresponding heaps with the query
         results. The default implementation uses InvertedListScanners
         to do the search.

        :type n: int
        :param n:      nb of vectors to query
        :type x: float
        :param x:      query vectors, size nx * d
        :type assign: int
        :param assign: coarse quantization indices, size nx * nprobe
        :type centroid_dis: float
        :param centroid_dis:
                          distances to coarse centroids, size nx * nprobe
        :param distance:
                          output distances, size n * k
        :type labels: int
        :param labels: output labels, size n * k
        :type store_pairs: boolean
        :param store_pairs: store inv list index + inv list offset
                                instead in upper/lower 32 bit of result,
                                instead of ids (used for reranking).
        :type params: :py:class:`IVFSearchParameters`, optional
        :param params: used to override the object's search parameters
        :type stats: :py:class:`IndexIVFStats`, optional
        :param stats:  search stats to be updated (can be null)
        )r   $IndexIVFInterface_search_preassignedr   rW   r>   rP  rF  centroid_disrQ  rR  store_pairsr9  statss              r   search_preassignedz$IndexIVFInterface.search_preassigned  sC    : CCD!QPQSY[girtz  }H  JP  RW  X  	Xr#   c
                 >    t        j                  | |||||||||	
      S )aZ  
         Range search a set of vectors, that are pre-quantized by the IVF
         quantizer. Fill in the RangeSearchResults results. The default
        implementation uses InvertedListScanners to do the search.

        :param n:      nb of vectors to query
        :type x: float
        :param x:      query vectors, size nx * d
        :param assign: coarse quantization indices, size nx * nprobe
        :param centroid_dis:
                          distances to coarse centroids, size nx * nprobe
        :type result: :py:class:`RangeSearchResult`
        :param result: Output results
        :type store_pairs: boolean, optional
        :param store_pairs: store inv list index + inv list offset
                                instead in upper/lower 32 bit of result,
                                instead of ids (used for reranking).
        :type params: :py:class:`IVFSearchParameters`, optional
        :param params: used to override the object's search parameters
        :type stats: :py:class:`IndexIVFStats`, optional
        :param stats:  search stats to be updated (can be null)
        )r   *IndexIVFInterface_range_search_preassigned
r   rk  r>   rV  r  
coarse_disrW  r  r9  r  s
             r   range_search_preassignedz*IndexIVFInterface.range_search_preassigned  sB    . II$PRTUW]_ceoqw  zE  GM  OT  U  	Ur#   r	  FNN)r   r   r6   r   r   rN   r   r   r   IndexIVFInterface_nprobe_getIndexIVFInterface_nprobe_setr  IndexIVFInterface_max_codes_getIndexIVFInterface_max_codes_setr  r  r  delete_IndexIVFInterfacer   r$   r#   r   r  r    s|    -/IOdeGKHoBBODpDp  w\  ]FHH/JyJy  @m  nIX>U0 '??r#   r  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                        Z ee	j                   e	j"                  d      Z ee	j&                  e	j(                  d	      Z ee	j,                        Z ee	j0                  e	j2                  d
      Z ee	j6                  e	j8                  d      Zd Zd Zd Z d Z!d.dZ"d/dZ#d Z$d Z%d Z&d Z'd0dZ(d1dZ)d.dZ*d.dZ+d1dZ,d Z-d Z.d Z/d.dZ0d2d Z1d! Z2d" Z3d# Z4d$ Z5d% Z6d& Z7e	jp                  Z9d' Z:d( Z;d3d)Z<d* Z=d/d+Z>d, Z?d- Z@y)4IndexIVFa  
     Index based on a inverted file (IVF)

    In the inverted file, the quantizer (an Index instance) provides a
    quantization index for each vector to be added. The quantization
    index maps to a list (aka inverted list or posting list), where the
    id of the vector is stored.

    The inverted list object is required only after trainng. If none is
    set externally, an ArrayInvertedLists is used automatically.

    At search time, the vector to be searched is also quantized, and
    only the list corresponding to the quantization index is
    searched. This speeds up the search by making it
    non-exhaustive. This can be relaxed using multi-probe search: a few
    (nprobe) quantization indices are selected and several inverted
    lists are visited.

    Sub-classes implement a post-filtering of the index that refines
    the distance estimation from the query to databse vectors.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVF.<lambda>J  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVF.<lambda>J  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexIVF.__init__L  rO   r#   Access to the actual datar  a]  
     Parallel mode determines how queries are parallelized with OpenMP

    0 (default): split over queries
    1: parallelize over inverted lists
    2: parallelize over both
    3: split over queries with a finer granularity

    PARALLEL_MODE_NO_HEAP_INIT: binary or with the previous to
    prevent the heap to be initialized and finalized
    z\
    optional map that maps back ids to invlist entries. This
    enables reconstruct()
    zX
    do the codes in the invlists encode the vectors relative to the
    centroids?
    c                 ,    t        j                  |       S r-   )r   IndexIVF_resetrR   s    r   r  zIndexIVF.resetg  r
  r#   c                 0    t        j                  | ||      S )zDTrains the quantizer and calls train_encoder to train sub-quantizers)r   IndexIVF_trainr!  s      r   r"  zIndexIVF.trainj      --dAq99r#   c                 0    t        j                  | ||      S )z Calls add_with_ids with NULL ids)r   IndexIVF_addr!  s      r   r)  zIndexIVF.addn  s    ++D!Q77r#   c                 2    t        j                  | |||      S )z0default implementation that calls encode_vectors)r   IndexIVF_add_with_idsr/  s       r   r1  zIndexIVF.add_with_idsr  s    44T1aFFr#   Nc                 6    t        j                  | |||||      S )aE  
         Implementation of vector addition where the vector assignments are
        predefined. The default implementation hands over the code extraction to
        encode_vectors.

        :type precomputed_idx: int
        :param precomputed_idx:    quantization indices for the input vectors
            (size n)
        )r   IndexIVF_add_corer   rW   r>   r0  precomputed_idxr  s         r   add_corezIndexIVF.add_corev  s      00q!T?Tijjr#   c                 6    t        j                  | |||||      S )a1  
         Encodes a set of vectors as they would appear in the inverted lists

        :type list_nos: int
        :param list_nos:   inverted list ids as returned by the
                              quantizer (size n). -1s are ignored.
        :type codes: uint8_t
        :param codes:      output codes, size n * code_size
        :type include_listno: boolean, optional
        :param include_listno:
                              include the list ids in the code (in this case add
                              ceil(log8(nlist)) to the code size)
        )r   IndexIVF_encode_vectorsr   rW   r>   r  r  include_listnos         r   encode_vectorszIndexIVF.encode_vectors  s      66tQ8UTbccr#   c                 4    t        j                  | ||||      S )at  
         Decodes a set of vectors as they would appear in a given set of inverted
        lists (inverse of encode_vectors)

        :type codes: uint8_t
        :param codes:      input codes, size n * code_size
        :type x: float
        :param x:          output decoded vectors
        :type list_nos: int
        :param list_nos:   input listnos, size n
        )r   IndexIVF_decode_vectorsr   rW   r  r  r>   s        r   decode_vectorszIndexIVF.decode_vectors  s     66tQxQRSSr#   c                 2    t        j                  | |||      S r  )r   IndexIVF_add_sa_codesr  s       r   r  zIndexIVF.add_sa_codes  s     44T1eTJJr#   c                 2    t        j                  | |||      S )z
         Train the encoder for the vectors.

        If by_residual then it is called with residuals and corresponding assign
        array, otherwise x is the raw training vectors and assign=nullptr
        )r   IndexIVF_train_encoderr   rW   r>   rF  s       r   train_encoderzIndexIVF.train_encoder  s     55dAq&IIr#   c                 ,    t        j                  |       S )zh
        can be redefined by subclasses to indicate how many training vectors
        they need
        )r   "IndexIVF_train_encoder_num_vectorsrR   s    r   train_encoder_num_vectorsz"IndexIVF.train_encoder_num_vectors  s    
 AA$GGr#   c                 @    t        j                  | |||||||||	|
      S r-   )r   IndexIVF_search_preassignedr  s              r   r  zIndexIVF.search_preassigned  s;    ::4Aq&R^`ikqs~  AG  IN  O  	Or#   c
                 >    t        j                  | |||||||||	
      S r-   )r   !IndexIVF_range_search_preassignedr  s
             r   r  z!IndexIVF.range_search_preassigned  s9    @@r1fVZ\fhnp{  ~D  FK  L  	Lr#   c           	      8    t        j                  | ||||||      S z.assign the vectors, then call search_preassign)r   IndexIVF_searchr8  s          r   r:  zIndexIVF.search       ..tQ1iQWXXr#   c                 6    t        j                  | |||||      S r-   )r   IndexIVF_range_searchrA  s         r   rB  zIndexIVF.range_search  s    44T1aQWXXr#   c                 2    t        j                  | |||      S )a2  
         Get a scanner for this index (store_pairs means ignore labels)

        The default search implementation uses this to compute the distances.
        Use sel instead of params->sel, because sel is initialized with
        params->sel, but may get overridden by IndexIVF's internal logic.
        )r    IndexIVF_get_InvertedListScannerr   r  rS  r9  s       r   get_InvertedListScannerz IndexIVF.get_InvertedListScanner  s     ??kSVX^__r#   c                 0    t        j                  | ||      S )zHreconstruct a vector. Works only if maintain_direct_map is set to 1 or 2)r   IndexIVF_reconstructrO  s      r   rR  zIndexIVF.reconstruct  s    33D#vFFr#   c                 2    t        j                  | |||      S )a=  
         Update a subset of vectors.

        The index must have a direct_map

        :type nv: int
        :param nv:     nb of vectors to update
        :type idx: int
        :param idx:    vector indices to update, size nv
        :type v: float
        :param v:      vectors of new values, size nv*d
        )r   IndexIVF_update_vectorsr   nvrb  rC   s       r   update_vectorszIndexIVF.update_vectors  s     66tRaHHr#   c                 2    t        j                  | |||      S )a  
         Reconstruct a subset of the indexed vectors.

        Overrides default implementation to bypass reconstruct() which requires
        direct_map to be maintained.

        :type i0: int
        :param i0:     first vector to reconstruct
        :type ni: int
        :param ni:     nb of vectors to reconstruct
        :type recons: float
        :param recons: output array of reconstructed vectors, size ni * d
        )r   IndexIVF_reconstruct_nrX  s       r   r[  zIndexIVF.reconstruct_n  s     55dBFKKr#   c           
      :    t        j                  | |||||||      S )a  
         Similar to search, but also reconstructs the stored vectors (or an
        approximation in the case of lossy coding) for the search results.

        Overrides default implementation to avoid having to maintain direct_map
        and instead fetch the code offsets through the `store_pairs` flag in
        search_preassigned().

        :type recons: float
        :param recons:      reconstructed vectors size (n, k, d)
        )r   IndexIVF_search_and_reconstructr^  s           r   r_  zIndexIVF.search_and_reconstruct  s&     >>tQ1iY_agioppr#   c	                 <    t        j                  | ||||||||	      S )a  
         Similar to search, but also returns the codes corresponding to the
        stored vectors for the search results.

        :param codes:      codes (n, k, code_size)
        :type include_listno: boolean, optional
        :param include_listno:
                              include the list ids in the code (in this case add
                              ceil(log8(nlist)) to the code size)
        )r    IndexIVF_search_and_return_codes)	r   rW   r>   rP  rQ  rR  rQ  r  r9  s	            r   search_and_return_codesz IndexIVF.search_and_return_codes  s3     ??aAyZ`bhjx  {A  B  	Br#   c                 2    t        j                  | |||      S a1  
         Reconstruct a vector given the location in terms of (inv list index +
        inv list offset) instead of the id.

        Useful for reconstructing when the direct_map is not maintained and
        the inv list offset is computed by search_preassigned() with
        `store_pairs` set.
        )r    IndexIVF_reconstruct_from_offsetr   r  r}  rQ  s       r   reconstruct_from_offsetz IndexIVF.reconstruct_from_offset  s     ??gvW]^^r#   c                 .    t        j                  | |      S zDataset manipulation functions)r   IndexIVF_remove_idsrK  s     r   rL  zIndexIVF.remove_ids  s    224==r#   c                 .    t        j                  | |      S r-   )r   #IndexIVF_check_compatible_for_merger  s     r   r  z#IndexIVF.check_compatible_for_merge  s    BB4TTr#   c                 0    t        j                  | ||      S r-   )r   IndexIVF_merge_fromr{  s      r   r~  zIndexIVF.merge_from"  s    224VLLr#   c                 ,    t        j                  |       S r-   )r   IndexIVF_get_CodePackerrR   s    r   r  zIndexIVF.get_CodePacker%  ro   r#   c                 4    t        j                  | ||||      S )z
         copy a subset of the entries index to the other index
        see Invlists::copy_subset_to for the meaning of subset_type
        )r   IndexIVF_copy_subset_tor  s        r   r  zIndexIVF.copy_subset_to(  s    
 66tUKQSUWXXr#   c                 .    t        j                  | |      S r-   )r   IndexIVF_get_list_sizer  s     r   get_list_sizezIndexIVF.get_list_size0  s    55dGDDr#   c                 ,    t        j                  |       S )zare the ids sorted?)r   IndexIVF_check_ids_sortedrR   s    r   check_ids_sortedzIndexIVF.check_ids_sorted3  r  r#   c                 .    t        j                  | |      S z
         initialize a direct map

        :type new_maintain_direct_map: boolean, optional
        :param new_maintain_direct_map:    if true, create a direct map,
                                              else clear it
        )r   IndexIVF_make_direct_mapr   new_maintain_direct_maps     r   make_direct_mapzIndexIVF.make_direct_map7  s     77>UVVr#   c                 .    t        j                  | |      S r-   )r   IndexIVF_set_direct_map_typer   r   s     r   set_direct_map_typezIndexIVF.set_direct_map_typeA      ;;D$GGr#   c                 0    t        j                  | ||      S )zBreplace the inverted lists, old one is deallocated if own_invlists)r   IndexIVF_replace_invlistsr   rE  r   s      r   replace_invlistszIndexIVF.replace_invlistsD  s    88r3GGr#   c                 ,    t        j                  |       S r-   )r   IndexIVF_sa_code_sizerR   s    r   ro  zIndexIVF.sa_code_sizeH      44T::r#   c                 2    t        j                  | |||      S )a  
         encode a set of vectors
        sa_encode will call encode_vectors with include_listno=true
        :type n: int
        :param n:      nb of vectors to encode
        :type x: float
        :param x:      the vectors to encode
        :type bytes: uint8_t
        :param bytes:  output array for the codes
        :rtype: void
        :return: nb of bytes written to codes
        )r   IndexIVF_sa_encoderr  s       r   rs  zIndexIVF.sa_encodeK  s     11$1eDDr#   r-   Fr	  r  )FNrD  )Ar   r   r6   r7   r   r   rN   r   r   r   IndexIVF_invlists_getIndexIVF_invlists_setr  IndexIVF_own_invlists_getIndexIVF_own_invlists_setown_invlistsIndexIVF_code_size_getIndexIVF_code_size_setr!  IndexIVF_parallel_mode_getIndexIVF_parallel_mode_setparallel_mode'IndexIVF_PARALLEL_MODE_NO_HEAP_INIT_getPARALLEL_MODE_NO_HEAP_INITIndexIVF_direct_map_getIndexIVF_direct_map_setr?  IndexIVF_by_residual_getIndexIVF_by_residual_setby_residualr  r"  r)  r1  r  r  r  r  r  r  r  r  r:  rB  r  rR  r  r[  r_  r  r  rL  r  r~  r  r  delete_IndexIVFr   r  r  r   r  r	  ro  rs  r$   r#   r   r  r  3  s   , -/IOdeGKH==?d?d  kK  LHOEEGpGpqL??AgAg  nR  SI_GGIsIs 
z 
	M "*/*a*a!b/AA?CjCj q 	J ?CC_EmEm t 	K
4:8G
kd T	KJHOLYY`GIL qB	_>UM=Y '66E?WHH;Er#   r  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Z ee	j&                  e	j(                  d
      Z ee	j,                  e	j.                  d      Zd Zd Zd Zd Zd Zd Zd Ze	j@                  Z!y)InvertedListScannerz
     Object that handles a query. The inverted lists to scan are
    provided externally. The object has a lot of state, but
    distance_to_code and scan_codes can be called in multiple
    threads
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInvertedListScanner.<lambda>d  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInvertedListScanner.<lambda>d  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zInvertedListScanner.__init__f  rO   r#   zremember current listzkeep maximum instead of minimumz.store positions in invlists rather than labelszsearch in this subset of idsz,used in default implementation of scan_codesc                 .    t        j                  | |      S z!from now on we handle this query.)r   InvertedListScanner_set_queryr   query_vectors     r   r  zInvertedListScanner.set_queryo  s    <<T<PPr#   c                 0    t        j                  | ||      S z,following codes come from this inverted list)r   InvertedListScanner_set_listr   r  r  s      r   set_listzInvertedListScanner.set_lists  s    ;;D':VVr#   c                 .    t        j                  | |      S z'compute a single query-to-code distance)r   $InvertedListScanner_distance_to_coder  s     r   r  z$InvertedListScanner.distance_to_codew  s    CCD$OOr#   c           	      8    t        j                  | ||||||      S )a  
         scan a set of codes, compute distances to current query and
        update heap of results if necessary. Default implementation
        calls distance_to_code.

        :type n: int
        :param n:      number of codes to scan
        :type codes: uint8_t
        :param codes:  codes to scan (n * code_size)
        :type ids: int
        :param ids:        corresponding ids (ignored if store_pairs)
        :type distances: float
        :param distances:  heap distances (size k)
        :type labels: int
        :param labels:     heap labels (size k)
        :type k: int
        :param k:          heap size
        :rtype: int
        :return: number of heap updates performed
        )r   InvertedListScanner_scan_codesr   rW   r  r{  rQ  rR  rP  s          r   
scan_codeszInvertedListScanner.scan_codes{  s$    * ==dAucS\^dfghhr#   c                 6    t        j                  | |||||      S r-   )r   !InvertedListScanner_iterate_codes)r   iteratorrQ  rR  rP  r  s         r   iterate_codesz!InvertedListScanner.iterate_codes  s!    @@xQZ\bdegpqqr#   c                 6    t        j                  | |||||      S )z
         scan a set of codes, compute distances to current query and
        update results if distances are below radius

        (default implementation fails)
        )r   $InvertedListScanner_scan_codes_ranger   rW   r  r{  rV  rW  s         r   scan_codes_rangez$InvertedListScanner.scan_codes_range  s"     CCD!UTWY_aghhr#   c                 4    t        j                  | ||||      S r-   )r   'InvertedListScanner_iterate_codes_range)r   r:  rV  rW  r  s        r   iterate_codes_rangez'InvertedListScanner.iterate_codes_range  s    FFtXW]_egpqqr#   N)"r   r   r6   r7   r   r   rN   r   r   r   InvertedListScanner_list_no_getInvertedListScanner_list_no_setr   InvertedListScanner_keep_max_get InvertedListScanner_keep_max_setr  #InvertedListScanner_store_pairs_get#InvertedListScanner_store_pairs_setr  InvertedListScanner_sel_getInvertedListScanner_sel_setrS  !InvertedListScanner_code_size_get!InvertedListScanner_code_size_setr!  r  r0  r  r7  r;  r?  rB  delete_InvertedListScannerr   r$   r#   r   r#  r#  \  s    -/IOdeGKHFFHwHw  ~Z  [GHH/JzJz  Ag  hH?NNP_  QD  QD  J  @K
?>>@k@k  rU  VCJJOL}L}  Dw  xIQWPi.rir&AAr#   r#  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Zd Zd Zd Zej:                  Zy)	IndexIVFStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFStats.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFStats.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   IndexIVFStats_swiginitnew_IndexIVFStatsrR   s    r   rN   zIndexIVFStats.__init__  r   r#   c                 ,    t        j                  |       S r-   )r   IndexIVFStats_resetrR   s    r   r  zIndexIVFStats.reset  rh   r#   c                 .    t        j                  | |      S r-   )r   IndexIVFStats_addr   s     r   r)  zIndexIVFStats.add  r`  r#   N)r   r   r6   r   r   r   r   r   IndexIVFStats_nq_getIndexIVFStats_nq_setr  IndexIVFStats_nlist_getIndexIVFStats_nlist_setr  IndexIVFStats_ndis_getIndexIVFStats_ndis_setndisIndexIVFStats_nheap_updates_getIndexIVFStats_nheap_updates_setnheap_updates#IndexIVFStats_quantization_time_get#IndexIVFStats_quantization_time_setquantization_timeIndexIVFStats_search_time_getIndexIVFStats_search_time_setsearch_timerN   r  r)  delete_IndexIVFStatsr   r$   r#   r   rO  rO    s    -/IOdeGH	/668\8\	]B_<<o>e>efEO::O<b<bcD_LLoN}N}~M !T!TVe  WJ  WJ  K?HH/JwJwxKZ9>&;;r#   rO  c                 .    t        j                  | |      S )zn
     check if two indexes have the same parameters and are trained in
    the same way, otherwise throw.
    )r   r  )index1index2s     r   r  r    s    
 55ffEEr#   c                  &    t        j                  |  S )z
     get an IndexIVF from an index. The index may be an IndexIVF or
    some wrapper class that encloses an IndexIVF

    throws an exception if this is not the case.
    )r   extract_index_ivfrH  s    r   rn  rn    s     ,,d33r#   c                  &    t        j                  |  S )z@same as above but returns nullptr instead of throwing on failure)r   try_extract_index_ivfrH  s    r   rp  rp    s    00$77r#   c                 0    t        j                  | ||      S )z
     Merge index1 into index0. Works on IndexIVF's and IndexIVF's
     embedded in a IndexPreTransform. On output, the index1 is empty.

    :type shift_ids: boolean
    :param shift_ids:: translate the ids from index1 to index0->prev_ntotal
    )r   
merge_into)index0rk  	shift_idss      r   rr  rr    s     %%ffi@@r#   c                 2    t        j                  | |||      S r-   )r   search_centroid)r  r>   rW   centroid_idss       r   rv  rv    s    **5!QEEr#   c           
      :    t        j                  | |||||||      S r-   )r   search_and_return_centroids)r  rW   xinrP  rQ  rR  query_centroid_idsresult_centroid_idss           r   ry  ry    s.    66uaaTZ\n  qD  E  Er#   c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Zd Zd Zej4                  Zy)SlidingIndexWindowz
     A set of IndexIVFs concatenated together in a FIFO fashion.
    at each "step", the oldest index slice is removed and a new index is added.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSlidingIndexWindow.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSlidingIndexWindow.<lambda>  rD   r#   rE   rF   z-common index that contains the sliding windowzInvertedLists of indexz#number of slices currently in indexzsame as index->nlistz#cumulative list sizes at each slicec                 V    t        j                  | t        j                  |             y)z+index should be initially empty and trainedN)r   SlidingIndexWindow_swiginitnew_SlidingIndexWindowr   r  s     r   rN   zSlidingIndexWindow.__init__  s    33D/:`:`af:ghr#   c                 0    t        j                  | ||      S )a$  
         Add one index to the current index and remove the oldest one.

        :type sub_index: :py:class:`Index`
        :param sub_index:        slice to swap in (can be NULL)
        :type remove_oldest: boolean
        :param remove_oldest:    if true, remove the oldest slices
        )r   SlidingIndexWindow_step)r   	sub_indexremove_oldests      r   stepzSlidingIndexWindow.step  s     66tYVVr#   N)r   r   r6   r7   r   r   r   r   r   SlidingIndexWindow_index_getSlidingIndexWindow_index_setr  SlidingIndexWindow_ils_getSlidingIndexWindow_ils_setr"  SlidingIndexWindow_n_slice_getSlidingIndexWindow_n_slice_setn_sliceSlidingIndexWindow_nlist_getSlidingIndexWindow_nlist_setr  SlidingIndexWindow_sizes_getSlidingIndexWindow_sizes_setr  rN   r  delete_SlidingIndexWindowr   r$   r#   r   r~  r~    s    
 -/IOdeGH_AA?CoCo  vj  kE
?==?i?i  pM  NCEEGuGu  |f  gG_AA?CoCo  vQ  RE_AA?CoCo  v`  aEi	W '@@r#   r~  c                 0    t        j                  | ||      S )z'Get a subset of inverted lists [i0, i1))r   get_invlist_range)r  rY  rF  s      r   r  r    s    ,,UB;;r#   c                 2    t        j                  | |||      S )zSet a subset of inverted lists)r   set_invlist_range)r  rY  rF  srcs       r   r  r    s    ,,UBC@@r#   c	                 <    t        j                  | ||||||||	      S )a  
     search an IndexIVF, possibly embedded in an IndexPreTransform with
    given parameters. This is a way to set the nprobe and get
    statdistics in a thread-safe way.

    Optionally returns (if non-nullptr):
    - nb_dis: number of distances computed
    - ms_per_stage: [0]: preprocessing time
                    [1]: coarse quantization,
                    [2]: list scanning
    )r   search_with_parameters)	r  rW   r>   rP  rQ  rR  r9  nb_disms_per_stages	            r   r  r    s(     11%Aq)VU[]ceqrrr#   c           
      :    t        j                  | |||||||      S )z3same as search_with_parameters but for range search)r   range_search_with_parameters)r  rW   r>   rV  rW  r9  r  r  s           r   r  r    s$    77q!VVU[]ceqrrr#   c                 .    t        j                  | |      S )z
     Build an IndexIVFResidualQuantizer from an ResidualQuantizer, using the
    nlevel first components as coarse quantizer and the rest as codes in invlists
    )r   ivf_residual_from_quantizer)r  nlevels     r   r  r    s    
 66tVDDr#   c                 2    t        j                  | |||      S )a  
     add from codes. NB that the norm component is not used, so the code_size can
    be provided.

    :type ivfrq: :py:class:`IndexIVFResidualQuantizer`
    :param ivfrq:      index to populate with the codes
    :type codes: uint8_t
    :param codes:      codes to add, size (ncode, code_size)
    :type code_size: int, optional
    :param code_size:  override the ivfrq's code_size, useful if the norm encoding
                          is different
    )r    ivf_residual_add_from_flat_codes)ivfrqr  r  r!  s       r   r  r     s     ;;E5%QZ[[r#   c                   N    e Zd Z ed d d      Zd ZeZd Ze	j                  Zy)ShardingFunctionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zShardingFunction.<lambda>/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zShardingFunction.<lambda>/  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zShardingFunction.__init__1  rO   r#   c                 0    t        j                  | ||      S r-   )r   ShardingFunction___call__r   r-  shard_counts      r   r  zShardingFunction.__call__5  s    88q+NNr#   N)r   r   r6   r   r   rN   r   r   r  r   delete_ShardingFunctionr   r$   r#   r   r  r  .  s0    -/IOdeGKHO&>>r#   r  c                   N    e Zd Z ed d d      ZeZd Zd Ze	j                  Zy)DefaultShardingFunctionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z DefaultShardingFunction.<lambda><  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z DefaultShardingFunction.<lambda><  rD   r#   rE   rF   c                 0    t        j                  | ||      S r-   )r    DefaultShardingFunction___call__r  s      r   r  z DefaultShardingFunction.__call__?  s    ??aUUr#   c                 T    t        j                  | t        j                                y r-   )r    DefaultShardingFunction_swiginitnew_DefaultShardingFunctionrR   s    r   rN   z DefaultShardingFunction.__init__B  r	  r#   N)r   r   r6   r   r   r   r   r  rN   r   delete_DefaultShardingFunctionr   r$   r#   r   r  r  ;  s0    -/IOdeGHVn&EEr#   r  c                  &    t        j                  |  S )a  
    Shards an IVF index centroids by the given sharding function, and writes
    the index to the path given by filename_generator. The centroids must already
    be added to the index quantizer.

    :type index: :py:class:`IndexIVF`
    :param index:             The IVF index containing centroids to shard.
    :type shard_count: int, optional
    :param shard_count:       Number of shards.
    :type filename_template: string, optional
    :param filename_template: Template for shard filenames.
    :type sharding_function: :py:class:`ShardingFunction`, optional
    :param sharding_function: The function to shard by. The default is ith vector
                                 mod shard_count.
    :type generate_ids: boolean, optional
    :param generate_ids:      Generates ids using IndexIDMap2. If true, ids will
                                 match the default ids in the unsharded index.
    :rtype: void
    :return: The number of shards written.
    )r   shard_ivf_index_centroidsrH  s    r   r  r  I  s    * 44d;;r#   c                  &    t        j                  |  S r-   )r    shard_binary_ivf_index_centroidsrH  s    r   r  r  `  s    ;;TBBr#   c                      e Zd ZdZ ed d d      ZeZej                  Z
	 ej                  Z	 ej                  Z	 ej                  Zej"                  Zej&                  Z	 ej*                  Z	 ej.                  Zej2                  Z	  eej6                  ej8                        Zej<                  Z	 ej@                  Z!	 ejD                  Z#	 ejH                  Z%	  eejL                  ejN                        Z( eejR                  ejT                        Z+ eejX                  ejZ                  d      Z. eej^                  ej`                  d      Z1d Z2d	 Z3d
 Z4d Z5d Z6d Z7d Z8ddZ9ejt                  Z;y)ScalarQuantizerz
    The uniform quantizer has a range [vmin, vmax]. The range can be
    the same for all dimensions (uniform) or specific per dimension
    (default).
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zScalarQuantizer.<lambda>i  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zScalarQuantizer.<lambda>i  rD   r#   rE   rF   zbits per scalar codez$trained values (including the range)c                 P    t        j                  | t        j                  |        y r-   )r   ScalarQuantizer_swiginitnew_ScalarQuantizerr   s     r   rN   zScalarQuantizer.__init__  r  r#   c                 ,    t        j                  |       S )z,updates internal values based on qtype and d)r   !ScalarQuantizer_set_derived_sizesrR   s    r   set_derived_sizesz!ScalarQuantizer.set_derived_sizes      @@FFr#   c                 0    t        j                  | ||      S r-   )r   ScalarQuantizer_trainr!  s      r   r"  zScalarQuantizer.train  r  r#   c                 2    t        j                  | |||      S )z
         Encode a set of vectors

        :type x: float
        :param x:      vectors to encode, size n * d
        :type codes: uint8_t
        :param codes:  output codes, size n * code_size
        )r   ScalarQuantizer_compute_codesr  s       r   r  zScalarQuantizer.compute_codes  s     <<T1eQOOr#   c                 2    t        j                  | |||      S )z
         Decode a set of vectors

        :param codes:  codes to decode, size n * code_size
        :type x: float
        :param x:      output vectors, size n * d
        )r   ScalarQuantizer_decoder  s       r   r  zScalarQuantizer.decode  s     55dD!QGGr#   c                 ,    t        j                  |       S r-   )r    ScalarQuantizer_select_quantizerrR   s    r   select_quantizerz ScalarQuantizer.select_quantizer  r  r#   c                 .    t        j                  | g| S r-   )r   %ScalarQuantizer_get_distance_computerr   s     r   rk  z%ScalarQuantizer.get_distance_computer  s    DDTQDQQr#   c                 6    t        j                  | |||||      S r-   )r   *ScalarQuantizer_select_InvertedListScanner)r   r  ri  r  rS  r   s         r   select_InvertedListScannerz*ScalarQuantizer.select_InvertedListScanner  s"    II$PRT]_jloq|}}r#   Nr  )<r   r   r6   r7   r   r   r   r   r   ScalarQuantizer_QT_8bitQT_8bitScalarQuantizer_QT_4bitQT_4bitScalarQuantizer_QT_8bit_uniformQT_8bit_uniformScalarQuantizer_QT_4bit_uniformQT_4bit_uniformScalarQuantizer_QT_fp16QT_fp16ScalarQuantizer_QT_8bit_directQT_8bit_directScalarQuantizer_QT_6bitQT_6bitScalarQuantizer_QT_bf16QT_bf16%ScalarQuantizer_QT_8bit_direct_signedQT_8bit_direct_signedScalarQuantizer_qtype_getScalarQuantizer_qtype_setqtypeScalarQuantizer_RS_minmax	RS_minmaxScalarQuantizer_RS_meanstd
RS_meanstdScalarQuantizer_RS_quantilesRS_quantilesScalarQuantizer_RS_optimRS_optimScalarQuantizer_rangestat_getScalarQuantizer_rangestat_set	rangestat!ScalarQuantizer_rangestat_arg_get!ScalarQuantizer_rangestat_arg_setrangestat_argScalarQuantizer_bits_getScalarQuantizer_bits_setbitsScalarQuantizer_trained_getScalarQuantizer_trained_settrainedrN   r  r"  r  r  r  rk  r  delete_ScalarQuantizerr   r$   r#   r   r  r  b  s    -/IOdeGH55G55G%EEO0%EEO55G$CCN"55G55G+QQ _>>@i@ijE99I3 ;;J-"??L77H9FFHuHuvI_NNP_  QB  QB  CMO<<o>f>f  mH  IDBBODoDo  va  bGcGA	PHFR~&==r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zd Zdd
Zd Zd Zd Zej$                  Zy	)IndexScalarQuantizerz'Flat index built on a scalar quantizer.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexScalarQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexScalarQuantizer.<lambda>  rD   r#   rE   rF   zUsed to encode the vectorsc                 P    t        j                  | t        j                  |        y)a9  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type qtype: int
        :param qtype:  type of scalar quantizer (e.g., QT_4bit)
        :type metric: int, optional
        :param metric: distance metric used for search (default: METRIC_L2)
        N)r   IndexScalarQuantizer_swiginitnew_IndexScalarQuantizerr   s     r   rN   zIndexScalarQuantizer.__init__  s      	55dO<d<dfj<klr#   c                 0    t        j                  | ||      S r-   )r   IndexScalarQuantizer_trainr!  s      r   r"  zIndexScalarQuantizer.train  r
  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexScalarQuantizer_searchr8  s          r   r:  zIndexScalarQuantizer.search  r  r#   c                 ,    t        j                  |       S r-   )r   2IndexScalarQuantizer_get_FlatCodesDistanceComputerrR   s    r   r  z2IndexScalarQuantizer.get_FlatCodesDistanceComputer  s    QQRVWWr#   c                 2    t        j                  | |||      S r-   )r   IndexScalarQuantizer_sa_encoderr  s       r   rs  zIndexScalarQuantizer.sa_encode  s    ==dAq%PPr#   c                 2    t        j                  | |||      S r-   )r   IndexScalarQuantizer_sa_decoderv  s       r   rw  zIndexScalarQuantizer.sa_decode  s    ==dAuaPPr#   r-   )r   r   r6   r7   r   r   r   r   r   IndexScalarQuantizer_sq_getIndexScalarQuantizer_sq_setsqrN   r"  r:  r  rs  rw  delete_IndexScalarQuantizerr   r$   r#   r   r  r    sm    2-/IOdeGH	/==?j?j  qR  
SBmFeXQQ&BBr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zdd	Zd
 ZddZd Zd Zd Zej*                  Zy)IndexIVFScalarQuantizerz
     An IVF implementation where the components of the residuals are
    encoded with a scalar quantizer. All distance computations
    are asymmetric, so the encoded vectors are decoded and approximate
    distances are computed.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z IndexIVFScalarQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z IndexIVFScalarQuantizer.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r    IndexIVFScalarQuantizer_swiginitnew_IndexIVFScalarQuantizerr   s     r   rN   z IndexIVFScalarQuantizer.__init__  r  r#   c                 2    t        j                  | |||      S r-   )r   %IndexIVFScalarQuantizer_train_encoderr  s       r   r  z%IndexIVFScalarQuantizer.train_encoder  s    DDT1aQWXXr#   c                 ,    t        j                  |       S r-   )r   1IndexIVFScalarQuantizer_train_encoder_num_vectorsrR   s    r   r  z1IndexIVFScalarQuantizer.train_encoder_num_vectors  s    PPQUVVr#   c                 6    t        j                  | |||||      S r-   )r   &IndexIVFScalarQuantizer_encode_vectorsr   rW   r>   r  r  include_listnoss         r   r  z&IndexIVFScalarQuantizer.encode_vectors  s     EEdAqRZ\acrssr#   c                 4    t        j                  | ||||      S r-   )r   &IndexIVFScalarQuantizer_decode_vectorsr  s        r   r  z&IndexIVFScalarQuantizer.decode_vectors  s    EEdAuV^`abbr#   Nc                 6    t        j                  | |||||      S r-   )r    IndexIVFScalarQuantizer_add_corer  s         r   r  z IndexIVFScalarQuantizer.add_core  s    ??aDRacxyyr#   c                 2    t        j                  | |||      S r-   )r   /IndexIVFScalarQuantizer_get_InvertedListScannerr  s       r   r  z/IndexIVFScalarQuantizer.get_InvertedListScanner  s    NNtU`begmnnr#   c                 2    t        j                  | |||      S r-   )r   /IndexIVFScalarQuantizer_reconstruct_from_offsetr  s       r   r  z/IndexIVFScalarQuantizer.reconstruct_from_offset  s    NNtU\^dflmmr#   c                 2    t        j                  | |||      S r-   )r   !IndexIVFScalarQuantizer_sa_decoderv  s       r   rw  z!IndexIVFScalarQuantizer.sa_decode   s    @@q%QRSSr#   r  r-   )r   r   r6   r7   r   r   r   r   r   IndexIVFScalarQuantizer_sq_getIndexIVFScalarQuantizer_sq_setr  rN   r  r  r  r  r  r  r  rw  delete_IndexIVFScalarQuantizerr   r$   r#   r   r  r    sy     -/IOdeGH	/@@/BpBp	qBsYWtczonT&EEr#   r  c                   >   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zej*                  Z	 ej.                  Z	 ej2                  Z	 ej6                  Z	  eej:                  ej<                        Z eej@                  ejB                  d
      Z"d Z#d Z$ddZ%d Z&d Z'ejP                  Z)y)IndexIVFSpectralHasha  
     Inverted list that stores binary codes of size nbit. Before the
    binary conversion, the dimension of the vectors is transformed from
    dim d into dim nbit by vt (a random rotation by default).

    Each coordinate is subtracted from a value determined by
    threshold_type, and split into intervals of size period. Half of
    the interval is a 0 bit, the other half a 1.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFSpectralHash.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFSpectralHash.<lambda>  rD   r#   rE   rF   z!transformation from d to nbit dimz
own the vtz"nb of bits of the binary signaturezinterval size for 0s and 1szH
    Trained threshold.
    size nlist * nbit or 0 if Thresh_global
    c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFSpectralHash_swiginitnew_IndexIVFSpectralHashr   s     r   rN   zIndexIVFSpectralHash.__init__%  r
  r#   c                 2    t        j                  | |||      S r-   )r   "IndexIVFSpectralHash_train_encoderr  s       r   r  z"IndexIVFSpectralHash.train_encoder(  s    AA$1fUUr#   c                 6    t        j                  | |||||      S r-   )r   #IndexIVFSpectralHash_encode_vectorsr$  s         r   r  z#IndexIVFSpectralHash.encode_vectors+  s    BB4AxY^`oppr#   c                 2    t        j                  | |||      S r-   )r   ,IndexIVFSpectralHash_get_InvertedListScannerr  s       r   r  z,IndexIVFSpectralHash.get_InvertedListScanner.  s    KKDR]_bdjkkr#   c                 .    t        j                  | g| S )a  
        *Overload 1:*
         replace the vector transform for an empty (and possibly untrained) index

        |

        *Overload 2:*
         convenience function to get the VT from an index constucted by an
        index_factory (should end in "LSH")

        |

        *Overload 3:*
         convenience function to get the VT from an index constucted by an
        index_factory (should end in "LSH")
        )r   IndexIVFSpectralHash_replace_vtr   s     r   
replace_vtzIndexIVFSpectralHash.replace_vt1  s    " >>tKdKKr#   Nr  )*r   r   r6   r7   r   r   r   r   r   IndexIVFSpectralHash_vt_getIndexIVFSpectralHash_vt_setr  #IndexIVFSpectralHash_own_fields_get#IndexIVFSpectralHash_own_fields_setrM  IndexIVFSpectralHash_nbit_getIndexIVFSpectralHash_nbit_setr%  IndexIVFSpectralHash_period_getIndexIVFSpectralHash_period_setperiod"IndexIVFSpectralHash_Thresh_globalThresh_global$IndexIVFSpectralHash_Thresh_centroidThresh_centroid)IndexIVFSpectralHash_Thresh_centroid_halfThresh_centroid_half"IndexIVFSpectralHash_Thresh_medianThresh_median'IndexIVFSpectralHash_threshold_type_get'IndexIVFSpectralHash_threshold_type_setthreshold_type IndexIVFSpectralHash_trained_get IndexIVFSpectralHash_trained_setr   rN   r  r  r  rB  delete_IndexIVFSpectralHashr   r$   r#   r   r4  r4    sX    -/IOdeGH	/==?j?j  qY  
ZB/MM  PC  PC  IZ  [JOAA?CpCp  w`  aDoEEGvGv  }_  `F#FFM %JJO*TT+#FFM!oUUWf  XO  XO  PNGGIyIy @ 	G
mVqlL$ 'BBr#   r4  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zd Zdd	Zd
 Zd Zd Zd Zej.                  Zy)IndexIVFAdditiveQuantizerz]
    Abstract class for IVF additive quantizers.
    The search functions are in common.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"IndexIVFAdditiveQuantizer.<lambda>M  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"IndexIVFAdditiveQuantizer.<lambda>M  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   "IndexIVFAdditiveQuantizer_swiginitnew_IndexIVFAdditiveQuantizerr   s     r   rN   z"IndexIVFAdditiveQuantizer.__init__R  s    ::4AnAnptAuvr#   c                 2    t        j                  | |||      S r-   )r   'IndexIVFAdditiveQuantizer_train_encoderr  s       r   r  z'IndexIVFAdditiveQuantizer.train_encoderU  s    FFtQPQSYZZr#   c                 ,    t        j                  |       S r-   )r   3IndexIVFAdditiveQuantizer_train_encoder_num_vectorsrR   s    r   r  z3IndexIVFAdditiveQuantizer.train_encoder_num_vectorsX  s    RRSWXXr#   c                 6    t        j                  | |||||      S r-   )r   (IndexIVFAdditiveQuantizer_encode_vectorsr$  s         r   r  z(IndexIVFAdditiveQuantizer.encode_vectors[  s!    GGaQRT\^cetuur#   c                 4    t        j                  | ||||      S r-   )r   (IndexIVFAdditiveQuantizer_decode_vectorsr  s        r   r  z(IndexIVFAdditiveQuantizer.decode_vectors^  s    GGaQVX`bcddr#   c                 2    t        j                  | |||      S r-   )r   1IndexIVFAdditiveQuantizer_get_InvertedListScannerr  s       r   r  z1IndexIVFAdditiveQuantizer.get_InvertedListScannera  s    PPQUWbdgioppr#   c                 2    t        j                  | |||      S r-   )r   #IndexIVFAdditiveQuantizer_sa_decoder   rW   r  r>   s       r   rw  z#IndexIVFAdditiveQuantizer.sa_decoded  s    BB4ESTUUr#   c                 2    t        j                  | |||      S r-   )r   1IndexIVFAdditiveQuantizer_reconstruct_from_offsetr  s       r   r  z1IndexIVFAdditiveQuantizer.reconstruct_from_offsetg  s    PPQUW^`fhnoor#   Nr  )r   r   r6   r7   r   r   r   r   r    IndexIVFAdditiveQuantizer_aq_get IndexIVFAdditiveQuantizer_aq_setr  3IndexIVFAdditiveQuantizer_use_precomputed_table_get3IndexIVFAdditiveQuantizer_use_precomputed_table_setuse_precomputed_tablerN   r  r  r  r  r  rw  r   delete_IndexIVFAdditiveQuantizerr   r$   r#   r   r[  r[  G  s    
 -/IOdeGH	/BBODtDt	uB$_%h%hjy  kn  kn  ow[YveqVp&GGr#   r[  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	IndexIVFResidualQuantizerv
     IndexIVF based on a residual quantizer. Stored vectors are
    approximated by residual quantization codes.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"IndexIVFResidualQuantizer.<lambda>s  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"IndexIVFResidualQuantizer.<lambda>s  rD   r#   rE   rF   r  c                 P    t        j                  | t        j                  |        y)a  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :param M:      number of subquantizers
        :type nbits: std::vector< size_t >
        :param nbits:  number of bit per subvector index
        N)r   "IndexIVFResidualQuantizer_swiginitnew_IndexIVFResidualQuantizerr   s     r   rN   z"IndexIVFResidualQuantizer.__init__w  s      	::4AnAnptAuvr#   N)r   r   r6   r7   r   r   r   r   r    IndexIVFResidualQuantizer_rq_get IndexIVFResidualQuantizer_rq_setrx	  rN    delete_IndexIVFResidualQuantizerr   r$   r#   r   rw  rw  m  sU    
 -/IOdeGH	/BBODtDt  {s  
tB
w 'GGr#   rw  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	IndexIVFLocalSearchQuantizerrx  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z%IndexIVFLocalSearchQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z%IndexIVFLocalSearchQuantizer.<lambda>  rD   r#   rE   rF   z,The LSQ quantizer used to encode the vectorsc                 P    t        j                  | t        j                  |        yrb  )r   %IndexIVFLocalSearchQuantizer_swiginit new_IndexIVFLocalSearchQuantizerr   s     r   rN   z%IndexIVFLocalSearchQuantizer.__init__  s      	==dODtDtvzD{|r#   N)r   r   r6   r7   r   r   r   r   r   $IndexIVFLocalSearchQuantizer_lsq_get$IndexIVFLocalSearchQuantizer_lsq_setr^
  rN   #delete_IndexIVFLocalSearchQuantizerr   r$   r#   r   r  r    sU    
 -/IOdeGH
?GGI}I}  Dw  xC} 'JJr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	 IndexIVFProductResidualQuantizerz
     IndexIVF based on a product residual quantizer. Stored vectors are
    approximated by product residual quantization codes.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z)IndexIVFProductResidualQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z)IndexIVFProductResidualQuantizer.<lambda>  rD   r#   rE   rF   r  c                 P    t        j                  | t        j                  |        y)ab  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of residual quantizers
        :type Msub: int
        :param Msub:   number of subquantizers per RQ
        :type nbits: int
        :param nbits:  number of bit per subvector index
        N)r   )IndexIVFProductResidualQuantizer_swiginit$new_IndexIVFProductResidualQuantizerr   s     r   rN   z)IndexIVFProductResidualQuantizer.__init__  s+     	AA$H|H|  C  ID  	Er#   N)r   r   r6   r7   r   r   r   r   r   (IndexIVFProductResidualQuantizer_prq_get(IndexIVFProductResidualQuantizer_prq_setr  rN   'delete_IndexIVFProductResidualQuantizerr   r$   r#   r   r  r    s]    
 -/IOdeGH
?KK_  NF  NF  LL  MCE 'NNr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	#IndexIVFProductLocalSearchQuantizerz
     IndexIVF based on a product local search quantizer. Stored vectors are
    approximated by product local search quantization codes.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z,IndexIVFProductLocalSearchQuantizer.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z,IndexIVFProductLocalSearchQuantizer.<lambda>  rD   r#   rE   rF   r"  c                 P    t        j                  | t        j                  |        y)ag  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of local search quantizers
        :type Msub: int
        :param Msub:   number of subquantizers per LSQ
        :type nbits: int
        :param nbits:  number of bit per subvector index
        N)r   ,IndexIVFProductLocalSearchQuantizer_swiginit'new_IndexIVFProductLocalSearchQuantizerr   s     r   rN   z,IndexIVFProductLocalSearchQuantizer.__init__  s3     	DDT?  LC  LC  EI  LJ  	Kr#   N)r   r   r6   r7   r   r   r   r   r   ,IndexIVFProductLocalSearchQuantizer_plsq_get,IndexIVFProductLocalSearchQuantizer_plsq_setr*  rN   *delete_IndexIVFProductLocalSearchQuantizerr   r$   r#   r   r  r    s^    
 -/IOdeGHOPPRa  SO  SO  UY  ZDK 'QQr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zej"                  Zd Zy)SearchParametersHNSWc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSearchParametersHNSW.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSearchParametersHNSW.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   SearchParametersHNSW_swiginitnew_SearchParametersHNSWrR   s    r   rN   zSearchParametersHNSW.__init__  r  r#   N)r   r   r6   r   r   r   r   r   !SearchParametersHNSW_efSearch_get!SearchParametersHNSW_efSearch_setefSearch0SearchParametersHNSW_check_relative_distance_get0SearchParametersHNSW_check_relative_distance_setcheck_relative_distance&SearchParametersHNSW_bounded_queue_get&SearchParametersHNSW_bounded_queue_setbounded_queuedelete_SearchParametersHNSWr   rN   r$   r#   r   r  r    s    -/IOdeGHII?K|K|}H&'g'gix  jj  jj  k_SSUd  VL  VL  MM&BBhr#   r  c                      e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Z eej                  ej                  d      Z eej"                  ej$                  d      Z eej(                  ej*                  d	      Z eej.                  ej0                  d
      Z eej4                  ej6                        Z eej:                  ej<                  d      Z eej@                  ejB                  d      Z" eejF                  ejH                  d      Z% eejL                  ejN                  d      Z( eejR                  ejT                  d      Z+d Z,d Z-d Z.d Z/d Z0d#dZ1d Z2d Z3d$dZ4d$dZ5d%dZ6d%dZ7d Z8d Z9d Z:d$d Z;e<d$d!       Z=d" Z>ej~                  Z@y)&HNSWc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zHNSW.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zHNSW.<lambda>  rD   r#   rE   rF   z,assignment probability to each layer (sum=1)zf
    number of neighbors stored per layer (cumulative), should not
    be changed after first add
    z4level of each vector (base level = 1), size = ntotalzf
    offsets[i] is the offset in the neighbors array where vector i is stored
    size ntotal + 1
    z
    neighbors[offsets[i]:offsets[i+1]] is the list of neighbors of vector i
    for all levels. this is where all storage goes.
    zW
    entry point in the search structure (one of the points with maximum
    level
    zmaximum levelz%expansion factor at construction timezexpansion factor at search timezW
    during search: do we check whether the next best distance is good
    enough?
    z$use bounded queue during explorationc                 0    t        j                  | ||      S )z
        initialize the assign_probas and cum_nneighbor_per_level to
        have 2*M links on level 0 and M links on levels > 0
        )r   HNSW_set_default_probas)r   rM  	levelMults      r   set_default_probaszHNSW.set_default_probas  s    
 66tQ	JJr#   c                 0    t        j                  | ||      S )z;set nb of neighbors for this level (before adding anything))r   HNSW_set_nb_neighbors)r   level_norW   s      r   set_nb_neighborszHNSW.set_nb_neighbors  s    44T8QGGr#   c                 .    t        j                  | |      S )znb of neighbors for this level)r   HNSW_nb_neighborsr   layer_nos     r   nb_neighborszHNSW.nb_neighbors  s    00x@@r#   c                 .    t        j                  | |      S )z/cumumlative nb up to (and excluding) this level)r   HNSW_cum_nb_neighborsr  s     r   cum_nb_neighborszHNSW.cum_nb_neighbors  s    44T8DDr#   c                 4    t        j                  | ||||      S )z@range of entries in the neighbors table of vertex no at layer_no)r   HNSW_neighbor_range)r   r  r  beginends        r   neighbor_rangezHNSW.neighbor_range  s    224XucRRr#   c                 V    t        j                  | t        j                  |             y)z)only mandatory parameter: nb of neighborsN)r   HNSW_swiginitnew_HNSW)r   rM  s     r   rN   zHNSW.__init__  s    %%dO,D,DQ,GHr#   c                 ,    t        j                  |       S )z#pick a random level for a new point)r   HNSW_random_levelrR   s    r   random_levelzHNSW.random_level      0066r#   c                 .    t        j                  | |      S )z/add n random levels to table (for debugging...))r   HNSW_fill_with_random_linksrV   s     r   fill_with_random_linkszHNSW.fill_with_random_links#  s    ::4CCr#   c	                 <    t        j                  | ||||||||	      S r-   )r   HNSW_add_links_starting_from)	r   ptdispt_idnearest	d_nearestlevellocksr  keep_max_size_level0s	            r   add_links_starting_fromzHNSW.add_links_starting_from'  s3    ;;D%PWYbdikprt  wK  L  	Lr#   c           	      8    t        j                  | ||||||      S )zk
         add point pt_id on all levels <= pt_level and build the link
        structure for them.
        )r   HNSW_add_with_locks)r   r  pt_levelr  r  r  r  s          r   add_with_lockszHNSW.add_with_locks*  s$    
 224%QVXZ\pqqr#   Nc                 4    t        j                  | ||||      S )z+search interface for 1 point, single thread)r   HNSW_search)r   qdisr8  r  r9  s        r   r:  zHNSW.search1  s    **4sBGGr#   c
                 >    t        j                  | |||||||||	
      S )z*search only in level 0 from a given vertex)r   HNSW_search_level_0)
r   r  r8  r  	nearest_i	nearest_drV	  search_statsr  r9  s
             r   search_level_0zHNSW.search_level_05  s4    224sFIW`bmo{}  BH  I  	Ir#   c                 ,    t        j                  |       S r-   )r   
HNSW_resetrR   s    r   r  z
HNSW.reset9  s    ))$//r#   c                 .    t        j                  | |      S r-   )r   HNSW_clear_neighbor_tablesr   r  s     r   clear_neighbor_tableszHNSW.clear_neighbor_tables<  r  r#   c                 .    t        j                  | |      S r-   )r   HNSW_print_neighbor_statsr  s     r   print_neighbor_statszHNSW.print_neighbor_stats?  r(  r#   c                 0    t        j                  | ||      S r-   )r   HNSW_prepare_level_tab)r   rW   preset_levelss      r   prepare_level_tabzHNSW.prepare_level_tabB  s    55dA}MMr#   c                 4    t        j                  | ||||      S r-   )r   HNSW_shrink_neighbor_list)r  inputoutputmax_sizer  s        r   shrink_neighbor_listzHNSW.shrink_neighbor_listE  s    88ufhXlmmr#   c                 .    t        j                  | |      S r-   )r   HNSW_permute_entriesr  s     r   r  zHNSW.permute_entriesI  s    33D#>>r#       r  r-   )Ar   r   r6   r   r   r   r   r   HNSW_assign_probas_getHNSW_assign_probas_setassign_probas HNSW_cum_nneighbor_per_level_get HNSW_cum_nneighbor_per_level_setcum_nneighbor_per_levelHNSW_levels_getHNSW_levels_setlevelsHNSW_offsets_getHNSW_offsets_setoffsetsHNSW_neighbors_getHNSW_neighbors_set	neighborsHNSW_entry_point_getHNSW_entry_point_setentry_pointHNSW_rng_getHNSW_rng_setrngHNSW_max_level_getHNSW_max_level_set	max_levelHNSW_efConstruction_getHNSW_efConstruction_setefConstructionHNSW_efSearch_getHNSW_efSearch_setr   HNSW_check_relative_distance_get HNSW_check_relative_distance_setr  HNSW_search_bounded_queue_getHNSW_search_bounded_queue_setsearch_bounded_queuer  r  r  r  r  rN   r  r  r  r  r:  r  r  r  r  r  r  r  r  delete_HNSWr   r$   r#   r   r  r    sB   -/IOdeGH_CC_EkEk  re  fM&'W'WYh  ZJ  ZJ P 	 o557V7V  ]X  YF779Y9Y ` 	G ;;_=_=_ f 	I ???AeAe l 	K ?//1M1M
NC;;_=_=_eyzIoEEGnGn  ua  bN99?;\;\  cI  JH&'W'WYh  ZJ  ZJ P 	 $O$Q$QSb  TA  TA  Gr  sKHAESI7DLrHI0GFN n n?&22r#   r  c                   H   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                  d      Z eej                  ej                  d      Z eej"                  ej$                  d      Zd Zd	 Zd
 Zej.                  Zy)	HNSWStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zHNSWStats.<lambda>P  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zHNSWStats.<lambda>P  rD   r#   rE   rF   znumber of vectors searchedz;number of queries for which the candidate list is exhaustedznumber of distances computedc                 ,    t        j                  |       S )z,number of hops aka number of edges traversed)r   HNSWStats_resetrR   s    r   r  zHNSWStats.resetW  r#  r#   c                 .    t        j                  | |      S r-   )r   HNSWStats_combiner   s     r   combinezHNSWStats.combine[  r`  r#   c                 T    t        j                  | t        j                                y r-   )r   HNSWStats_swiginitnew_HNSWStatsrR   s    r   rN   zHNSWStats.__init__^  r  r#   N)r   r   r6   r   r   r   r   r   HNSWStats_n1_getHNSWStats_n1_setr\  HNSWStats_n2_getHNSWStats_n2_setr]  HNSWStats_ndis_getHNSWStats_ndis_setr_  HNSWStats_nhops_getHNSWStats_nhops_setnhopsr  r,  rN   delete_HNSWStatsr   r$   r#   r   r%  r%  O  s    -/IOdeGH	/22O4T4T	UB	/22O4T4TZ{	|BO668Z8Z  ac  dD_88/:]:]  dG  HE5>R&77r#   r%  c	                 <    t        j                  | ||||||||	      S r-   )r   search_from_candidates)	hnswr  r8  
candidatesr  r  r  nres_inr9  s	            r   r;  r;  e  s'    11$c:rSXZ_ahjpqqr#   c                 4    t        j                  | ||||      S r-   )r   greedy_update_nearest)r<  r  r  r  r  s        r   r@  r@  h  s    00tUGYWWr#   c                 6    t        j                  | |||||      S r-   )r   search_from_candidate_unbounded)r<  noder  efr  r  s         r   rB  rB  k  s    ::4tRQSUZ[[r#   c           
      :    t        j                  | |||||||      S r-   )r   search_neighbors_to_add)r<  r  resultsr  d_entry_pointr  r  reference_versions           r   rF  rF  n  s/    224wUbdikm  pA  B  Br#   c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Zd Zej2                  Zd Zd Zdd
ZddZd Zd Z d Z!ddZ"d Z#d Z$d Z%d Z&d Z'd Z(y	)	IndexHNSWe
     The HNSW index is a normal random-access index with a HNSW
    link structure built on top
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSW.<lambda>v  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSW.<lambda>v  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSW_swiginitnew_IndexHNSWr   s     r   rN   zIndexHNSW.__init__~  r
  r#   c                 0    t        j                  | ||      S r-   )r   IndexHNSW_addr!  s      r   r)  zIndexHNSW.add  rg  r#   c                 0    t        j                  | ||      S zTrains the storage if needed)r   IndexHNSW_trainr!  s      r   r"  zIndexHNSW.train      ..tQ::r#   Nc           	      8    t        j                  | ||||||      S zentry point for search)r   IndexHNSW_searchr8  s          r   r:  zIndexHNSW.search  s     //aAy&RXYYr#   c                 6    t        j                  | |||||      S r-   )r   IndexHNSW_range_searchrA  s         r   rB  zIndexHNSW.range_search  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexHNSW_reconstructrO  s      r   rR  zIndexHNSW.reconstruct  r  r#   c                 ,    t        j                  |       S r-   )r   IndexHNSW_resetrR   s    r   r  zIndexHNSW.reset  r   r#   c                 .    t        j                  | |      S r-   )r   "IndexHNSW_shrink_level_0_neighborsr   r   s     r   shrink_level_0_neighborsz"IndexHNSW.shrink_level_0_neighbors      AA$MMr#   c                 @    t        j                  | |||||||||	|
      S )a  
         Perform search only on level 0, given the starting points for
        each vertex.

        :type search_type: int, optional
        :param search_type: 1:perform one search per nprobe, 2: enqueue
                               all entry points
        )r   IndexHNSW_search_level_0)r   rW   r>   rP  r  r  rQ  rR  r  rV	  r9  s              r   r  zIndexHNSW.search_level_0  s=     77aAwPY[dflnt  wB  DJ  K  	Kr#   c                 2    t        j                  | |||      S zalternative graph building)r   $IndexHNSW_init_level_0_from_knngraph)r   rP  r  r  s       r   init_level_0_from_knngraphz$IndexHNSW.init_level_0_from_knngraph  s    CCD!QPQRRr#   c                 2    t        j                  | |||      S ri  )r   (IndexHNSW_init_level_0_from_entry_points)r   nptpointsnearestss       r   init_level_0_from_entry_pointsz(IndexHNSW.init_level_0_from_entry_points  s    GGcSY[cddr#   c                 ,    t        j                  |       S r-   )r   IndexHNSW_reorder_linksrR   s    r   reorder_linkszIndexHNSW.reorder_links  ro   r#   c                 ,    t        j                  |       S r-   )r   IndexHNSW_link_singletonsrR   s    r   link_singletonszIndexHNSW.link_singletons  r  r#   c                 .    t        j                  | |      S r-   )r   IndexHNSW_permute_entriesr  s     r   r  zIndexHNSW.permute_entries  s    88tDDr#   c                 ,    t        j                  |       S r-   )r   IndexHNSW_get_distance_computerrR   s    r   rk  zIndexHNSW.get_distance_computer  r  r#   r-   )r   r   N))r   r   r6   r7   r   r   r   r   r   IndexHNSW_hnsw_getIndexHNSW_hnsw_setr<  IndexHNSW_own_fields_getIndexHNSW_own_fields_setrM  IndexHNSW_storage_getIndexHNSW_storage_setstorageIndexHNSW_init_level0_getIndexHNSW_init_level0_setinit_level0"IndexHNSW_keep_max_size_level0_get"IndexHNSW_keep_max_size_level0_setr  rN   delete_IndexHNSWr   r)  r"  r:  rB  rR  r  rd  r  rk  rq  rt  rw  r  rk  r$   r#   r   rK  rK  p  s   
 -/IOdeGHO668Z8Z[D/BBODlDlmJ<<o>c>cdG?DDoFoFopK#O$V$VXg  YK  YK  LW&779;ZZH5N	KSe=?EEr#   rK  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)IndexHNSWFlatz_
    Flat index topped with with a HNSW structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSWFlat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSWFlat.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSWFlat_swiginitnew_IndexHNSWFlatr   s     r   rN   zIndexHNSWFlat.__init__      ..t_5V5VX\5]^r#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_IndexHNSWFlatr   r$   r#   r   r  r    s1    
 -/IOdeGH_&;;r#   r  c                   R    e Zd ZdZ ed d d      ZeZd Zd Z	e
j                  Zy)	IndexHNSWPQz]
    PQ index topped with with a HNSW structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSWPQ.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSWPQ.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSWPQ_swiginitnew_IndexHNSWPQr   s     r   rN   zIndexHNSWPQ.__init__  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexHNSWPQ_trainr!  s      r   r"  zIndexHNSWPQ.train  rf  r#   N)r   r   r6   r7   r   r   r   r   rN   r"  r   delete_IndexHNSWPQr   r$   r#   r   r  r    s6    
 -/IOdeGH[=&99r#   r  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)IndexHNSWSQzX
    SQ index topped with a HNSW structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSWSQ.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSWSQ.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSWSQ_swiginitnew_IndexHNSWSQr   s     r   rN   zIndexHNSWSQ.__init__  r  r#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_IndexHNSWSQr   r$   r#   r   r  r    s1    
 -/IOdeGH[&99r#   r  c                   Z    e Zd ZdZ ed d d      ZeZd Zd Z	d
d	Z
ej                  Zy)IndexHNSW2Levelz.2-level code structure with fast random accessc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSW2Level.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSW2Level.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSW2Level_swiginitnew_IndexHNSW2Levelr   s     r   rN   zIndexHNSW2Level.__init__  r  r#   c                 ,    t        j                  |       S r-   )r   IndexHNSW2Level_flip_to_ivfrR   s    r   flip_to_ivfzIndexHNSW2Level.flip_to_ivf  r  r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexHNSW2Level_searchr8  s          r   r:  zIndexHNSW2Level.search  !    55dAq!YPVX^__r#   r-   )r   r   r6   r7   r   r   r   r   rN   r  r:  r   delete_IndexHNSW2Levelr   r$   r#   r   r  r    s;    9-/IOdeGHcA` '==r#   r  c                      e Zd Z ed d d      ZeZd Z eej                  ej                  d      Z eej                  ej                  d      Zd Zdd
Zd Zd Z eej&                  ej(                        Zej,                  Zy	)IndexHNSWCagrac                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexHNSWCagra.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexHNSWCagra.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexHNSWCagra_swiginitnew_IndexHNSWCagrar   s     r   rN   zIndexHNSWCagra.__init__  r  r#   a  
    When set to true, the index is immutable.
    This option is used to copy the knn graph from GpuIndexCagra
    to the base level of IndexHNSWCagra without adding upper levels.
    Doing so enables to search the HNSW index, but removes the
    ability to add vectors.
    
    When `base_level_only` is set to `True`, the search function
    searches only the base level knn graph of the HNSW index.
    This parameter selects the entry point by randomly selecting
    some points and using the best one.
    c                 0    t        j                  | ||      S r-   )r   IndexHNSWCagra_addr!  s      r   r)  zIndexHNSWCagra.add  r  r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexHNSWCagra_searchr8  s          r   r:  zIndexHNSWCagra.search  r  r#   c                 ,    t        j                  |       S r-   )r   IndexHNSWCagra_get_numeric_typerR   s    r   get_numeric_typezIndexHNSWCagra.get_numeric_type  r  r#   c                 .    t        j                  | |      S r-   )r   IndexHNSWCagra_set_numeric_type)r   r
  s     r   set_numeric_typezIndexHNSWCagra.set_numeric_type  s    >>t\RRr#   r-   )r   r   r6   r   r   r   r   rN   r   "IndexHNSWCagra_base_level_only_get"IndexHNSWCagra_base_level_only_setbase_level_only4IndexHNSWCagra_num_base_level_search_entrypoints_get4IndexHNSWCagra_num_base_level_search_entrypoints_set!num_base_level_search_entrypointsr)  r:  r  r   IndexHNSWCagra_numeric_type__get IndexHNSWCagra_numeric_type__setnumeric_type_delete_IndexHNSWCagrar   r$   r#   r   r  r    s    -/IOdeGHaQQSb  TF  TF L 	O )11u1u  xG  x|  x| B )	%>_ES_MMOO  AM&<<r#   r  c                 2    t        j                  | |||      S )ab  
     SMAWK algorithm. Find the row minima of a monotone matrix.

    Expose this for testing.

    :type nrows: int
    :param nrows:    number of rows
    :type ncols: int
    :param ncols:    number of columns
    :type x: float
    :param x:        input matrix, size (nrows, ncols)
    :type argmins: int
    :param argmins:  argmin of each row
    )r   smawk)nrowsncolsr>   argminss       r   r  r  #  s       q'::r#   c                 2    t        j                  | |||      S )u}  
     Exact 1D K-Means by dynamic programming

    From  "Fast Exact k-Means, k-Medians and Bregman Divergence Clustering in 1D"
    Allan Grønlund, Kasper Green Larsen, Alexander Mathiasen, Jesper Sindahl
    Nielsen, Stefan Schneider, Mingzhou Song, ArXiV'17

    Section 2.2

    https://arxiv.org/abs/1701.07204

    :type x: float
    :param x:          input 1D array
    :type n: int
    :param n:          input array length
    :type nclusters: int
    :param nclusters:  number of clusters
    :type centroids: float
    :param centroids:  output centroids, size nclusters
    :rtype: float
    :return: imbalancce factor
    )r   kmeans1d)r>   rW   	nclustersr  s       r   r  r  4  s    . ##Aq)Y??r#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zd Zej&                  Zy)Neighborc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNeighbor.<lambda>M  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNeighbor.<lambda>M  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   Neighbor_swiginitnew_Neighborr   s     r   rN   zNeighbor.__init__S  r  r#   c                 .    t        j                  | |      S r-   )r   Neighbor___lt__r   s     r   __lt__zNeighbor.__lt__V  r   r#   N)r   r   r6   r   r   r   r   r   Neighbor_id_getNeighbor_id_setr  Neighbor_distance_getNeighbor_distance_setr`   Neighbor_flag_getNeighbor_flag_setflagrN   r  delete_Neighborr   r$   r#   r   r  r  L  sw    -/IOdeGH	/11?3R3R	SB==?d?deHO557X7XYDU<&66r#   r  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Zd Zd Zej8                  Zy)Nhoodc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNhood.<lambda>]  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNhood.<lambda>]  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   Nhood_swiginit	new_Nhoodr   s     r   rN   zNhood.__init__f  s    &&t_-F-F-MNr#   c                 0    t        j                  | ||      S r-   )r   Nhood_insert)r   r  dists      r   r  zNhood.inserti  s    ++D"d;;r#   N)r   r   r6   r   r   r   r   r   Nhood_pool_getNhood_pool_setr~	  Nhood_M_getNhood_M_setrM  Nhood_nn_old_getNhood_nn_old_setnn_oldNhood_nn_new_getNhood_nn_new_setnn_newNhood_rnn_old_getNhood_rnn_old_setrnn_oldNhood_rnn_new_getNhood_rnn_new_setrnn_newrN   r  delete_Nhoodr   r$   r#   r   r  r  \  s    -/IOdeGHO22O4R4RSD,,o.I.IJAo668X8XYFo668X8XYF88/:[:[\G88/:[:[\GO<&33r#   r  c                   6   e Zd Z ed d d      ZeZd Zej                  Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Z eej(                  ej*                        Z eej.                  ej0                        Z eej4                  ej6                        Z eej:                  ej<                        Z eej@                  ejB                        Z" eejF                  ejH                        Z% eejL                  ejN                        Z( eejR                  ejT                        Z+ eejX                  ejZ                        Z. eej^                  ej`                        Z1 eejd                  ejf                        Z4 eejj                  ejl                        Z7y)	NNDescentc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNNDescent.<lambda>p  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNNDescent.<lambda>p  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   NNDescent_swiginitnew_NNDescent)r   r
  r3
  s      r   rN   zNNDescent.__init__s  s     **41N1NqRS1TUr#   c                 2    t        j                  | |||      S r-   )r   NNDescent_build)r   r  rW   r  s       r   buildzNNDescent.buildw  s    ..tT1gFFr#   c                 6    t        j                  | |||||      S r-   )r   NNDescent_search)r   r  topkindicesdistsr  s         r   r:  zNNDescent.searchz  s    //dD'5RTUUr#   c                 ,    t        j                  |       S r-   )r   NNDescent_resetrR   s    r   r  zNNDescent.reset}  r   r#   c                 .    t        j                  | |      S )z!Initialize the KNN graph randomly)r   NNDescent_init_graphr   r  s     r   
init_graphzNNDescent.init_graph  s    33D$??r#   c                 0    t        j                  | ||      S )zPerform NNDescent algorithm)r   NNDescent_nndescent)r   r  r  s      r   	nndescentzNNDescent.nndescent  s    224wGGr#   c                 .    t        j                  | |      S )zPerform local join on each node)r   NNDescent_joinr  s     r   joinzNNDescent.join  s    --dD99r#   c                 ,    t        j                  |       S )z=Sample new neighbors for each node to peform local join later)r   NNDescent_updaterR   s    r   updatezNNDescent.update  s    //55r#   c                 4    t        j                  | ||||      S )zESample a small number of points to evaluate the quality of KNNG built)r   NNDescent_generate_eval_set)r   r  rx  rC   Ns        r   generate_eval_setzNNDescent.generate_eval_set  s    ::4q!QOOr#   c                 0    t        j                  | ||      S )z"Evaluate the quality of KNNG built)r   NNDescent_eval_recall)r   ctrl_pointsacc_eval_sets      r   eval_recallzNNDescent.eval_recall  s    44T;UUr#   N)8r   r   r6   r   r   r   r   rN   r   delete_NNDescentr   r  r:  r  r  r  r  r   r$  r)  NNDescent_has_built_getNNDescent_has_built_set	has_builtNNDescent_S_getNNDescent_S_setSNNDescent_R_getNNDescent_R_setRNNDescent_iter_getNNDescent_iter_setiterNNDescent_search_L_getNNDescent_search_L_setsearch_LNNDescent_random_seed_getNNDescent_random_seed_setrK
  NNDescent_K_getNNDescent_K_setr3
  NNDescent_d_getNNDescent_d_setr
  NNDescent_L_getNNDescent_L_setLNNDescent_ntotal_getNNDescent_ntotal_setr  NNDescent_graph_getNNDescent_graph_setgraphNNDescent_final_graph_getNNDescent_final_graph_setfinal_graphr$   r#   r   r  r  o  s   -/IOdeGHV&77GV5@H:6PV @@/BiBijI00/2Q2QRA00/2Q2QRAO668Z8Z[D>>@f@fgH?DDoFoFopK00/2Q2QRA00/2Q2QRA00/2Q2QRAo::O<`<`aF_88/:]:]^E?DDoFoFopKr#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                        Z eej                  ej                         Zd Zej&                  Zd Zd	 ZddZd Zd Zy
)IndexNNDescentzp
     The NNDescent index is a normal random-access index with an NNDescent
    link structure built on top
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNNDescent.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNNDescent.<lambda>  rD   r#   rE   rF   zFaiss results are 64-bitc                 P    t        j                  | t        j                  |        y r-   )r   IndexNNDescent_swiginitnew_IndexNNDescentr   s     r   rN   zIndexNNDescent.__init__  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexNNDescent_addr!  s      r   r)  zIndexNNDescent.add  r  r#   c                 0    t        j                  | ||      S rU  )r   IndexNNDescent_trainr!  s      r   r"  zIndexNNDescent.train      33D!Q??r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexNNDescent_searchr8  s          r   r:  zIndexNNDescent.search  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexNNDescent_reconstructrO  s      r   rR  zIndexNNDescent.reconstruct  r  r#   c                 ,    t        j                  |       S r-   )r   IndexNNDescent_resetrR   s    r   r  zIndexNNDescent.reset  rS   r#   r-   )r   r   r6   r7   r   r   r   r   r   IndexNNDescent_nndescent_getIndexNNDescent_nndescent_setr  IndexNNDescent_own_fields_getIndexNNDescent_own_fields_setrM  IndexNNDescent_storage_getIndexNNDescent_storage_setr  rN   delete_IndexNNDescentr   r)  r"  r:  rR  r  r$   r#   r   rL  rL    s    
 -/IOdeGHEEGsGs  zY  ZI/GGIvIvwJAA?CmCmnGa&<<>@_M:r#   rL  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)IndexNNDescentFlatzd
    Flat index topped with with a NNDescent structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNNDescentFlat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNNDescentFlat.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexNNDescentFlat_swiginitnew_IndexNNDescentFlatr   s     r   rN   zIndexNNDescentFlat.__init__  r  r#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_IndexNNDescentFlatr   r$   r#   r   re  re    s1    
 -/IOdeGHi&@@r#   re  c                   t    e Zd ZdZ ed d d      ZeZddZddZ	d	 Z
d
 Zd Zd Zd Zej                   Zy)IndexIVFFlatz
     Inverted file with stored vectors. Here the inverted file
    pre-selects the vectors to be searched, but they are not otherwise
    encoded, the code array just contains the raw float entries.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFFlat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFFlat.<lambda>  rD   r#   rE   rF   Nc                 6    t        j                  | |||||      S r-   )r   IndexIVFFlat_add_corer  s         r   r  zIndexIVFFlat.add_core  s    44T1aXmnnr#   c                 6    t        j                  | |||||      S r-   )r   IndexIVFFlat_encode_vectorsr$  s         r   r  zIndexIVFFlat.encode_vectors  s    ::4AxQVXghhr#   c                 4    t        j                  | ||||      S r-   )r   IndexIVFFlat_decode_vectorsr  s        r   r  zIndexIVFFlat.decode_vectors  s    ::4E8UVWWr#   c                 2    t        j                  | |||      S r-   )r   $IndexIVFFlat_get_InvertedListScannerr  s       r   r  z$IndexIVFFlat.get_InvertedListScanner  s    CCD+WZ\bccr#   c                 2    t        j                  | |||      S r-   )r   $IndexIVFFlat_reconstruct_from_offsetr  s       r   r  z$IndexIVFFlat.reconstruct_from_offset  s    CCD'SY[abbr#   c                 2    t        j                  | |||      S r-   )r   IndexIVFFlat_sa_decoderv  s       r   rw  zIndexIVFFlat.sa_decode      55dAuaHHr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFFlat_swiginitnew_IndexIVFFlatr   s     r   rN   zIndexIVFFlat.__init__  r  r#   r-   r  )r   r   r6   r7   r   r   r   r   r  r  r  r  r  rw  rN   r   delete_IndexIVFFlatr   r$   r#   r   rm  rm    sU     -/IOdeGHoiXdcI]&::r#   rm  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
d Zd Zdd	Zd
 ZddZd Zd Zd Zej&                  Zy)IndexIVFFlatDedupc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFFlatDedup.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFFlatDedup.<lambda>  rD   r#   rE   rF   z
    Maps ids stored in the index to the ids of vectors that are
    the same. When a vector is unique, it does not appear in the
    instances map
    c                 0    t        j                  | ||      S )zalso dedups the training set)r   IndexIVFFlatDedup_trainr!  s      r   r"  zIndexIVFFlatDedup.train  r	  r#   c                 2    t        j                  | |||      S )z%implemented for all IndexIVF* classes)r   IndexIVFFlatDedup_add_with_idsr/  s       r   r1  zIndexIVFFlatDedup.add_with_ids  s    ==dAq$OOr#   Nc                 @    t        j                  | |||||||||	|
      S r-   )r   $IndexIVFFlatDedup_search_preassignedr  s              r   r  z$IndexIVFFlatDedup.search_preassigned  sA    CCD!QPQSY[girtz  }H  JP  RW  X  	Xr#   c                 .    t        j                  | |      S r-   )r   IndexIVFFlatDedup_remove_idsrK  s     r   rL  zIndexIVFFlatDedup.remove_ids      ;;D#FFr#   c                 6    t        j                  | |||||      S r  )r   IndexIVFFlatDedup_range_searchrA  s         r   rB  zIndexIVFFlatDedup.range_search  s    ==dAq&RXZ`aar#   c                 2    t        j                  | |||      S r  )r    IndexIVFFlatDedup_update_vectorsr  s       r   r  z IndexIVFFlatDedup.update_vectors  s    ??b#qQQr#   c                 2    t        j                  | |||      S r  )r   )IndexIVFFlatDedup_reconstruct_from_offsetr  s       r   r  z)IndexIVFFlatDedup.reconstruct_from_offset  s    HHwX^`fggr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFFlatDedup_swiginitnew_IndexIVFFlatDedupr   s     r   rN   zIndexIVFFlatDedup.__init__  r	  r#   r	  r-   )r   r   r6   r   r   r   r   r   IndexIVFFlatDedup_instances_getIndexIVFFlatDedup_instances_set	instancesr"  r1  r  rL  rB  r  r  rN   delete_IndexIVFFlatDedupr   r$   r#   r   r  r    st    -/IOdeGHHH/JyJy @ 	ICPXGbRhg&??r#   r  c                 ,    t        j                  |       S r-   )r   storage_distance_computer)r  s    r   r  r  $  s    44W==r#   c                      e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Z eej                  ej                  d      Z eej"                  ej$                  d      Z eej(                  ej*                  d	      Z eej.                  ej0                  d
      Z eej4                  ej6                  d      Z eej:                  ej<                  d      Z eej@                  ejB                  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/ej`                  Z1y)NSGc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNSG.<lambda>'  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNSG.<lambda>'  rD   r#   rE   rF   znb of nodesnb of neighbors per nodez.length of the search path at construction timez(candidate pool size at construction timezlength of the search path
enterpointzNSG graph structurezNSG is built or notzrandom generatorc                 V    t        j                  | t        j                  |             y r-   )r   NSG_swiginitnew_NSG)r   r3  s     r   rN   zNSG.__init__3  s    $$T?+B+B1+EFr#   c                 4    t        j                  | ||||      S r-   )r   	NSG_build)r   r  rW   	knn_graphr  s        r   r  z	NSG.build6  s    ((w9gNNr#   c                 ,    t        j                  |       S r-   )r   	NSG_resetrR   s    r   r  z	NSG.reset9  s    ((..r#   c                 6    t        j                  | |||||      S r-   )r   
NSG_search)r   rE  rP  r  r  r  s         r   r:  z
NSG.search<  s    ))$Q1bAAr#   c                 0    t        j                  | ||      S r-   )r   NSG_init_graph)r   r  r  s      r   r  zNSG.init_graph?  s    --dGYGGr#   c                 4    t        j                  | ||||      S r-   )r   NSG_add_reverse_links)r   qr  rE  rG  s        r   add_reverse_linkszNSG.add_reverse_linksB  s    44T1eS%PPr#   c           	      8    t        j                  | ||||||      S r-   )r   NSG_sync_prune)r   r  r~	  rE  r  r  rG  s          r   
sync_prunezNSG.sync_pruneE  s     --dAtS"iQVWWr#   c                 4    t        j                  | ||||      S r-   )r   NSG_link)r   r  r  rG  r  s        r   linkzNSG.linkH  s    ''gy%QQr#   c                 0    t        j                  | ||      S r-   )r   NSG_tree_grow)r   r  degreess      r   	tree_growzNSG.tree_growK  s    ,,T7GDDr#   c                 2    t        j                  | |||      S r-   )r   NSG_dfs)r   r  rootcnts       r   dfszNSG.dfsN  s    &&tRs;;r#   c                 4    t        j                  | ||||      S r-   )r   NSG_attach_unlinked)r   r  r  vt2r  s        r   attach_unlinkedzNSG.attach_unlinkedQ  s    224"c7SSr#   c                 ,    t        j                  |       S r-   )r   NSG_check_graphrR   s    r   check_graphzNSG.check_graphT  r   r#   c                 ,    t        j                  |       S r-   )r   NSG_get_final_graphrR   s    r   get_final_graphzNSG.get_final_graphW  rh   r#   Nr  )2r   r   r6   r   r   r   r   r   NSG_ntotal_getNSG_ntotal_setr  	NSG_R_get	NSG_R_setr3  	NSG_L_get	NSG_L_setrB  	NSG_C_get	NSG_C_setCNSG_search_L_getNSG_search_L_setr9  NSG_enterpoint_getNSG_enterpoint_setr  NSG_final_graph_getNSG_final_graph_setrJ  NSG_is_built_getNSG_is_built_setis_builtNSG_rng_getNSG_rng_setr  rN   r  r  r:  r  r  r  r  r  r  r  r  r  
delete_NSGr   r$   r#   r   r  r  &  sv   -/IOdeGHo44o6T6TZlmF**O,E,EKjkA**O,E,E  LA  	BA**O,E,EKz{A88/:Z:Z  aA  BH/<<o>`>`fwxJ?>>@c@c  jD  EK88/:Z:Z`z{H
?..0K0KQh
iCGO/BHQXRE<T59&11r#   r  c                   L   e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Z eej                  ej                  d      Z eej"                  ej$                  d      Zd	 Zej*                  Zd
 Zd Zy)NSG_Graph_intc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNSG_Graph_int.<lambda>^  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNSG_Graph_int.<lambda>^  rD   r#   rE   rF   z+the flattened adjacency matrix, size N-by-Kr  ztotal nb of nodesz*the underlying data owned by itself or notc                 P    t        j                  | t        j                  |        y r-   )r   NSG_Graph_int_swiginitnew_NSG_Graph_intr   s     r   rN   zNSG_Graph_int.__init__e  r  r#   c                 .    t        j                  | g| S r-   )r   NSG_Graph_int_atr   s     r   r   zNSG_Graph_int.ati  r  r#   c                 0    t        j                  | ||      S r-   )r   NSG_Graph_int_get_neighbors)r   r-  r  s      r   get_neighborszNSG_Graph_int.get_neighborsl  s    ::4INNr#   N)r   r   r6   r   r   r   r   r   NSG_Graph_int_data_getNSG_Graph_int_data_setr   NSG_Graph_int_K_getNSG_Graph_int_K_setr3
  NSG_Graph_int_N_getNSG_Graph_int_N_setr#  NSG_Graph_int_own_fields_getNSG_Graph_int_own_fields_setrM  rN   delete_NSG_Graph_intr   r   r  r$   r#   r   r  r  ]  s    -/IOdeGHO::O<b<b  i[  \D44o6Y6Y_~A44o6Y6Y_wxA/FFHtHt  {l  mJ_&;;=Or#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                  d	      Z eej0                  ej2                  d
      Z eej6                  ej8                  d      Z eej<                  ej>                        Z  eejB                  ejD                        Z# eejH                  ejJ                        Z&d Z'ejP                  Z)d Z*d Z+d Z,ddZ-d Z.d Z/d Z0y)IndexNSGzc
     The NSG index is a normal random-access index with a NSG
    link structure built on top
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNSG.<lambda>w  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNSG.<lambda>w  rD   r#   rE   rF   zthe link structurezthe sequential storagezthe index is built or notzK of KNN graph for buildingzx
    indicate how to build a knn graph
    - 0: build NSG with brute force search
    - 1: build NSG with NNDescent
    zparameters for nndescentc                 P    t        j                  | t        j                  |        y r-   )r   IndexNSG_swiginitnew_IndexNSGr   s     r   rN   zIndexNSG.__init__  r  r#   c                 4    t        j                  | ||||      S r-   )r   IndexNSG_build)r   rW   r>   r  GKs        r   r  zIndexNSG.build  s    --dAq)RHHr#   c                 0    t        j                  | ||      S r-   )r   IndexNSG_addr!  s      r   r)  zIndexNSG.add  s    ++D!Q77r#   c                 0    t        j                  | ||      S rU  )r   IndexNSG_trainr!  s      r   r"  zIndexNSG.train  r  r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexNSG_searchr8  s          r   r:  zIndexNSG.search  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexNSG_reconstructrO  s      r   rR  zIndexNSG.reconstruct  s    33D#vFFr#   c                 ,    t        j                  |       S r-   )r   IndexNSG_resetrR   s    r   r  zIndexNSG.reset  r
  r#   c                 2    t        j                  | |||      S r-   )r   IndexNSG_check_knn_graph)r   r  rW   r3
  s       r   check_knn_graphzIndexNSG.check_knn_graph  s    77iANNr#   r-   )1r   r   r6   r7   r   r   r   r   r   IndexNSG_nsg_getIndexNSG_nsg_setnsgIndexNSG_own_fields_getIndexNSG_own_fields_setrM  IndexNSG_storage_getIndexNSG_storage_setr  IndexNSG_is_built_getIndexNSG_is_built_setr  IndexNSG_GK_getIndexNSG_GK_setr  IndexNSG_build_type_getIndexNSG_build_type_set
build_typeIndexNSG_nndescent_S_getIndexNSG_nndescent_S_setnndescent_SIndexNSG_nndescent_R_getIndexNSG_nndescent_R_setnndescent_RIndexNSG_nndescent_L_getIndexNSG_nndescent_L_setnndescent_LIndexNSG_nndescent_iter_getIndexNSG_nndescent_iter_setnndescent_iterrN   delete_IndexNSGr   r  r)  r"  r:  rR  r  r  r$   r#   r   r  r  q  sv   
 -/IOdeGH
?33_5U5U[t
uC/AA?CjCj  qN  OJ;;_=a=abG==?d?d  kK  LH	/11?3R3RXz	{B/AA?CjCj q 	J
 ?CC_EmEm  tS  TK?CC_EmEmnK?CC_EmEmnKoII?KvKvwNU&66I8:YG4Or#   r  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)IndexNSGFlatz^
    Flat index topped with with a NSG structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNSGFlat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNSGFlat.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexNSGFlat_swiginitnew_IndexNSGFlatr   s     r   rN   zIndexNSGFlat.__init__  r  r#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_IndexNSGFlatr   r$   r#   r   r)  r)    s1    
 -/IOdeGH]&::r#   r)  c                   R    e Zd ZdZ ed d d      ZeZd Zd Z	e
j                  Zy)	
IndexNSGPQz\
    PQ index topped with with a NSG structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNSGPQ.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNSGPQ.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexNSGPQ_swiginitnew_IndexNSGPQr   s     r   rN   zIndexNSGPQ.__init__  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexNSGPQ_trainr!  s      r   r"  zIndexNSGPQ.train      //a;;r#   N)r   r   r6   r7   r   r   r   r   rN   r"  r   delete_IndexNSGPQr   r$   r#   r   r1  r1    s6    
 -/IOdeGHY<&88r#   r1  c                   L    e Zd ZdZ ed d d      ZeZd Ze	j                  Zy)
IndexNSGSQz\
    SQ index topped with with a NSG structure to access elements
    more efficiently.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNSGSQ.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNSGSQ.<lambda>  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexNSGSQ_swiginitnew_IndexNSGSQr   s     r   rN   zIndexNSGSQ.__init__  r  r#   N)r   r   r6   r7   r   r   r   r   rN   r   delete_IndexNSGSQr   r$   r#   r   r<  r<    s1    
 -/IOdeGHY&88r#   r<  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zej$                  Zy)OnDiskOneListc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOnDiskOneList.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOnDiskOneList.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   OnDiskOneList_swiginitnew_OnDiskOneListrR   s    r   rN   zOnDiskOneList.__init__  r   r#   N)r   r   r6   r   r   r   r   r   OnDiskOneList_size_getOnDiskOneList_size_setr   OnDiskOneList_capacity_getOnDiskOneList_capacity_setcapacityOnDiskOneList_offset_getOnDiskOneList_offset_setr}  rN   delete_OnDiskOneListr   r$   r#   r   rD  rD    sr    -/IOdeGHO::O<b<bcDBBODnDnoHo>>@h@hiFZ&;;r#   rD  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Z eej0                  ej2                        Zd Zd Zd Zd	 Zd
 Zd Z ddZ!ddZ"d Z#d Z$ejJ                  Z& eejN                  ejP                        Z) eejT                  ejV                        Z, eejZ                  ej\                        Z/d Z0d Z1d Z2d Z3d Z4d Z5d Z6y)OnDiskInvertedListsa.  
     On-disk storage of inverted lists.

    The data is stored in a mmapped chunk of memory (base pointer ptr,
    size totsize). Each list is a range of memory that contains (object
    List) that contains:

    - uint8_t codes[capacity * code_size]
    - followed by idx_t ids[capacity]

    in each of the arrays, the size <= capacity first elements are
    used, the rest is not initialized.

    Addition and resize are supported by:
    - roundind up the capacity of the lists to a power of two
    - maintaining a list of empty slots, sorted by size.
    - resizing the mmapped block is adjusted as needed.

    An OnDiskInvertedLists is compact if the size == capacity for all
    lists and there are no available slots.

    Addition to the invlists is slow. For incremental add it is better
    to use a default ArrayInvertedLists object and convert it to an
    OnDisk with merge_from.

    When it is known that a set of lists will be accessed, it is useful
    to call prefetch_lists, that launches a set of threads to read the
    lists in parallel.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOnDiskInvertedLists.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOnDiskInvertedLists.<lambda>  rD   r#   rE   rF   c                 .    t        j                  | |      S r-   )r   OnDiskInvertedLists_list_sizer  s     r   r  zOnDiskInvertedLists.list_size
  r&  r#   c                 .    t        j                  | |      S r-   )r   OnDiskInvertedLists_get_codesr  s     r   r  zOnDiskInvertedLists.get_codes  r&  r#   c                 .    t        j                  | |      S r-   )r   OnDiskInvertedLists_get_idsr  s     r   r  zOnDiskInvertedLists.get_ids  r+  r#   c                 4    t        j                  | ||||      S r-   )r   OnDiskInvertedLists_add_entriesr  s        r   r  zOnDiskInvertedLists.add_entries  s    >>tWgWZ\`aar#   c                 6    t        j                  | |||||      S r-   )r   "OnDiskInvertedLists_update_entriesr  s         r   r  z"OnDiskInvertedLists.update_entries  s!    AA$QWY`begkllr#   c                 0    t        j                  | ||      S r-   )r   OnDiskInvertedLists_resizer  s      r   r   zOnDiskInvertedLists.resize  s    99$RRr#   c                 4    t        j                  | ||||      S r-   )r   'OnDiskInvertedLists_merge_from_multiple)r   r"  n_ilrt  r  s        r   merge_from_multiplez'OnDiskInvertedLists.merge_from_multiple  s    FFtSRVXacjkkr#   c                 0    t        j                  | ||      S )z'same as merge_from for a single invlist)r    OnDiskInvertedLists_merge_from_1)r   rE  r  s      r   merge_from_1z OnDiskInvertedLists.merge_from_1  s    ??b'RRr#   c                 0    t        j                  | ||      S )zHrestrict the inverted lists to l0:l1 without touching the mmapped region)r   !OnDiskInvertedLists_crop_invlists)r   l0l1s      r   crop_invlistsz!OnDiskInvertedLists.crop_invlists#  s    @@r2NNr#   c                 0    t        j                  | ||      S r-   )r   "OnDiskInvertedLists_prefetch_listsr  s      r   r  z"OnDiskInvertedLists.prefetch_lists'  r.  r#   c                 ,    t        j                  |       S r-   )r   OnDiskInvertedLists_do_mmaprR   s    r   do_mmapzOnDiskInvertedLists.do_mmap.  r  r#   c                 .    t        j                  | |      S r-   )r   "OnDiskInvertedLists_update_totsize)r   new_totsizes     r   update_totsizez"OnDiskInvertedLists.update_totsize1  s    AA$TTr#   c                 0    t        j                  | ||      S r-   )r   !OnDiskInvertedLists_resize_lockedr  s      r   resize_lockedz!OnDiskInvertedLists.resize_locked4  s    @@wPXYYr#   c                 .    t        j                  | |      S r-   )r   !OnDiskInvertedLists_allocate_slot)r   rN  s     r   allocate_slotz!OnDiskInvertedLists.allocate_slot7  s    @@xPPr#   c                 0    t        j                  | ||      S r-   )r   OnDiskInvertedLists_free_slot)r   r}  rN  s      r   	free_slotzOnDiskInvertedLists.free_slot:  s    <<T68TTr#   c                 .    t        j                  | |      S )z1override all list sizes and make a packed storage)r   'OnDiskInvertedLists_set_all_lists_sizes)r   r  s     r   set_all_lists_sizesz'OnDiskInvertedLists.set_all_lists_sizes=  s    FFtUSSr#   c                 P    t        j                  | t        j                  |        y)z#are inverted lists mapped read-onlyN)r   OnDiskInvertedLists_swiginitnew_OnDiskInvertedListsr   s     r   rN   zOnDiskInvertedLists.__init__A  s    44T?;b;bdh;ijr#   N)FFr  )7r   r   r6   r7   r   r   r   r   r   OnDiskInvertedLists_lists_getOnDiskInvertedLists_lists_setlistsOnDiskInvertedLists_slots_getOnDiskInvertedLists_slots_setslots OnDiskInvertedLists_filename_get OnDiskInvertedLists_filename_setfilenameOnDiskInvertedLists_totsize_getOnDiskInvertedLists_totsize_settotsizeOnDiskInvertedLists_ptr_getOnDiskInvertedLists_ptr_setr  !OnDiskInvertedLists_read_only_get!OnDiskInvertedLists_read_only_set	read_onlyr  r  r  r  r  r   re  rh  rm  r  delete_OnDiskInvertedListsr   OnDiskInvertedLists_locks_getOnDiskInvertedLists_locks_setr  OnDiskInvertedLists_pf_getOnDiskInvertedLists_pf_setpf(OnDiskInvertedLists_prefetch_nthread_get(OnDiskInvertedLists_prefetch_nthread_setprefetch_nthreadrr  rv  ry  r|  r  r  rN   r$   r#   r   rS  rS    sv   < -/IOdeGH_BBODqDqrE_BBODqDqrEHH/JzJz{HFFHwHwxG
?>>@k@k
lCJJOL}L}~ILLJbmSlSOY&AA_BBODqDqrE	/<<o>h>h	iB X XZi  [S  [S  TAUZQUTkr#   rS  c                   D   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                  d      Zd Zd Zd	 Zej0                  Zy
)ZnSphereSearcha   
     returns the nearest vertex in the sphere to a query. Returns only
    the coordinates, not an id.

    Algorithm: all points are derived from a one atom vector up to a
    permutation and sign changes. The search function finds the most
    appropriate atom and transformation.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zZnSphereSearch.<lambda>Q  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zZnSphereSearch.<lambda>Q  rD   r#   rE   rF   zsize dim * ntatomc                 X    t        j                  | t        j                  ||             y r-   )r   ZnSphereSearch_swiginitnew_ZnSphereSearchr   r  r  s      r   rN   zZnSphereSearch.__init__X  s!    //o6X6XY\^`6abr#   c                 .    t        j                  | g| S )a  
        *Overload 1:*
        find nearest centroid. x does not need to be normalized

        |

        *Overload 2:*
        full call. Requires externally-allocated temp space

        |

        *Overload 3:*
        full call. Requires externally-allocated temp space
        )r   ZnSphereSearch_searchr   s     r   r:  zZnSphereSearch.search[  s     44TADAAr#   c                 4    t        j                  | ||||      S r-   )r   ZnSphereSearch_search_multi)r   rW   r>   c_outdp_outs        r   search_multizZnSphereSearch.search_multil  s    ::4AufUUr#   N)r   r   r6   r7   r   r   r   r   r   ZnSphereSearch_dimS_getZnSphereSearch_dimS_setdimSZnSphereSearch_r2_getZnSphereSearch_r2_setr  ZnSphereSearch_natom_getZnSphereSearch_natom_setnatomZnSphereSearch_voc_getZnSphereSearch_voc_setvocrN   r:  r  delete_ZnSphereSearchr   r$   r#   r   r  r  G  s     -/IOdeGHO;;_=d=deD	/779^9^	_B_==?g?ghE
?99?;a;ag  ACcB"V&<<r#   r  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                  d      Z eej                  ej                        Zd Zd Zd	 Zd
 Zd Zej(                  Zy)EnumeratedVectorsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zEnumeratedVectors.<lambda>s  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zEnumeratedVectors.<lambda>s  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zEnumeratedVectors.__init__u  rO   r#   zsize of the collectionc                 .    t        j                  | |      S )z!encode a vector from a collection)r   EnumeratedVectors_encoder_   s     r   r  zEnumeratedVectors.encode{  s    77a@@r#   c                 0    t        j                  | ||      S )z	decode it)r   EnumeratedVectors_decoder   r   rx  s      r   r  zEnumeratedVectors.decode  s    77dAFFr#   c                 2    t        j                  | |||      S r-   )r   EnumeratedVectors_encode_multi)r   ncrx  r  s       r   encode_multizEnumeratedVectors.encode_multi  s    ==dB5QQr#   c                 2    t        j                  | |||      S r-   )r   EnumeratedVectors_decode_multi)r   r  r  rx  s       r   decode_multizEnumeratedVectors.decode_multi  s    ==dBqQQr#   c           	      8    t        j                  | ||||||      S r-   )r   EnumeratedVectors_find_nn)r   rW   r  r  rQ  rb  rE  s          r   find_nnzEnumeratedVectors.find_nn  s!    88q%RQTVYZZr#   N)r   r   r6   r   r   rN   r   r   r   EnumeratedVectors_nv_getEnumeratedVectors_nv_setr  EnumeratedVectors_dim_getEnumeratedVectors_dim_setr  r  r  r  r  r  delete_EnumeratedVectorsr   r$   r#   r   r  r  r  s    -/IOdeGKH	/::O<d<d  kH  
IB
?<<o>g>g
hCAGRR[&??r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zej                  Zy)Repeatc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRepeat.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRepeat.<lambda>  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   Repeat_swiginit
new_RepeatrR   s    r   rN   zRepeat.__init__      ''o.H.H.JKr#   N)r   r   r6   r   r   r   r   r   Repeat_val_getRepeat_val_setvalRepeat_n_getRepeat_n_setrW   rN   delete_Repeatr   r$   r#   r   r  r    sZ    -/IOdeGH
?11?3Q3Q
RC--/K/KLAL&44r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        ZddZd Zd	 Zd
 Zej&                  Zy)Repeatsz
    Repeats: used to encode a vector that has n occurrences of
    val. Encodes the signs and permutation of the vector. Useful for
    atoms.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRepeats.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRepeats.<lambda>  rD   r#   rE   rF   Nc                 X    t        j                  | t        j                  ||             y r-   )r   Repeats_swiginitnew_Repeats)r   r  rx  s      r   rN   zRepeats.__init__  s     ((/J/J3PQ/RSr#   c                 ,    t        j                  |       S r-   )r   Repeats_countrR   s    r   countzRepeats.count  s    ,,T22r#   c                 .    t        j                  | |      S r-   )r   Repeats_encoder  s     r   r  zRepeats.encode  r   r#   c                 0    t        j                  | ||      S r-   )r   Repeats_decoder  s      r   r  zRepeats.decode  s    --dD!<<r#   r   N)r   r   r6   r7   r   r   r   r   r   Repeats_dim_getRepeats_dim_setr  Repeats_repeats_getRepeats_repeats_setrepeatsrN   r  r  r  delete_Repeatsr   r$   r#   r   r  r    sp     -/IOdeGH
?22O4S4S
TC::O<_<_`GT37=&55r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zd Zd	 Zej,                  Zy
)ZnSphereCodecz
     codec that can return ids for the encoded vectors

    uses the ZnSphereSearch to encode the vector by encoding the
    permutation and signs. Depends on ZnSphereSearch because it uses
    the atom numbers
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zZnSphereCodec.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zZnSphereCodec.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   ZnSphereCodec_swiginitnew_ZnSphereCodecr  s      r   rN   zZnSphereCodec.__init__  s!    ..t_5V5VWZ\^5_`r#   c                 .    t        j                  | |      S r-   )r   ZnSphereCodec_search_and_encoder_   s     r   search_and_encodezZnSphereCodec.search_and_encode  s    >>tQGGr#   c                 0    t        j                  | ||      S r-   )r   ZnSphereCodec_decoder  s      r   r  zZnSphereCodec.decode  s    33D$BBr#   c                 .    t        j                  | |      S )z.takes vectors that do not need to be centroids)r   ZnSphereCodec_encoder_   s     r   r  zZnSphereCodec.encode      33D!<<r#   N)r   r   r6   r7   r   r   r   r   r   ZnSphereCodec_code_segments_getZnSphereCodec_code_segments_setcode_segmentsZnSphereCodec_nv_getZnSphereCodec_nv_setr  ZnSphereCodec_code_size_getZnSphereCodec_code_size_setr!  rN   r   r  r  delete_ZnSphereCodecr   r$   r#   r   r  r    s     -/IOdeGH_LLoN}N}~M	/668\8\	]BDDoFqFqrIaHC= ';;r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zd Zd	 Z eej,                  ej.                        Z eej2                  ej4                        Z eej8                  ej:                        Z eej>                  ej@                        Z!d
 Z"d Z#d Z$ejJ                  Z&y)ZnSphereCodecRecz
     recursive sphere codec

    Uses a recursive decomposition on the dimensions to encode
    centroids found by the ZnSphereSearch. The codes are *not*
    compatible with the ones of ZnSpehreCodec
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zZnSphereCodecRec.<lambda>  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zZnSphereCodecRec.<lambda>  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   ZnSphereCodecRec_swiginitnew_ZnSphereCodecRecr  s      r   rN   zZnSphereCodecRec.__init__  !    11$8\8\]`bd8efr#   c                 .    t        j                  | |      S r-   )r    ZnSphereCodecRec_encode_centroidr  s     r   encode_centroidz ZnSphereCodecRec.encode_centroid  r  r#   c                 0    t        j                  | ||      S r-   )r   ZnSphereCodecRec_decoder  s      r   r  zZnSphereCodecRec.decode      66tT1EEr#   c                 .    t        j                  | |      S )z[
        vectors need to be centroids (does not work on arbitrary
        vectors)
        )r   ZnSphereCodecRec_encoder_   s     r   r  zZnSphereCodecRec.encode  s    
 66tQ??r#   c                 0    t        j                  | ||      S r-   )r   ZnSphereCodecRec_get_nv)r   ldr2as      r   get_nvzZnSphereCodecRec.get_nv  s    66tREEr#   c                 2    t        j                  | |||      S r-   )r   ZnSphereCodecRec_get_nv_cum)r   r   r2tr!  s       r   
get_nv_cumzZnSphereCodecRec.get_nv_cum  s    ::4S#NNr#   c                 4    t        j                  | ||||      S r-   )r   ZnSphereCodecRec_set_nv_cum)r   r   r%  r!  rC   s        r   
set_nv_cumzZnSphereCodecRec.set_nv_cum  s    ::4S#qQQr#   N)'r   r   r6   r7   r   r   r   r   r   ZnSphereCodecRec_r2_getZnSphereCodecRec_r2_setr  ZnSphereCodecRec_log2_dim_getZnSphereCodecRec_log2_dim_setlog2_dimZnSphereCodecRec_code_size_getZnSphereCodecRec_code_size_setr!  rN   r  r  r  ZnSphereCodecRec_all_nv_getZnSphereCodecRec_all_nv_setall_nvZnSphereCodecRec_all_nv_cum_getZnSphereCodecRec_all_nv_cum_set
all_nv_cum$ZnSphereCodecRec_decode_cache_ld_get$ZnSphereCodecRec_decode_cache_ld_setdecode_cache_ld!ZnSphereCodecRec_decode_cache_get!ZnSphereCodecRec_decode_cache_setdecode_cacher"  r&  r)  delete_ZnSphereCodecRecr   r$   r#   r   r  r    s    -/IOdeGH	/99?;b;b	cBEEGtGtuHGGIwIwxIgIF@ oAA?CnCnoF/II?KzKz{JSSUd  VJ  VJ  KOOMM  PA  PA  BLFOR&>>r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zd Zej$                  Zy	)
ZnSphereCodecAltzg
     Codec that uses the recursive codec if dim is a power of 2 and
    the regular one otherwise
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zZnSphereCodecAlt.<lambda>
   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zZnSphereCodecAlt.<lambda>
   rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   ZnSphereCodecAlt_swiginitnew_ZnSphereCodecAltr  s      r   rN   zZnSphereCodecAlt.__init__   r  r#   c                 .    t        j                  | |      S r-   )r   ZnSphereCodecAlt_encoder_   s     r   r  zZnSphereCodecAlt.encode   ra   r#   c                 0    t        j                  | ||      S r-   )r   ZnSphereCodecAlt_decoder  s      r   r  zZnSphereCodecAlt.decode   r  r#   N)r   r   r6   r7   r   r   r   r   r   ZnSphereCodecAlt_use_rec_getZnSphereCodecAlt_use_rec_setuse_recZnSphereCodecAlt_znc_rec_getZnSphereCodecAlt_znc_rec_setznc_recrN   r  r  delete_ZnSphereCodecAltr   r$   r#   r   r?  r?     sm    
 -/IOdeGHCC_EqEqrGCC_EqEqrGg@F&>>r#   r?  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                        Z eej0                  ej2                  d
      Zd Zd Zd Zd Zd Zej@                  Z!y)IndexLatticezBIndex that encodes a vector with a series of Zn lattice quantizersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexLattice.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexLattice.<lambda>   rD   r#   rE   rF   znumber of sub-vectorszdimension of sub-vectorszthe lattice quantizerz/nb bits used to encode the scale, per subvectorz4mins and maxes of the vector norms, per subquantizerc           	      \    t        j                  | t        j                  ||||             y r-   )r   IndexLattice_swiginitnew_IndexLattice)r   r
  nsq
scale_nbitr  s        r   rN   zIndexLattice.__init__'   s'    --dO4T4TUVX[]gik4lmr#   c                 0    t        j                  | ||      S r-   )r   IndexLattice_trainr!  s      r   r"  zIndexLattice.train*   r  r#   c                 ,    t        j                  |       S r-   )r   IndexLattice_sa_code_sizerR   s    r   ro  zIndexLattice.sa_code_size-   r  r#   c                 2    t        j                  | |||      S r-   )r   IndexLattice_sa_encoderr  s       r   rs  zIndexLattice.sa_encode0   s    55dAq%HHr#   c                 2    t        j                  | |||      S r-   )r   IndexLattice_sa_decoderv  s       r   rw  zIndexLattice.sa_decode3   r|  r#   N)"r   r   r6   r7   r   r   r   r   r   IndexLattice_nsq_getIndexLattice_nsq_setrW  IndexLattice_dsq_getIndexLattice_dsq_setdsq IndexLattice_zn_sphere_codec_get IndexLattice_zn_sphere_codec_setzn_sphere_codecIndexLattice_scale_nbit_getIndexLattice_scale_nbit_setrX  IndexLattice_lattice_nbit_getIndexLattice_lattice_nbit_setlattice_nbitIndexLattice_trained_getIndexLattice_trained_setr   rN   r"  ro  rs  rw  delete_IndexLatticer   r$   r#   r   rQ  rQ     s
   M-/IOdeGH
?779]9]c  AC
?779]9]  dC  DCOOQ`  RB  RB  Hd  eO/EEGrGr  yo  pJOII?KxKxyL??AiAi  pk  lGn>?II&::r#   rQ  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Zd Zej                  Zy)	IVFPQSearchParametersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIVFPQSearchParameters.<lambda>:   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIVFPQSearchParameters.<lambda>:   rD   r#   rE   rF   $use table computation or on-the-fly?'Hamming thresh for polysemous filteringc                 T    t        j                  | t        j                                y r-   )r   IVFPQSearchParameters_swiginitnew_IVFPQSearchParametersrR   s    r   rN   zIVFPQSearchParameters.__init__?   r  r#   N)r   r   r6   r   r   r   r   r   .IVFPQSearchParameters_scan_table_threshold_get.IVFPQSearchParameters_scan_table_threshold_setscan_table_threshold'IVFPQSearchParameters_polysemous_ht_get'IVFPQSearchParameters_polysemous_ht_setrr  rN   delete_IVFPQSearchParametersr   r$   r#   r   rr  rr  9   s    -/IOdeGH#O$b$bds  ec  ec  iT  U_TTVe  WN  WN  TB  CMj&CCr#   rr  c                   Z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                  d      Z eej6                  ej8                  d      ZddZd Zd Z ddZ!ddZ"d Z#d Z$d Z%d Z&d Z'ddZ(d Z)d Z*d Z+d Z,ejZ                  Z.y) 
IndexIVFPQzz
     Inverted file with Product Quantizer encoding. Each residual
    vector is encoded as a product quantizer code.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFPQ.<lambda>K   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFPQ.<lambda>K   rD   r#   rE   rF   produces the codesz$reorder PQ centroids after training?zif NULL, use defaultru  rv  z
     Precompute table that speed up query preprocessing at some
    memory cost (used only for by_residual with L2 metric)
    zA
    if use_precompute_table
    size nlist * pq.M * pq.ksub
    c                 6    t        j                  | |||||      S r-   )r   IndexIVFPQ_encode_vectorsr$  s         r   r  zIndexIVFPQ.encode_vectors[   s    88q!XuVeffr#   c                 4    t        j                  | ||||      S r-   )r   IndexIVFPQ_decode_vectors)r   rW   r  listnosr>   s        r   r  zIndexIVFPQ.decode_vectors^   s    88q%RSTTr#   c                 2    t        j                  | |||      S r-   )r   IndexIVFPQ_sa_decoderv  s       r   rw  zIndexIVFPQ.sa_decodea   s    33D!UAFFr#   Nc                 6    t        j                  | |||||      S r-   )r   IndexIVFPQ_add_corer  s         r   r  zIndexIVFPQ.add_cored   s    224At_Vkllr#   c           	      8    t        j                  | ||||||      S )z
        same as add_core, also:
        - output 2nd level residuals if residuals_2 != NULL
        - accepts precomputed_idx = nullptr
        )r   IndexIVFPQ_add_core_o)r   rW   r>   r0  residuals_2r  r  s          r   
add_core_ozIndexIVFPQ.add_core_og   s#     44T1a{Tcez{{r#   c                 2    t        j                  | |||      S )ztrains the product quantizer)r   IndexIVFPQ_train_encoderr  s       r   r  zIndexIVFPQ.train_encodero   s    77aFKKr#   c                 ,    t        j                  |       S r-   )r   $IndexIVFPQ_train_encoder_num_vectorsrR   s    r   r  z$IndexIVFPQ.train_encoder_num_vectorss   rf  r#   c                 2    t        j                  | |||      S r-   )r   "IndexIVFPQ_reconstruct_from_offsetr  s       r   r  z"IndexIVFPQ.reconstruct_from_offsetv   s    AA$QWY_``r#   c                 0    t        j                  | ||      S )a  
         Find exact duplicates in the dataset.

        the duplicates are returned in pre-allocated arrays (see the
        max sizes).

        :type lims: int
        :param lims:   limits between groups of duplicates
                           (max size ntotal / 2 + 1)
        :type ids: int
        :param ids:    ids[lims[i]] : ids[lims[i+1]-1] is a group of
                           duplicates (max size ntotal)
        :rtype: int
        :return: n      number of groups found
        )r   IndexIVFPQ_find_duplicates)r   r{  r  s      r   find_duplicateszIndexIVFPQ.find_duplicatesy   s      99$TJJr#   c                 2    t        j                  | |||      S r-   )r   IndexIVFPQ_encode)r   rP  r>   r   s       r   r  zIndexIVFPQ.encode   s    00sAtDDr#   c                 6    t        j                  | |||||      S )a  
         Encode multiple vectors

        :type n: int
        :param n:       nb vectors to encode
        :type keys: int
        :param keys:    posting list ids for those vectors (size n)
        :type x: float
        :param x:       vectors (size n * d)
        :type codes: uint8_t
        :param codes:   output codes (size n * code_size)
        :type compute_keys: boolean, optional
        :param compute_keys:  if false, assume keys are precomputed,
                                 otherwise compute them
        )r   IndexIVFPQ_encode_multiple)r   rW   r  r>   r  compute_keyss         r   encode_multiplezIndexIVFPQ.encode_multiple   s       99$4ES_``r#   c                 4    t        j                  | ||||      S )zinverse of encode_multiple)r   IndexIVFPQ_decode_multiple)r   rW   r  xcodesr>   s        r   decode_multiplezIndexIVFPQ.decode_multiple   s    99$4QRSSr#   c                 2    t        j                  | |||      S r-   )r   "IndexIVFPQ_get_InvertedListScannerr  s       r   r  z"IndexIVFPQ.get_InvertedListScanner   s    AA$UXZ`aar#   c                 ,    t        j                  |       S )zbuild precomputed table)r   IndexIVFPQ_precompute_tablerR   s    r   precompute_tablezIndexIVFPQ.precompute_table       ::4@@r#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFPQ_swiginitnew_IndexIVFPQr   s     r   rN   zIndexIVFPQ.__init__   r  r#   r  r-   r	  )/r   r   r6   r7   r   r   r   r   r   IndexIVFPQ_pq_getIndexIVFPQ_pq_setr  %IndexIVFPQ_do_polysemous_training_get%IndexIVFPQ_do_polysemous_training_setr  "IndexIVFPQ_polysemous_training_get"IndexIVFPQ_polysemous_training_setr  #IndexIVFPQ_scan_table_threshold_get#IndexIVFPQ_scan_table_threshold_setr|  IndexIVFPQ_polysemous_ht_getIndexIVFPQ_polysemous_ht_setrr  $IndexIVFPQ_use_precomputed_table_get$IndexIVFPQ_use_precomputed_table_setrt   IndexIVFPQ_precomputed_table_get IndexIVFPQ_precomputed_table_setprecomputed_tabler  r  rw  r  r  r  r  r  r  r  r  r  r  r  rN   delete_IndexIVFPQr   r$   r#   r   r  r  E   s   
 -/IOdeGH	/33_5V5V\u	vB%o&[&[]l  ^S  ^S  YD  E"?#U#UWf  XJ  XJ  Pk  l#O$W$WYh  ZM  ZM  S~  _II?KwKw  ~l  mM$_%Y%Y[j  \P  \P V 	 !!Q!QSb  TD  TD J 	
gUGm|LJaK$Ea$TbAY&88r#   r  c                 6    t        j                  | |||||      S )ap  
     Pre-compute distance tables for IVFPQ with by-residual and METRIC_L2

    :type use_precomputed_table: int
    :param use_precomputed_table: (I/O)
               =-1: force disable
               =0: decide heuristically (default: use tables only if they are
                   < precomputed_tables_max_bytes), set use_precomputed_table on
        output =1: tables that work for all quantizers (size 256 * nlist * M) =2:
        specific version for MultiIndexQuantizer (much more compact)
    :type precomputed_table: faiss::AlignedTable< float,32 >
    :param precomputed_table: precomputed table to initialize
    )r   "initialize_IVFPQ_precomputed_table)rt  ri  r  r  r   r  s         r   r  r     s3     ==>SU^`bdu  xC  EL  M  Mr#   c                   F   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                         Z eej$                  ej&                  d      Zd	 Zd
 Zej.                  Zy)IndexIVFPQStatsz
    statistics are robust to internal threading, but not if
    IndexIVFPQ::search_preassigned is called by multiple threads
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFPQStats.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFPQStats.<lambda>   rD   r#   rE   rF   znb of refines (IVFPQR)z4nb of passed Hamming distance tests (for polysemous)zonly for IVFPQRc                 T    t        j                  | t        j                                y r-   )r   IndexIVFPQStats_swiginitnew_IndexIVFPQStatsrR   s    r   rN   zIndexIVFPQStats.__init__       007Z7Z7\]r#   c                 ,    t        j                  |       S r-   )r   IndexIVFPQStats_resetrR   s    r   r  zIndexIVFPQStats.reset   r  r#   N)r   r   r6   r7   r   r   r   r   r   IndexIVFPQStats_nrefine_getIndexIVFPQStats_nrefine_setnrefine"IndexIVFPQStats_n_hamming_pass_get"IndexIVFPQStats_n_hamming_pass_setr  !IndexIVFPQStats_search_cycles_get!IndexIVFPQStats_search_cycles_setsearch_cycles!IndexIVFPQStats_refine_cycles_get!IndexIVFPQStats_refine_cycles_setrefine_cyclesrN   r  delete_IndexIVFPQStatsr   r$   r#   r   r  r     s    
 -/IOdeGHBBODoDo  vS  TGoPPRa  SE  SE  KF  GN_NNP_  QB  QB  CM_NNP_  QB  QB  H^  _M^;&==r#   r  c                   @   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Zd	 Zd
 Zd Zd Zd ZddZd Zd ZddZd Zej8                  Zy)IndexIVFPQRz/Index with an additional level of PQ refinementc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFPQR.<lambda>   r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFPQR.<lambda>   rD   r#   rE   rF   z3rd level quantizerzcorresponding codeszGfactor between k requested in search and the k requested from the IVFPQc                 ,    t        j                  |       S r-   )r   IndexIVFPQR_resetrR   s    r   r  zIndexIVFPQR.reset   r   r#   c                 .    t        j                  | |      S r-   )r   IndexIVFPQR_remove_idsrK  s     r   rL  zIndexIVFPQR.remove_ids       55dC@@r#   c                 2    t        j                  | |||      S )z!trains the two product quantizers)r   IndexIVFPQR_train_encoderr  s       r   r  zIndexIVFPQR.train_encoder   s    88q!VLLr#   c                 ,    t        j                  |       S r-   )r   %IndexIVFPQR_train_encoder_num_vectorsrR   s    r   r  z%IndexIVFPQR.train_encoder_num_vectors   r  r#   c                 2    t        j                  | |||      S r-   )r   IndexIVFPQR_add_with_idsr/  s       r   r1  zIndexIVFPQR.add_with_ids       77aDIIr#   Nc                 6    t        j                  | |||||      S )zAsame as add_with_ids, but optionally use the precomputed list ids)r   IndexIVFPQR_add_corer  s         r   r  zIndexIVFPQR.add_core   s    33D!QoWlmmr#   c                 2    t        j                  | |||      S r-   )r   #IndexIVFPQR_reconstruct_from_offsetr  s       r   r  z#IndexIVFPQR.reconstruct_from_offset   s    BB4RXZ`aar#   c                 0    t        j                  | ||      S r-   )r   IndexIVFPQR_merge_fromr{  s      r   r~  zIndexIVFPQR.merge_from       55dJOOr#   c                 @    t        j                  | |||||||||	|
      S r-   )r   IndexIVFPQR_search_preassignedr  s              r   r  zIndexIVFPQR.search_preassigned   s?    ==dAq!VUaclnt  wB  DJ  LQ  R  	Rr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFPQR_swiginitnew_IndexIVFPQRr   s     r   rN   zIndexIVFPQR.__init__   r  r#   r-   r	  )r   r   r6   r7   r   r   r   r   r   IndexIVFPQR_refine_pq_getIndexIVFPQR_refine_pq_set	refine_pqIndexIVFPQR_refine_codes_getIndexIVFPQR_refine_codes_setrefine_codesIndexIVFPQR_k_factor_getIndexIVFPQR_k_factor_setrX  r  rL  r  r  r1  r  r  r~  r  rN   delete_IndexIVFPQRr   r$   r#   r   r  r     s    :-/IOdeGHBBODmDm  tN  OIOHH/JvJv  }W  XL@@/BjBj  q  @H7AMKJnbPR[&99r#   r  c                   j   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zej,                  Zd ZddZd Zd Zd Zd Zy)Index2Layerz
     Same as an IndexIVFPQ without the inverted lists: codes are stored
    sequentially

    The class is mainly inteded to store encoded vectors that can be
    accessed randomly, the search function is not implemented.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndex2Layer.<lambda>!  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndex2Layer.<lambda>!  rD   r#   rE   rF   zfirst level quantizerz%second level quantizer is always a PQz;size of the code for the first level (ceil(log8(q1.nlist)))z%size of the code for the second levelc                 P    t        j                  | t        j                  |        y r-   )r   Index2Layer_swiginitnew_Index2Layerr   s     r   rN   zIndex2Layer.__init__!  r  r#   c                 0    t        j                  | ||      S r-   )r   Index2Layer_trainr!  s      r   r"  zIndex2Layer.train!  rf  r#   Nc           	      8    t        j                  | ||||||      S r  )r   Index2Layer_searchr8  s          r   r:  zIndex2Layer.search!  rC  r#   c                 ,    t        j                  |       S r-   )r   !Index2Layer_get_distance_computerrR   s    r   rk  z!Index2Layer.get_distance_computer!  r  r#   c                 .    t        j                  | |      S )z)transfer the flat codes to an IVFPQ index)r   Index2Layer_transfer_to_IVFPQr   s     r   transfer_to_IVFPQzIndex2Layer.transfer_to_IVFPQ!!  s    <<T5IIr#   c                 2    t        j                  | |||      S r-   )r   Index2Layer_sa_encoderr  s       r   rs  zIndex2Layer.sa_encode%!  rx  r#   c                 2    t        j                  | |||      S r-   )r   Index2Layer_sa_decoderv  s       r   rw  zIndex2Layer.sa_decode(!      44T1eQGGr#   r-   )r   r   r6   r7   r   r   r   r   r   Index2Layer_q1_getIndex2Layer_q1_setq1Index2Layer_pq_getIndex2Layer_pq_setr  Index2Layer_code_size_1_getIndex2Layer_code_size_1_setcode_size_1Index2Layer_code_size_2_getIndex2Layer_code_size_2_setcode_size_2rN   delete_Index2Layerr   r"  r:  rk  r
  rs  rw  r$   r#   r   r  r  !  s     -/IOdeGH	/44o6X6X^z	{B	/44o6X6X  _K  
LB?FFHsHs  z|  }K?FFHsHs  zf  gK[&99=\GJHHr#   r  c                   \   e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Z ee	j                  e	j                        Z ee	j                   e	j"                        Z ee	j&                  e	j(                        Z ee	j,                  e	j.                        Z ee	j2                  e	j4                        Z ee	j8                  e	j:                        Z ee	j>                  e	j@                        Z! ee	jD                  e	jF                        Z$ ee	jJ                  e	jL                        Z' ee	jP                  e	jR                        Z* ee	jV                  e	jX                        Z-d Z.d Z/dd
Z0d Z1d Z2d Z3d Z4d Z5d Z6d Z7ddZ8d Z9d Z:d Z;e	jx                  Z=y	)IndexFastScana*  
     Fast scan version of IndexPQ and IndexAQ. Works for 4-bit PQ and AQ for now.

    The codes are not stored sequentially but grouped in blocks of size bbs.
    This makes it possible to compute distances quickly with SIMD instructions.
    The trailing codes (padding codes that are added to complete the last code)
    are garbage.

    Implementations:
    12: blocked loop with internal loop on Q with qbs
    13: same with reservoir accumulator to store results
    14: no qbs with heap accumulator
    15: no qbs with reservoir accumulator
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexFastScan.<lambda>=!  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexFastScan.<lambda>=!  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexFastScan.__init__?!  rO   r#   c                 6    t        j                  | |||||      S r-   )r   IndexFastScan_init_fastscan)r   r
  rM  r  metricbbss         r   init_fastscanzIndexFastScan.init_fastscanO!  s    ::4AufVYZZr#   c                 ,    t        j                  |       S r-   )r   IndexFastScan_resetrR   s    r   r  zIndexFastScan.resetR!  rh   r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexFastScan_searchr8  s          r   r:  zIndexFastScan.searchU!  s     33D!Q9fV\]]r#   c                 0    t        j                  | ||      S r-   )r   IndexFastScan_addr!  s      r   r)  zIndexFastScan.addX!  rf  r#   c                 2    t        j                  | |||      S r-   )r   IndexFastScan_compute_codesr   r  rW   r>   s       r   r  zIndexFastScan.compute_codes[!  s    ::41MMr#   c                 2    t        j                  | |||      S r-   )r   IndexFastScan_compute_float_LUTr   lutrW   r>   s       r   compute_float_LUTzIndexFastScan.compute_float_LUT^!  s    >>tS!QOOr#   c                 4    t        j                  | ||||      S r-   )r   #IndexFastScan_compute_quantized_LUT)r   rW   r>   r2  normalizerss        r   compute_quantized_LUTz#IndexFastScan.compute_quantized_LUTa!  s    BB4AsT_``r#   c                 0    t        j                  | ||      S r-   )r   IndexFastScan_reconstructrO  s      r   rR  zIndexFastScan.reconstructd!  s    88sFKKr#   c                 .    t        j                  | |      S r-   )r   IndexFastScan_remove_idsrK  s     r   rL  zIndexFastScan.remove_idsg!  s    77cBBr#   c                 ,    t        j                  |       S r-   )r   IndexFastScan_get_CodePackerrR   s    r   r  zIndexFastScan.get_CodePackerj!  r7  r#   c                 0    t        j                  | ||      S r-   )r   IndexFastScan_merge_fromr{  s      r   r~  zIndexFastScan.merge_fromm!  s    77j&QQr#   c                 .    t        j                  | |      S r-   )r   (IndexFastScan_check_compatible_for_merger  s     r   r  z(IndexFastScan.check_compatible_for_mergep!  s    GGjYYr#   c                 ,    t        j                  |       S )z8standalone codes interface (but the codes are flattened))r   IndexFastScan_sa_code_sizerR   s    r   ro  zIndexFastScan.sa_code_sizes!  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexFastScan_sa_encoderr  s       r   rs  zIndexFastScan.sa_encodew!  s    66tQ5IIr#   r-   r  )>r   r   r6   r7   r   r   rN   r   r   r   IndexFastScan_implem_getIndexFastScan_implem_setimplemIndexFastScan_skip_getIndexFastScan_skip_setskipIndexFastScan_bbs_getIndexFastScan_bbs_setr$  IndexFastScan_qbs_getIndexFastScan_qbs_setqbsIndexFastScan_M_getIndexFastScan_M_setrM  IndexFastScan_nbits_getIndexFastScan_nbits_setr  IndexFastScan_ksub_getIndexFastScan_ksub_setr  IndexFastScan_code_size_getIndexFastScan_code_size_setr!  IndexFastScan_ntotal2_getIndexFastScan_ntotal2_setntotal2IndexFastScan_M2_getIndexFastScan_M2_setM2IndexFastScan_codes_getIndexFastScan_codes_setr  IndexFastScan_orig_codes_getIndexFastScan_orig_codes_set
orig_codesr%  r  r:  r)  r  r3  r7  rR  rL  r  r~  r  ro  rs  delete_IndexFastScanr   r$   r#   r   r  r  -!  s    -/IOdeGKHo>>@h@hiFO::O<b<bcD
?88/:_:_
`C
?88/:_:_
`C44o6Y6YZA_<<o>e>efEO::O<b<bcDDDoFqFqrI@@/BkBklG	/668\8\	]B_<<o>e>efE/FFHtHtuJ[9^=NPaLCBRZ@J&;;r#   r  c                   6   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Zd Zd Zej,                  Zy)FastScanStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFastScanStats.<lambda>~!  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFastScanStats.<lambda>~!  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   FastScanStats_swiginitnew_FastScanStatsrR   s    r   rN   zFastScanStats.__init__!  r   r#   c                 ,    t        j                  |       S r-   )r   FastScanStats_resetrR   s    r   r  zFastScanStats.reset!  rh   r#   N)r   r   r6   r   r   r   r   r   FastScanStats_t0_getFastScanStats_t0_setr
  FastScanStats_t1_getFastScanStats_t1_sett1FastScanStats_t2_getFastScanStats_t2_sett2FastScanStats_t3_getFastScanStats_t3_sett3rN   r  delete_FastScanStatsr   r$   r#   r   rf  rf  }!  s    -/IOdeGH	/668\8\	]B	/668\8\	]B	/668\8\	]B	/668\8\	]BZ9&;;r#   rf  c                   `   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Zd Zej,                  Zd Zd Zd	 Zd
 Zd ZddZd Zy)IndexAdditiveQuantizerFastScana  
     Fast scan version of IndexAQ. Works for 4-bit AQ for now.

    The codes are not stored sequentially but grouped in blocks of size bbs.
    This makes it possible to compute distances quickly with SIMD instructions.

    Implementations:
    12: blocked loop with internal loop on Q with qbs
    13: same with reservoir accumulator to store results
    14: no qbs with heap accumulator
    15: no qbs with reservoir accumulator
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z'IndexAdditiveQuantizerFastScan.<lambda>!  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z'IndexAdditiveQuantizerFastScan.<lambda>!  rD   r#   rE   rF   c                 .    t        j                  | g| S r-   )r   #IndexAdditiveQuantizerFastScan_initr   s     r   r
  z#IndexAdditiveQuantizerFastScan.init!  s    BB4O$OOr#   c                 P    t        j                  | t        j                  |        y)z
        *Overload 1:*
        build from an existing IndexAQ

        |

        *Overload 2:*
        build from an existing IndexAQ
        N)r   'IndexAdditiveQuantizerFastScan_swiginit"new_IndexAdditiveQuantizerFastScanr   s     r   rN   z'IndexAdditiveQuantizerFastScan.__init__!  s#     	??oFxFxz~F  	Ar#   c                 0    t        j                  | ||      S r-   )r   $IndexAdditiveQuantizerFastScan_trainr!  s      r   r"  z$IndexAdditiveQuantizerFastScan.train!      CCD!QOOr#   c                 0    t        j                  | ||      S r-   )r   2IndexAdditiveQuantizerFastScan_estimate_norm_scaler!  s      r   estimate_norm_scalez2IndexAdditiveQuantizerFastScan.estimate_norm_scale!  s    QQRVXY[\]]r#   c                 2    t        j                  | |||      S r-   )r   ,IndexAdditiveQuantizerFastScan_compute_codesr.  s       r   r  z,IndexAdditiveQuantizerFastScan.compute_codes!  s    KKDRWYZ\]^^r#   c                 2    t        j                  | |||      S r-   )r   0IndexAdditiveQuantizerFastScan_compute_float_LUTr1  s       r   r3  z0IndexAdditiveQuantizerFastScan.compute_float_LUT!  s    OOPTVY[\^_``r#   Nc           	      8    t        j                  | ||||||      S r-   )r   %IndexAdditiveQuantizerFastScan_searchr8  s          r   r:  z%IndexAdditiveQuantizerFastScan.search!  s#    DDT1aQRT]_egmnnr#   c                 2    t        j                  | |||      S )a  
         Decode a set of vectors.

         NOTE: The codes in the IndexAdditiveQuantizerFastScan object are non-
               contiguous. But this method requires a contiguous representation.

        :type n: int
        :param n:       number of vectors
        :type bytes: uint8_t
        :param bytes:   input encoded vectors, size n * code_size
        :type x: float
        :param x:       output vectors, size n * d
        )r   (IndexAdditiveQuantizerFastScan_sa_decoderv  s       r   rw  z(IndexAdditiveQuantizerFastScan.sa_decode!  s     GGaQVXYZZr#   r-   )r   r   r6   r7   r   r   r   r   r   %IndexAdditiveQuantizerFastScan_aq_get%IndexAdditiveQuantizerFastScan_aq_setr  /IndexAdditiveQuantizerFastScan_rescale_norm_get/IndexAdditiveQuantizerFastScan_rescale_norm_setrescale_norm-IndexAdditiveQuantizerFastScan_norm_scale_get-IndexAdditiveQuantizerFastScan_norm_scale_set
norm_scale3IndexAdditiveQuantizerFastScan_max_train_points_get3IndexAdditiveQuantizerFastScan_max_train_points_setr  r
  %delete_IndexAdditiveQuantizerFastScanr   rN   r"  r  r  r3  r:  rw  r$   r#   r   r{  r{  !  s     -/IOdeGH	/GGI~I~	BO[[]l  ^]  ^]  ^L/WWYh  ZW  ZW  XJ c cet  fi  fi  jP&LL
AP^_ao[r#   r{  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	IndexResidualQuantizerFastScanr  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z'IndexResidualQuantizerFastScan.<lambda>!  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z'IndexResidualQuantizerFastScan.<lambda>!  rD   r#   rE   rF   r  c                 P    t        j                  | t        j                  |        ya~  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type M: int
        :param M:      number of subquantizers
        :type nbits: int
        :param nbits:  number of bit per subvector index
        :type metric: int, optional
        :param metric:  metric type
        :type search_type: int, optional
        :param search_type: AQ search type

        :type d: int
        :param d: dimensionality of the input vectors
        :type M: int
        :param M: number of subquantizers
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   'IndexResidualQuantizerFastScan_swiginit"new_IndexResidualQuantizerFastScanr   s     r   rN   z'IndexResidualQuantizerFastScan.__init__!  s#    , 	??oFxFxz~F  	Ar#   N)r   r   r6   r7   r   r   r   r   r   %IndexResidualQuantizerFastScan_rq_get%IndexResidualQuantizerFastScan_rq_setrx	  rN   %delete_IndexResidualQuantizerFastScanr   r$   r#   r   r  r  !  sU     -/IOdeGH	/GGI~I~  E}  
~BA. 'LLr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zej                  Zy)!IndexLocalSearchQuantizerFastScanz
     Index based on a local search quantizer. Stored vectors are
    approximated by local search quantization codes.
    Can also be used as a codec
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z*IndexLocalSearchQuantizerFastScan.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z*IndexLocalSearchQuantizerFastScan.<lambda>"  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        yr  )r   *IndexLocalSearchQuantizerFastScan_swiginit%new_IndexLocalSearchQuantizerFastScanr   s     r   rN   z*IndexLocalSearchQuantizerFastScan.__init__"  s+    , 	BB4I~I~  AE  JF  	Gr#   N)r   r   r6   r7   r   r   r   r   r   )IndexLocalSearchQuantizerFastScan_lsq_get)IndexLocalSearchQuantizerFastScan_lsq_setr^
  rN   (delete_IndexLocalSearchQuantizerFastScanr   r$   r#   r   r  r  !  sV     -/IOdeGH
?LLo  OH  OH  ICG. 'OOr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	%IndexProductResidualQuantizerFastScanz
     Index based on a product residual quantizer. Stored vectors are
    approximated by product residual quantization codes.
    Can also be used as a codec
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z.IndexProductResidualQuantizerFastScan.<lambda>'"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z.IndexProductResidualQuantizerFastScan.<lambda>'"  rD   r#   rE   rF   r  c                 P    t        j                  | t        j                  |        y)a:  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of residual quantizers
        :type Msub: int
        :param Msub:     number of subquantizers per RQ
        :type nbits: int
        :param nbits:  number of bit per subvector index
        :type metric: int, optional
        :param metric:  metric type
        :type search_type: int, optional
        :param search_type: AQ search type

        :type d: int
        :param d: dimensionality of the input vectors
        :type nsplits: int
        :param nsplits: number of residual quantizers
        :type Msub: int
        :param Msub: number of subquantizers per RQ
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   .IndexProductResidualQuantizerFastScan_swiginit)new_IndexProductResidualQuantizerFastScanr   s     r   rN   z.IndexProductResidualQuantizerFastScan.__init__+"  s3    4 	FFt_  NG  NG  IM  NN  	Or#   N)r   r   r6   r7   r   r   r   r   r   -IndexProductResidualQuantizerFastScan_prq_get-IndexProductResidualQuantizerFastScan_prq_setr  rN   ,delete_IndexProductResidualQuantizerFastScanr   r$   r#   r   r  r   "  s^     -/IOdeGH
?PPRa  SP  SP  VV  WCO6 'SSr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Zd Zej                  Zy)	(IndexProductLocalSearchQuantizerFastScanz
     Index based on a product local search quantizer. Stored vectors are
    approximated by product local search quantization codes.
    Can also be used as a codec
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z1IndexProductLocalSearchQuantizerFastScan.<lambda>Q"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z1IndexProductLocalSearchQuantizerFastScan.<lambda>Q"  rD   r#   rE   rF   r"  c                 P    t        j                  | t        j                  |        y)aD  
         Constructor.

        :type d: int
        :param d:      dimensionality of the input vectors
        :type nsplits: int
        :param nsplits:  number of local search quantizers
        :type Msub: int
        :param Msub:     number of subquantizers per LSQ
        :type nbits: int
        :param nbits:  number of bit per subvector index
        :type metric: int, optional
        :param metric:  metric type
        :type search_type: int, optional
        :param search_type: AQ search type

        :type d: int
        :param d: dimensionality of the input vectors
        :type nsplits: int
        :param nsplits: number of local search quantizers
        :type Msub: int
        :param Msub: number of subquantizers per LSQ
        :type nbits: int
        :param nbits: number of bit per subvector index
        N)r   1IndexProductLocalSearchQuantizerFastScan_swiginit,new_IndexProductLocalSearchQuantizerFastScanr   s     r   rN   z1IndexProductLocalSearchQuantizerFastScan.__init__U"  s4    4 	II$P_  QM  QM  OS  QT  	Ur#   N)r   r   r6   r7   r   r   r   r   r   1IndexProductLocalSearchQuantizerFastScan_plsq_get1IndexProductLocalSearchQuantizerFastScan_plsq_setr*  rN   /delete_IndexProductLocalSearchQuantizerFastScanr   r$   r#   r   r  r  J"  s^     -/IOdeGHOUUWf  XY  XY  _c  dDU6 'VVr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zd
 Zej"                  Zy)IndexPQFastScana  
     Fast scan version of IndexPQ. Works for 4-bit PQ for now.

    The codes are not stored sequentially but grouped in blocks of size bbs.
    This makes it possible to compute distances quickly with SIMD instructions.

    Implementations:
    12: blocked loop with internal loop on Q with qbs
    13: same with reservoir accumulator to store results
    14: no qbs with heap accumulator
    15: no qbs with reservoir accumulator
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexPQFastScan.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexPQFastScan.<lambda>"  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)z
        *Overload 1:*
        build from an existing IndexPQ

        |

        *Overload 2:*
        build from an existing IndexPQ
        N)r   IndexPQFastScan_swiginitnew_IndexPQFastScanr   s     r   rN   zIndexPQFastScan.__init__"  s      	007Z7Z\`7abr#   c                 0    t        j                  | ||      S r-   )r   IndexPQFastScan_trainr!  s      r   r"  zIndexPQFastScan.train"  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexPQFastScan_compute_codesr.  s       r   r  zIndexPQFastScan.compute_codes"  s    <<T5!QOOr#   c                 2    t        j                  | |||      S r-   )r   !IndexPQFastScan_compute_float_LUTr1  s       r   r3  z!IndexPQFastScan.compute_float_LUT"  s    @@sAqQQr#   c                 2    t        j                  | |||      S r-   )r   IndexPQFastScan_sa_decoderv  s       r   rw  zIndexPQFastScan.sa_decode"  s    88q%KKr#   N)r   r   r6   r7   r   r   r   r   r   IndexPQFastScan_pq_getIndexPQFastScan_pq_setr  rN   r"  r  r3  rw  delete_IndexPQFastScanr   r$   r#   r   r  r  t"  sa     -/IOdeGH	/88/:`:`	aB
cAPRL&==r#   r  c                   H    e Zd Z ed d d      ZeZd Zej                  Z
y)simd16uint16c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zsimd16uint16.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zsimd16uint16.<lambda>"  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   simd16uint16_swiginitnew_simd16uint16rR   s    r   rN   zsimd16uint16.__init__"  rO  r#   N)r   r   r6   r   r   r   r   rN   r   delete_simd16uint16r   r$   r#   r   r  r  "  s*    -/IOdeGHX&::r#   r  c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Z ee	j                  e	j                        Z ee	j                   e	j"                        Zd Zd Ze	j*                  Zy	)
SIMDResultHandlerz@This file contains callbacks for kernels that compute distances.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zSIMDResultHandler.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zSIMDResultHandler.<lambda>"  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zSIMDResultHandler.__init__"  rO   r#   c                 4    t        j                  | ||||      S )z
        called when 32 distances are computed and provided in two
        simd16uint16. (q, b) indicate which entry it is in the block.
        )r   SIMDResultHandler_handler   r  r	  d0d1s        r   handlezSIMDResultHandler.handle"  s    
 77aBKKr#   c                 0    t        j                  | ||      S )z)set the sub-matrix that is being computed)r   "SIMDResultHandler_set_block_origin)r   rY  j0s      r   set_block_originz"SIMDResultHandler.set_block_origin"  s    AA$BOOr#   N)r   r   r6   r7   r   r   rN   r   r   r   SIMDResultHandler_is_CMax_getSIMDResultHandler_is_CMax_setis_CMax SIMDResultHandler_sizeof_ids_get SIMDResultHandler_sizeof_ids_set
sizeof_ids!SIMDResultHandler_with_fields_get!SIMDResultHandler_with_fields_setwith_fieldsr  r  delete_SIMDResultHandlerr   r$   r#   r   r  r  "  s    K-/IOdeGKHDDoFsFstG/JJOL|L|}J?LLoNN  AKLP '??r#   r  c                      e Zd Z ed d d      Zd ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                   d      Z eej$                  ej&                        Z eej*                  ej,                        Z eej0                  ej2                        Zd Zd Zej:                  Zy	)
SIMDResultHandlerToFloatc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!SIMDResultHandlerToFloat.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!SIMDResultHandlerToFloat.<lambda>"  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   z!SIMDResultHandlerToFloat.__init__"  rO   r#   zDthese fields are used mainly for the IVF variants (with_id_map=true)c                 .    t        j                  | |      S r-   )r   SIMDResultHandlerToFloat_beginr	  s     r   r  zSIMDResultHandlerToFloat.begin"  s    ==dEJJr#   c                 ,    t        j                  |       S r-   )r   SIMDResultHandlerToFloat_endrR   s    r   r  zSIMDResultHandlerToFloat.end"  r7  r#   N)r   r   r6   r   r   rN   r   r   r   SIMDResultHandlerToFloat_nq_getSIMDResultHandlerToFloat_nq_setr  #SIMDResultHandlerToFloat_ntotal_get#SIMDResultHandlerToFloat_ntotal_setr  #SIMDResultHandlerToFloat_id_map_get#SIMDResultHandlerToFloat_id_map_setid_map"SIMDResultHandlerToFloat_q_map_get"SIMDResultHandlerToFloat_q_map_setq_map"SIMDResultHandlerToFloat_dbias_get"SIMDResultHandlerToFloat_dbias_setdbias(SIMDResultHandlerToFloat_normalizers_get(SIMDResultHandlerToFloat_normalizers_setr6  r  r  delete_SIMDResultHandlerToFloatr   r$   r#   r   r  r  "  s    -/IOdeGKH	/AA?CrCr	sBoII?K~K~FoII?K~K~  EP  QF_GGI{I{|E_GGI{I{|E?SSUd  VN  VN  OKKB&FFr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zej                  Zd Zy	)
DummyResultHandlerzx
     Dummy structure that just computes a chqecksum on results
    (to avoid the computation to be optimized away)
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zDummyResultHandler.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zDummyResultHandler.<lambda>"  rD   r#   rE   rF   c                 4    t        j                  | ||||      S r-   )r   DummyResultHandler_handler  s        r   r  zDummyResultHandler.handle"      88q!RLLr#   c                 0    t        j                  | ||      S r-   )r   #DummyResultHandler_set_block_origin)r   r   arg3s      r   r  z#DummyResultHandler.set_block_origin"  s    BB4tTTr#   c                 T    t        j                  | t        j                                y r-   )r   DummyResultHandler_swiginitnew_DummyResultHandlerrR   s    r   rN   zDummyResultHandler.__init__"  r8  r#   N)r   r   r6   r7   r   r   r   r   r   DummyResultHandler_cs_getDummyResultHandler_cs_setr  r  r  delete_DummyResultHandlerr   rN   r$   r#   r   r  r  "  sU    
 -/IOdeGH	/;;_=f=f	gBMU&@@dr#   r  c                   @   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Zd Zd Zd Zej0                  Zy	)
StoreResultHandlerzg
     memorize results in a nq-by-nb matrix.

    j0 is the current upper-left block of the matrix
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zStoreResultHandler.<lambda>"  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zStoreResultHandler.<lambda>"  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   StoreResultHandler_swiginitnew_StoreResultHandler)r   r   r   s      r   rN   zStoreResultHandler.__init__"  s!    33D/:`:`aegi:jkr#   c                 4    t        j                  | ||||      S r-   )r   StoreResultHandler_handler  s        r   r  zStoreResultHandler.handle#  r  r#   c                 0    t        j                  | ||      S r-   )r   #StoreResultHandler_set_block_origin)r   i0_inj0_ins      r   r  z#StoreResultHandler.set_block_origin#  s    BB4PUVVr#   N)r   r   r6   r7   r   r   r   r   r   StoreResultHandler_data_getStoreResultHandler_data_setr   StoreResultHandler_ld_getStoreResultHandler_ld_setr   StoreResultHandler_i0_getStoreResultHandler_i0_setrY  StoreResultHandler_j0_getStoreResultHandler_j0_setr  rN   r  r  delete_StoreResultHandlerr   r$   r#   r   r"  r"  "  s     -/IOdeGHO??AlAlmD	/;;_=f=f	gB	/;;_=f=f	gB	/;;_=f=f	gBlMW&@@r#   r"  c                   J   e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                        Z ee	j                  e	j                        Z ee	j                   e	j"                        Z ee	j&                  e	j(                        Z ee	j,                  e	j.                        Z ee	j2                  e	j4                        Z ee	j8                  e	j:                        Z ee	j>                  e	j@                        Z! ee	jD                  e	jF                        Z$ ee	jJ                  e	jL                        Z'd Z(d Z)e	jT                  Z+ ee	jX                  e	jZ                  d	      Z.d
 Z/d Z0d Z1d Z2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8ddZ9ddZ:d Z;d Z<d Z=d Z>y)IndexIVFFastScana  
     Fast scan version of IVFPQ and IVFAQ. Works for 4-bit PQ/AQ for now.

    The codes in the inverted lists are not stored sequentially but
    grouped in blocks of size bbs. This makes it possible to very quickly
    compute distances with SIMD instructions.

    Implementations (implem):
    0: auto-select implementation (default)
    1: orig's search, re-implemented
    2: orig's search, re-ordered by invlist
    10: optimizer int16 search, collect results in heap, no qbs
    11: idem, collect results in reservoir
    12: optimizer int16 search, collect results in heap, uses qbs
    13: idem, collect results in reservoir
    14: internally multithreaded implem over nq * nprobe
    15: same with reservoir

    For range search, only 10 and 12 are supported.
    add 100 to the implem to force single-thread scanning (the coarse quantizer
    may still use multiple threads).
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFFastScan.<lambda>##  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFFastScan.<lambda>##  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexIVFFastScan.__init__%#  rO   r#   c           
      :    t        j                  | |||||||      S )zcalled by implementations)r   IndexIVFFastScan_init_fastscan)r   fine_quantizerrM  r  r  r#  r$  r  s           r   r%  zIndexIVFFastScan.init_fastscan3#  s'    ==dNTUW\^cekmpr~r#   c                 ,    t        j                  |       S r-   )r   !IndexIVFFastScan_init_code_packerrR   s    r   init_code_packerz!IndexIVFFastScan.init_code_packer7#  r  r#   z%orig's inverted lists (for debugging)c                 2    t        j                  | |||      S r-   )r   IndexIVFFastScan_add_with_idsr/  s       r   r1  zIndexIVFFastScan.add_with_ids<#      <<T1aNNr#   c                 ,    t        j                  |       S r-   )r   #IndexIVFFastScan_lookup_table_is_3drR   s    r   lookup_table_is_3dz#IndexIVFFastScan.lookup_table_is_3d?#  ri  r#   c                 6    t        j                  | |||||      S r-   )r   IndexIVFFastScan_compute_LUTr   rW   r>   cqr  biasess         r   r
	  zIndexIVFFastScan.compute_LUTB#  s    ;;D!QJX^__r#   c           	      8    t        j                  | ||||||      S r-   )r   "IndexIVFFastScan_compute_LUT_uint8)r   rW   r>   rK  r  rL  r6  s          r   compute_LUT_uint8z"IndexIVFFastScan.compute_LUT_uint8E#  s"    AA$1bR\^dfqrrr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexIVFFastScan_searchr8  s          r   r:  zIndexIVFFastScan.searchH#  !    66tQ1iQWY_``r#   c                 @    t        j                  | |||||||||	|
      S r-   )r   #IndexIVFFastScan_search_preassignedr  s              r   r  z#IndexIVFFastScan.search_preassignedK#  s@    BB4AqRXZfhqsy  |G  IO  QV  W  	Wr#   c                 6    t        j                  | |||||      S r-   )r   IndexIVFFastScan_range_searchrA  s         r   rB  zIndexIVFFastScan.range_searchN#      <<T1aQWY_``r#   c	                 <    t        j                  | ||||||||	      S r-   )r   'IndexIVFFastScan_search_dispatch_implem)	r   rW   r>   rP  rQ  rR  rK  scalerr9  s	            r   search_dispatch_implemz'IndexIVFFastScan.search_dispatch_implemQ#  s*    FFtQPQSTV_agikmsu{||r#   c           
      :    t        j                  | |||||||      S r-   )r   -IndexIVFFastScan_range_search_dispatch_implem)r   rW   r>   rV  rrescq_inrZ  r9  s           r   range_search_dispatch_implemz-IndexIVFFastScan.range_search_dispatch_implemT#  s(    LLTSTVWY_aeglntv|}}r#   c	                 <    t        j                  | ||||||||	      S r-   )r   !IndexIVFFastScan_search_implem_10	r   rW   r>   handlerrK  ndis_out	nlist_outrZ  r9  s	            r   search_implem_10z!IndexIVFFastScan.search_implem_10W#  (    @@q!WVXZbdmouw}~~r#   c	                 <    t        j                  | ||||||||	      S r-   )r   !IndexIVFFastScan_search_implem_12rc  s	            r   search_implem_12z!IndexIVFFastScan.search_implem_12Z#  rh  r#   c
                 >    t        j                  | |||||||||	
      S r-   )r   !IndexIVFFastScan_search_implem_14)
r   rW   r>   rP  rQ  rR  rK  implrZ  r9  s
             r   search_implem_14z!IndexIVFFastScan.search_implem_14]#  s+    @@q!QPY[acegkmsu{||r#   c                 2    t        j                  | |||      S r-   )r   (IndexIVFFastScan_reconstruct_from_offsetr  s       r   r  z(IndexIVFFastScan.reconstruct_from_offset`#  s    GGgW]_effr#   c                 ,    t        j                  |       S r-   )r   IndexIVFFastScan_get_CodePackerrR   s    r   r  zIndexIVFFastScan.get_CodePackerc#  r  r#   c                 ,    t        j                  |       S r-   )r   *IndexIVFFastScan_reconstruct_orig_invlistsrR   s    r   reconstruct_orig_invlistsz*IndexIVFFastScan.reconstruct_orig_invlistsf#  s    II$OOr#   c                 2    t        j                  | |||      S )a  
         Decode a set of vectors.

         NOTE: The codes in the IndexFastScan object are non-contiguous.
               But this method requires a contiguous representation.

        :type n: int
        :param n:       number of vectors
        :type bytes: uint8_t
        :param bytes:   input encoded vectors, size n * code_size
        :type x: float
        :param x:       output vectors, size n * d
        )r   IndexIVFFastScan_sa_decoderv  s       r   rw  zIndexIVFFastScan.sa_decodei#  s     99$5!LLr#   r-   r	  )?r   r   r6   r7   r   r   rN   r   r   r   IndexIVFFastScan_bbs_getIndexIVFFastScan_bbs_setr$  IndexIVFFastScan_M_getIndexIVFFastScan_M_setrM  IndexIVFFastScan_nbits_getIndexIVFFastScan_nbits_setr  IndexIVFFastScan_ksub_getIndexIVFFastScan_ksub_setr  IndexIVFFastScan_M2_getIndexIVFFastScan_M2_setr^  IndexIVFFastScan_implem_getIndexIVFFastScan_implem_setrH  IndexIVFFastScan_skip_getIndexIVFFastScan_skip_setrK  IndexIVFFastScan_qbs_getIndexIVFFastScan_qbs_setrP  IndexIVFFastScan_qbs2_getIndexIVFFastScan_qbs2_setqbs2#IndexIVFFastScan_fine_quantizer_get#IndexIVFFastScan_fine_quantizer_setr>  r%  rA  delete_IndexIVFFastScanr   "IndexIVFFastScan_orig_invlists_get"IndexIVFFastScan_orig_invlists_setorig_invlistsr1  rG  r
	  rO  r:  r  rB  r[  r`  rg  rk  ro  r  r  rv  rw  r$   r#   r   r8  r8  #  s   . -/IOdeGKH
?;;_=e=e
fC779_9_`A_??AkAklEO==?h?hiD	/99?;b;b	cBoAA?CnCnoFO==?h?hiD
?;;_=e=e
fCO==?h?hiDoQQSb  TG  TG  HN@G&>>_OOQ`  RD  RD  Jv  wMOI`saWa}~}gEPMr#   r8  c                   d   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Z eej4                  ej6                        Z eej:                  ej<                        Z eej@                  ejB                        Z"d Z#d Z$d Z%d Z&ejN                  Z(y	)
IVFFastScanStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIVFFastScanStats.<lambda>|#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIVFFastScanStats.<lambda>|#  rD   r#   rE   rF   c                 .    t        j                  | |      S r-   )r   IVFFastScanStats_Mcy_atr  s     r   Mcy_atzIVFFastScanStats.Mcy_at#  ra   r#   c                 .    t        j                  | |      S r-   )r   !IVFFastScanStats_Mcy_reservoir_atr  s     r   Mcy_reservoir_atz!IVFFastScanStats.Mcy_reservoir_at#  rn  r#   c                 T    t        j                  | t        j                                y r-   )r   IVFFastScanStats_swiginitnew_IVFFastScanStatsrR   s    r   rN   zIVFFastScanStats.__init__#  r  r#   c                 ,    t        j                  |       S r-   )r   IVFFastScanStats_resetrR   s    r   r  zIVFFastScanStats.reset#  r  r#   N))r   r   r6   r   r   r   r   r   IVFFastScanStats_times_getIVFFastScanStats_times_settimes.IVFFastScanStats_t_compute_distance_tables_get.IVFFastScanStats_t_compute_distance_tables_sett_compute_distance_tablesIVFFastScanStats_t_round_getIVFFastScanStats_t_round_sett_round IVFFastScanStats_t_copy_pack_get IVFFastScanStats_t_copy_pack_sett_copy_packIVFFastScanStats_t_scan_getIVFFastScanStats_t_scan_sett_scanIVFFastScanStats_t_to_flat_getIVFFastScanStats_t_to_flat_set	t_to_flat$IVFFastScanStats_reservoir_times_get$IVFFastScanStats_reservoir_times_setreservoir_times IVFFastScanStats_t_aq_encode_get IVFFastScanStats_t_aq_encode_sett_aq_encode%IVFFastScanStats_t_aq_norm_encode_get%IVFFastScanStats_t_aq_norm_encode_sett_aq_norm_encoder  r  rN   r  delete_IVFFastScanStatsr   r$   r#   r   r  r  {#  s9   -/IOdeGH_??AkAklE ()g)gix  jh  jh  !iCC_EqEqrG?KK_M}M}~KoAA?CnCnoFGGIwIwxISSUd  VJ  VJ  KO?KK_M}M}~K U UWf  XM  XM  N@J`<&>>r#   r  c                   h   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Zd Zej,                  Zd Zd Zd	 Zd
 ZddZddZd Zd Zy)!IndexIVFAdditiveQuantizerFastScanas  
     Fast scan version of IVFAQ. Works for 4-bit AQ for now.

    The codes in the inverted lists are not stored sequentially but
    grouped in blocks of size bbs. This makes it possible to very quickly
    compute distances with SIMD instructions.

    Implementations (implem):
    0: auto-select implementation (default)
    1: orig's search, re-implemented
    2: orig's search, re-ordered by invlist
    10: optimizer int16 search, collect results in heap, no qbs
    11: idem, collect results in reservoir
    12: optimizer int16 search, collect results in heap, uses qbs
    13: idem, collect results in reservoir
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z*IndexIVFAdditiveQuantizerFastScan.<lambda>#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z*IndexIVFAdditiveQuantizerFastScan.<lambda>#  rD   r#   rE   rF   c                 6    t        j                  | |||||      S r-   )r   &IndexIVFAdditiveQuantizerFastScan_init)r   r  r  r#  r$  r  s         r   r
  z&IndexIVFAdditiveQuantizerFastScan.init#  s!    EEdBPUW]_bdpqqr#   c                 P    t        j                  | t        j                  |        y r-   )r   *IndexIVFAdditiveQuantizerFastScan_swiginit%new_IndexIVFAdditiveQuantizerFastScanr   s     r   rN   z*IndexIVFAdditiveQuantizerFastScan.__init__#  )    BB4I~I~  AE  JF  	Gr#   c                 2    t        j                  | |||      S r-   )r   /IndexIVFAdditiveQuantizerFastScan_train_encoderr  s       r   r  z/IndexIVFAdditiveQuantizerFastScan.train_encoder#  s    NNtUVXY[abbr#   c                 ,    t        j                  |       S r-   )r   ;IndexIVFAdditiveQuantizerFastScan_train_encoder_num_vectorsrR   s    r   r  z;IndexIVFAdditiveQuantizerFastScan.train_encoder_num_vectors#  s    ZZ[_``r#   c                 0    t        j                  | ||      S r-   )r   5IndexIVFAdditiveQuantizerFastScan_estimate_norm_scaler!  s      r   r  z5IndexIVFAdditiveQuantizerFastScan.estimate_norm_scale#  s    TTUY[\^_``r#   c                 6    t        j                  | |||||      S )zq
        same as the regular IVFAQ encoder. The codes are not reorganized by
        blocks a that point
        )r   0IndexIVFAdditiveQuantizerFastScan_encode_vectorsr  s         r   r  z0IndexIVFAdditiveQuantizerFastScan.encode_vectors#  s%    
 OOPTVWYZ\dfkm{||r#   Nc           	      8    t        j                  | ||||||      S r-   )r   (IndexIVFAdditiveQuantizerFastScan_searchr8  s          r   r:  z(IndexIVFAdditiveQuantizerFastScan.search#  s$    GGaQRTUW`bhjpqqr#   c                 ,    t        j                  |       S r-   )r   4IndexIVFAdditiveQuantizerFastScan_lookup_table_is_3drR   s    r   rG  z4IndexIVFAdditiveQuantizerFastScan.lookup_table_is_3d#  r  r#   c                 6    t        j                  | |||||      S r-   )r   -IndexIVFAdditiveQuantizerFastScan_compute_LUTrJ  s         r   r
	  z-IndexIVFAdditiveQuantizerFastScan.compute_LUT#  s"    LLTSTVWY[]gioppr#   r  r-   ) r   r   r6   r7   r   r   r   r   r   (IndexIVFAdditiveQuantizerFastScan_aq_get(IndexIVFAdditiveQuantizerFastScan_aq_setr  2IndexIVFAdditiveQuantizerFastScan_rescale_norm_get2IndexIVFAdditiveQuantizerFastScan_rescale_norm_setr  0IndexIVFAdditiveQuantizerFastScan_norm_scale_get0IndexIVFAdditiveQuantizerFastScan_norm_scale_setr  6IndexIVFAdditiveQuantizerFastScan_max_train_points_get6IndexIVFAdditiveQuantizerFastScan_max_train_points_setr  r
  (delete_IndexIVFAdditiveQuantizerFastScanr   rN   r  r  r  r  r:  rG  r
	  r$   r#   r   r  r  #  s    " -/IOdeGH	/JJO  ME  ME  
FBO^^`o  ac  ac  dL/ZZ\k  ]]  ]]  ^J f fhw  io  io  pr&OOGcaa}rZqr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)$IndexIVFLocalSearchQuantizerFastScanc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z-IndexIVFLocalSearchQuantizerFastScan.<lambda>#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z-IndexIVFLocalSearchQuantizerFastScan.<lambda>#  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   -IndexIVFLocalSearchQuantizerFastScan_swiginit(new_IndexIVFLocalSearchQuantizerFastScanr   s     r   rN   z-IndexIVFLocalSearchQuantizerFastScan.__init__#  s1    EEdO  ME  ME  GK  ML  	Mr#   N)r   r   r6   r   r   r   r   r   ,IndexIVFLocalSearchQuantizerFastScan_lsq_get,IndexIVFLocalSearchQuantizerFastScan_lsq_setr^
  rN   +delete_IndexIVFLocalSearchQuantizerFastScanr   r$   r#   r   r  r  #  sN    -/IOdeGH
?OOQ`  RN  RN  OCM&RRr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)!IndexIVFResidualQuantizerFastScanc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z*IndexIVFResidualQuantizerFastScan.<lambda>#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z*IndexIVFResidualQuantizerFastScan.<lambda>#  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   *IndexIVFResidualQuantizerFastScan_swiginit%new_IndexIVFResidualQuantizerFastScanr   s     r   rN   z*IndexIVFResidualQuantizerFastScan.__init__#  r  r#   N)r   r   r6   r   r   r   r   r   (IndexIVFResidualQuantizerFastScan_rq_get(IndexIVFResidualQuantizerFastScan_rq_setrx	  rN   (delete_IndexIVFResidualQuantizerFastScanr   r$   r#   r   r  r  #  sM    -/IOdeGH	/JJO  ME  ME  
FBG&OOr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)+IndexIVFProductLocalSearchQuantizerFastScanc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z4IndexIVFProductLocalSearchQuantizerFastScan.<lambda>#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z4IndexIVFProductLocalSearchQuantizerFastScan.<lambda>#  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   4IndexIVFProductLocalSearchQuantizerFastScan_swiginit/new_IndexIVFProductLocalSearchQuantizerFastScanr   s     r   rN   z4IndexIVFProductLocalSearchQuantizerFastScan.__init__#  s2    LLTSb  TS  TS  UY  TZ  	[r#   N)r   r   r6   r   r   r   r   r   4IndexIVFProductLocalSearchQuantizerFastScan_plsq_get4IndexIVFProductLocalSearchQuantizerFastScan_plsq_setr*  rN   2delete_IndexIVFProductLocalSearchQuantizerFastScanr   r$   r#   r   r  r  #  sN    -/IOdeGHOXXZi  [_  [_  `D[&YYr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)(IndexIVFProductResidualQuantizerFastScanc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z1IndexIVFProductResidualQuantizerFastScan.<lambda>#  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z1IndexIVFProductResidualQuantizerFastScan.<lambda>#  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   1IndexIVFProductResidualQuantizerFastScan_swiginit,new_IndexIVFProductResidualQuantizerFastScanr   s     r   rN   z1IndexIVFProductResidualQuantizerFastScan.__init__#  s2    II$P_  QM  QM  OS  QT  	Ur#   N)r   r   r6   r   r   r   r   r   0IndexIVFProductResidualQuantizerFastScan_prq_get0IndexIVFProductResidualQuantizerFastScan_prq_setr  rN   /delete_IndexIVFProductResidualQuantizerFastScanr   r$   r#   r   r  r  #  sN    -/IOdeGH
?SSUd  VV  VV  WCU&VVr#   r  c                   ^   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zd ZddZd Zej4                  Zy)IndexIVFIndependentQuantizerz
     An IVF index with a quantizer that has a different input dimension from the
    payload size. The vectors to encode are obtained from the input vectors by a
    VectorTransform.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z%IndexIVFIndependentQuantizer.<lambda>$  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z%IndexIVFIndependentQuantizer.<lambda>$  rD   r#   rE   rF   z0quantizer is fed directly with the input vectorsz,transform before the IVF vectors are appliedz(the IVF index, controls nlist and nprobezwhether *this owns the 3 fieldsc                 P    t        j                  | t        j                  |        y r-   )r   %IndexIVFIndependentQuantizer_swiginit new_IndexIVFIndependentQuantizerr   s     r   rN   z%IndexIVFIndependentQuantizer.__init__$  s    ==dODtDtvzD{|r#   c                 0    t        j                  | ||      S r-   )r   "IndexIVFIndependentQuantizer_trainr!  s      r   r"  z"IndexIVFIndependentQuantizer.train$  s    AA$1MMr#   c                 0    t        j                  | ||      S r-   )r    IndexIVFIndependentQuantizer_addr!  s      r   r)  z IndexIVFIndependentQuantizer.add$      ??aKKr#   Nc           	      8    t        j                  | ||||||      S r-   )r   #IndexIVFIndependentQuantizer_searchr8  s          r   r:  z#IndexIVFIndependentQuantizer.search$  s"    BB4AqR[]cekllr#   c                 ,    t        j                  |       S r-   )r   "IndexIVFIndependentQuantizer_resetrR   s    r   r  z"IndexIVFIndependentQuantizer.reset$  r  r#   r-   )r   r   r6   r7   r   r   r   r   r   *IndexIVFIndependentQuantizer_quantizer_get*IndexIVFIndependentQuantizer_quantizer_setri  #IndexIVFIndependentQuantizer_vt_get#IndexIVFIndependentQuantizer_vt_setr  *IndexIVFIndependentQuantizer_index_ivf_get*IndexIVFIndependentQuantizer_index_ivf_set	index_ivf+IndexIVFIndependentQuantizer_own_fields_get+IndexIVFIndependentQuantizer_own_fields_setrM  rN   r"  r)  r:  r  #delete_IndexIVFIndependentQuantizerr   r$   r#   r   r  r  #  s     -/IOdeGHSSUd  VP  VP  VM  NI	/EEGzGz  At  
uBSSUd  VP  VP  VE  FI/UUWf  XS  XS  Y  @J}NLmH&JJr#   r  c                   ,   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Zd	 Zd
 Zd Zd ZddZd Zd Zej2                  Zy)IndexIVFPQFastScanas  
     Fast scan version of IVFPQ. Works for 4-bit PQ for now.

    The codes in the inverted lists are not stored sequentially but
    grouped in blocks of size bbs. This makes it possible to very quickly
    compute distances with SIMD instructions.

    Implementations (implem):
    0: auto-select implementation (default)
    1: orig's search, re-implemented
    2: orig's search, re-ordered by invlist
    10: optimizer int16 search, collect results in heap, no qbs
    11: idem, collect results in reservoir
    12: optimizer int16 search, collect results in heap, uses qbs
    13: idem, collect results in reservoir
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFPQFastScan.<lambda>0$  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFPQFastScan.<lambda>0$  rD   r#   rE   rF   r  zprecomputed tables managementz3if use_precompute_table size (nlist, pq.M, pq.ksub)c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFPQFastScan_swiginitnew_IndexIVFPQFastScanr   s     r   rN   zIndexIVFPQFastScan.__init__6$  r  r#   c                 2    t        j                  | |||      S r-   )r    IndexIVFPQFastScan_train_encoderr  s       r   r  z IndexIVFPQFastScan.train_encoder9$  s    ??aFSSr#   c                 ,    t        j                  |       S r-   )r   ,IndexIVFPQFastScan_train_encoder_num_vectorsrR   s    r   r  z,IndexIVFPQFastScan.train_encoder_num_vectors<$  s    KKDQQr#   c                 ,    t        j                  |       S )z@build precomputed table, possibly updating use_precomputed_table)r   #IndexIVFPQFastScan_precompute_tablerR   s    r   r  z#IndexIVFPQFastScan.precompute_table?$  r  r#   c                 6    t        j                  | |||||      S )zq
        same as the regular IVFPQ encoder. The codes are not reorganized by
        blocks a that point
        )r   !IndexIVFPQFastScan_encode_vectorsr  s         r   r  z!IndexIVFPQFastScan.encode_vectorsC$  s!    
 @@q!XW\^lmmr#   c                 ,    t        j                  |       S r-   )r   %IndexIVFPQFastScan_lookup_table_is_3drR   s    r   rG  z%IndexIVFPQFastScan.lookup_table_is_3dJ$  r  r#   c                 6    t        j                  | |||||      S r-   )r   IndexIVFPQFastScan_compute_LUTrJ  s         r   r
	  zIndexIVFPQFastScan.compute_LUTM$  s    ==dAq"jZ`aar#   Nr  )r   r   r6   r7   r   r   r   r   r   IndexIVFPQFastScan_pq_getIndexIVFPQFastScan_pq_setr  ,IndexIVFPQFastScan_use_precomputed_table_get,IndexIVFPQFastScan_use_precomputed_table_setrt  (IndexIVFPQFastScan_precomputed_table_get(IndexIVFPQFastScan_precomputed_table_setr  rN   r  r  r  r  rG  r
	  delete_IndexIVFPQFastScanr   r$   r#   r   r!  r!  $  s    " -/IOdeGH	/;;_=f=f  mF  
GB$_%a%acr  d`  d`  fJ  K !Y!Y[j  \T  \T  ZT  UiTRInKb&@@r#   r!  c                 4    t        j                  | ||||      S )a  
     Functions to quantize PQ floating-point Look Up Tables (LUT) to uint8, and
    biases to uint16. The accumulation is supposed to take place in uint16.
    The quantization coefficients are float (a, b) such that

         original_value = quantized_value * a / b

    The hardest part of the quantization is with multiple LUTs that need to be
    added up together. In that case, coefficient a has to be chosen so that
    the sum fits in a uint16 accumulator.
    )r   round_uint8_per_column)r  rW   r
  a_outb_outs        r   r;  r;  T$  s     11#q!UEJJr#   c                 6    t        j                  | |||||      S r-   )r   round_uint8_per_column_multi)r  r  rW   r
  r<  r=  s         r   r?  r?  b$  s    77Q1eUSSr#   c                 @    t        j                  | |||||||||	|
      S )a)  
     LUT quantization to uint8 and bias to uint16.

    (nprobe, M, ksub, lut_is_3d) determine the size of the the LUT

     LUT input:
     - 2D size (M, ksub): single matrix per probe (lut_is_3d=false)
     - 3D size (nprobe, M, ksub): separate LUT per probe (lut_is_3d=true)
     bias input:
     - nullptr: bias is 0
     - size (nprobe): one bias per probe
     Output:
     - LUTq uint8 version of the LUT (M size is rounded up to M2)
     - biasq (or nullptr): uint16 version of the LUT
     - a, b: scalars to approximate the true distance
    )r   quantize_LUT_and_bias)r  rM  r  	lut_is_3dr	  biasLUTqr^  biasqr<  r=  s              r   rA  rA  e$  s/    " 00D)SRVX\^`bginpuvvr#   c                 B    t        j                  | |||||||||	|
|      S r-   )r   aq_quantize_LUT_and_bias)r  rM  r  r	  rC  M_normr  rD  r^  rE  r<  r=  s               r   rG  rG  x$  s:    33FAtS$PVXbdhjlnsuz  }B  C  Cr#   c                 2    t        j                  | |||      S r-   )r   aq_estimate_norm_scale)rM  r  rH  r	  s       r   rJ  rJ  {$  s    11!T63GGr#   c                   D   e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Z ee	j&                  e	j(                  d
      Z ee	j,                  e	j.                  d      Z ee	j2                  e	j4                  d      Ze	j8                  Zd Zd Zd Z d Z!d Z"d Z#d"dZ$d"dZ%d"dZ&d#dZ'd Z(d Z)d Z*d Z+d"dZ,d Z-d$dZ.d Z/d  Z0d! Z1y)%IndexBinaryz
     Abstract structure for a binary index.

    Supports adding vertices and searching them.

    All queries are symmetric because there is no distinction between codes and
    vectors.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinary.<lambda>$  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinary.<lambda>$  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexBinary.__init__$  rO   r#   r  z&number of bytes per vector ( = d / 8 )r  r  zX
    set if the Index does not require training, or if training is done
    already
    r  c                 0    t        j                  | ||      S )z
         Perform training on a representative set of vectors.

        :type n: int
        :param n:      nb of training vectors
        :type x: uint8_t
        :param x:      training vecors, size n * d / 8
        )r   IndexBinary_trainr!  s      r   r"  zIndexBinary.train$  s     00q!<<r#   c                 2    t        j                  | |||      S r-   )r   IndexBinary_trainExr%  s       r   r&  zIndexBinary.trainEx$  s    224A|LLr#   c                 0    t        j                  | ||      S )z
         Add n vectors of dimension d to the index.

        Vectors are implicitly assigned labels ntotal .. ntotal + n - 1
        :type x: uint8_t
        :param x:      input matrix, size n * d / 8
        )r   IndexBinary_addr!  s      r   r)  zIndexBinary.add$  s     ..tQ::r#   c                 2    t        j                  | |||      S r-   )r   IndexBinary_addExr%  s       r   r,  zIndexBinary.addEx$  s    00q!\JJr#   c                 2    t        j                  | |||      S )a  
         Same as add, but stores xids instead of sequential ids.

        The default implementation fails with an assertion, as it is
        not supported by all indexes.

        :type xids: int
        :param xids: if non-null, ids to store for the vectors (size n)
        )r   IndexBinary_add_with_idsr/  s       r   r1  zIndexBinary.add_with_ids$  s     77aDIIr#   c                 4    t        j                  | ||||      S r-   )r   IndexBinary_add_with_idsExr4  s        r   r5  zIndexBinary.add_with_idsEx$      99$1lTXYYr#   Nc           	      8    t        j                  | ||||||      S )a  
         Query n vectors of dimension d to the index.

        return at most k vectors. If there are not enough results for a
        query, the result array is padded with -1s.

        :type x: uint8_t
        :param x:           input vectors to search, size n * d / 8
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        :type distances: int
        :param distances:   output pairwise distances, size n*k
        )r   IndexBinary_searchr8  s          r   r:  zIndexBinary.search$  s"     11$1aFTZ[[r#   c           
      :    t        j                  | |||||||      S r-   )r   IndexBinary_searchExr=  s           r   r>  zIndexBinary.searchEx$  s$    33D!QaQZ\bdjkkr#   c                 6    t        j                  | |||||      S )a  
         Query n vectors of dimension d to the index.

        return all vectors with distance < radius. Note that many indexes
        do not implement the range_search (only the k-NN search is
        mandatory). The distances are converted to float to reuse the
        RangeSearchResult structure, but they are integer. By convention,
        only distances < radius (strict comparison) are returned,
        ie. radius = 0 does not return any result and 1 returns only
        exact same vectors.

        :type x: uint8_t
        :param x:           input vectors to search, size n * d / 8
        :type radius: int
        :param radius:      search radius
        :type result: :py:class:`RangeSearchResult`
        :param result:      result table
        )r   IndexBinary_range_searchrA  s         r   rB  zIndexBinary.range_search$  s     & 77aFFTZ[[r#   c                 4    t        j                  | ||||      S )a`  
         Return the indexes of the k vectors closest to the query x.

        This function is identical to search but only returns labels of
        neighbors.
        :type x: uint8_t
        :param x:           input vectors to search, size n * d / 8
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        )r   IndexBinary_assignrE  s        r   rF  zIndexBinary.assign$  s     11$1faHHr#   c                 ,    t        j                  |       S )z'Removes all elements from the database.)r   IndexBinary_resetrR   s    r   r  zIndexBinary.reset$  r  r#   c                 .    t        j                  | |      S )z9Removes IDs from the index. Not supported by all indexes.)r   IndexBinary_remove_idsrK  s     r   rL  zIndexBinary.remove_ids$  s    55dC@@r#   c                 0    t        j                  | ||      S )a  
         Reconstruct a stored vector.

        This function may not be defined for some indexes.
        :type key: int
        :param key:         id of the vector to reconstruct
        :type recons: uint8_t
        :param recons:      reconstucted vector (size d / 8)
        )r   IndexBinary_reconstructrO  s      r   rR  zIndexBinary.reconstruct$  s     66tS&IIr#   c                 2    t        j                  | |||      S )z
         Reconstruct vectors i0 to i0 + ni - 1.

        This function may not be defined for some indexes.
        :type recons: uint8_t
        :param recons:      reconstucted vectors (size ni * d / 8)
        )r   IndexBinary_reconstruct_nrX  s       r   r[  zIndexBinary.reconstruct_n
%  s     88r2vNNr#   c           
      :    t        j                  | |||||||      S )af  
         Similar to search, but also reconstructs the stored vectors (or an
        approximation in the case of lossy coding) for the search results.

        If there are not enough results for a query, the resulting array
        is padded with -1s.

        :type recons: uint8_t
        :param recons:      reconstructed vectors size (n, k, d)
        )r   "IndexBinary_search_and_reconstructr^  s           r   r_  z"IndexBinary.search_and_reconstruct%  s'     AA$1aQZ\bdjlrssr#   c                 ,    t        j                  |       S )z1Display the actual class name and some more info.)r   IndexBinary_displayrR   s    r   displayzIndexBinary.display!%  s    22488r#   c                 0    t        j                  | ||      S ry  )r   IndexBinary_merge_fromr{  s      r   r~  zIndexBinary.merge_from%%  s     55dJOOr#   c                 .    t        j                  | |      S r  )r   &IndexBinary_check_compatible_for_merger  s     r   r  z&IndexBinary.check_compatible_for_merge.%  s     EEdJWWr#   c                 ,    t        j                  |       S rm  )r   IndexBinary_sa_code_sizerR   s    r   ro  zIndexBinary.sa_code_size6%      77==r#   c                 2    t        j                  | |||      S )z%Same as add_with_ids for IndexBinary.)r   IndexBinary_add_sa_codesr  s       r   r  zIndexBinary.add_sa_codes:%  s    77aMMr#   r-   r   r  )2r   r   r6   r7   r   r   rN   r   r   r   IndexBinary_d_getIndexBinary_d_setr
  IndexBinary_code_size_getIndexBinary_code_size_setr!  IndexBinary_ntotal_getIndexBinary_ntotal_setr  IndexBinary_verbose_getIndexBinary_verbose_setr  IndexBinary_is_trained_getIndexBinary_is_trained_setr  IndexBinary_metric_type_getIndexBinary_metric_type_setr  delete_IndexBinaryr   r"  r&  r)  r,  r1  r5  r:  r>  rB  rF  r  rL  rR  r[  r_  rq  r~  r  ro  r  r$   r#   r   rL  rL  }$  si    -/IOdeGKH22O4U4U[rsABBODmDm  ta  bIo<<o>d>d  kM  NF>>@g@g  nD  EG/DDoFpFp w 	J ?FFHsHs  zj  kK&99	=M;K
JZ\ l\*I7A
JOt9PX>Nr#   rL  c                   d   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                         Z eej$                  ej&                        Zd Zd	 ZddZddZd Zd Zd Zej8                  Zy
)IndexBinaryFlatzBIndex that stores the full vectors and performs exhaustive search.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryFlat.<lambda>C%  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryFlat.<lambda>C%  rD   r#   rE   rF   z%database vectors, size ntotal * d / 8t
     Select between using a heap or counting to select the k smallest values
    when scanning inverted lists.
    c                 0    t        j                  | ||      S r-   )r   IndexBinaryFlat_addr!  s      r   r)  zIndexBinaryFlat.addM%      224A>>r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryFlat_resetrR   s    r   r  zIndexBinaryFlat.resetP%  r  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryFlat_searchr8  s          r   r:  zIndexBinaryFlat.searchS%  r  r#   c                 6    t        j                  | |||||      S r-   )r   IndexBinaryFlat_range_searchrA  s         r   rB  zIndexBinaryFlat.range_searchV%      ;;D!QPVX^__r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryFlat_reconstructrO  s      r   rR  zIndexBinaryFlat.reconstructY%      ::4fMMr#   c                 .    t        j                  | |      S )z
         Remove some ids. Note that because of the indexing structure,
        the semantics of this operation are different from the usual ones:
        the new ids are shifted.
        )r   IndexBinaryFlat_remove_idsrK  s     r   rL  zIndexBinaryFlat.remove_ids\%  s     99$DDr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryFlat_swiginitnew_IndexBinaryFlatr   s     r   rN   zIndexBinaryFlat.__init__d%  r  r#   r-   )r   r   r6   r7   r   r   r   r   r   IndexBinaryFlat_xb_getIndexBinaryFlat_xb_setrR  IndexBinaryFlat_use_heap_getIndexBinaryFlat_use_heap_setuse_heap$IndexBinaryFlat_query_batch_size_get$IndexBinaryFlat_query_batch_size_setquery_batch_size$IndexBinaryFlat_approx_topk_mode_get$IndexBinaryFlat_approx_topk_mode_setr	  r)  r  r:  rB  rR  rL  rN   delete_IndexBinaryFlatr   r$   r#   r   r  r  @%  s    M-/IOdeGH	/88/:`:`  gS  
TBDDoFrFr y 	H   T TVe  WK  WK  L T TVe  WK  WK  L?;``NEc&==r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                        Z eej                  ej                   d      Z eej$                  ej&                  d      Z eej*                  ej,                  d	      Z eej0                  ej2                  d
      Z eej6                  ej8                  d      Z eej<                  ej>                  d      Z  eejB                  ejD                  d      Z# eejH                  ejJ                  d      Z& eejN                  ejP                  d      Z) eejT                  ejV                  d      Z,d Z-ej\                  Z/d Z0d Z1d Z2d Z3d Z4d(dZ5d)dZ6d(dZ7d(dZ8d Z9d Z:d Z;d(dZ<d  Z=d! Z>d" Z?d# Z@d$ ZAd*d%ZBd& ZCd)d'ZDy)+IndexBinaryIVFa_  
     Index based on a inverted file (IVF)

    In the inverted file, the quantizer (an IndexBinary instance) provides a
    quantization index for each vector to be added. The quantization
    index maps to a list (aka inverted list or posting list), where the
    id of the vector is stored.

    Otherwise the object is similar to the IndexIVF
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryIVF.<lambda>v%  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryIVF.<lambda>v%  rD   r#   rE   rF   r  r{  r|  r  zcollect computations per batchz=map for direct access to the elements. Enables reconstruct().rT  r  rU  rV  rW  c                 P    t        j                  | t        j                  |        y)a  
         The Inverted file takes a quantizer (an IndexBinary) on input,
        which implements the function mapping a vector to a list
        identifier. The pointer is borrowed: the quantizer should not
        be deleted while the IndexBinaryIVF is in use.
        N)r   IndexBinaryIVF_swiginitnew_IndexBinaryIVFr   s     r   rN   zIndexBinaryIVF.__init__%  s      	//o6X6XZ^6_`r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryIVF_resetrR   s    r   r  zIndexBinaryIVF.reset%  rS   r#   c                 0    t        j                  | ||      S )zTrains the quantizer)r   IndexBinaryIVF_trainr!  s      r   r"  zIndexBinaryIVF.train%  rV  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIVF_addr!  s      r   r)  zIndexBinaryIVF.add%  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryIVF_add_with_idsr/  s       r   r1  zIndexBinaryIVF.add_with_ids%  r  r#   c                 4    t        j                  | ||||      S )z
         Implementation of vector addition where the vector assignments are
        predefined.

        :type precomputed_idx: int
        :param precomputed_idx:    quantization indices for the input vectors
            (size n)
        )r   IndexBinaryIVF_add_core)r   rW   r>   r0  r  s        r   r  zIndexBinaryIVF.add_core%  s     66tQ4YYr#   Nc
                 >    t        j                  | |||||||||	
      S )aB  
         Search a set of vectors, that are pre-quantized by the IVF
         quantizer. Fill in the corresponding heaps with the query
         results. search() calls this.

        :type n: int
        :param n:      nb of vectors to query
        :type x: uint8_t
        :param x:      query vectors, size nx * d
        :type assign: int
        :param assign: coarse quantization indices, size nx * nprobe
        :type centroid_dis: int
        :param centroid_dis:
                          distances to coarse centroids, size nx * nprobe
        :param distance:
                          output distances, size n * k
        :type labels: int
        :param labels: output labels, size n * k
        :type store_pairs: boolean
        :param store_pairs: store inv list index + inv list offset
                                instead in upper/lower 32 bit of result,
                                instead of ids (used for reranking).
        :type params: :py:class:`IVFSearchParameters`, optional
        :param params: used to override the object's search parameters
        )r   !IndexBinaryIVF_search_preassigned)
r   rW   r>   rP  rF  r  rQ  rR  r  r9  s
             r   r  z!IndexBinaryIVF.search_preassigned%  s;    4 @@q!QPVXdfoqw  zE  GM  N  	Nr#   c                 .    t        j                  | |      S r-   )r   &IndexBinaryIVF_get_InvertedListScanner)r   r  s     r   r  z&IndexBinaryIVF.get_InvertedListScanner%  s    EEdKXXr#   c           	      8    t        j                  | ||||||      S r  )r   IndexBinaryIVF_searchr8  s          r   r:  zIndexBinaryIVF.search%  r  r#   c                 6    t        j                  | |||||      S r-   )r   IndexBinaryIVF_range_searchrA  s         r   rB  zIndexBinaryIVF.range_search%  r  r#   c           	      8    t        j                  | ||||||      S r-   )r   'IndexBinaryIVF_range_search_preassigned)r   rW   r>   rV  rF  r  rW  s          r   r  z'IndexBinaryIVF.range_search_preassigned%  s$    FFtQPQSY[acoqwxxr#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIVF_reconstructrO  s      r   rR  zIndexBinaryIVF.reconstruct%  r  r#   c                 2    t        j                  | |||      S )a  
         Reconstruct a subset of the indexed vectors.

        Overrides default implementation to bypass reconstruct() which requires
        direct_map to be maintained.

        :type i0: int
        :param i0:     first vector to reconstruct
        :type ni: int
        :param ni:     nb of vectors to reconstruct
        :type recons: uint8_t
        :param recons: output array of reconstructed vectors, size ni * d / 8
        )r   IndexBinaryIVF_reconstruct_nrX  s       r   r[  zIndexBinaryIVF.reconstruct_n%  s     ;;D"b&QQr#   c           
      :    t        j                  | |||||||      S )a  
         Similar to search, but also reconstructs the stored vectors (or an
        approximation in the case of lossy coding) for the search results.

        Overrides default implementation to avoid having to maintain direct_map
        and instead fetch the code offsets through the `store_pairs` flag in
        search_preassigned().

        :type recons: uint8_t
        :param recons:      reconstructed vectors size (n, k, d / 8)
        )r   %IndexBinaryIVF_search_and_reconstructr^  s           r   r_  z%IndexBinaryIVF.search_and_reconstruct%  s(     DDT1aQRT]_egmouvvr#   c                 2    t        j                  | |||      S r  )r   &IndexBinaryIVF_reconstruct_from_offsetr  s       r   r  z&IndexBinaryIVF.reconstruct_from_offset%  s     EEdGU[]cddr#   c                 .    t        j                  | |      S r  )r   IndexBinaryIVF_remove_idsrK  s     r   rL  zIndexBinaryIVF.remove_ids%  s    88sCCr#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIVF_merge_from)r   r   r}  s      r   r~  zIndexBinaryIVF.merge_from&  s    88ufMMr#   c                 .    t        j                  | |      S r-   )r   )IndexBinaryIVF_check_compatible_for_merger  s     r   r  z)IndexBinaryIVF.check_compatible_for_merge&  r  r#   c                 .    t        j                  | |      S r-   )r   IndexBinaryIVF_get_list_sizer  s     r   r  zIndexBinaryIVF.get_list_size	&  r  r#   c                 .    t        j                  | |      S r  )r   IndexBinaryIVF_make_direct_mapr  s     r   r   zIndexBinaryIVF.make_direct_map&  s     ==dD[\\r#   c                 .    t        j                  | |      S r-   )r   "IndexBinaryIVF_set_direct_map_typer  s     r   r  z"IndexBinaryIVF.set_direct_map_type&  re  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIVF_replace_invlistsr  s      r   r	  zIndexBinaryIVF.replace_invlists&  s    >>tRMMr#   r-   r  rD  )Er   r   r6   r7   r   r   r   r   r   IndexBinaryIVF_invlists_getIndexBinaryIVF_invlists_setr  IndexBinaryIVF_own_invlists_getIndexBinaryIVF_own_invlists_setr  IndexBinaryIVF_nprobe_getIndexBinaryIVF_nprobe_setr  IndexBinaryIVF_max_codes_getIndexBinaryIVF_max_codes_setr  IndexBinaryIVF_use_heap_getIndexBinaryIVF_use_heap_setr  %IndexBinaryIVF_per_invlist_search_get%IndexBinaryIVF_per_invlist_search_setper_invlist_searchIndexBinaryIVF_direct_map_getIndexBinaryIVF_direct_map_setr?  IndexBinaryIVF_quantizer_getIndexBinaryIVF_quantizer_setri  IndexBinaryIVF_nlist_getIndexBinaryIVF_nlist_setr  IndexBinaryIVF_own_fields_getIndexBinaryIVF_own_fields_setrM  IndexBinaryIVF_cp_getIndexBinaryIVF_cp_setrf  #IndexBinaryIVF_clustering_index_get#IndexBinaryIVF_clustering_index_setru  rN   delete_IndexBinaryIVFr   r  r"  r)  r1  r  r  r  r:  rB  r  rR  r[  r_  r  rL  r~  r  r  r   r  r	  r$   r#   r   r  r  j%  sQ   	 -/IOdeGHCC_EpEp  wW  XHOKK_M|M|}Lo??AjAj  qV  WFEEGsGs  zg  hICC_EpEp w 	H "/"W"WYh  ZO  ZO  Uz  {/GGIvIv  }A  BJEEGsGs  zn  oI_==?g?g  nR  SE/GGIvIv  }e  fJ	/779^9^  eQ  
RB S SUd  VI  VI  O~  a '<<:@>M	ZN8Y__yMR w	eDN[K]NNr#   r  c                   f    e Zd Z ed d d      Zd ZeZd Zd Z	d Z
d	 Zd
 Zej                  Zy)BinaryInvertedListScannerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"BinaryInvertedListScanner.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"BinaryInvertedListScanner.<lambda>&  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   z"BinaryInvertedListScanner.__init__!&  rO   r#   c                 .    t        j                  | |      S r(  )r   #BinaryInvertedListScanner_set_queryr*  s     r   r  z#BinaryInvertedListScanner.set_query%&  s    BB4VVr#   c                 0    t        j                  | ||      S r-  )r   "BinaryInvertedListScanner_set_listr/  s      r   r0  z"BinaryInvertedListScanner.set_list)&  s    AA$Q[\\r#   c                 .    t        j                  | |      S r2  )r   *BinaryInvertedListScanner_distance_to_coder  s     r   r  z*BinaryInvertedListScanner.distance_to_code-&  r  r#   c           	      8    t        j                  | ||||||      S )a@  
         compute the distances to codes. (distances, labels) should be
        organized as a min- or max-heap

        :type n: int
        :param n:      number of codes to scan
        :type codes: uint8_t
        :param codes:  codes to scan (n * code_size)
        :type ids: int
        :param ids:        corresponding ids (ignored if store_pairs)
        :type distances: int
        :param distances:  heap distances (size k)
        :type labels: int
        :param labels:     heap labels (size k)
        :type k: int
        :param k:          heap size
        )r   $BinaryInvertedListScanner_scan_codesr6  s          r   r7  z$BinaryInvertedListScanner.scan_codes1&  s%    $ CCD!UTWYbdjlmnnr#   c                 6    t        j                  | |||||      S r-   )r   *BinaryInvertedListScanner_scan_codes_ranger>  s         r   r?  z*BinaryInvertedListScanner.scan_codes_rangeE&  s"    II$PQSXZ]_egmnnr#   N)r   r   r6   r   r   rN   r   r   r  r0  r  r7  r?  r    delete_BinaryInvertedListScannerr   r$   r#   r   r  r  &  sH    -/IOdeGKHW]Vo(o&GGr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Zd Zej                   Zd Zd	 ZddZd Zy
)IndexBinaryFromFloatz
     IndexBinary backed by a float Index.

    Supports adding vertices and searching them.

    All queries are symmetric because there is no distinction between codes and
    vectors.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryFromFloat.<lambda>U&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryFromFloat.<lambda>U&  rD   r#   rE   rF   z&Whether object owns the index pointer.c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryFromFloat_swiginitnew_IndexBinaryFromFloatr   s     r   rN   zIndexBinaryFromFloat.__init__Z&  r
  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryFromFloat_addr!  s      r   r)  zIndexBinaryFromFloat.add^&  r  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryFromFloat_resetrR   s    r   r  zIndexBinaryFromFloat.reseta&  r  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryFromFloat_searchr8  s          r   r:  zIndexBinaryFromFloat.searchd&  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryFromFloat_trainr!  s      r   r"  zIndexBinaryFromFloat.traing&  r
  r#   r-   )r   r   r6   r7   r   r   r   r   r   IndexBinaryFromFloat_index_getIndexBinaryFromFloat_index_setr  #IndexBinaryFromFloat_own_fields_get#IndexBinaryFromFloat_own_fields_setrM  rN   delete_IndexBinaryFromFloatr   r)  r  r:  r"  r$   r#   r   r  r  K&  s     -/IOdeGH_CC_EsEstE/MM  PC  PC  Iv  wJm&BBD@eFr#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Z eej*                  ej,                        Zd Zej2                  Zd Zd Zd	 ZddZd Zd Z y
)IndexBinaryHNSWrL  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryHNSW.<lambda>r&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryHNSW.<lambda>r&  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryHNSW_swiginitnew_IndexBinaryHNSWr   s     r   rN   zIndexBinaryHNSW.__init__z&  r  r#   c                 ,    t        j                  |       S r-   )r   %IndexBinaryHNSW_get_distance_computerrR   s    r   rk  z%IndexBinaryHNSW.get_distance_computer~&  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryHNSW_addr!  s      r   r)  zIndexBinaryHNSW.add&  r  r#   c                 0    t        j                  | ||      S rU  )r   IndexBinaryHNSW_trainr!  s      r   r"  zIndexBinaryHNSW.train&      44T1a@@r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexBinaryHNSW_searchr8  s          r   r:  zIndexBinaryHNSW.search&  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryHNSW_reconstructrO  s      r   rR  zIndexBinaryHNSW.reconstruct&  r  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryHNSW_resetrR   s    r   r  zIndexBinaryHNSW.reset&  r  r#   r-   )!r   r   r6   r7   r   r   r   r   r   IndexBinaryHNSW_hnsw_getIndexBinaryHNSW_hnsw_setr<  IndexBinaryHNSW_own_fields_getIndexBinaryHNSW_own_fields_setrM  IndexBinaryHNSW_storage_getIndexBinaryHNSW_storage_setr  IndexBinaryHNSW_init_level0_getIndexBinaryHNSW_init_level0_setr  (IndexBinaryHNSW_keep_max_size_level0_get(IndexBinaryHNSW_keep_max_size_level0_setr  rN   delete_IndexBinaryHNSWr   rk  r)  r"  r:  rR  r  r$   r#   r   r  r  l&  s    
 -/IOdeGHO<<o>f>fgD/HH/JxJxyJBBODoDopG?JJOL{L{|K#O$\$\^m  _W  _W  Xc&==K?A`N;r#   r  c                       e Zd Z ed d d      ZeZd Z eej                  ej                  d      Z eej                  ej                  d      Zd Zdd
Zej"                  Zy	)IndexBinaryHNSWCagrac                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryHNSWCagra.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryHNSWCagra.<lambda>&  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryHNSWCagra_swiginitnew_IndexBinaryHNSWCagrar   s     r   rN   zIndexBinaryHNSWCagra.__init__&  r
  r#   a   
    When set to true, the index is immutable.
    This option is used to copy the knn graph from GpuIndexBinaryCagra
    to the base level of IndexBinaryHNSWCagra without adding upper levels.
    Doing so enables to search the HNSW index, but removes the
    ability to add vectors.
    r  c                 0    t        j                  | ||      S r-   )r   IndexBinaryHNSWCagra_addr!  s      r   r)  zIndexBinaryHNSWCagra.add&  r  r#   Nc           	      8    t        j                  | ||||||      S rY  )r   IndexBinaryHNSWCagra_searchr8  s          r   r:  zIndexBinaryHNSWCagra.search&  s!    ::4Aq)U[]cddr#   r-   )r   r   r6   r   r   r   r   rN   r   (IndexBinaryHNSWCagra_base_level_only_get(IndexBinaryHNSWCagra_base_level_only_setr  :IndexBinaryHNSWCagra_num_base_level_search_entrypoints_get:IndexBinaryHNSWCagra_num_base_level_search_entrypoints_setr  r)  r:  delete_IndexBinaryHNSWCagrar   r$   r#   r   r9  r9  &  s    -/IOdeGHmWWYh  ZR  ZR X 	O )11{1{  ~M  ~H  ~H N )	%De 'BBr#   r9  c                   (   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zd Zd	 ZddZddZd Zd Zej4                  Zy
)IndexBinaryHash*just uses the b first bits as a hash valuec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryHash.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryHash.<lambda>&  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryHash_swiginitnew_IndexBinaryHashr   s     r   rN   zIndexBinaryHash.__init__&  r  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryHash_resetrR   s    r   r  zIndexBinaryHash.reset&  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryHash_addr!  s      r   r)  zIndexBinaryHash.add&  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryHash_add_with_idsr/  s       r   r1  zIndexBinaryHash.add_with_ids&  s    ;;D!QMMr#   Nc                 6    t        j                  | |||||      S r-   )r   IndexBinaryHash_range_searchrA  s         r   rB  zIndexBinaryHash.range_search&  r  r#   c           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryHash_searchr8  s          r   r:  zIndexBinaryHash.search&  r  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryHash_displayrR   s    r   rq  zIndexBinaryHash.display&  ro   r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryHash_hashtable_sizerR   s    r   hashtable_sizezIndexBinaryHash.hashtable_size&  r  r#   r-   )r   r   r6   r7   r   r   r   r   r   IndexBinaryHash_invlists_getIndexBinaryHash_invlists_setr  IndexBinaryHash_b_getIndexBinaryHash_b_setr	  IndexBinaryHash_nflip_getIndexBinaryHash_nflip_setnfliprN   r  r)  r1  rB  r:  rq  r^  delete_IndexBinaryHashr   r$   r#   r   rI  rI  &  s    5-/IOdeGHDDoFrFrsH668]8]^A_>>@i@ijEc;?N``=D&==r#   rI  c                   6   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Zd Zd Zej,                  Zy)IndexBinaryHashStatsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryHashStats.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryHashStats.<lambda>&  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   IndexBinaryHashStats_swiginitnew_IndexBinaryHashStatsrR   s    r   rN   zIndexBinaryHashStats.__init__&  r  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryHashStats_resetrR   s    r   r  zIndexBinaryHashStats.reset&  r  r#   N)r   r   r6   r   r   r   r   r   IndexBinaryHashStats_nq_getIndexBinaryHashStats_nq_setr  IndexBinaryHashStats_n0_getIndexBinaryHashStats_n0_setn0IndexBinaryHashStats_nlist_getIndexBinaryHashStats_nlist_setr  IndexBinaryHashStats_ndis_getIndexBinaryHashStats_ndis_setr_  rN   r  delete_IndexBinaryHashStatsr   r$   r#   r   rh  rh  &  s    -/IOdeGH	/==?j?j	kB	/==?j?j	kB_CC_EsEstEOAA?CpCpqDh@&BBr#   rh  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                  d      Z eej*                  ej,                  d      Z eej0                  ej2                  d      Zd	 Zej8                  Zd
 Zd ZddZ ddZ!d Z"y)IndexBinaryMultiHashrJ  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryMultiHash.<lambda>&  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryMultiHash.<lambda>&  rD   r#   rE   rF   znb of hash mapsznb bits per hash mapz"nb bit flips to use at search timec                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryMultiHash_swiginitnew_IndexBinaryMultiHashr   s     r   rN   zIndexBinaryMultiHash.__init__&  r
  r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryMultiHash_resetrR   s    r   r  zIndexBinaryMultiHash.reset&  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryMultiHash_addr!  s      r   r)  zIndexBinaryMultiHash.add&  r  r#   Nc                 6    t        j                  | |||||      S r-   )r   !IndexBinaryMultiHash_range_searchrA  s         r   rB  z!IndexBinaryMultiHash.range_search&  s    @@q!VU[]cddr#   c           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryMultiHash_searchr8  s          r   r:  zIndexBinaryMultiHash.search '  r  r#   c                 ,    t        j                  |       S r-   )r   #IndexBinaryMultiHash_hashtable_sizerR   s    r   r^  z#IndexBinaryMultiHash.hashtable_size'  ri  r#   r-   )#r   r   r6   r7   r   r   r   r   r    IndexBinaryMultiHash_storage_get IndexBinaryMultiHash_storage_setr  #IndexBinaryMultiHash_own_fields_get#IndexBinaryMultiHash_own_fields_setrM  IndexBinaryMultiHash_maps_getIndexBinaryMultiHash_maps_setmapsIndexBinaryMultiHash_nhash_getIndexBinaryMultiHash_nhash_setnhashIndexBinaryMultiHash_b_getIndexBinaryMultiHash_b_setr	  IndexBinaryMultiHash_nflip_getIndexBinaryMultiHash_nflip_setre  rN   delete_IndexBinaryMultiHashr   r  r)  rB  r:  r^  r$   r#   r   r{  r{  &  s   5-/IOdeGHGGIyIyzG/MM  PC  PC  DJOAA?CpCpqD_CC_EsEs  zP  QE;;_=g=g  nI  	JA_CC_EsEs  zc  dEm&BB@DeeIr#   r{  c                       e Zd ZdZ ed d d      Zd ZeZe	j                  Zd Zd Zd	 Zd
 Zd Zd Z ee	j$                  e	j&                  d      Zy)ThreadedIndexBaser
    A holder of indices in a collection of threads
    The interface to this class itself is not thread safe
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zThreadedIndexBase.<lambda>'  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zThreadedIndexBase.<lambda>'  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zThreadedIndexBase.__init__'  rO   r#   c                 .    t        j                  | |      S a  
        override an index that is managed by ourselves.
        WARNING: once an index is added, it becomes unsafe to touch it from any
        other thread than that on which is managing it, until we are shut
        down. Use runOnIndex to perform work on it instead.
        )r   ThreadedIndexBase_addIndexr  s     r   addIndexzThreadedIndexBase.addIndex'  s     99$FFr#   c                 .    t        j                  | |      S z
        Remove an index that is managed by ourselves.
        This will flush all pending work on that index, and then shut
        down its managing thread, and will remove the index.
        )r   ThreadedIndexBase_removeIndexr  s     r   removeIndexzThreadedIndexBase.removeIndex'  s     <<T5IIr#   c                 .    t        j                  | g| S z
        Run a function on all indices, in the thread that the index is
        managed in.
        Function arguments are (index in collection, index pointer)
        )r   ThreadedIndexBase_runOnIndexr   s     r   
runOnIndexzThreadedIndexBase.runOnIndex&'  s     ;;DH4HHr#   c                 ,    t        j                  |       S zL
        faiss::Index API
        All indices receive the same call
        )r   ThreadedIndexBase_resetrR   s    r   r  zThreadedIndexBase.reset.'  s    
 66t<<r#   c                 ,    t        j                  |       S z!Returns the number of sub-indices)r   ThreadedIndexBase_countrR   s    r   r  zThreadedIndexBase.count5'  s    66t<<r#   c                 .    t        j                  | g| S z
        *Overload 1:*
        Returns the i-th sub-index

        |

        *Overload 2:*
        Returns the i-th sub-index (const version)
        )r   ThreadedIndexBase_atr   s     r   r   zThreadedIndexBase.at9'  s     33D@4@@r#   DWhether or not we are responsible for deleting our contained indicesN)r   r   r6   r7   r   r   rN   r   r   r   delete_ThreadedIndexBaser   r  r  r  r  r  r   !ThreadedIndexBase_own_indices_get!ThreadedIndexBase_own_indices_setown_indicesr$   r#   r   r  r  '  sw    
 -/IOdeGKH&??GJI==
A ?LLoNN  FQ  RKr#   r  c                       e Zd ZdZ ed d d      Zd ZeZe	j                  Zd Zd Zd	 Zd
 Zd Zd Z ee	j$                  e	j&                  d      Zy)ThreadedIndexBaseBinaryr  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z ThreadedIndexBaseBinary.<lambda>N'  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z ThreadedIndexBaseBinary.<lambda>N'  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   z ThreadedIndexBaseBinary.__init__P'  rO   r#   c                 .    t        j                  | |      S r  )r    ThreadedIndexBaseBinary_addIndexr  s     r   r  z ThreadedIndexBaseBinary.addIndexU'  s     ??eLLr#   c                 .    t        j                  | |      S r  )r   #ThreadedIndexBaseBinary_removeIndexr  s     r   r  z#ThreadedIndexBaseBinary.removeIndex^'  s     BB4OOr#   c                 .    t        j                  | g| S r  )r   "ThreadedIndexBaseBinary_runOnIndexr   s     r   r  z"ThreadedIndexBaseBinary.runOnIndexf'  s     AA$NNNr#   c                 ,    t        j                  |       S r  )r   ThreadedIndexBaseBinary_resetrR   s    r   r  zThreadedIndexBaseBinary.resetn'  s    
 <<TBBr#   c                 ,    t        j                  |       S r  )r   ThreadedIndexBaseBinary_countrR   s    r   r  zThreadedIndexBaseBinary.countu'  r?  r#   c                 .    t        j                  | g| S r  )r   ThreadedIndexBaseBinary_atr   s     r   r   zThreadedIndexBaseBinary.aty'  s     99$FFFr#   r  N)r   r   r6   r7   r   r   rN   r   r   r   delete_ThreadedIndexBaseBinaryr   r  r  r  r  r  r   'ThreadedIndexBaseBinary_own_indices_get'ThreadedIndexBaseBinary_own_indices_setr  r$   r#   r   r  r  H'  s    
 -/IOdeGKH&EEMPOCC
G ?RRTc  UL  UL  R]  ^Kr#   r  c                       e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 ZddZd Z eej                   ej"                        Zd Zej(                  Zy)IndexShards<Index that concatenates the results from several sub-indexesc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexShards.<lambda>'  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexShards.<lambda>'  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        ya7  
        *Overload 1:*

        The dimension that all sub-indices must share will be the dimension of
        the first sub-index added

        :type threaded: boolean, optional
        :param threaded:     do we use one thread per sub_index or do
                                queries sequentially?
        :type successive_ids: boolean, optional
        :param successive_ids: should we shift the returned ids by
                                the size of each sub-index or return them
                                as they are?

        |

        *Overload 2:*

        :type threaded: boolean, optional
        :param threaded:     do we use one thread per sub_index or do
                                queries sequentially?
        :type successive_ids: boolean, optional
        :param successive_ids: should we shift the returned ids by
                                the size of each sub-index or return them
                                as they are?

        |

        *Overload 3:*

        :type threaded: boolean, optional
        :param threaded:     do we use one thread per sub_index or do
                                queries sequentially?
        :param successive_ids: should we shift the returned ids by
                                the size of each sub-index or return them
                                as they are?

        |

        *Overload 4:*

        :param threaded:     do we use one thread per sub_index or do
                                queries sequentially?
        :param successive_ids: should we shift the returned ids by
                                the size of each sub-index or return them
                                as they are?

        |

        *Overload 5:*
         int version due to the implicit bool conversion ambiguity of int as
         dimension

        |

        *Overload 6:*
         int version due to the implicit bool conversion ambiguity of int as
         dimension

        |

        *Overload 7:*
         int version due to the implicit bool conversion ambiguity of int as
         dimension
        N)r   IndexShards_swiginitnew_IndexShardsr   s     r   rN   zIndexShards.__init__'  s!    D 	,,T?3R3RTX3YZr#   c                 .    t        j                  | |      S zAlias for addIndex())r   IndexShards_add_shardr  s     r   	add_shardzIndexShards.add_shard'  s    44T5AAr#   c                 .    t        j                  | |      S zAlias for removeIndex())r   IndexShards_remove_shardr  s     r   remove_shardzIndexShards.remove_shard'  s    77eDDr#   c                 0    t        j                  | ||      S z:supported only for sub-indices that implement add_with_ids)r   IndexShards_addr!  s      r   r)  zIndexShards.add'  rW  r#   c                 2    t        j                  | |||      S a>  
        Cases (successive_ids, xids):
        - true, non-NULL       ERROR: it makes no sense to pass in ids and
                               request them to be shifted
        - true, NULL           OK: but should be called only once (calls add()
                               on sub-indexes).
        - false, non-NULL      OK: will call add_with_ids with passed in xids
                               distributed evenly over shards
        - false, NULL          OK: will call add_with_ids on each sub-index,
                               starting at ntotal
        )r   IndexShards_add_with_idsr/  s       r   r1  zIndexShards.add_with_ids'  s     77aDIIr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexShards_searchr8  s          r   r:  zIndexShards.search'  rm  r#   c                 0    t        j                  | ||      S r-   )r   IndexShards_trainr!  s      r   r"  zIndexShards.train'  rf  r#   c                 ,    t        j                  |       S zd
        Synchronize the top-level index (IndexShards) with data in the
        sub-indices
        )r   IndexShards_syncWithSubIndexesrR   s    r   syncWithSubIndexeszIndexShards.syncWithSubIndexes'  r;  r#   r-   )r   r   r6   r7   r   r   r   r   rN   r  r  r)  r1  r:  r"  r   IndexShards_successive_ids_getIndexShards_successive_ids_setsuccessive_idsr  delete_IndexShardsr   r$   r#   r   r  r  '  sq    G-/IOdeGHB[HBE;J\=oLLoN|N|}ND '99r#   r  c                       e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 ZddZd Z eej                   ej"                        Zd Zej(                  Zy)IndexBinaryShardsr  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryShards.<lambda> (  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryShards.<lambda> (  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        yr  )r   IndexBinaryShards_swiginitnew_IndexBinaryShardsr   s     r   rN   zIndexBinaryShards.__init__(  s!    D 	2249^9^`d9efr#   c                 .    t        j                  | |      S r  )r   IndexBinaryShards_add_shardr  s     r   r  zIndexBinaryShards.add_shardG(  s    ::4GGr#   c                 .    t        j                  | |      S r  )r   IndexBinaryShards_remove_shardr  s     r   r  zIndexBinaryShards.remove_shardK(      ==dEJJr#   c                 0    t        j                  | ||      S r  )r   IndexBinaryShards_addr!  s      r   r)  zIndexBinaryShards.addO(  r&  r#   c                 2    t        j                  | |||      S r  )r   IndexBinaryShards_add_with_idsr/  s       r   r1  zIndexBinaryShards.add_with_idsS(  s     ==dAq$OOr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryShards_searchr8  s          r   r:  zIndexBinaryShards.searcha(  r)  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryShards_trainr!  s      r   r"  zIndexBinaryShards.traind(  r  r#   c                 ,    t        j                  |       S r  )r   $IndexBinaryShards_syncWithSubIndexesrR   s    r   r  z$IndexBinaryShards.syncWithSubIndexesh(  s    
 CCDIIr#   r-   )r   r   r6   r7   r   r   r   r   rN   r  r  r)  r1  r:  r"  r   $IndexBinaryShards_successive_ids_get$IndexBinaryShards_successive_ids_setr  r  delete_IndexBinaryShardsr   r$   r#   r   r  r  '  s    G-/IOdeGHBgHHKAPbCoRRTc  UI  UI  JNJ '??r#   r  c                   h    e Zd ZdZ ed d d      ZeZddZd Z	d Z
d	 ZddZej                  Zy
)IndexShardsIVFz
    IndexShards with a common coarse quantizer. All the indexes added should be
    IndexIVFInterface indexes so that the search_precomputed can be called.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexShardsIVF.<lambda>x(  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexShardsIVF.<lambda>x(  rD   r#   rE   rF   c           	      \    t        j                  | t        j                  ||||             y r-   )r   IndexShardsIVF_swiginitnew_IndexShardsIVF)r   ri  r  threadedr  s        r   rN   zIndexShardsIVF.__init__{(  s1    //o6X6XYbdiks  vD  7E  	Fr#   c                 .    t        j                  | |      S r-   )r   IndexShardsIVF_addIndexr  s     r   r  zIndexShardsIVF.addIndex~(  s    66tUCCr#   c                 2    t        j                  | |||      S r-   )r   IndexShardsIVF_add_with_idsr/  s       r   r1  zIndexShardsIVF.add_with_ids(  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexShardsIVF_trainr!  s      r   r"  zIndexShardsIVF.train(      33D!Q??r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexShardsIVF_searchr8  s          r   r:  zIndexShardsIVF.search(  s     44T1aIvW]^^r#   )FTr-   )r   r   r6   r7   r   r   r   r   rN   r  r1  r"  r:  r   delete_IndexShardsIVFr   r$   r#   r   r  r  r(  sI    
 -/IOdeGHFDM@_&<<r#   r  c                   x    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 ZddZd Zd Zej"                  Zy)IndexReplicas
    Takes individual faiss::Index instances, and splits queries for
    sending to each Index instance, and joins the results together
    when done.
    Each index is managed by a separate CPU thread.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexReplicas.<lambda>(  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexReplicas.<lambda>(  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        ya  
        *Overload 1:*
        The dimension that all sub-indices must share will be the dimension of
        the first sub-index added
        :type threaded: boolean, optional
        :param threaded: do we use one thread per sub-index or do queries
            sequentially?

        |

        *Overload 2:*
        :type d: int
        :param d: the dimension that all sub-indices must share
        :type threaded: boolean, optional
        :param threaded: do we use one thread per sub index or do queries
            sequentially?

        |

        *Overload 3:*
        :type d: int
        :param d: the dimension that all sub-indices must share
        :param threaded: do we use one thread per sub index or do queries
            sequentially?

        |

        *Overload 4:*
        int version due to the implicit bool conversion ambiguity of int as
        dimension

        |

        *Overload 5:*
        int version due to the implicit bool conversion ambiguity of int as
        dimension
        N)r   IndexReplicas_swiginitnew_IndexReplicasr   s     r   rN   zIndexReplicas.__init__(  s!    L 	..t_5V5VX\5]^r#   c                 .    t        j                  | |      S r  )r   IndexReplicas_add_replicar  s     r   add_replicazIndexReplicas.add_replica(      88uEEr#   c                 .    t        j                  | |      S r  )r   IndexReplicas_remove_replicar  s     r   remove_replicazIndexReplicas.remove_replica(  s    ;;D%HHr#   c                 0    t        j                  | ||      S r  )r   IndexReplicas_trainr!  s      r   r"  zIndexReplicas.train(  s    
 224A>>r#   c                 0    t        j                  | ||      S r  )r   IndexReplicas_addr!  s      r   r)  zIndexReplicas.add(  s    
 00q!<<r#   Nc           	      8    t        j                  | ||||||      S z
        faiss::Index API
        Query is partitioned into a slice for each sub-index
        split by ceil(n / #indices) for our sub-indices
        )r   IndexReplicas_searchr8  s          r   r:  zIndexReplicas.search(  s"     33D!Q9fV\]]r#   c                 0    t        j                  | ||      S z!reconstructs from the first index)r   IndexReplicas_reconstructr   r   rC   s      r   rR  zIndexReplicas.reconstruct(  s    88tQGGr#   c                 ,    t        j                  |       S r  )r    IndexReplicas_syncWithSubIndexesrR   s    r   r  z IndexReplicas.syncWithSubIndexes(  s    
 ??EEr#   r-   )r   r   r6   r7   r   r   r   r   rN   r'  r+  r"  r)  r:  rR  r  r   delete_IndexReplicasr   r$   r#   r   r  r  (  s\     -/IOdeGH&_PFI?=^HF ';;r#   r  c                   x    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 ZddZd Zd Zej"                  Zy)IndexBinaryReplicasr  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryReplicas.<lambda>(  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryReplicas.<lambda>(  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        yr"  )r   IndexBinaryReplicas_swiginitnew_IndexBinaryReplicasr   s     r   rN   zIndexBinaryReplicas.__init__(  s!    L 	44T?;b;bdh;ijr#   c                 .    t        j                  | |      S r  )r   IndexBinaryReplicas_add_replicar  s     r   r'  zIndexBinaryReplicas.add_replica)  s    >>tUKKr#   c                 .    t        j                  | |      S r  )r   "IndexBinaryReplicas_remove_replicar  s     r   r+  z"IndexBinaryReplicas.remove_replica#)  s    AA$NNr#   c                 0    t        j                  | ||      S r  )r   IndexBinaryReplicas_trainr!  s      r   r"  zIndexBinaryReplicas.train')  s    
 88q!DDr#   c                 0    t        j                  | ||      S r  )r   IndexBinaryReplicas_addr!  s      r   r)  zIndexBinaryReplicas.add.)  s    
 66tQBBr#   Nc           	      8    t        j                  | ||||||      S r1  )r   IndexBinaryReplicas_searchr8  s          r   r:  zIndexBinaryReplicas.search5)  s#     99$1aTZ\bccr#   c                 0    t        j                  | ||      S r4  )r   IndexBinaryReplicas_reconstructr6  s      r   rR  zIndexBinaryReplicas.reconstruct=)  s    >>tT1MMr#   c                 ,    t        j                  |       S r  )r   &IndexBinaryReplicas_syncWithSubIndexesrR   s    r   r  z&IndexBinaryReplicas.syncWithSubIndexesA)  s    
 EEdKKr#   r-   )r   r   r6   r7   r   r   r   r   rN   r'  r+  r"  r)  r:  rR  r  r   delete_IndexBinaryReplicasr   r$   r#   r   r;  r;  (  s^     -/IOdeGH&kPLOECdNL 'AAr#   r;  c                   \   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        ZddZd Zd Zd	 ZddZd Zd Zej8                  Zy
)IndexSplitVectorsz
     splits input vectors in segments and assigns each segment to a sub-index
    used to distribute a MultiIndexQuantizer
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexSplitVectors.<lambda>Q)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexSplitVectors.<lambda>Q)  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y)zsum of dimensions seen so farN)r   IndexSplitVectors_swiginitnew_IndexSplitVectors)r   r
  r  s      r   rN   zIndexSplitVectors.__init__X)  s!    2249^9^_`bj9klr#   c                 .    t        j                  | |      S r-   )r   IndexSplitVectors_add_sub_indexr   s     r   add_sub_indexzIndexSplitVectors.add_sub_index\)  r  r#   c                 ,    t        j                  |       S r-   )r   'IndexSplitVectors_sync_with_sub_indexesrR   s    r   sync_with_sub_indexesz'IndexSplitVectors.sync_with_sub_indexes_)  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexSplitVectors_addr!  s      r   r)  zIndexSplitVectors.addb)  r  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexSplitVectors_searchr8  s          r   r:  zIndexSplitVectors.searche)  r)  r#   c                 0    t        j                  | ||      S r-   )r   IndexSplitVectors_trainr!  s      r   r"  zIndexSplitVectors.trainh)  r  r#   c                 ,    t        j                  |       S r-   )r   IndexSplitVectors_resetrR   s    r   r  zIndexSplitVectors.resetk)  ro   r#   r  r-   )r   r   r6   r7   r   r   r   r   r    IndexSplitVectors_own_fields_get IndexSplitVectors_own_fields_setrM  IndexSplitVectors_threaded_getIndexSplitVectors_threaded_setr  !IndexSplitVectors_sub_indexes_get!IndexSplitVectors_sub_indexes_setsub_indexesIndexSplitVectors_sum_d_getIndexSplitVectors_sum_d_setsum_drN   rY  r\  r)  r:  r"  r  delete_IndexSplitVectorsr   r$   r#   r   rQ  rQ  K)  s    
 -/IOdeGH/JJOL|L|}JFFHvHvwH?LLoNN  AK_@@/BmBmnEmKMAbC=&??r#   rQ  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zdd	Zd
 Zd Zej"                  Zy)IndexRandomzQ
     index that returns random results.
    used mainly for time benchmarks
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRandom.<lambda>w)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRandom.<lambda>w)  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexRandom_swiginitnew_IndexRandomr   s     r   rN   zIndexRandom.__init__{)  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexRandom_addr!  s      r   r)  zIndexRandom.add~)  r>  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexRandom_searchr8  s          r   r:  zIndexRandom.search)  rm  r#   c                 0    t        j                  | ||      S r-   )r   IndexRandom_reconstructrO  s      r   rR  zIndexRandom.reconstruct)  rs  r#   c                 ,    t        j                  |       S r-   )r   IndexRandom_resetrR   s    r   r  zIndexRandom.reset)  r   r#   r-   )r   r   r6   r7   r   r   r   r   r   IndexRandom_seed_getIndexRandom_seed_setr  rN   r)  r:  rR  r  delete_IndexRandomr   r$   r#   r   rq  rq  q)  s_    
 -/IOdeGHO88/:^:^_D[;\J7&99r#   rq  c                       e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Ze	j                   Zd	 ZddZd Zd Zy
)IndexRowwiseMinMaxBasea  
     Index wrapper that performs rowwise normalization to [0,1], preserving
     the coefficients. This is a vector codec index only.

     Basically, this index performs a rowwise scaling to [0,1] of every row
     in an input dataset before calling subindex::train() and
     subindex::sa_encode(). sa_encode() call stores the scaling coefficients
      (scaler and minv) in the very beginning of every output code. The format:
         [scaler][minv][subindex::sa_encode() output]
     The de-scaling in sa_decode() is done using:
         output_rescaled = scaler * output + minv

     An additional ::train_inplace() function is provided in order to do
     an inplace scaling before calling subindex::train() and, thus, avoiding
     the cloning of the input dataset, but modifying the input dataset because
     of the scaling and the scaling back. It is up to user to call
     this function instead of ::train()

     Derived classes provide different data types for scaling coefficients.
     Currently, versions with fp16 and fp32 scaling coefficients are available.
    fp16 version adds 4 extra bytes per encoded vector
    fp32 version adds 8 extra bytes per encoded vector
     Provides base functions for rowwise normalizing indices.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRowwiseMinMaxBase.<lambda>)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRowwiseMinMaxBase.<lambda>)  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIndexRowwiseMinMaxBase.__init__)  rO   r#   z	sub-indexz9whether the subindex needs to be freed in the destructor.c                 0    t        j                  | ||      S r-   )r   IndexRowwiseMinMaxBase_addr!  s      r   r)  zIndexRowwiseMinMaxBase.add)  r
  r#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexRowwiseMinMaxBase_searchr8  s          r   r:  zIndexRowwiseMinMaxBase.search)  r  r#   c                 ,    t        j                  |       S r-   )r   IndexRowwiseMinMaxBase_resetrR   s    r   r  zIndexRowwiseMinMaxBase.reset)  r7  r#   c                 0    t        j                  | ||      S r-   )r   $IndexRowwiseMinMaxBase_train_inplacer!  s      r   train_inplacez$IndexRowwiseMinMaxBase.train_inplace)  r  r#   r-   )r   r   r6   r7   r   r   rN   r   r   r    IndexRowwiseMinMaxBase_index_get IndexRowwiseMinMaxBase_index_setr  %IndexRowwiseMinMaxBase_own_fields_get%IndexRowwiseMinMaxBase_own_fields_setrM  delete_IndexRowwiseMinMaxBaser   r)  r:  r  r  r$   r#   r   r  r  )  s    2 -/IOdeGKH_EEGwGw  ~N  OE/OOQ`  RG  RG  MM  NJ&DDFgBPr#   r  c                   j    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 Zd Zej                  Zy)IndexRowwiseMinMaxFP16z+Stores scaling coefficients as fp16 values.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRowwiseMinMaxFP16.<lambda>)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRowwiseMinMaxFP16.<lambda>)  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexRowwiseMinMaxFP16_swiginitnew_IndexRowwiseMinMaxFP16r   s     r   rN   zIndexRowwiseMinMaxFP16.__init__)  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexRowwiseMinMaxFP16_trainr!  s      r   r"  zIndexRowwiseMinMaxFP16.train)  r   r#   c                 0    t        j                  | ||      S r-   )r   $IndexRowwiseMinMaxFP16_train_inplacer!  s      r   r  z$IndexRowwiseMinMaxFP16.train_inplace)  r  r#   c                 ,    t        j                  |       S r-   )r   #IndexRowwiseMinMaxFP16_sa_code_sizerR   s    r   ro  z#IndexRowwiseMinMaxFP16.sa_code_size)  ri  r#   c                 2    t        j                  | |||      S r-   )r    IndexRowwiseMinMaxFP16_sa_encoderr  s       r   rs  z IndexRowwiseMinMaxFP16.sa_encode)  r  r#   c                 2    t        j                  | |||      S r-   )r    IndexRowwiseMinMaxFP16_sa_decoderv  s       r   rw  z IndexRowwiseMinMaxFP16.sa_decode)  r  r#   N)r   r   r6   r7   r   r   r   r   rN   r"  r  ro  rs  rw  r   delete_IndexRowwiseMinMaxFP16r   r$   r#   r   r  r  )  sK    6-/IOdeGHqHPISS&DDr#   r  c                   j    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
d	 Zd
 Zd Zej                  Zy)IndexRowwiseMinMaxz+Stores scaling coefficients as fp32 values.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRowwiseMinMax.<lambda>)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRowwiseMinMax.<lambda>)  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexRowwiseMinMax_swiginitnew_IndexRowwiseMinMaxr   s     r   rN   zIndexRowwiseMinMax.__init__)  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexRowwiseMinMax_trainr!  s      r   r"  zIndexRowwiseMinMax.train)  r  r#   c                 0    t        j                  | ||      S r-   )r    IndexRowwiseMinMax_train_inplacer!  s      r   r  z IndexRowwiseMinMax.train_inplace)  r  r#   c                 ,    t        j                  |       S r-   )r   IndexRowwiseMinMax_sa_code_sizerR   s    r   ro  zIndexRowwiseMinMax.sa_code_size)  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexRowwiseMinMax_sa_encoderr  s       r   rs  zIndexRowwiseMinMax.sa_encode)  s    ;;D!QNNr#   c                 2    t        j                  | |||      S r-   )r   IndexRowwiseMinMax_sa_decoderv  s       r   rw  zIndexRowwiseMinMax.sa_decode)      ;;D!UANNr#   N)r   r   r6   r7   r   r   r   r   rN   r"  r  ro  rs  rw  r   delete_IndexRowwiseMinMaxr   r$   r#   r   r  r  )  sK    6-/IOdeGHiDLEOO&@@r#   r  c                   <   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Z eej$                  ej&                        Zd	dZd Zej.                  Zy)
Linearz minimal translation of nn.Linearc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zLinear.<lambda>)  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zLinear.<lambda>)  rD   r#   rE   rF   c                 Z    t        j                  | t        j                  |||             y r-   )r   Linear_swiginit
new_Linear)r   in_featuresout_featuresrC  s       r   rN   zLinear.__init__)  s#    ''o.H.HVbdh.ijr#   c                 .    t        j                  | |      S r-   )r   Linear___call__r_   s     r   r  zLinear.__call__*  r[  r#   NrD  )r   r   r6   r7   r   r   r   r   r   Linear_in_features_getLinear_in_features_setr  Linear_out_features_getLinear_out_features_setr  Linear_weight_getLinear_weight_setweightLinear_bias_getLinear_bias_setrC  rN   r  delete_Linearr   r$   r#   r   r  r  )  s    +-/IOdeGH?AA?CiCijKOCC_ElElmLo779Z9Z[FO33_5T5TUDk8&44r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zd Zej*                  Zy	)
	Embeddingz#minimal translation of nn.Embeddingc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zEmbedding.<lambda>
*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zEmbedding.<lambda>
*  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   Embedding_swiginitnew_Embedding)r   num_embeddingsembedding_dims      r   rN   zEmbedding.__init__*  s     **41N1N~_l1mnr#   c                 .    t        j                  | |      S r-   )r   Embedding___call__r   s     r   r  zEmbedding.__call__*      11$==r#   c                 .    t        j                  | g| S r-   )r   Embedding_datar   s     r   r   zEmbedding.data*  s    --d:T::r#   N)r   r   r6   r7   r   r   r   r   r   Embedding_num_embeddings_getEmbedding_num_embeddings_setr  Embedding_embedding_dim_getEmbedding_embedding_dim_setr  Embedding_weight_getEmbedding_weight_setr  rN   r  r   delete_Embeddingr   r$   r#   r   r  r  *  s    .-/IOdeGHoJJOLxLxyN_HH/JuJuvMo::O<`<`aFo>;&77r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	FFNz
    Feed forward layer that expands to a hidden dimension, applies a ReLU non
    linearity and maps back to the orignal dimension
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zFFN.<lambda>"*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zFFN.<lambda>"*  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   FFN_swiginitnew_FFN)r   r
  r  s      r   rN   zFFN.__init__'*  s    $$T?+B+B1a+HIr#   c                 .    t        j                  | |      S r-   )r   FFN___call__r_   s     r   r  zFFN.__call__**      ++D!44r#   N)r   r   r6   r7   r   r   r   r   r   FFN_linear1_getFFN_linear1_setlinear1FFN_linear2_getFFN_linear2_setlinear2rN   r  
delete_FFNr   r$   r#   r   r  r  *  sf    
 -/IOdeGH668W8WXG668W8WXGJ5&11r#   r  c                      e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Zd Z eej*                  ej,                        Z eej0                  ej2                        Z eej6                  ej8                        Zd Zdd	Zd
 Z ejB                  Z"y)	QINCoStepc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zQINCoStep.<lambda>1*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zQINCoStep.<lambda>1*  rD   r#   rE   rF   zFd: input dim, K: codebook size, L: # of residual blocks, h: hidden dimc           	      \    t        j                  | t        j                  ||||             y r-   )r   QINCoStep_swiginitnew_QINCoStep)r   r
  r3
  rB  r  s        r   rN   zQINCoStep.__init__8*  s&    **41N1NqRSUVXY1Z[r#   c                 .    t        j                  | |      S r-   )r   QINCoStep_get_residual_blockr  s     r   get_residual_blockzQINCoStep.get_residual_block>*  r  r#   Nc                 2    t        j                  | |||      S )z
         encode a set of vectors x with intial estimate xhat. Optionally return
        the delta to be added to xhat to form the new xhat
        )r   QINCoStep_encode)r   xhatr>   rg  s       r   r  zQINCoStep.encodeA*  s    
 //dAyIIr#   c                 0    t        j                  | ||      S r-   )r   QINCoStep_decode)r   r  r  s      r   r  zQINCoStep.decodeH*  s    //dEBBr#   r-   )#r   r   r6   r   r   r   r   r   QINCoStep_d_getQINCoStep_d_setr
  QINCoStep_K_getQINCoStep_K_setr3
  QINCoStep_L_getQINCoStep_L_setrB  QINCoStep_h_getQINCoStep_h_setr  rN   QINCoStep_codebook_getQINCoStep_codebook_setcodebookQINCoStep_MLPconcat_getQINCoStep_MLPconcat_set	MLPconcatQINCoStep_residual_blocks_getQINCoStep_residual_blocks_setresidual_blocksr  r  r  delete_QINCoStepr   r$   r#   r   r  r  0*  s    -/IOdeGH00/2Q2Q  Xe  	fA00/2Q2QRA00/2Q2QRA00/2Q2QRA\>>@f@fgH@@/BiBijILLoN{N{|OEJC&77r#   r  c                       e Zd Z ed d d      Zd ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	NeuralNetCodecc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zNeuralNetCodec.<lambda>O*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zNeuralNetCodec.<lambda>O*  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zNeuralNetCodec.__init__Q*  rO   r#   c                 .    t        j                  | |      S r-   )r   NeuralNetCodec_decoder   r  s     r   r  zNeuralNetCodec.decodeW*  s    44T5AAr#   c                 .    t        j                  | |      S r-   )r   NeuralNetCodec_encoder_   s     r   r  zNeuralNetCodec.encodeZ*  rz   r#   N)r   r   r6   r   r   rN   r   r   r   NeuralNetCodec_d_getNeuralNetCodec_d_setr
  NeuralNetCodec_M_getNeuralNetCodec_M_setrM  r  r  delete_NeuralNetCodecr   r$   r#   r   r  r  N*  se    -/IOdeGKH557[7[\A557[7[\AB>&<<r#   r  c                   |   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Zd Zd Zd Zd Zej6                  Zy	)
QINCoc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zQINCo.<lambda>a*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zQINCo.<lambda>a*  rD   r#   rE   rF   c           
      ^    t        j                  | t        j                  |||||             y r-   )r   QINCo_swiginit	new_QINCo)r   r
  r3
  rB  rM  r  s         r   rN   zQINCo.__init__i*  s'    &&t_-F-Fq!QPQST-UVr#   c                 .    t        j                  | |      S r-   )r   QINCo_get_stepr  s     r   get_stepzQINCo.get_stepl*  r   r#   c                 .    t        j                  | |      S r-   )r   QINCo_decoder  s     r   r  zQINCo.decodeo*  s    ++D%88r#   c                 .    t        j                  | |      S r-   )r   QINCo_encoder_   s     r   r  zQINCo.encoder*  r  r#   N)r   r   r6   r   r   r   r   r   QINCo_K_getQINCo_K_setr3
  QINCo_L_getQINCo_L_setrB  QINCo_h_getQINCo_h_setr  QINCo_codebook0_getQINCo_codebook0_set	codebook0QINCo_steps_getQINCo_steps_setstepsrN   r.  r  r  delete_QINCor   r$   r#   r   r&  r&  `*  s    -/IOdeGH,,o.I.IJA,,o.I.IJA,,o.I.IJA<<o>a>abI_44o6U6UVEW795&33r#   r&  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        ZddZd Zd	 Zd
 Zd Zej(                  Zy)Tensor2D;Implements a few neural net layers, mainly to support QINCoc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zTensor2D.<lambda>{*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zTensor2D.<lambda>{*  rD   r#   rE   rF   Nc                 Z    t        j                  | t        j                  |||             y r-   )r   Tensor2D_swiginitnew_Tensor2Dr   rt  r\  r   s       r   rN   zTensor2D.__init__*  s#    ))$0L0LRQSUY0Z[r#   c                 .    t        j                  | |      S r-   )r   Tensor2D___iadd__r   s     r   r   zTensor2D.__iadd__*  s    00t<<r#   c                 .    t        j                  | |      S z$get column #j as a 1-column Tensor2D)r   Tensor2D_columnr   r  s     r   columnzTensor2D.column*  s    ..tQ77r#   c                 ,    t        j                  |       S r-   )r   Tensor2D_numelrR   s    r   numelzTensor2D.numel*  r
  r#   c                 .    t        j                  | g| S r-   )r   Tensor2D_datar   s     r   r   zTensor2D.data*  s    ,,T9D99r#   r-   )r   r   r6   r7   r   r   r   r   r   Tensor2D_shape_getTensor2D_shape_setshapeTensor2D_v_getTensor2D_v_setrC   rN   r   rO  rR  r   delete_Tensor2Dr   r$   r#   r   rA  rA  x*  sq    F-/IOdeGH_779[9[\E//1O1OPA\=84:&66r#   rA  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        ZddZd Zd	 Zd
 Zd Zej(                  Zy)Int32Tensor2DrB  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInt32Tensor2D.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInt32Tensor2D.<lambda>*  rD   r#   rE   rF   Nc                 Z    t        j                  | t        j                  |||             y r-   )r   Int32Tensor2D_swiginitnew_Int32Tensor2DrH  s       r   rN   zInt32Tensor2D.__init__*  s$    ..t_5V5VWY[]_c5der#   c                 .    t        j                  | |      S r-   )r   Int32Tensor2D___iadd__r   s     r   r   zInt32Tensor2D.__iadd__*  rR  r#   c                 .    t        j                  | |      S rL  )r   Int32Tensor2D_columnrN  s     r   rO  zInt32Tensor2D.column*  r  r#   c                 ,    t        j                  |       S r-   )r   Int32Tensor2D_numelrR   s    r   rR  zInt32Tensor2D.numel*  rh   r#   c                 .    t        j                  | g| S r-   )r   Int32Tensor2D_datar   s     r   r   zInt32Tensor2D.data*  s    11$>>>r#   r-   )r   r   r6   r7   r   r   r   r   r   Int32Tensor2D_shape_getInt32Tensor2D_shape_setrW  Int32Tensor2D_v_getInt32Tensor2D_v_setrC   rN   r   rO  rR  r   delete_Int32Tensor2Dr   r$   r#   r   r\  r\  *  sr    F-/IOdeGH_<<o>e>efE44o6Y6YZAfB=9?&;;r#   r\  c                      e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zd Zd Zd Zej*                  Zy	)
IndexNeuralNetCodecc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexNeuralNetCodec.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexNeuralNetCodec.<lambda>*  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexNeuralNetCodec_swiginitnew_IndexNeuralNetCodecr   s     r   rN   zIndexNeuralNetCodec.__init__*      44T?;b;bdh;ijr#   c                 0    t        j                  | ||      S r-   )r   IndexNeuralNetCodec_trainr!  s      r   r"  zIndexNeuralNetCodec.train*  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexNeuralNetCodec_sa_encode)r   rW   r>   r  s       r   rs  zIndexNeuralNetCodec.sa_encode*  s    <<T1aOOr#   c                 2    t        j                  | |||      S r-   )r   IndexNeuralNetCodec_sa_decoderm  s       r   rw  zIndexNeuralNetCodec.sa_decode*  s    <<T1eQOOr#   N)r   r   r6   r   r   r   r   r   IndexNeuralNetCodec_net_getIndexNeuralNetCodec_net_setnetIndexNeuralNetCodec_M_getIndexNeuralNetCodec_M_setrM  IndexNeuralNetCodec_nbits_getIndexNeuralNetCodec_nbits_setr  rN   r"  rs  rw  delete_IndexNeuralNetCodecr   r$   r#   r   rp  rp  *  s    -/IOdeGH
?>>@k@k
lC::O<e<efA_BBODqDqrEkEPP&AAr#   rp  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)
IndexQINCoc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexQINCo.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexQINCo.<lambda>*  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexQINCo_swiginitnew_IndexQINCor   s     r   rN   zIndexQINCo.__init__*  r  r#   N)r   r   r6   r   r   r   r   r   IndexQINCo_qinco_getIndexQINCo_qinco_setqincorN   delete_IndexQINCor   r$   r#   r   r  r  *  sB    -/IOdeGH_99?;_;_`EY&88r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zd Zd Zd	 Zd
 ZddZej*                  Zy)RaBitQuantizerc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRaBitQuantizer.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRaBitQuantizer.<lambda>*  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   RaBitQuantizer_swiginitnew_RaBitQuantizerr   s     r   rN   zRaBitQuantizer.__init__*  r  r#   c                 0    t        j                  | ||      S r-   )r   RaBitQuantizer_trainr!  s      r   r"  zRaBitQuantizer.train*  r  r#   c                 2    t        j                  | |||      S r-   )r   RaBitQuantizer_compute_codesr  s       r   r  zRaBitQuantizer.compute_codes*  r  r#   c                 4    t        j                  | ||||      S r-   )r   !RaBitQuantizer_compute_codes_core)r   r>   r  rW   centroid_ins        r   compute_codes_corez!RaBitQuantizer.compute_codes_core*  s    @@q%QRT_``r#   c                 2    t        j                  | |||      S r-   )r   RaBitQuantizer_decoder  s       r   r  zRaBitQuantizer.decode*  s    44T5!QGGr#   c                 4    t        j                  | ||||      S r-   )r   RaBitQuantizer_decode_core)r   r  r>   rW   r  s        r   decode_corezRaBitQuantizer.decode_core*  s    99$q![YYr#   Nc                 0    t        j                  | ||      S r-   )r   $RaBitQuantizer_get_distance_computer)r   qbr  s      r   rk  z$RaBitQuantizer.get_distance_computer*  s    CCD"kZZr#   r-   )r   r   r6   r   r   r   r   r   RaBitQuantizer_centroid_getRaBitQuantizer_centroid_setcentroidRaBitQuantizer_metric_type_getRaBitQuantizer_metric_type_setr  rN   r"  r  r  r  r  rk  delete_RaBitQuantizerr   r$   r#   r   r  r  *  s~    -/IOdeGHCC_EpEpqH?II?KyKyzKa@OaHZ[&<<r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)RaBitQSearchParametersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRaBitQSearchParameters.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRaBitQSearchParameters.<lambda>*  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   RaBitQSearchParameters_swiginitnew_RaBitQSearchParametersrR   s    r   rN   zRaBitQSearchParameters.__init__*  r2  r#   N)r   r   r6   r   r   r   r   r   RaBitQSearchParameters_qb_getRaBitQSearchParameters_qb_setr  rN   delete_RaBitQSearchParametersr   r$   r#   r   r  r  *  sB    -/IOdeGH	/??AnAn	oBl&DDr#   r  c                   $   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Zd Zd Zd Zd Zd	 Zd
 ZddZddZej2                  Zy)IndexRaBitQc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexRaBitQ.<lambda>*  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexRaBitQ.<lambda>*  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexRaBitQ_swiginitnew_IndexRaBitQr   s     r   rN   zIndexRaBitQ.__init__*  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexRaBitQ_trainr!  s      r   r"  zIndexRaBitQ.train+  rf  r#   c                 2    t        j                  | |||      S r-   )r   IndexRaBitQ_sa_encoderr  s       r   rs  zIndexRaBitQ.sa_encode+  rx  r#   c                 2    t        j                  | |||      S r-   )r   IndexRaBitQ_sa_decoderv  s       r   rw  zIndexRaBitQ.sa_decode+  r  r#   c                 ,    t        j                  |       S r-   )r   )IndexRaBitQ_get_FlatCodesDistanceComputerrR   s    r   r  z)IndexRaBitQ.get_FlatCodesDistanceComputer+  r%  r#   c                 .    t        j                  | |      S r-   )r   +IndexRaBitQ_get_quantized_distance_computer)r   qb_ins     r   get_quantized_distance_computerz+IndexRaBitQ.get_quantized_distance_computer+  s    JJ4QVWWr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexRaBitQ_searchr8  s          r   r:  zIndexRaBitQ.search+  rm  r#   c                 6    t        j                  | |||||      S r-   )r   IndexRaBitQ_range_searchrA  s         r   rB  zIndexRaBitQ.range_search+  rp  r#   r-   )r   r   r6   r   r   r   r   r   IndexRaBitQ_rabitq_getIndexRaBitQ_rabitq_setrabitqIndexRaBitQ_center_getIndexRaBitQ_center_setcenterIndexRaBitQ_qb_getIndexRaBitQ_qb_setr  rN   r"  rs  rw  r  r  r:  rB  delete_IndexRaBitQr   r$   r#   r   r  r  *  s    -/IOdeGHo<<o>d>deFo<<o>d>deF	/44o6X6X	YB[=HHOX\\&99r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zy)IVFRaBitQSearchParametersc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z"IVFRaBitQSearchParameters.<lambda>+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z"IVFRaBitQSearchParameters.<lambda>+  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   "IVFRaBitQSearchParameters_swiginitnew_IVFRaBitQSearchParametersrR   s    r   rN   z"IVFRaBitQSearchParameters.__init__+  s    ::4AnAnApqr#   N)r   r   r6   r   r   r   r   r    IVFRaBitQSearchParameters_qb_get IVFRaBitQSearchParameters_qb_setr  rN    delete_IVFRaBitQSearchParametersr   r$   r#   r   r  r  +  sB    -/IOdeGH	/BBODtDt	uBr&GGr#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd ZddZd Zdd
Zd Zd Zd Zd Zej.                  Zy	)IndexIVFRaBitQc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIVFRaBitQ.<lambda>&+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIVFRaBitQ.<lambda>&+  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIVFRaBitQ_swiginitnew_IndexIVFRaBitQr   s     r   rN   zIndexIVFRaBitQ.__init__++  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexIVFRaBitQ_train_encoderr  s       r   r  zIndexIVFRaBitQ.train_encoder.+  s    ;;D!QOOr#   c                 6    t        j                  | |||||      S r-   )r   IndexIVFRaBitQ_encode_vectorsr$  s         r   r  zIndexIVFRaBitQ.encode_vectors1+  s    <<T1aSXZijjr#   c                 4    t        j                  | ||||      S r-   )r   IndexIVFRaBitQ_decode_vectorsr  s        r   r  zIndexIVFRaBitQ.decode_vectors4+  s    <<T1eXWXYYr#   Nc                 6    t        j                  | |||||      S r-   )r   IndexIVFRaBitQ_add_corer  s         r   r  zIndexIVFRaBitQ.add_core7+  s    66tQ4Zoppr#   c                 2    t        j                  | |||      S r-   )r   &IndexIVFRaBitQ_get_InvertedListScannerr  s       r   r  z&IndexIVFRaBitQ.get_InvertedListScanner:+  s    EEdKY\^deer#   c                 2    t        j                  | |||      S r-   )r   &IndexIVFRaBitQ_reconstruct_from_offsetr  s       r   r  z&IndexIVFRaBitQ.reconstruct_from_offset=+  s    EEdGU[]cddr#   c                 2    t        j                  | |||      S r-   )r   IndexIVFRaBitQ_sa_decoderv  s       r   rw  zIndexIVFRaBitQ.sa_decode@+  s    77aJJr#   c                 ,    t        j                  |       S r-   )r   $IndexIVFRaBitQ_get_distance_computerrR   s    r   rk  z$IndexIVFRaBitQ.get_distance_computerC+  rf  r#   r  r-   )r   r   r6   r   r   r   r   r   IndexIVFRaBitQ_rabitq_getIndexIVFRaBitQ_rabitq_setr  IndexIVFRaBitQ_qb_getIndexIVFRaBitQ_qb_setr  rN   r  r  r  r  r  r  rw  rk  delete_IndexIVFRaBitQr   r$   r#   r   r  r  %+  s    -/IOdeGHo??AjAjkF	/779^9^	_BaPkZqfeKJ&<<r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      ZddZd Zej4                  Zy)RangeSearchResulta	  
    The objective is to have a simple result structure while
    minimizing the number of mem copies in the result. The method
    do_allocation can be overloaded to allocate the result tables in
    the matrix type of a scripting language like Lua or Python.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRangeSearchResult.<lambda>Q+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRangeSearchResult.<lambda>Q+  rD   r#   rE   rF   r  zsize (nq + 1)z/result for query i is labels[lims[i]:lims[i+1]]z$corresponding distances (not sorted)zsize of the result buffers usedc                 X    t        j                  | t        j                  ||             y)z0lims must be allocated on input to range_search.N)r   RangeSearchResult_swiginitnew_RangeSearchResult)r   r  
alloc_limss      r   rN   zRangeSearchResult.__init__Y+  s!    2249^9^_acm9nor#   c                 ,    t        j                  |       S )zd
        called when lims contains the nb of elements result entries
        for each query
        )r   RangeSearchResult_do_allocationrR   s    r   do_allocationzRangeSearchResult.do_allocation]+  s    
 >>tDDr#   NrD  )r   r   r6   r7   r   r   r   r   r   RangeSearchResult_nq_getRangeSearchResult_nq_setr  RangeSearchResult_lims_getRangeSearchResult_lims_setr  RangeSearchResult_labels_getRangeSearchResult_labels_setrR  RangeSearchResult_distances_getRangeSearchResult_distances_setrQ  !RangeSearchResult_buffer_size_get!RangeSearchResult_buffer_size_setbuffer_sizerN   r  delete_RangeSearchResultr   r$   r#   r   r  r  I+  s     -/IOdeGH	/::O<d<dj~	BO>>@j@j  qE  FDoBBODpDp  wm  nFHH/JyJy  @k  lI?LLoNN  Fl  mKpE '??r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                   d      Zd Zej&                  Zd Zd	 Zd
 Zy)
BufferListzu
    List of temporary buffers used to store results before they are
    copied to the RangeSearchResult object.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zBufferList.<lambda>m+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zBufferList.<lambda>m+  rD   r#   rE   rF   z!write pointer in the last buffer.c                 V    t        j                  | t        j                  |             y r-   )r   BufferList_swiginitnew_BufferList)r   r  s     r   rN   zBufferList.__init__s+  s    ++D/2P2PQ\2]^r#   c                 ,    t        j                  |       S )zcreate a new buffer)r   BufferList_append_bufferrR   s    r   append_bufferzBufferList.append_bufferw+  rx  r#   c                 0    t        j                  | ||      S )z9add one result, possibly appending a new buffer if needed)r   BufferList_add)r   r  rE  s      r   r)  zBufferList.add{+  s    --dB<<r#   c                 4    t        j                  | ||||      S )zr
        copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
        tables dest_ids, dest_dis
        )r   BufferList_copy_range)r   rL  rW   dest_idsdest_diss        r   
copy_rangezBufferList.copy_range+  s    
 44T38XVVr#   N)r   r   r6   r7   r   r   r   r   r   BufferList_buffer_size_getBufferList_buffer_size_setr  BufferList_buffers_getBufferList_buffers_setbuffersBufferList_wp_getBufferList_wp_setwprN   delete_BufferListr   r  r)  r$  r$   r#   r   r  r  g+  s    
 -/IOdeGH?EEGqGqrK==?e?efG	/33_5V5V  ]E  
FB_&88>=Wr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                         Zd Zd Zej(                  Zy)	RangeQueryResultz#result structure for a single queryc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zRangeQueryResult.<lambda>+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zRangeQueryResult.<lambda>+  rD   r#   rE   rF   c                 0    t        j                  | ||      S )z0called by search function to report a new result)r   RangeQueryResult_add)r   rE  r  s      r   r)  zRangeQueryResult.add+  s    33D#rBBr#   c                 T    t        j                  | t        j                                y r-   )r   RangeQueryResult_swiginitnew_RangeQueryResultrR   s    r   rN   zRangeQueryResult.__init__+  r  r#   N)r   r   r6   r7   r   r   r   r   r   RangeQueryResult_qno_getRangeQueryResult_qno_setqnoRangeQueryResult_nres_getRangeQueryResult_nres_setnresRangeQueryResult_pres_getRangeQueryResult_pres_setpresr)  rN   delete_RangeQueryResultr   r$   r#   r   r/  r/  +  s{    .-/IOdeGH
?;;_=e=e
fCO==?h?hiDO==?h?hiDC`&>>r#   r/  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Z eej                  ej                  d      Zd Zd	 Zd
 ZddZedd       Zej,                  Zy)RangeSearchPartialResultz.the entries in the buffers are split per queryc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z!RangeSearchPartialResult.<lambda>+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z!RangeSearchPartialResult.<lambda>+  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y)z.eventually the result will be stored in res_inN)r   !RangeSearchPartialResult_swiginitnew_RangeSearchPartialResult)r   res_ins     r   rN   z!RangeSearchPartialResult.__init__+  s    99$@l@lms@tur#   z$query ids + nb of results per query.c                 .    t        j                  | |      S )zbegin a new result)r   #RangeSearchPartialResult_new_result)r   r9  s     r   
new_resultz#RangeSearchPartialResult.new_result+  r  r#   c                 ,    t        j                  |       S r-   )r   !RangeSearchPartialResult_finalizerR   s    r   finalizez!RangeSearchPartialResult.finalize+  r  r#   c                 ,    t        j                  |       S )z+called by range_search before do_allocation)r   !RangeSearchPartialResult_set_limsrR   s    r   set_limsz!RangeSearchPartialResult.set_lims+  r  r#   c                 .    t        j                  | |      S )z*called by range_search after do_allocation)r   $RangeSearchPartialResult_copy_result)r   incrementals     r   copy_resultz$RangeSearchPartialResult.copy_result+  s    CCD+VVr#   c                 .    t        j                  | |      S )z{
        merge a set of PartialResult's into one RangeSearchResult
        on output the partialresults are empty!
        )r   RangeSearchPartialResult_merge)partial_results	do_deletes     r   mergezRangeSearchPartialResult.merge+  s     ==oyYYr#   Nr  rD  )r   r   r6   r7   r   r   r   r   r    RangeSearchPartialResult_res_get RangeSearchPartialResult_res_setr8  rN   $RangeSearchPartialResult_queries_get$RangeSearchPartialResult_queries_setqueriesrK  rN  rQ  rU  r  rZ  delete_RangeSearchPartialResultr   r$   r#   r   rB  rB  +  s    9-/IOdeGH
?CC_EuEu
vCv KK_  NB  NB  Hs  tGNGGW Z Z 'FFr#   rB  c                       e Zd Z ed d d      Zd ZeZd Ze	j                  Zed        Zed        Zed	        Zed
        Zy)InterruptCallbackc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zInterruptCallback.<lambda>+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zInterruptCallback.<lambda>+  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zInterruptCallback.__init__+  rO   r#   c                 ,    t        j                  |       S r-   )r    InterruptCallback_want_interruptrR   s    r   want_interruptz InterruptCallback.want_interrupt+  r  r#   c                  *    t        j                         S r-   )r    InterruptCallback_clear_instancer$   r#   r   clear_instancez InterruptCallback.clear_instance+  s    ??AAr#   c                  *    t        j                         S )z
         check if:
        - an interrupt callback is set
        - the callback returns true
        if this is the case, then throw an exception. Should not be called
        from multiple threads.
        )r   InterruptCallback_checkr$   r#   r   checkzInterruptCallback.check+  s     6688r#   c                  *    t        j                         S )z
        same as check() but return true if is interrupted instead of
        throwing. Can be called from multiple threads.
        )r    InterruptCallback_is_interruptedr$   r#   r   is_interruptedz InterruptCallback.is_interrupted+  s     ??AAr#   c                 ,    t        j                  |       S )z
         assuming each iteration takes a certain number of flops, what
        is a reasonable interval to check for interrupts?
        )r   !InterruptCallback_get_period_hint)flopss    r   get_period_hintz!InterruptCallback.get_period_hint+  s     @@GGr#   N)r   r   r6   r   r   rN   r   r   rh  r   delete_InterruptCallbackr   r  rk  rn  rq  ru  r$   r#   r   rb  rb  +  s    -/IOdeGKHF&??B B 9 9 B B H Hr#   rb  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zed        Zd Zej&                  Zy	)
TimeoutCallbackc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zTimeoutCallback.<lambda>+  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zTimeoutCallback.<lambda>+  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r   TimeoutCallback_want_interruptrR   s    r   rh  zTimeoutCallback.want_interrupt+  r  r#   c                 .    t        j                  | |      S r-   )r   TimeoutCallback_set_timeout)r   timeout_in_secondss     r   set_timeoutzTimeoutCallback.set_timeout+  s    ::4ASTTr#   c                 ,    t        j                  |       S r-   )r   TimeoutCallback_reset)r  s    r   r  zTimeoutCallback.reset+  s    445GHHr#   c                 T    t        j                  | t        j                                y r-   )r   TimeoutCallback_swiginitnew_TimeoutCallbackrR   s    r   rN   zTimeoutCallback.__init__+  r  r#   N)r   r   r6   r   r   r   r   r   TimeoutCallback_start_getTimeoutCallback_start_setstartTimeoutCallback_timeout_getTimeoutCallback_timeout_settimeoutrh  r  r  r  rN   delete_TimeoutCallbackr   r$   r#   r   rx  rx  +  s|    -/IOdeGH_>>@i@ijEBBODoDopGDU I I^&==r#   rx  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zd Zd	 Zej&                  Zy
)VisitedTablez-set implementation optimized for fast access.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zVisitedTable.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zVisitedTable.<lambda>,  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   VisitedTable_swiginitnew_VisitedTablerc  s     r   rN   zVisitedTable.__init__,  s    --dO4T4TUY4Z[r#   c                 .    t        j                  | |      S )zset flag #no to true)r   VisitedTable_setr   r  s     r   r!   zVisitedTable.set,      //b99r#   c                 .    t        j                  | |      S )zget flag #no)r   VisitedTable_getr  s     r   rq
  zVisitedTable.get,  r  r#   c                 ,    t        j                  |       S )zreset all flags to false)r   VisitedTable_advancerR   s    r   ru   zVisitedTable.advance,  rj  r#   N)r   r   r6   r7   r   r   r   r   r   VisitedTable_visited_getVisitedTable_visited_setvisitedVisitedTable_visno_getVisitedTable_visno_setvisnorN   r!   rq
  ru   delete_VisitedTabler   r$   r#   r   r  r  ,  sn    8-/IOdeGH??AiAijG_;;_=c=cdE\::: '::r#   r  c                   R    e Zd ZdZ ed d d      Zd ZeZd Z	e
j                  Zy)	
IDSelectorz$Encapsulates a set of ids to handle.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelector.<lambda> ,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelector.<lambda> ,  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zIDSelector.__init__",  rO   r#   c                 .    t        j                  | |      S r-   )r   IDSelector_is_memberr  s     r   	is_memberzIDSelector.is_member&,  s    33D"==r#   N)r   r   r6   r7   r   r   rN   r   r   r  r   delete_IDSelectorr   r$   r#   r   r  r  ,  s2    /-/IOdeGKH>&88r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Z eej                  ej                   d      ZddZd Zd	 Zej*                  Zy
)IDSelectorRangezids between [imin, imax)c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorRange.<lambda>/,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorRange.<lambda>/,  rD   r#   rE   rF   zb
    Assume that the ids to handle are sorted. In some cases this can speed
    up processing
    c                 Z    t        j                  | t        j                  |||             y r-   )r   IDSelectorRange_swiginitnew_IDSelectorRange)r   iminimaxassume_sorteds       r   rN   zIDSelectorRange.__init__8,  s$    007Z7Z[_aegt7uvr#   c                 .    t        j                  | |      S r-   )r   IDSelectorRange_is_memberr  s     r   r  zIDSelectorRange.is_member;,      88rBBr#   c                 4    t        j                  | ||||      S )zg
        for sorted ids, find the range of list indices where the valid ids are
        stored
        )r   &IDSelectorRange_find_sorted_ids_bounds)r   r  r{  jminjmaxs        r   find_sorted_ids_boundsz&IDSelectorRange.find_sorted_ids_bounds>,  s     
 EEdIWZ\`bfggr#   Nr  )r   r   r6   r7   r   r   r   r   r   IDSelectorRange_imin_getIDSelectorRange_imin_setr  IDSelectorRange_imax_getIDSelectorRange_imax_setr  !IDSelectorRange_assume_sorted_get!IDSelectorRange_assume_sorted_setr  rN   r  r  delete_IDSelectorRanger   r$   r#   r   r  r  ,,  s    #-/IOdeGHO<<o>f>fgDO<<o>f>fgD_NNP_  QB  QB H 	M
wCh '==r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorArrayz
     Simple array of elements

    is_member calls are very inefficient, but some operations can use the ids
    directly.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorArray.<lambda>P,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorArray.<lambda>P,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y)a  
         Construct with an array of ids to process

        :type n: int
        :param n: number of ids to store
        :type ids: int
        :param ids: elements to store. The pointer should remain valid during
                       IDSelectorArray's lifetime
        N)r   IDSelectorArray_swiginitnew_IDSelectorArray)r   rW   r{  s      r   rN   zIDSelectorArray.__init__U,  s#     	007Z7Z[\^a7bcr#   c                 .    t        j                  | |      S r-   )r   IDSelectorArray_is_memberr  s     r   r  zIDSelectorArray.is_membera,  r  r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorArray_n_getIDSelectorArray_n_setrW   IDSelectorArray_ids_getIDSelectorArray_ids_setr{  rN   r  delete_IDSelectorArrayr   r$   r#   r   r  r  H,  sg     -/IOdeGH668]8]^A
?::O<c<c
dC
dC&==r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorBatcha  
     Ids from a set.

    Repetitions of ids in the indices set passed to the constructor does not hurt
    performance.

    The hash function used for the bloom filter and GCC's implementation of
    unordered_set are just the least significant bits of the id. This works fine
    for random ids or ids in sequences but will produce many hash collisions if
    lsb's are always the same
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorBatch.<lambda>t,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorBatch.<lambda>t,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y)z
         Construct with an array of ids to process

        :type n: int
        :param n: number of ids to store
        :param ids: elements to store. The pointer can be released after
                       construction
        N)r   IDSelectorBatch_swiginitnew_IDSelectorBatch)r   rW   r  s      r   rN   zIDSelectorBatch.__init__y,  s#     	007Z7Z[\^e7fgr#   c                 .    t        j                  | |      S r-   )r   IDSelectorBatch_is_memberr  s     r   r  zIDSelectorBatch.is_member,  r  r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorBatch_nbits_getIDSelectorBatch_nbits_setr  IDSelectorBatch_mask_getIDSelectorBatch_mask_setr  rN   r  delete_IDSelectorBatchr   r$   r#   r   r  r  g,  sg    
 -/IOdeGH_>>@i@ijEO<<o>f>fgD	hC&==r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorBitmapzAOne bit per element. Constructed with a bitmap, size ceil(n / 8).c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorBitmap.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorBitmap.<lambda>,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y)a  
         Construct with a binary mask

        :type n: int
        :param n: size of the bitmap array
        :type bitmap: uint8_t
        :param bitmap: id will be selected iff id / 8 < n and bit number
                          (i%8) of bitmap[floor(i / 8)] is 1.
        N)r   IDSelectorBitmap_swiginitnew_IDSelectorBitmap)r   rW   bitmaps      r   rN   zIDSelectorBitmap.__init__,  s#     	11$8\8\]^`f8ghr#   c                 .    t        j                  | |      S r-   )r   IDSelectorBitmap_is_memberr  s     r   r  zIDSelectorBitmap.is_member,  s    99$CCr#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorBitmap_n_getIDSelectorBitmap_n_setrW   IDSelectorBitmap_bitmap_getIDSelectorBitmap_bitmap_setr  rN   r  delete_IDSelectorBitmapr   r$   r#   r   r  r  ,  sc    L-/IOdeGH779_9_`AoAA?CnCnoF
iD&>>r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zej                  Zy)	IDSelectorNotz/reverts the membership test of another selectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorNot.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorNot.<lambda>,  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   IDSelectorNot_swiginitnew_IDSelectorNotrK  s     r   rN   zIDSelectorNot.__init__,  s    ..t_5V5VWZ5[\r#   c                 .    t        j                  | |      S r-   )r   IDSelectorNot_is_memberr  s     r   r  zIDSelectorNot.is_member,      66tR@@r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorNot_sel_getIDSelectorNot_sel_setrS  rN   r  delete_IDSelectorNotr   r$   r#   r   r  r  ,  sK    :-/IOdeGH
?88/:_:_
`C]A&;;r#   r  c                   R    e Zd ZdZ ed d d      ZeZd Ze	j                  Zd Zy)	IDSelectorAllz-selects all entries (useful for benchmarking)c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorAll.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorAll.<lambda>,  rD   r#   rE   rF   c                 .    t        j                  | |      S r-   )r   IDSelectorAll_is_memberr  s     r   r  zIDSelectorAll.is_member,  r  r#   c                 T    t        j                  | t        j                                y r-   )r   IDSelectorAll_swiginitnew_IDSelectorAllrR   s    r   rN   zIDSelectorAll.__init__,  r   r#   N)r   r   r6   r7   r   r   r   r   r  r   delete_IDSelectorAllr   rN   r$   r#   r   r  r  ,  s3    8-/IOdeGHA&;;Zr#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorAndz\
    does an AND operation on the the two given IDSelector's is_membership
    results.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorAnd.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorAnd.<lambda>,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   IDSelectorAnd_swiginitnew_IDSelectorAndr   lhsrhss      r   rN   zIDSelectorAnd.__init__,  !    ..t_5V5VWZ\_5`ar#   c                 .    t        j                  | |      S r-   )r   IDSelectorAnd_is_memberr  s     r   r  zIDSelectorAnd.is_member,  r  r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorAnd_lhs_getIDSelectorAnd_lhs_setr  IDSelectorAnd_rhs_getIDSelectorAnd_rhs_setr  rN   r  delete_IDSelectorAndr   r$   r#   r   r  r  ,  g    
 -/IOdeGH
?88/:_:_
`C
?88/:_:_
`CbA&;;r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorOrz[
    does an OR operation on the the two given IDSelector's is_membership
    results.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorOr.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorOr.<lambda>,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   IDSelectorOr_swiginitnew_IDSelectorOrr  s      r   rN   zIDSelectorOr.__init__,  s!    --dO4T4TUXZ]4^_r#   c                 .    t        j                  | |      S r-   )r   IDSelectorOr_is_memberr  s     r   r  zIDSelectorOr.is_member,  s    55dB??r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorOr_lhs_getIDSelectorOr_lhs_setr  IDSelectorOr_rhs_getIDSelectorOr_rhs_setr  rN   r  delete_IDSelectorOrr   r$   r#   r   r  r  ,  sg    
 -/IOdeGH
?779]9]
^C
?779]9]
^C`@&::r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zd Zej"                  Zy)	IDSelectorXOrz\
    does an XOR operation on the the two given IDSelector's is_membership
    results.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorXOr.<lambda>,  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorXOr.<lambda>,  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   IDSelectorXOr_swiginitnew_IDSelectorXOrr  s      r   rN   zIDSelectorXOr.__init__,  r  r#   c                 .    t        j                  | |      S r-   )r   IDSelectorXOr_is_memberr  s     r   r  zIDSelectorXOr.is_member,  r  r#   N)r   r   r6   r7   r   r   r   r   r   IDSelectorXOr_lhs_getIDSelectorXOr_lhs_setr  IDSelectorXOr_rhs_getIDSelectorXOr_rhs_setr  rN   r  delete_IDSelectorXOrr   r$   r#   r   r)  r)  ,  r  r#   r)  c                       e Zd Z ed d d      ZeZ eej                        Z	 eej                  ej                        Zd Zd Zej                  Zy)IDSelectorTranslatedc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIDSelectorTranslated.<lambda> -  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIDSelectorTranslated.<lambda> -  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   IDSelectorTranslated_swiginitnew_IDSelectorTranslatedr   s     r   rN   zIDSelectorTranslated.__init__-  r
  r#   c                 .    t        j                  | |      S r-   )r   IDSelectorTranslated_is_memberr  s     r   r  zIDSelectorTranslated.is_member-      ==dBGGr#   N)r   r   r6   r   r   r   r   r   IDSelectorTranslated_id_map_getr  IDSelectorTranslated_sel_getIDSelectorTranslated_sel_setrS  rN   r  delete_IDSelectorTranslatedr   r$   r#   r   r7  r7  ,  sX    -/IOdeGHoEEFF
???AmAm
nCmH&BBr#   r7  c                   d   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Zd Zd	 Zd
 Zd ZddZddZd Zd Zd Zd ZddZddZd Zd Zd Z ejB                  Z"d Z#y)
IndexIDMap+Index that translates search results to idsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIDMap.<lambda>-  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIDMap.<lambda>-  rD   r#   rE   rF   r  )whether pointers are deleted in destructoc                 2    t        j                  | |||      S zi
        :type xids: int
        :param xids: if non-null, ids to store for the vectors (size n)
        )r   IndexIDMap_add_with_idsr/  s       r   r1  zIndexIDMap.add_with_ids-  s    
 66tQ4HHr#   c                 4    t        j                  | ||||      S r-   )r   IndexIDMap_add_with_idsExr4  s        r   r5  zIndexIDMap.add_with_idsEx-  s    88q!\SWXXr#   c                 0    t        j                  | ||      S z this will fail. Use add_with_ids)r   IndexIDMap_addr!  s      r   r)  zIndexIDMap.add!-  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexIDMap_addExr%  s       r   r,  zIndexIDMap.addEx%-  s    //aLIIr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexIDMap_searchr8  s          r   r:  zIndexIDMap.search(-  s     00q!Q	6SYZZr#   c           
      :    t        j                  | |||||||      S r-   )r   IndexIDMap_searchExr=  s           r   r>  zIndexIDMap.searchEx+-  s$    224A|QPY[acijjr#   c                 0    t        j                  | ||      S r-   )r   IndexIDMap_trainr!  s      r   r"  zIndexIDMap.train.-  r9  r#   c                 2    t        j                  | |||      S r-   )r   IndexIDMap_trainExr%  s       r   r&  zIndexIDMap.trainEx1-  s    11$1lKKr#   c                 ,    t        j                  |       S r-   )r   IndexIDMap_resetrR   s    r   r  zIndexIDMap.reset4-  r   r#   c                 .    t        j                  | |      S zremove ids adapted to IndexFlat)r   IndexIDMap_remove_idsrK  s     r   rL  zIndexIDMap.remove_ids7-  s    44T3??r#   c                 6    t        j                  | |||||      S r-   )r   IndexIDMap_range_searchrA  s         r   rB  zIndexIDMap.range_search;-  s    66tQ66SYZZr#   c                 0    t        j                  | ||      S r-   )r   IndexIDMap_merge_fromr{  s      r   r~  zIndexIDMap.merge_from>-  s    44T:vNNr#   c                 .    t        j                  | |      S r-   )r   %IndexIDMap_check_compatible_for_merger  s     r   r  z%IndexIDMap.check_compatible_for_mergeA-  s    DDT:VVr#   c                 ,    t        j                  |       S r-   )r   IndexIDMap_sa_code_sizerR   s    r   ro  zIndexIDMap.sa_code_sizeD-  ro   r#   c                 2    t        j                  | |||      S r-   )r   IndexIDMap_add_sa_codesr/  s       r   r  zIndexIDMap.add_sa_codesG-  s    66tQ4HHr#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIDMap_swiginitnew_IndexIDMapr   s     r   rN   zIndexIDMap.__init__K-  r  r#   r-   r  )$r   r   r6   r7   r   r   r   r   r   IndexIDMap_index_getIndexIDMap_index_setr  IndexIDMap_own_fields_getIndexIDMap_own_fields_setrM  IndexIDMap_id_map_getIndexIDMap_id_map_setr  r1  r5  r)  r,  r:  r>  r"  r&  r  rL  rB  r~  r  ro  r  delete_IndexIDMapr   rN   r$   r#   r   rE  rE  -  s    6-/IOdeGH_99?;_;_`E/CC_EnEn  uI  JJo;;_=b=b  iY  ZFIY:J[k<L6@[OW=I&88Yr#   rE  c                   d   e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                  d      Z eej                  ej                   d      Zd Zd	 Zd
 Zd ZddZddZd Zd Zd Zd ZddZddZd Zd Zd Z ejB                  Z"d Z#y)IndexBinaryIDMaprF  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryIDMap.<lambda>S-  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryIDMap.<lambda>S-  rD   r#   rE   rF   r  rI  c                 2    t        j                  | |||      S rK  )r   IndexBinaryIDMap_add_with_idsr/  s       r   r1  zIndexBinaryIDMap.add_with_idsY-  s    
 <<T1aNNr#   c                 4    t        j                  | ||||      S r-   )r   IndexBinaryIDMap_add_with_idsExr4  s        r   r5  zIndexBinaryIDMap.add_with_idsEx`-  s    >>tQ<Y]^^r#   c                 0    t        j                  | ||      S rP  )r   IndexBinaryIDMap_addr!  s      r   r)  zIndexBinaryIDMap.addc-  rV  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryIDMap_addExr%  s       r   r,  zIndexBinaryIDMap.addExg-  s    55dAq,OOr#   Nc           	      8    t        j                  | ||||||      S r-   )r   IndexBinaryIDMap_searchr8  s          r   r:  zIndexBinaryIDMap.searchj-  rR  r#   c           
      :    t        j                  | |||||||      S r-   )r   IndexBinaryIDMap_searchExr=  s           r   r>  zIndexBinaryIDMap.searchExm-  s%    88q!\STV_agioppr#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIDMap_trainr!  s      r   r"  zIndexBinaryIDMap.trainp-  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryIDMap_trainExr%  s       r   r&  zIndexBinaryIDMap.trainExs-  s    77aLQQr#   c                 ,    t        j                  |       S r-   )r   IndexBinaryIDMap_resetrR   s    r   r  zIndexBinaryIDMap.resetv-  r  r#   c                 .    t        j                  | |      S r_  )r   IndexBinaryIDMap_remove_idsrK  s     r   rL  zIndexBinaryIDMap.remove_idsy-      ::4EEr#   c                 6    t        j                  | |||||      S r-   )r   IndexBinaryIDMap_range_searchrA  s         r   rB  zIndexBinaryIDMap.range_search}-  rW  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIDMap_merge_fromr{  s      r   r~  zIndexBinaryIDMap.merge_from-  s    ::4VTTr#   c                 .    t        j                  | |      S r-   )r   +IndexBinaryIDMap_check_compatible_for_merger  s     r   r  z+IndexBinaryIDMap.check_compatible_for_merge-  s    JJ4Q[\\r#   c                 ,    t        j                  |       S r-   )r   IndexBinaryIDMap_sa_code_sizerR   s    r   ro  zIndexBinaryIDMap.sa_code_size-  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryIDMap_add_sa_codesr/  s       r   r  zIndexBinaryIDMap.add_sa_codes-  rD  r#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryIDMap_swiginitnew_IndexBinaryIDMapr   s     r   rN   zIndexBinaryIDMap.__init__-  ra  r#   r-   r  )$r   r   r6   r7   r   r   r   r   r   IndexBinaryIDMap_index_getIndexBinaryIDMap_index_setr  IndexBinaryIDMap_own_fields_getIndexBinaryIDMap_own_fields_setrM  IndexBinaryIDMap_id_map_getIndexBinaryIDMap_id_map_setr  r1  r5  r)  r,  r:  r>  r"  r&  r  rL  rB  r~  r  ro  r  delete_IndexBinaryIDMapr   rN   r$   r#   r   rv  rv  P-  s    6-/IOdeGH_??AkAklE/II?KzKz  AU  VJoAA?CnCn  ue  fFO_@PaqBR<FaU]CO&>>er#   rv  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zd
 Zd ZddZej&                  Zd Zy)IndexIDMap2o
    same as IndexIDMap but also provides an efficient reconstruction
    implementation via a 2-way index
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexIDMap2.<lambda>-  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexIDMap2.<lambda>-  rD   r#   rE   rF   c                 ,    t        j                  |       S zmake the rev_map from scratch)r   IndexIDMap2_construct_rev_maprR   s    r   construct_rev_mapzIndexIDMap2.construct_rev_map-  r?  r#   c                 2    t        j                  | |||      S r-   )r   IndexIDMap2_add_with_idsr/  s       r   r1  zIndexIDMap2.add_with_ids-  r  r#   c                 4    t        j                  | ||||      S r-   )r   IndexIDMap2_add_with_idsExr4  s        r   r5  zIndexIDMap2.add_with_idsEx-  r\  r#   c                 .    t        j                  | |      S r-   )r   IndexIDMap2_remove_idsrK  s     r   rL  zIndexIDMap2.remove_ids-  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexIDMap2_reconstructrO  s      r   rR  zIndexIDMap2.reconstruct-  rs  r#   c                 ,    t        j                  |       S z1check that the rev_map and the id_map are in sync)r   IndexIDMap2_check_consistencyrR   s    r   check_consistencyzIndexIDMap2.check_consistency-  r?  r#   c                 0    t        j                  | ||      S r-   )r   IndexIDMap2_merge_fromr{  s      r   r~  zIndexIDMap2.merge_from-  r  r#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexIDMap2_swiginitnew_IndexIDMap2r   s     r   rN   zIndexIDMap2.__init__-  r  r#   Nr  )r   r   r6   r7   r   r   r   r   r   IndexIDMap2_rev_map_getIndexIDMap2_rev_map_setrev_mapr  r1  r5  rL  rR  r  r~  delete_IndexIDMap2r   rN   r$   r#   r   r  r  -  ss    
 -/IOdeGH>>@g@ghGCJZAJCP&99[r#   r  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Zd Zd Zd Zd	 Zd
 Zd ZddZej&                  Zd Zy)IndexBinaryIDMap2r  c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIndexBinaryIDMap2.<lambda>-  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIndexBinaryIDMap2.<lambda>-  rD   r#   rE   rF   c                 ,    t        j                  |       S r  )r   #IndexBinaryIDMap2_construct_rev_maprR   s    r   r  z#IndexBinaryIDMap2.construct_rev_map-  r  r#   c                 2    t        j                  | |||      S r-   )r   IndexBinaryIDMap2_add_with_idsr/  s       r   r1  zIndexBinaryIDMap2.add_with_ids-  r"  r#   c                 4    t        j                  | ||||      S r-   )r    IndexBinaryIDMap2_add_with_idsExr4  s        r   r5  z IndexBinaryIDMap2.add_with_idsEx-  s    ??aLZ^__r#   c                 .    t        j                  | |      S r-   )r   IndexBinaryIDMap2_remove_idsrK  s     r   rL  zIndexBinaryIDMap2.remove_ids-  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIDMap2_reconstructrO  s      r   rR  zIndexBinaryIDMap2.reconstruct-  r.  r#   c                 ,    t        j                  |       S r  )r   #IndexBinaryIDMap2_check_consistencyrR   s    r   r  z#IndexBinaryIDMap2.check_consistency-  r  r#   c                 0    t        j                  | ||      S r-   )r   IndexBinaryIDMap2_merge_fromr{  s      r   r~  zIndexBinaryIDMap2.merge_from-  rC  r#   c                 P    t        j                  | t        j                  |        y r-   )r   IndexBinaryIDMap2_swiginitnew_IndexBinaryIDMap2r   s     r   rN   zIndexBinaryIDMap2.__init__-  r	  r#   Nr  )r   r   r6   r7   r   r   r   r   r   IndexBinaryIDMap2_rev_map_getIndexBinaryIDMap2_rev_map_setr  r  r1  r5  rL  rR  r  r~  delete_IndexBinaryIDMap2r   rN   r$   r#   r   r  r  -  ss    
 -/IOdeGHDDoFsFstGIP`GPIV&??gr#   r  c                 ,    t        j                  |       S r-   )r   downcast_indexr  s    r   r  r  -  s    ))%00r#   c                 ,    t        j                  |       S r-   )r   downcast_VectorTransform)r  s    r   r  r  -  s    33B77r#   c                 ,    t        j                  |       S r-   )r   downcast_IndexBinaryr  s    r   r  r  -  s    //66r#   c                 ,    t        j                  |       S r-   )r   downcast_InvertedLists)rE  s    r   r  r  -  s    11"55r#   c                 ,    t        j                  |       S r-   )r   downcast_AdditiveQuantizerr  s    r   r  r  -  s    55b99r#   c                 ,    t        j                  |       S r-   )r   downcast_Quantizerr  s    r   r  r  -  s    --b11r#   c                  &    t        j                  |  S r-   )r   write_indexrH  s    r   r  r  -  s    &&--r#   c                  &    t        j                  |  S r-   )r   write_index_binaryrH  s    r   r  r  -  s    --t44r#   c                  &    t        j                  |  S r-   )r   
read_indexrH  s    r   r  r  -  rv  r#   c                  &    t        j                  |  S r-   )r   read_index_binaryrH  s    r   r  r  .  s    ,,d33r#   c                  &    t        j                  |  S r-   )r   write_VectorTransformrH  s    r   r  r  .      00$77r#   c                  &    t        j                  |  S r-   )r   read_VectorTransformrH  s    r   r  r  .  s    //66r#   c                  &    t        j                  |  S r-   )r   read_ProductQuantizerrH  s    r   r  r  
.  r  r#   c                  &    t        j                  |  S r-   )r   write_ProductQuantizerrH  s    r   r  r  .      11488r#   c                 .    t        j                  | |      S r-   )r   write_InvertedLists)r"  r$  s     r   r  r  .  s    ..sA66r#   c                 .    t        j                  | |      S r-   )r   read_InvertedLists)rF  r  s     r   r  r  .  s    --fh??r#   c                 ,    t        j                  |       S r-   )r   clone_indexr  s    r   r  r  .  s    &&t,,r#   c                   ^    e Zd ZdZ ed d d      ZeZd Zd Z	d Z
ej                  Zd	 Zy
)Clonerz
     Cloner class, useful to override classes with other cloning
    functions. The cloning function above just calls
    Cloner::clone_Index.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zCloner.<lambda>.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zCloner.<lambda>.  rD   r#   rE   rF   c                 .    t        j                  | |      S r-   )r   Cloner_clone_VectorTransformr   s     r   clone_VectorTransformzCloner.clone_VectorTransform".  r  r#   c                 .    t        j                  | |      S r-   )r   Cloner_clone_Indexr   s     r   clone_IndexzCloner.clone_Index%.  r  r#   c                 .    t        j                  | |      S r-   )r   Cloner_clone_IndexIVFr   s     r   clone_IndexIVFzCloner.clone_IndexIVF(.  r   r#   c                 T    t        j                  | t        j                                y r-   )r   Cloner_swiginit
new_ClonerrR   s    r   rN   zCloner.__init__,.  r  r#   N)r   r   r6   r7   r   r   r   r   r  r  r
  r   delete_Clonerr   rN   r$   r#   r   r  r  .  sB     -/IOdeGHH>A&44Lr#   r  c                 ,    t        j                  |       S r-   )r   clone_Quantizer)quants    r   r  r  ;.  s    **511r#   c                 ,    t        j                  |       S r-   )r   clone_binary_indexr  s    r   r  r  >.  s    --e44r#   c                      e Zd ZdZ ed d d      Zd ZeZ ee	j                  e	j                  d      Z ee	j                  e	j                  d      Z ee	j                   e	j"                  d	      Z ee	j&                  e	j(                  d
      Z ee	j,                  e	j.                  d      Zd Zd Ze	j6                  Zy)AutoTuneCriterionz]
    Evaluation criterion. Returns a performance measure in [0,1],
    higher is better.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zAutoTuneCriterion.<lambda>F.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zAutoTuneCriterion.<lambda>F.  rD   r#   rE   rF   c                     t        d      rI   rJ   rK   s      r   rN   zAutoTuneCriterion.__init__H.  rO   r#   z,nb of queries this criterion is evaluated onz'nb of NNs that the query should requestz+nb of GT NNs required to evaluate criterionz)Ground-truth distances (size nq * gt_nnn)z'Ground-truth indexes (size nq * gt_nnn)c                 2    t        j                  | |||      S )z
         Intitializes the gt_D and gt_I vectors. Must be called before evaluating

        :type gt_D_in: float
        :param gt_D_in:  size nq * gt_nnn
        :type gt_I_in: int
        :param gt_I_in:  size nq * gt_nnn
        )r   !AutoTuneCriterion_set_groundtruth)r   gt_nnngt_D_ingt_I_ins       r   set_groundtruthz!AutoTuneCriterion.set_groundtruthQ.  s     @@vwX_``r#   c                 0    t        j                  | ||      S )z
         Evaluate the criterion.

        :type D: float
        :param D:  size nq * nnn
        :type I: int
        :param I:  size nq * nnn
        :rtype: float
        :return: the criterion, between 0 and 1. Larger is better.
        )r   AutoTuneCriterion_evaluater   r  r  s      r   r0
  zAutoTuneCriterion.evaluate\.  s     99$1EEr#   N)r   r   r6   r7   r   r   rN   r   r   r   AutoTuneCriterion_nq_getAutoTuneCriterion_nq_setr  AutoTuneCriterion_nnn_getAutoTuneCriterion_nnn_setnnnAutoTuneCriterion_gt_nnn_getAutoTuneCriterion_gt_nnn_setr  AutoTuneCriterion_gt_D_getAutoTuneCriterion_gt_D_setgt_DAutoTuneCriterion_gt_I_getAutoTuneCriterion_gt_I_setgt_Ir  r0
  delete_AutoTuneCriterionr   r$   r#   r   r  r  @.  s    
 -/IOdeGKH	/::O<d<d  k^  
_B
?<<o>g>g  n\  ]CoBBODpDp  wi  jFO>>@j@j  qa  bDO>>@j@j  q_  `D	aF '??r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)OneRecallAtRCriterionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOneRecallAtRCriterion.<lambda>m.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOneRecallAtRCriterion.<lambda>m.  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   OneRecallAtRCriterion_swiginitnew_OneRecallAtRCriterionr   r  r3  s      r   rN   zOneRecallAtRCriterion.__init__q.  !    66t_=f=fgikl=mnr#   c                 0    t        j                  | ||      S r-   )r   OneRecallAtRCriterion_evaluater!  s      r   r0
  zOneRecallAtRCriterion.evaluatet.  r
  r#   N)r   r   r6   r   r   r   r   r   OneRecallAtRCriterion_R_getOneRecallAtRCriterion_R_setr3  rN   r0
  delete_OneRecallAtRCriterionr   r$   r#   r   r1  r1  l.  H    -/IOdeGH<<o>i>ijAoJ&CCr#   r1  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)IntersectionCriterionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zIntersectionCriterion.<lambda>{.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zIntersectionCriterion.<lambda>{.  rD   r#   rE   rF   c                 X    t        j                  | t        j                  ||             y r-   )r   IntersectionCriterion_swiginitnew_IntersectionCriterionr7  s      r   rN   zIntersectionCriterion.__init__.  r8  r#   c                 0    t        j                  | ||      S r-   )r   IntersectionCriterion_evaluater!  s      r   r0
  zIntersectionCriterion.evaluate.  r
  r#   N)r   r   r6   r   r   r   r   r   IntersectionCriterion_R_getIntersectionCriterion_R_setr3  rN   r0
  delete_IntersectionCriterionr   r$   r#   r   r@  r@  z.  r>  r#   r@  c                   D   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zej,                  Zy)OperatingPointa<  
    Maintains a list of experimental results. Each operating point is a
    (perf, t, key) triplet, where higher perf and lower t is
    better. The key field is an arbitrary identifier for the operating point.

    Includes primitives to extract the Pareto-optimal operating points in the
    (perf, t) space.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOperatingPoint.<lambda>.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOperatingPoint.<lambda>.  rD   r#   rE   rF   z+performance measure (output of a Criterion)z!corresponding execution time (ms)zkey that identifies this op ptzinteger identifierc                 T    t        j                  | t        j                                y r-   )r   OperatingPoint_swiginitnew_OperatingPointrR   s    r   rN   zOperatingPoint.__init__.  r  r#   N)r   r   r6   r7   r   r   r   r   r   OperatingPoint_perf_getOperatingPoint_perf_setperfOperatingPoint_t_getOperatingPoint_t_setr
  OperatingPoint_key_getOperatingPoint_key_setrP  OperatingPoint_cno_getOperatingPoint_cno_setcnorN   delete_OperatingPointr   r$   r#   r   rL  rL  .  s     -/IOdeGHO;;_=d=d  k]  ^D557[7[  bJ  	KA
?99?;a;a  hM  NC
?99?;a;a  hA  BC\&<<r#   rL  c                       e Zd Z ed d d      ZeZ eej                  ej                  d      Z
 eej                  ej                  d      Zd Zd Zd	 Zdd
Zd ZddZd Zd Zej,                  Zy)OperatingPointsc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zOperatingPoints.<lambda>.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zOperatingPoints.<lambda>.  rD   r#   rE   rF   zall operating pointsz(optimal operating points, sorted by perfc                 T    t        j                  | t        j                                y r-   )r   OperatingPoints_swiginitnew_OperatingPointsrR   s    r   rN   zOperatingPoints.__init__.  r  r#   c                 .    t        j                  | g| S )zBadd operating points from other to this, with a prefix to the keys)r   OperatingPoints_merge_withr   s     r   
merge_withzOperatingPoints.merge_with.  s    99$FFFr#   c                 ,    t        j                  |       S r-   )r   OperatingPoints_clearrR   s    r   r   zOperatingPoints.clear.  r  r#   c                 4    t        j                  | ||||      S )z@add a performance measure. Return whether it is an optimal point)r   OperatingPoints_add)r   rT  r
  rP  r[  s        r   r)  zOperatingPoints.add.  s    224q#sKKr#   c                 .    t        j                  | |      S )z7get time required to obtain a given performance measure)r   OperatingPoints_t_for_perf)r   rT  s     r   
t_for_perfzOperatingPoints.t_for_perf.  s    99$EEr#   c                 .    t        j                  | |      S )zeasy-to-read output)r   OperatingPoints_display)r   only_optimals     r   rq  zOperatingPoints.display.  s    66t\JJr#   c                 .    t        j                  | |      S )z,output to a format easy to digest by gnuplot)r   OperatingPoints_all_to_gnuplotr   fnames     r   all_to_gnuplotzOperatingPoints.all_to_gnuplot.  r  r#   c                 .    t        j                  | |      S r-   )r   "OperatingPoints_optimal_to_gnuplotrs  s     r   optimal_to_gnuplotz"OperatingPoints.optimal_to_gnuplot.  r  r#   Nr  rD  )r   r   r6   r   r   r   r   r   OperatingPoints_all_pts_getOperatingPoints_all_pts_setall_ptsOperatingPoints_optimal_pts_getOperatingPoints_optimal_pts_setoptimal_ptsrN   rf  r   r)  rm  rq  ru  rx  delete_OperatingPointsr   r$   r#   r   r^  r^  .  s    -/IOdeGHBBODoDo  vQ  RG?JJOL{L{  Bq  rK^G;LFKKO&==r#   r^  c                       e Zd ZdZ ed d d      ZeZ eej                  ej                        Z eej                  ej                        Zd Zej                   Zy)ParameterRangezLpossible values of a parameter, sorted from least to most expensive/accuratec                 6    | j                   j                         S r-   r<   r=   s    r   r?   zParameterRange.<lambda>.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zParameterRange.<lambda>.  rD   r#   rE   rF   c                 T    t        j                  | t        j                                y r-   )r   ParameterRange_swiginitnew_ParameterRangerR   s    r   rN   zParameterRange.__init__.  r  r#   N)r   r   r6   r7   r   r   r   r   r   ParameterRange_name_getParameterRange_name_setr   ParameterRange_values_getParameterRange_values_setvaluesrN   delete_ParameterRanger   r$   r#   r   r  r  .  s]    W-/IOdeGHO;;_=d=deDo??AjAjkF\&<<r#   r  c                      e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Z eej*                  ej,                  d
      Z eej0                  ej2                  d      Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%ejL                  Z'y)ParameterSpacezKUses a-priori knowledge on the Faiss indexes to extract tunable parameters.c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zParameterSpace.<lambda>.  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zParameterSpace.<lambda>.  rD   r#   rE   rF   zall tunable parameterszverbosity during explorationz@nb of experiments during optimization (0 = try all combinations)z.maximum number of queries to submit at a time.z_
    use multithreading over batches (useful to benchmark
    independent single-searches)
    zm
    run tests several times until they reach at least this
    duration (to avoid jittering in MT mode)
    c                 T    t        j                  | t        j                                y r-   )r   ParameterSpace_swiginitnew_ParameterSpacerR   s    r   rN   zParameterSpace.__init__.  r  r#   c                 ,    t        j                  |       S )z-nb of combinations, = product of values sizes)r   ParameterSpace_n_combinationsrR   s    r   n_combinationszParameterSpace.n_combinations.  r?  r#   c                 0    t        j                  | ||      S )z8returns whether combinations c1 >= c2 in the tuple sense)r   ParameterSpace_combination_ge)r   c1c2s      r   combination_gezParameterSpace.combination_ge.  s    <<T2rJJr#   c                 .    t        j                  | |      S )z,get string representation of the combination)r   ParameterSpace_combination_name)r   r[  s     r   combination_namezParameterSpace.combination_name.  s    >>tSIIr#   c                 ,    t        j                  |       S )zprint a description on stdout)r   ParameterSpace_displayrR   s    r   rq  zParameterSpace.display.  s    55d;;r#   c                 .    t        j                  | |      S )z/add a new parameter (or return it if it exists))r   ParameterSpace_add_ranger
  s     r   	add_rangezParameterSpace.add_range.  s    77dCCr#   c                 .    t        j                  | |      S )z3initialize with reasonable parameters for the index)r   ParameterSpace_initializer  s     r   
initializezParameterSpace.initialize.  r(  r#   c                 .    t        j                  | g| S )z
        *Overload 1:*
        set a combination of parameters on an index

        |

        *Overload 2:*
        set a combination of parameters described by a string
        )r   #ParameterSpace_set_index_parametersr   s     r   set_index_parametersz#ParameterSpace.set_index_parameters /  s     BB4O$OOr#   c                 2    t        j                  | |||      S )zAset one of the parameters, returns whether setting was successful)r   "ParameterSpace_set_index_parameter)r   r  r   r  s       r   set_index_parameterz"ParameterSpace.set_index_parameter/  s    AA$tUXYYr#   c                 4    t        j                  | ||||      S )z
         find an upper bound on the performance and a lower bound on t
        for configuration cno given another operating point op
        )r   ParameterSpace_update_bounds)r   r[  opupper_bound_perflower_bound_ts        r   update_boundszParameterSpace.update_bounds/  s    
 ;;D#rK[]jkkr#   c                 6    t        j                  | |||||      S )a  
         explore operating points
        :type index: :py:class:`Index`
        :param index:   index to run on
        :type xq: float
        :param xq:      query vectors (size nq * index.d)
        :type crit: :py:class:`AutoTuneCriterion`
        :param crit:    selection criterion
        :type ops: :py:class:`OperatingPoints`
        :param ops:     resulting operating points
        )r   ParameterSpace_explore)r   r  r  rQ  critopss         r   explorezParameterSpace.explore/  s      55dE2r4QTUUr#   N)(r   r   r6   r7   r   r   r   r   r   #ParameterSpace_parameter_ranges_get#ParameterSpace_parameter_ranges_setparameter_rangesParameterSpace_verbose_getParameterSpace_verbose_setr   ParameterSpace_n_experiments_get ParameterSpace_n_experiments_setn_experimentsParameterSpace_batchsize_getParameterSpace_batchsize_set	batchsize&ParameterSpace_thread_over_batches_get&ParameterSpace_thread_over_batches_setthread_over_batches$ParameterSpace_min_test_duration_get$ParameterSpace_min_test_duration_setmin_test_durationrN   r  r  r  rq  r  r  r  r  r  r  delete_ParameterSpacer   r$   r#   r   r  r  .  sR   V-/IOdeGH S SUd  VI  VI  Ol  mAA?CmCm  tW  XG_MMOO  FM  NMEEGsGs  zo  pI"?#Y#Y[j  \R  \R X 	 !!U!UWf  XL  XL R 	
\CKJ<DF
PZlV '<<r#   r  c                  &    t        j                  |  S )z\
    Build and index with the sequence of processing steps described in
    the string.
    )r   index_factoryrH  s    r   r  r  )/  s    
 (($//r#   c                 0    t        j                  | ||      S r-   )r   index_binary_factory)r
  descriptionr  s      r   r  r  0/  s    //;MMr#   c                   D   e Zd ZdZ ed d d      ZeZd Z ee	j                  e	j                        Z ee	j                  e	j                        Z ee	j                   e	j"                        Z ee	j&                  e	j(                        Z ee	j,                  e	j.                        Z ee	j2                  e	j4                        Z ee	j8                  e	j:                        Z ee	j>                  e	j@                        Z! ee	jD                  e	jF                        Z$ ee	jJ                  e	jL                        Z' ee	jP                  e	jR                        Z* ee	jV                  e	jX                        Z- ee	j\                  e	j^                        Z0d Z1e	jd                  Z3y)	MatrixStatsz
     Reports some statistics on a dataset and comments on them.

    It is a class rather than a function so that all stats can also be
    accessed from code
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMatrixStats.<lambda>:/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMatrixStats.<lambda>:/  rD   r#   rE   rF   c                 Z    t        j                  | t        j                  |||             y r-   )r   MatrixStats_swiginitnew_MatrixStats)r   rW   r
  r>   s       r   rN   zMatrixStats.__init__=/  s$    ,,T?3R3RSTVWYZ3[\r#   c                 .    t        j                  | |      S r-   )r   MatrixStats_do_comment)r   fmts     r   
do_commentzMatrixStats.do_commentM/  r  r#   N)4r   r   r6   r7   r   r   r   r   rN   r   MatrixStats_comments_getMatrixStats_comments_setcommentsMatrixStats_n_getMatrixStats_n_setrW   MatrixStats_d_getMatrixStats_d_setr
  MatrixStats_n_collision_getMatrixStats_n_collision_setn_collisionMatrixStats_n_valid_getMatrixStats_n_valid_setn_validMatrixStats_n0_getMatrixStats_n0_setrt  MatrixStats_min_norm2_getMatrixStats_min_norm2_set	min_norm2MatrixStats_max_norm2_getMatrixStats_max_norm2_set	max_norm2MatrixStats_hash_value_getMatrixStats_hash_value_set
hash_valueMatrixStats_per_dim_stats_getMatrixStats_per_dim_stats_setper_dim_statsMatrixStats_occurrences_getMatrixStats_occurrences_setoccurrencesMatrixStats_buf_getMatrixStats_buf_setbufMatrixStats_nbuf_getMatrixStats_nbuf_setnbufr  delete_MatrixStatsr   r$   r#   r   r  r  2/  so    -/IOdeGH]@@/BjBjkH22O4U4UVA22O4U4UVA?FFHsHstK>>@g@ghG	/44o6X6X	YBBBODmDmnIBBODmDmnI/DDoFpFpqJ_JJOLyLyzM?FFHsHstK
?668[8[
\CO88/:^:^_DA&99r#   r  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zej                   Zy)PyCallbackIOWriterc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPyCallbackIOWriter.<lambda>T/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPyCallbackIOWriter.<lambda>T/  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)z
        Callback: Python function that takes a bytes object and
        returns the number of bytes successfully written.
        N)r   PyCallbackIOWriter_swiginitnew_PyCallbackIOWriterr   s     r   rN   zPyCallbackIOWriter.__init__Y/       
 	33D/:`:`bf:ghr#   c                 2    t        j                  | |||      S r-   )r   PyCallbackIOWriter___call__r   ptrvr   r  s       r   r  zPyCallbackIOWriter.__call__`/      ::4tVTTr#   N)r   r   r6   r   r   r   r   r   PyCallbackIOWriter_callback_getPyCallbackIOWriter_callback_setcallbackPyCallbackIOWriter_bs_getPyCallbackIOWriter_bs_setbsrN   r  delete_PyCallbackIOWriterr   r$   r#   r   r    r    S/  `    -/IOdeGHGGIxIxyH	/;;_=f=f	gBiU&@@r#   r    c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zd Zd Zej                   Zy)PyCallbackIOReaderc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPyCallbackIOReader.<lambda>g/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPyCallbackIOReader.<lambda>g/  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y)zy
         Callback: Python function that takes a size and returns a
        bytes object with the resulting read
        N)r   PyCallbackIOReader_swiginitnew_PyCallbackIOReaderr   s     r   rN   zPyCallbackIOReader.__init__l/  r   r#   c                 2    t        j                  | |||      S r-   )r   PyCallbackIOReader___call__r	   s       r   r  zPyCallbackIOReader.__call__s/  r   r#   N)r   r   r6   r   r   r   r   r   PyCallbackIOReader_callback_getPyCallbackIOReader_callback_setr   PyCallbackIOReader_bs_getPyCallbackIOReader_bs_setr   rN   r  delete_PyCallbackIOReaderr   r$   r#   r   r   r   f/  r   r#   r   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zej                  Zy)PyCallbackIDSelectorc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zPyCallbackIDSelector.<lambda>z/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zPyCallbackIDSelector.<lambda>z/  rD   r#   rE   rF   c                 V    t        j                  | t        j                  |             y r-   )r   PyCallbackIDSelector_swiginitnew_PyCallbackIDSelector)r   r   s     r   rN   zPyCallbackIDSelector.__init__~/  s    55dO<d<dem<nor#   c                 .    t        j                  | |      S r-   )r   PyCallbackIDSelector_is_memberr  s     r   r  zPyCallbackIDSelector.is_member/  r?  r#   N)r   r   r6   r   r   r   r   r   !PyCallbackIDSelector_callback_get!PyCallbackIDSelector_callback_setr   rN   r  delete_PyCallbackIDSelectorr   r$   r#   r   r#   r#   y/  sH    -/IOdeGHII?K|K|}HpH&BBr#   r#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zej                  Zd Zy)PyCallbackShardingFunctionc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z#PyCallbackShardingFunction.<lambda>/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z#PyCallbackShardingFunction.<lambda>/  rD   r#   rE   rF   c                 0    t        j                  | ||      S r-   )r   #PyCallbackShardingFunction___call__r  s      r   r  z#PyCallbackShardingFunction.__call__/  s    BB4KXXr#   c                 P    t        j                  | t        j                  |        y r-   )r   #PyCallbackShardingFunction_swiginitnew_PyCallbackShardingFunctionr   s     r   rN   z#PyCallbackShardingFunction.__init__/  s    ;;D/BpBprvBwxr#   N)r   r   r6   r   r   r   r   r   'PyCallbackShardingFunction_callback_get'PyCallbackShardingFunction_callback_setr   r  !delete_PyCallbackShardingFunctionr   rN   r$   r#   r   r/   r/   /  sT    -/IOdeGHOOQ`  RI  RI  JHY&HHyr#   r/   c                   z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zd ZddZddZddZd Zd Zd Zej<                  Zy)float_minheap_array_t
     a template structure for a set of [min|max]-heaps it is tailored
    so that the actual data of the heaps can just live in compact
    arrays.
    c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zfloat_minheap_array_t.<lambda>/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zfloat_minheap_array_t.<lambda>/  rD   r#   rE   rF   number of heapsallocated size per heapidentifiers (size nh * k)/values (distances or similarities), size nh * kc                 .    t        j                  | |      S z$Return the list of values for a heap)r   float_minheap_array_t_get_valr   rP  s     r   get_valzfloat_minheap_array_t.get_val/  r  r#   c                 .    t        j                  | |      S zCorrespponding identifiers)r   float_minheap_array_t_get_idsrF   s     r   r  zfloat_minheap_array_t.get_ids/  r  r#   c                 ,    t        j                  |       S z#prepare all the heaps before adding)r   float_minheap_array_t_heapifyrR   s    r   heapifyzfloat_minheap_array_t.heapify/  r?  r#   c                 6    t        j                  | |||||      S a  
         add nj elements to heaps i0:i0+ni, with sequential ids

        :type nj: int
        :param nj:    nb of elements to add to each heap
        :type vin: float
        :param vin:   elements to add, size ni * nj
        :type j0: int, optional
        :param j0:    add this to the ids that are added
        :type i0: int, optional
        :param i0:    first heap to update
        :type ni: int, optional
        :param ni:    nb of elements to update (-1 = use nh)
        )r   float_minheap_array_t_addnr   njvinr  rY  rZ  s         r   addnzfloat_minheap_array_t.addn/        99$CRQSTTr#   Nc           	      8    t        j                  | ||||||      S z
         same as addn

        :type id_in: int, optional
        :param id_in:     ids of the elements to add, size ni * nj
        :type id_stride: int, optional
        :param id_stride: stride for id_in
        )r   #float_minheap_array_t_addn_with_idsr   rS   rT   id_in	id_striderY  rZ  s          r   addn_with_idsz#float_minheap_array_t.addn_with_ids/  %     BB4SRWYbdfhjkkr#   c           	      8    t        j                  | ||||||      S a  
         same as addn_with_ids, but for just a subset of queries

        :type nsubset: int
        :param nsubset:  number of query entries to update
        :type subset: int
        :param subset:   indexes of queries to update, in 0..nh-1, size nsubset
        )r   0float_minheap_array_t_addn_query_subset_with_idsr   r  r  rS   rT   r[   r\   s          r   addn_query_subset_with_idsz0float_minheap_array_t.addn_query_subset_with_ids/  2     OOPTV]_egiknpu  xA  B  	Br#   c                 ,    t        j                  |       S zreorder all the heaps)r   float_minheap_array_t_reorderrR   s    r   reorderzfloat_minheap_array_t.reorder/  r?  r#   c                 0    t        j                  | ||      S aC  
         this is not really a heap function. It just finds the per-line
          extrema of each line of array D
        :type vals_out: float
        :param vals_out:    extreme value of each line (size nh, or NULL)
        :type idx_out: int
        :param idx_out:     index of extreme value (size nh or NULL)
        )r   &float_minheap_array_t_per_line_extremar   vals_outidx_outs      r   per_line_extremaz&float_minheap_array_t.per_line_extrema/       EEdHV]^^r#   c                 T    t        j                  | t        j                                y r-   )r   float_minheap_array_t_swiginitnew_float_minheap_array_trR   s    r   rN   zfloat_minheap_array_t.__init__/  r  r#   r   r   r	  Nr   r   r	  Nr   ) r   r   r6   r7   r   r   r   r   r   float_minheap_array_t_nh_getfloat_minheap_array_t_nh_setnhfloat_minheap_array_t_k_getfloat_minheap_array_t_k_setrP  float_minheap_array_t_ids_getfloat_minheap_array_t_ids_setr{  float_minheap_array_t_val_getfloat_minheap_array_t_val_setr  rG   r  rN   rU   r]   rc   rh   ro   rN   delete_float_minheap_array_tr   r$   r#   r   r;   r;   /       -/IOdeGH	/>>@l@l  sI  
JB<<o>i>i  pN  	OA
?@@/BoBo  vV  WC
?@@/BoBo  vl  mCHHCU"	l	BC	_j&CCr#   r;   c                   z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zd ZddZddZddZd Zd Zd Zej<                  Zy)int_minheap_array_tr<   c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zint_minheap_array_t.<lambda>/  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zint_minheap_array_t.<lambda>/  rD   r#   rE   rF   r?   r@   rA   rB   c                 .    t        j                  | |      S rD   )r   int_minheap_array_t_get_valrF   s     r   rG   zint_minheap_array_t.get_val/  r  r#   c                 .    t        j                  | |      S rI   )r   int_minheap_array_t_get_idsrF   s     r   r  zint_minheap_array_t.get_ids/  r  r#   c                 ,    t        j                  |       S rL   )r   int_minheap_array_t_heapifyrR   s    r   rN   zint_minheap_array_t.heapify0  r  r#   c                 6    t        j                  | |||||      S a  
         add nj elements to heaps i0:i0+ni, with sequential ids

        :type nj: int
        :param nj:    nb of elements to add to each heap
        :type vin: int
        :param vin:   elements to add, size ni * nj
        :type j0: int, optional
        :param j0:    add this to the ids that are added
        :type i0: int, optional
        :param i0:    first heap to update
        :type ni: int, optional
        :param ni:    nb of elements to update (-1 = use nh)
        )r   int_minheap_array_t_addnrR   s         r   rU   zint_minheap_array_t.addn0       77b#r2rRRr#   Nc           	      8    t        j                  | ||||||      S rX   )r   !int_minheap_array_t_addn_with_idsrZ   s          r   r]   z!int_minheap_array_t.addn_with_ids0  %     @@r3PUW`bdfhiir#   c           	      8    t        j                  | ||||||      S r`   )r   .int_minheap_array_t_addn_query_subset_with_idsrb   s          r   rc   z.int_minheap_array_t.addn_query_subset_with_ids!0  '     MMdT[]cegilnsu~r#   c                 ,    t        j                  |       S rf   )r   int_minheap_array_t_reorderrR   s    r   rh   zint_minheap_array_t.reorder,0  r  r#   c                 0    t        j                  | ||      S aA  
         this is not really a heap function. It just finds the per-line
          extrema of each line of array D
        :type vals_out: int
        :param vals_out:    extreme value of each line (size nh, or NULL)
        :type idx_out: int
        :param idx_out:     index of extreme value (size nh or NULL)
        )r   $int_minheap_array_t_per_line_extremarl   s      r   ro   z$int_minheap_array_t.per_line_extrema00       CCD(T[\\r#   c                 T    t        j                  | t        j                                y r-   )r   int_minheap_array_t_swiginitnew_int_minheap_array_trR   s    r   rN   zint_minheap_array_t.__init__;0  r  r#   rt   ru   rv   ) r   r   r6   r7   r   r   r   r   r   int_minheap_array_t_nh_getint_minheap_array_t_nh_setry   int_minheap_array_t_k_getint_minheap_array_t_k_setrP  int_minheap_array_t_ids_getint_minheap_array_t_ids_setr{  int_minheap_array_t_val_getint_minheap_array_t_val_setr  rG   r  rN   rU   r]   rc   rh   ro   rN   delete_int_minheap_array_tr   r$   r#   r   r   r   /       -/IOdeGH	/<<o>h>h  oE  
FB::O<e<e  lJ  	KA
?>>@k@k  rR  SC
?>>@k@k  rh  iCFFAS"	j	@A	]f&AAr#   r   c                   z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zd ZddZddZddZd Zd Zd Zej<                  Zy)float_maxheap_array_tr<   c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zfloat_maxheap_array_t.<lambda>H0  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zfloat_maxheap_array_t.<lambda>H0  rD   r#   rE   rF   r?   r@   rA   rB   c                 .    t        j                  | |      S rD   )r   float_maxheap_array_t_get_valrF   s     r   rG   zfloat_maxheap_array_t.get_valO0  r  r#   c                 .    t        j                  | |      S rI   )r   float_maxheap_array_t_get_idsrF   s     r   r  zfloat_maxheap_array_t.get_idsS0  r  r#   c                 ,    t        j                  |       S rL   )r   float_maxheap_array_t_heapifyrR   s    r   rN   zfloat_maxheap_array_t.heapifyW0  r?  r#   c                 6    t        j                  | |||||      S rP   )r   float_maxheap_array_t_addnrR   s         r   rU   zfloat_maxheap_array_t.addn[0  rV   r#   Nc           	      8    t        j                  | ||||||      S rX   )r   #float_maxheap_array_t_addn_with_idsrZ   s          r   r]   z#float_maxheap_array_t.addn_with_idsl0  r^   r#   c           	      8    t        j                  | ||||||      S r`   )r   0float_maxheap_array_t_addn_query_subset_with_idsrb   s          r   rc   z0float_maxheap_array_t.addn_query_subset_with_idsw0  rd   r#   c                 ,    t        j                  |       S rf   )r   float_maxheap_array_t_reorderrR   s    r   rh   zfloat_maxheap_array_t.reorder0  r?  r#   c                 0    t        j                  | ||      S rj   )r   &float_maxheap_array_t_per_line_extremarl   s      r   ro   z&float_maxheap_array_t.per_line_extrema0  rp   r#   c                 T    t        j                  | t        j                                y r-   )r   float_maxheap_array_t_swiginitnew_float_maxheap_array_trR   s    r   rN   zfloat_maxheap_array_t.__init__0  r  r#   rt   ru   rv   ) r   r   r6   r7   r   r   r   r   r   float_maxheap_array_t_nh_getfloat_maxheap_array_t_nh_setry   float_maxheap_array_t_k_getfloat_maxheap_array_t_k_setrP  float_maxheap_array_t_ids_getfloat_maxheap_array_t_ids_setr{  float_maxheap_array_t_val_getfloat_maxheap_array_t_val_setr  rG   r  rN   rU   r]   rc   rh   ro   rN   delete_float_maxheap_array_tr   r$   r#   r   r   r   A0  r   r#   r   c                   z   e Zd ZdZ ed d d      ZeZ eej                  ej                  d      Z eej                  ej                  d      Z eej                  ej                   d      Z eej$                  ej&                  d	      Zd
 Zd Zd ZddZddZddZd Zd Zd Zej<                  Zy)int_maxheap_array_tr<   c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zint_maxheap_array_t.<lambda>0  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zint_maxheap_array_t.<lambda>0  rD   r#   rE   rF   r?   r@   rA   rB   c                 .    t        j                  | |      S rD   )r   int_maxheap_array_t_get_valrF   s     r   rG   zint_maxheap_array_t.get_val0  r  r#   c                 .    t        j                  | |      S rI   )r   int_maxheap_array_t_get_idsrF   s     r   r  zint_maxheap_array_t.get_ids0  r  r#   c                 ,    t        j                  |       S rL   )r   int_maxheap_array_t_heapifyrR   s    r   rN   zint_maxheap_array_t.heapify0  r  r#   c                 6    t        j                  | |||||      S r   )r   int_maxheap_array_t_addnrR   s         r   rU   zint_maxheap_array_t.addn0  r   r#   Nc           	      8    t        j                  | ||||||      S rX   )r   !int_maxheap_array_t_addn_with_idsrZ   s          r   r]   z!int_maxheap_array_t.addn_with_ids0  r   r#   c           	      8    t        j                  | ||||||      S r`   )r   .int_maxheap_array_t_addn_query_subset_with_idsrb   s          r   rc   z.int_maxheap_array_t.addn_query_subset_with_ids0  r   r#   c                 ,    t        j                  |       S rf   )r   int_maxheap_array_t_reorderrR   s    r   rh   zint_maxheap_array_t.reorder0  r  r#   c                 0    t        j                  | ||      S r   )r   $int_maxheap_array_t_per_line_extremarl   s      r   ro   z$int_maxheap_array_t.per_line_extrema0  r   r#   c                 T    t        j                  | t        j                                y r-   )r   int_maxheap_array_t_swiginitnew_int_maxheap_array_trR   s    r   rN   zint_maxheap_array_t.__init__0  r  r#   rt   ru   rv   ) r   r   r6   r7   r   r   r   r   r   int_maxheap_array_t_nh_getint_maxheap_array_t_nh_setry   int_maxheap_array_t_k_getint_maxheap_array_t_k_setrP  int_maxheap_array_t_ids_getint_maxheap_array_t_ids_setr{  int_maxheap_array_t_val_getint_maxheap_array_t_val_setr  rG   r  rN   rU   r]   rc   rh   ro   rN   delete_int_maxheap_array_tr   r$   r#   r   r   r   0  r   r#   r   c                 6    t        j                  | |||||      S z
     partitions the table into 0:q and q:n where all elements above q are >= all
    elements below q (for C = CMax, for CMin comparisons are reversed)

    Returns the partition threshold. The elements q:n are destroyed on output.
    )r   CMin_float_partition_fuzzyr  r{  rW   q_minq_maxq_outs         r   r   r   0        55dCE5RWXXr#   c                 6    t        j                  | |||||      S r   )r   CMax_float_partition_fuzzyr   s         r   r   r   0  r   r#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zed        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zej0                  Zy)AlignedTableUint8c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zAlignedTableUint8.<lambda> 1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zAlignedTableUint8.<lambda> 1  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r    AlignedTableUint8_round_capacityrW   s    r   round_capacityz AlignedTableUint8.round_capacity1  s    ??BBr#   c                 P    t        j                  | t        j                  |        y r-   )r   AlignedTableUint8_swiginitnew_AlignedTableUint8r   s     r   rN   zAlignedTableUint8.__init__	1  r	  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint8_itemsizerR   s    r   itemsizezAlignedTableUint8.itemsize1  r  r#   c                 .    t        j                  | |      S r-   )r   AlignedTableUint8_resizerV   s     r   r   zAlignedTableUint8.resize1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint8_clearrR   s    r   r   zAlignedTableUint8.clear1  ro   r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint8_sizerR   s    r   r   zAlignedTableUint8.size1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint8_nbytesrR   s    r   nbyteszAlignedTableUint8.nbytes1  r  r#   c                 .    t        j                  | g| S r-   )r   AlignedTableUint8_getr   s     r   rq
  zAlignedTableUint8.get1  s    44TADAAr#   c                 .    t        j                  | g| S r-   )r   AlignedTableUint8_datar   s     r   r   zAlignedTableUint8.data1  r   r#   N)r   r   r6   r   r   r   r   r   AlignedTableUint8_tab_getAlignedTableUint8_tab_setr  AlignedTableUint8_numel_getAlignedTableUint8_numel_setrR  r  r   rN   r !  r   r   r   r	!  rq
  r   delete_AlignedTableUint8r   r$   r#   r   r   r   0  s    -/IOdeGH
?<<o>g>g
hC_@@/BmBmnEC Cg@A=<>BC&??r#   r   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zed        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zej0                  Zy)AlignedTableUint16c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zAlignedTableUint16.<lambda>%1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zAlignedTableUint16.<lambda>%1  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r   !AlignedTableUint16_round_capacityr   s    r   r   z!AlignedTableUint16.round_capacity*1  s    @@CCr#   c                 P    t        j                  | t        j                  |        y r-   )r   AlignedTableUint16_swiginitnew_AlignedTableUint16r   s     r   rN   zAlignedTableUint16.__init__.1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint16_itemsizerR   s    r   r !  zAlignedTableUint16.itemsize11  r  r#   c                 .    t        j                  | |      S r-   )r   AlignedTableUint16_resizerV   s     r   r   zAlignedTableUint16.resize41  r>  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint16_clearrR   s    r   r   zAlignedTableUint16.clear71  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint16_sizerR   s    r   r   zAlignedTableUint16.size:1  ro   r#   c                 ,    t        j                  |       S r-   )r   AlignedTableUint16_nbytesrR   s    r   r	!  zAlignedTableUint16.nbytes=1  r  r#   c                 .    t        j                  | g| S r-   )r   AlignedTableUint16_getr   s     r   rq
  zAlignedTableUint16.get@1  r   r#   c                 .    t        j                  | g| S r-   )r   AlignedTableUint16_datar   s     r   r   zAlignedTableUint16.dataC1      66tCdCCr#   N)r   r   r6   r   r   r   r   r   AlignedTableUint16_tab_getAlignedTableUint16_tab_setr  AlignedTableUint16_numel_getAlignedTableUint16_numel_setrR  r  r   rN   r !  r   r   r   r	!  rq
  r   delete_AlignedTableUint16r   r$   r#   r   r!  r!  $1  s    -/IOdeGH
?==?i?i
jC_AA?CoCopED DiAB>=?CD&@@r#   r!  c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Zed        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zej0                  Zy)AlignedTableFloat32c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zAlignedTableFloat32.<lambda>J1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zAlignedTableFloat32.<lambda>J1  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r   "AlignedTableFloat32_round_capacityr   s    r   r   z"AlignedTableFloat32.round_capacityO1  s    AA!DDr#   c                 P    t        j                  | t        j                  |        y r-   )r   AlignedTableFloat32_swiginitnew_AlignedTableFloat32r   s     r   rN   zAlignedTableFloat32.__init__S1  rv  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableFloat32_itemsizerR   s    r   r !  zAlignedTableFloat32.itemsizeV1  r7  r#   c                 .    t        j                  | |      S r-   )r   AlignedTableFloat32_resizerV   s     r   r   zAlignedTableFloat32.resizeY1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableFloat32_clearrR   s    r   r   zAlignedTableFloat32.clear\1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableFloat32_sizerR   s    r   r   zAlignedTableFloat32.size_1  r  r#   c                 ,    t        j                  |       S r-   )r   AlignedTableFloat32_nbytesrR   s    r   r	!  zAlignedTableFloat32.nbytesb1  r  r#   c                 .    t        j                  | g| S r-   )r   AlignedTableFloat32_getr   s     r   rq
  zAlignedTableFloat32.gete1  r*!  r#   c                 .    t        j                  | g| S r-   )r   AlignedTableFloat32_datar   s     r   r   zAlignedTableFloat32.datah1      77DtDDr#   N)r   r   r6   r   r   r   r   r   AlignedTableFloat32_tab_getAlignedTableFloat32_tab_setr  AlignedTableFloat32_numel_getAlignedTableFloat32_numel_setrR  r  r   rN   r !  r   r   r   r	!  rq
  r   delete_AlignedTableFloat32r   r$   r#   r   r1!  r1!  I1  s    -/IOdeGH
?>>@k@k
lC_BBODqDqrEE EkBC?>@DE&AAr#   r1!  c                   $   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Z eej4                  ej6                        Zd Zed        Zd Z d Z!d	 Z"d
 Z#d Z$d Z%d Z&d Z'd Z(ejR                  Z*y)MaybeOwnedVectorUInt8c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMaybeOwnedVectorUInt8.<lambda>o1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMaybeOwnedVectorUInt8.<lambda>o1  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   MaybeOwnedVectorUInt8_swiginitnew_MaybeOwnedVectorUInt8r   s     r   rN   zMaybeOwnedVectorUInt8.__init__y1      66t_=f=fhl=mnr#   c                 0    t        j                  | ||      S r-   )r   !MaybeOwnedVectorUInt8_create_viewaddress
n_elementsr  s      r   create_viewz!MaybeOwnedVectorUInt8.create_view|1      @@*V[\\r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorUInt8_datar   s     r   r   zMaybeOwnedVectorUInt8.data1      99$FFFr#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorUInt8_sizerR   s    r   r   zMaybeOwnedVectorUInt8.size1  r  r#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorUInt8_byte_sizerR   s    r   	byte_sizezMaybeOwnedVectorUInt8.byte_size1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorUInt8_atr   s     r   r   zMaybeOwnedVectorUInt8.at1  rG!  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorUInt8_beginr   s     r   r  zMaybeOwnedVectorUInt8.begin1      ::4G$GGr#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorUInt8_endr   s     r   r  zMaybeOwnedVectorUInt8.end1      88EEEr#   c                 0    t        j                  | ||      S r-   )r   MaybeOwnedVectorUInt8_eraser   r  r  s      r   erasezMaybeOwnedVectorUInt8.erase1      ::4LLr#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorUInt8_clearrR   s    r   r   zMaybeOwnedVectorUInt8.clear1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorUInt8_resizer   s     r   r   zMaybeOwnedVectorUInt8.resize1      ;;DH4HHr#   N)+r   r   r6   r   r   r   r   r   "MaybeOwnedVectorUInt8_is_owned_get"MaybeOwnedVectorUInt8_is_owned_setis_owned$MaybeOwnedVectorUInt8_owned_data_get$MaybeOwnedVectorUInt8_owned_data_set
owned_data#MaybeOwnedVectorUInt8_view_data_get#MaybeOwnedVectorUInt8_view_data_set	view_data#MaybeOwnedVectorUInt8_view_size_get#MaybeOwnedVectorUInt8_view_size_set	view_sizeMaybeOwnedVectorUInt8_owner_getMaybeOwnedVectorUInt8_owner_setr  MaybeOwnedVectorUInt8_c_ptr_getMaybeOwnedVectorUInt8_c_ptr_setc_ptr MaybeOwnedVectorUInt8_c_size_get MaybeOwnedVectorUInt8_c_size_setc_sizerN   r  rZ!  r   r   rc!  r   r  r  ro!  r   r   delete_MaybeOwnedVectorUInt8r   r$   r#   r   rN!  rN!  n1  @   -/IOdeGHJJOL~L~H/NNP_  QE  QE  FJLLo  OB  OB  CILLo  OB  OB  CI_DDoFuFuvE_DDoFuFuvEoFFHxHxyFo ] ]G@EEHFMAI&CCr#   rN!  c                   $   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Z eej4                  ej6                        Zd Zed        Zd Z d Z!d	 Z"d
 Z#d Z$d Z%d Z&d Z'd Z(ejR                  Z*y)MaybeOwnedVectorInt32c                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMaybeOwnedVectorInt32.<lambda>1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMaybeOwnedVectorInt32.<lambda>1  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r   MaybeOwnedVectorInt32_swiginitnew_MaybeOwnedVectorInt32r   s     r   rN   zMaybeOwnedVectorInt32.__init__1  rT!  r#   c                 0    t        j                  | ||      S r-   )r   !MaybeOwnedVectorInt32_create_viewrW!  s      r   rZ!  z!MaybeOwnedVectorInt32.create_view1  r[!  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorInt32_datar   s     r   r   zMaybeOwnedVectorInt32.data1  r^!  r#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorInt32_sizerR   s    r   r   zMaybeOwnedVectorInt32.size1  r  r#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorInt32_byte_sizerR   s    r   rc!  zMaybeOwnedVectorInt32.byte_size1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorInt32_atr   s     r   r   zMaybeOwnedVectorInt32.at1  rG!  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorInt32_beginr   s     r   r  zMaybeOwnedVectorInt32.begin1  rh!  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorInt32_endr   s     r   r  zMaybeOwnedVectorInt32.end1  rk!  r#   c                 0    t        j                  | ||      S r-   )r   MaybeOwnedVectorInt32_erasern!  s      r   ro!  zMaybeOwnedVectorInt32.erase1  rp!  r#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorInt32_clearrR   s    r   r   zMaybeOwnedVectorInt32.clear1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorInt32_resizer   s     r   r   zMaybeOwnedVectorInt32.resize1  ru!  r#   N)+r   r   r6   r   r   r   r   r   "MaybeOwnedVectorInt32_is_owned_get"MaybeOwnedVectorInt32_is_owned_setrx!  $MaybeOwnedVectorInt32_owned_data_get$MaybeOwnedVectorInt32_owned_data_setr{!  #MaybeOwnedVectorInt32_view_data_get#MaybeOwnedVectorInt32_view_data_setr~!  #MaybeOwnedVectorInt32_view_size_get#MaybeOwnedVectorInt32_view_size_setr!  MaybeOwnedVectorInt32_owner_getMaybeOwnedVectorInt32_owner_setr  MaybeOwnedVectorInt32_c_ptr_getMaybeOwnedVectorInt32_c_ptr_setr!   MaybeOwnedVectorInt32_c_size_get MaybeOwnedVectorInt32_c_size_setr!  rN   r  rZ!  r   r   rc!  r   r  r  ro!  r   r   delete_MaybeOwnedVectorInt32r   r$   r#   r   r!  r!  1  r!  r#   r!  c                   $   e Zd Z ed d d      ZeZ eej                  ej                        Z
 eej                  ej                        Z eej                  ej                        Z eej"                  ej$                        Z eej(                  ej*                        Z eej.                  ej0                        Z eej4                  ej6                        Zd Zed        Zd Z d Z!d	 Z"d
 Z#d Z$d Z%d Z&d Z'd Z(ejR                  Z*y)MaybeOwnedVectorFloat32c                 6    | j                   j                         S r-   r<   r=   s    r   r?   z MaybeOwnedVectorFloat32.<lambda>1  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z MaybeOwnedVectorFloat32.<lambda>1  rD   r#   rE   rF   c                 P    t        j                  | t        j                  |        y r-   )r    MaybeOwnedVectorFloat32_swiginitnew_MaybeOwnedVectorFloat32r   s     r   rN   z MaybeOwnedVectorFloat32.__init__1  r  r#   c                 0    t        j                  | ||      S r-   )r   #MaybeOwnedVectorFloat32_create_viewrW!  s      r   rZ!  z#MaybeOwnedVectorFloat32.create_view1  s    BB7JX]^^r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorFloat32_datar   s     r   r   zMaybeOwnedVectorFloat32.data1  ru!  r#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorFloat32_sizerR   s    r   r   zMaybeOwnedVectorFloat32.size1  r7  r#   c                 ,    t        j                  |       S r-   )r   !MaybeOwnedVectorFloat32_byte_sizerR   s    r   rc!  z!MaybeOwnedVectorFloat32.byte_size1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorFloat32_atr   s     r   r   zMaybeOwnedVectorFloat32.at1  r^!  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorFloat32_beginr   s     r   r  zMaybeOwnedVectorFloat32.begin1  s    <<TIDIIr#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorFloat32_endr   s     r   r  zMaybeOwnedVectorFloat32.end1  rh!  r#   c                 0    t        j                  | ||      S r-   )r   MaybeOwnedVectorFloat32_erasern!  s      r   ro!  zMaybeOwnedVectorFloat32.erase1  s    <<T5#NNr#   c                 ,    t        j                  |       S r-   )r   MaybeOwnedVectorFloat32_clearrR   s    r   r   zMaybeOwnedVectorFloat32.clear1  r  r#   c                 .    t        j                  | g| S r-   )r   MaybeOwnedVectorFloat32_resizer   s     r   r   zMaybeOwnedVectorFloat32.resize1  s    ==dJTJJr#   N)+r   r   r6   r   r   r   r   r   $MaybeOwnedVectorFloat32_is_owned_get$MaybeOwnedVectorFloat32_is_owned_setrx!  &MaybeOwnedVectorFloat32_owned_data_get&MaybeOwnedVectorFloat32_owned_data_setr{!  %MaybeOwnedVectorFloat32_view_data_get%MaybeOwnedVectorFloat32_view_data_setr~!  %MaybeOwnedVectorFloat32_view_size_get%MaybeOwnedVectorFloat32_view_size_setr!  !MaybeOwnedVectorFloat32_owner_get!MaybeOwnedVectorFloat32_owner_setr  !MaybeOwnedVectorFloat32_c_ptr_get!MaybeOwnedVectorFloat32_c_ptr_setr!  "MaybeOwnedVectorFloat32_c_size_get"MaybeOwnedVectorFloat32_c_size_setr!  rN   r  rZ!  r   r   rc!  r   r  r  ro!  r   r   delete_MaybeOwnedVectorFloat32r   r$   r#   r   r!  r!  1  sM   -/IOdeGHLLo  OC  OC  DH/PPRa  SI  SI  JJNNP_  QF  QF  GINNP_  QF  QF  GI_FFHyHyzE_FFHyHyzEoHH/J|J|}Fs _ _IBGGJHOCK&EEr#   r!  c                  &    t        j                  |  S r-   )r   CMin_uint16_partition_fuzzyrH  s    r   r!  r!  1      66==r#   c                  &    t        j                  |  S r-   )r   CMax_uint16_partition_fuzzyrH  s    r   r!  r!  2  r!  r#   c                  &    t        j                  |  S r-   )r   merge_knn_results_CMinrH  s    r   r!  r!  2  r  r#   c                  &    t        j                  |  S r-   )r   merge_knn_results_CMaxrH  s    r   r!  r!  2  r  r#   c                       e Zd Z ed d d      ZeZ eej                  ej                        Z
d Zd Zd Zd Zej                  Zy	)
MapLong2Longc                 6    | j                   j                         S r-   r<   r=   s    r   r?   zMapLong2Long.<lambda>2  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   zMapLong2Long.<lambda>2  rD   r#   rE   rF   c                 2    t        j                  | |||      S r-   )r   MapLong2Long_addr   rW   r  r  s       r   r)  zMapLong2Long.add2  s    //atDDr#   c                 .    t        j                  | |      S r-   )r   MapLong2Long_searchrF   s     r   r:  zMapLong2Long.search2  s    224==r#   c                 2    t        j                  | |||      S r-   )r   MapLong2Long_search_multipler!  s       r   search_multiplezMapLong2Long.search_multiple2  s    ;;D!T4PPr#   c                 T    t        j                  | t        j                                y r-   )r   MapLong2Long_swiginitnew_MapLong2LongrR   s    r   rN   zMapLong2Long.__init__2  rO  r#   N)r   r   r6   r   r   r   r   r   MapLong2Long_map_getMapLong2Long_map_setr  r)  r:  r!  rN   delete_MapLong2Longr   r$   r#   r   r!  r!  
2  sS    -/IOdeGH
?779]9]
^CE>QX&::r#   r!  c                 ,    t        j                  |       S r-   )r   omp_set_num_threads)num_threadss    r   r!  r!  2  s    ..{;;r#   c                  *    t        j                         S r-   )r   omp_get_max_threadsr$   r#   r   r!  r!  "2  s    ..00r#   c                 0    t        j                  | ||      S r-   )r   memcpy)destr  rW   s      r   r"  r"  %2  s    !!$Q//r#   c                   ^    e Zd Z ed d d      ZeZd Zed        Z	d Z
ej                  Zy)	PythonInterruptCallbackc                 6    | j                   j                         S r-   r<   r=   s    r   r?   z PythonInterruptCallback.<lambda>(2  r@   r#   c                 8    | j                   j                  |      S r-   r<   rB   s     r   r?   z PythonInterruptCallback.<lambda>(2  rD   r#   rE   rF   c                 ,    t        j                  |       S r-   )r   &PythonInterruptCallback_want_interruptrR   s    r   rh  z&PythonInterruptCallback.want_interrupt+2  r{  r#   c                  *    t        j                         S r-   )r   PythonInterruptCallback_resetr$   r#   r   r  zPythonInterruptCallback.reset.2  s    <<>>r#   c                 T    t        j                  | t        j                                y r-   )r    PythonInterruptCallback_swiginitnew_PythonInterruptCallbackrR   s    r   rN   z PythonInterruptCallback.__init__22  r	  r#   N)r   r   r6   r   r   r   r   rh  r  r  rN   r   delete_PythonInterruptCallbackr   r$   r#   r   r"  r"  '2  sD    -/IOdeGHL ? ?n&EEr#   r"  c                 ,    t        j                  |       S r-   )r   swig_ptr)r  s    r   r"  r"  92  s    ##A&&r#   c                  &    t        j                  |  S r-   )r   rev_swig_ptrrH  s    r   r"  r"  <2  s    ''..r#   c                 ,    t        j                  |       S r-   )r   cast_integer_to_uint8_ptrr=   s    r   r"  r"  ?2      44Q77r#   c                 ,    t        j                  |       S r-   )r   cast_integer_to_float_ptrr=   s    r   r"  r"  B2  r"  r#   c                 ,    t        j                  |       S r-   )r   cast_integer_to_idx_t_ptrr=   s    r   r"  r"  E2  r"  r#   c                 ,    t        j                  |       S r-   )r   cast_integer_to_int_ptrr=   s    r   r"  r"  H2  s    22155r#   c                 ,    t        j                  |       S r-   )r   cast_integer_to_void_ptrr=   s    r   r"  r"  K2  s    33A66r#   c                  *    t        j                         S r-   )r   swig_versionr$   r#   r   r"  r"  N2  rs  r#   r-   r   )Tr   )Fr  )r	  r	  r	  r	  r  r	  r  r  rD  (1  sysr   _swig_python_version_info__package__r   r   r   builtinsr   ImportErrorr   r%   r*   r3   r   r5   objectr:   SwigPyIterator_swigregisterSHARED_PTR_DISOWNr   Float32Vector_swigregisterr   Float64Vector_swigregisterr   Int8Vector_swigregisterr   Int16Vector_swigregisterr  Int32Vector_swigregisterr  Int64Vector_swigregisterr3  UInt8Vector_swigregisterrI  UInt16Vector_swigregisterrd  UInt32Vector_swigregisterrz  UInt64Vector_swigregisterr   Float32VectorVector_swigregisterr  UInt8VectorVector_swigregisterr  Int32VectorVector_swigregisterr  Int64VectorVector_swigregisterr  "VectorTransformVector_swigregisterr  !OperatingPointVector_swigregisterr,  #InvertedListsPtrVector_swigregisterrE  RepeatVector_swigregisterr[  +ClusteringIterationStatsVector_swigregisterru  !ParameterRangeVector_swigregisterr  (MaybeOwnedVectorUInt8Vector_swigregisterr  (MaybeOwnedVectorInt32Vector_swigregisterr  *MaybeOwnedVectorFloat32Vector_swigregisterr   OnDiskOneListVector_swigregisterr  r  r  PartitionStats_swigregisterr  r  r  r  r  r  BitstringWriter_swigregistercvarr0  BitstringReader_swigregisterrA  rG  rJ  rO  rU  rY  ra  rd  rg  ri  rk  rm  rp  rr  ru  rw  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  CodeSet_swigregisterhamdis_tab_ham_bytesr  "CombinerRangeKNNfloat_swigregisterr  "CombinerRangeKNNint16_swigregisterr9  r=  r?  rA  rC  rN  rP  rW  r[  r]  ra  rd  rf  rh  rm  ro  rq  ru  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  RandomGenerator_swigregisterr  &SplitMix64RandomGenerator_swigregisterr  r  r  r  r  r  r  r  r  r  r  r  r  r   r  METRIC_INNER_PRODUCT	METRIC_L2	METRIC_L1METRIC_Linf	METRIC_LpMETRIC_CanberraMETRIC_BrayCurtisMETRIC_JensenShannonMETRIC_JaccardMETRIC_NaNEuclideanMETRIC_GOWERr  FAISS_VERSION_MAJORFAISS_VERSION_MINORFAISS_VERSION_PATCHVERSION_STRINGFloat32Float16UInt8Int8r	  r  SearchParameters_swigregisterr  Index_swigregisterr  DistanceComputer_swigregisterr  %NegativeDistanceComputer_swigregisterr  &FlatCodesDistanceComputer_swigregisterr  IOReader_swigregisterr  IOWriter_swigregisterr  VectorIOReader_swigregisterr
  VectorIOWriter_swigregisterr  FileIOReader_swigregisterr+  FileIOWriter_swigregisterr;  BufferedIOReader_swigregisterr[  BufferedIOWriter_swigregisterrs  ru  rx  rz  "MaybeOwnedVectorOwner_swigregisterr  $MmappedFileMappingOwner_swigregisterr  MappedFileIOReader_swigregisterr  ZeroCopyIOReader_swigregisterr  IndexFlatCodes_swigregisterr  IndexFlat_swigregisterr  IndexFlatIP_swigregisterr  IndexFlatL2_swigregisterr1  IndexFlat1D_swigregisterrK  !ClusteringParameters_swigregisterrx  %ClusteringIterationStats_swigregisterr  Clustering_swigregisterr  Clustering1D_swigregisterr  /ProgressiveDimClusteringParameters_swigregisterr  'ProgressiveDimIndexFactory_swigregisterr  %ProgressiveDimClustering_swigregisterr  r  r  r  r  Quantizer_swigregisterr  ProductQuantizer_swigregisterrw  PQEncoderGeneric_swigregisterr  PQEncoder8_swigregisterr  PQEncoder16_swigregisterr  PQDecoderGeneric_swigregisterr  PQDecoder8_swigregisterr  PQDecoder16_swigregisterr  AdditiveQuantizer_swigregisterr_	  ra	  rc	  !RefineBeamMemoryPool_swigregisterrw	  r	  $RefineBeamLUTMemoryPool_swigregisterr	  r	  3ComputeCodesAddCentroidsLUT0MemoryPool_swigregisterr	  r	  3ComputeCodesAddCentroidsLUT1MemoryPool_swigregisterr	  r	  ResidualQuantizer_swigregisterr
  !LocalSearchQuantizer_swigregisterrW
  IcmEncoder_swigregisterrl
  IcmEncoderFactory_swigregisterrw
  LSQTimer_swigregisterr
  LSQTimerScope_swigregisterr
  %ProductAdditiveQuantizer_swigregisterr
  (ProductLocalSearchQuantizer_swigregisterr
  %ProductResidualQuantizer_swigregisterr
  CodePacker_swigregisterr
  CodePackerFlat_swigregisterr  VectorTransform_swigregisterr'  LinearTransform_swigregisterrN  !RandomRotationMatrix_swigregisterrZ  PCAMatrix_swigregisterr  ITQMatrix_swigregisterr  ITQTransform_swigregisterr  OPQMatrix_swigregisterr  %RemapDimensionsTransform_swigregisterr  #NormalizationTransform_swigregisterr  CenteringTransform_swigregisterr  )SearchParametersPreTransform_swigregisterr  IndexPreTransform_swigregisterrP  (IndexRefineSearchParameters_swigregisterr^  IndexRefine_swigregisterr  IndexRefineFlat_swigregisterr  IndexLSH_swigregisterr  )SimulatedAnnealingParameters_swigregisterr  !PermutationObjective_swigregisterr  (ReproduceDistancesObjective_swigregisterr  (SimulatedAnnealingOptimizer_swigregisterr2  PolysemousTraining_swigregisterr^  IndexPQ_swigregisterr  SearchParametersPQ_swigregisterr  IndexPQStats_swigregisterr   MultiIndexQuantizer_swigregisterr  !MultiIndexQuantizer2_swigregisterr  #IndexAdditiveQuantizer_swigregisterr  #IndexResidualQuantizer_swigregisterr  &IndexLocalSearchQuantizer_swigregisterr  *IndexProductResidualQuantizer_swigregisterr  -IndexProductLocalSearchQuantizer_swigregisterr-  $AdditiveCoarseQuantizer_swigregisterrF  4SearchParametersResidualCoarseQuantizer_swigregisterrQ  $ResidualCoarseQuantizer_swigregisterre  'LocalSearchCoarseQuantizer_swigregisterro  "InvertedListsIterator_swigregisterr~  InvertedLists_swigregisterr  ArrayInvertedLists_swigregisterr  "ReadOnlyInvertedLists_swigregisterr   HStackInvertedLists_swigregisterr?  SliceInvertedLists_swigregisterr_   VStackInvertedLists_swigregisterr|   MaskedInvertedLists_swigregisterr  #StopWordsInvertedLists_swigregisterr   InvertedListsIOHook_swigregisterr  BlockInvertedLists_swigregisterr  r  r  r	  DirectMap_swigregisterr9  DirectMapAdd_swigregisterrQ  Level1Quantizer_swigregisterrx   SearchParametersIVF_swigregisterr  IndexIVFInterface_swigregisterr  IndexIVF_swigregisterr#   InvertedListScanner_swigregisterrO  IndexIVFStats_swigregisterr  rn  rp  rr  rv  ry  r~  SlidingIndexWindow_swigregisterr  r  r  r  r  r  r  ShardingFunction_swigregisterr  $DefaultShardingFunction_swigregisterr  r  r  ScalarQuantizer_swigregisterr  !IndexScalarQuantizer_swigregisterr  $IndexIVFScalarQuantizer_swigregisterr4  !IndexIVFSpectralHash_swigregisterr[  &IndexIVFAdditiveQuantizer_swigregisterrw  &IndexIVFResidualQuantizer_swigregisterr  )IndexIVFLocalSearchQuantizer_swigregisterr  -IndexIVFProductResidualQuantizer_swigregisterr  0IndexIVFProductLocalSearchQuantizer_swigregisterr  !SearchParametersHNSW_swigregisterr  HNSW_swigregisterr%  HNSWStats_swigregisterr;  r@  rB  rF  rK  IndexHNSW_swigregisterr  IndexHNSWFlat_swigregisterr  IndexHNSWPQ_swigregisterr  IndexHNSWSQ_swigregisterr  IndexHNSW2Level_swigregisterr  IndexHNSWCagra_swigregisterr  r  r  Neighbor_swigregisterr  Nhood_swigregisterr  NNDescent_swigregisterrL  IndexNNDescent_swigregisterre  IndexNNDescentFlat_swigregisterrm  IndexIVFFlat_swigregisterr  IndexIVFFlatDedup_swigregisterr  r  NSG_swigregisterr  NSG_Graph_int_swigregisterr  IndexNSG_swigregisterr)  IndexNSGFlat_swigregisterr1  IndexNSGPQ_swigregisterr<  IndexNSGSQ_swigregisterrD  OnDiskOneList_swigregisterrS   OnDiskInvertedLists_swigregisterr  ZnSphereSearch_swigregisterr  EnumeratedVectors_swigregisterr  Repeat_swigregisterr  Repeats_swigregisterr  ZnSphereCodec_swigregisterr  ZnSphereCodecRec_swigregisterr?  ZnSphereCodecAlt_swigregisterrQ  IndexLattice_swigregisterrr  "IVFPQSearchParameters_swigregisterr  IndexIVFPQ_swigregisterr  r  IndexIVFPQStats_swigregisterr  IndexIVFPQR_swigregisterr  Index2Layer_swigregisterr  IndexFastScan_swigregisterrf  FastScanStats_swigregisterr{  +IndexAdditiveQuantizerFastScan_swigregisterr  +IndexResidualQuantizerFastScan_swigregisterr  .IndexLocalSearchQuantizerFastScan_swigregisterr  2IndexProductResidualQuantizerFastScan_swigregisterr  5IndexProductLocalSearchQuantizerFastScan_swigregisterr  IndexPQFastScan_swigregisterr  simd16uint16_swigregisterr  SIMDResultHandler_swigregisterr  %SIMDResultHandlerToFloat_swigregisterr  DummyResultHandler_swigregisterr"  StoreResultHandler_swigregisterr8  IndexIVFFastScan_swigregisterr  IVFFastScanStats_swigregisterr  .IndexIVFAdditiveQuantizerFastScan_swigregisterr  1IndexIVFLocalSearchQuantizerFastScan_swigregisterr  .IndexIVFResidualQuantizerFastScan_swigregisterr  8IndexIVFProductLocalSearchQuantizerFastScan_swigregisterr  5IndexIVFProductResidualQuantizerFastScan_swigregisterr  )IndexIVFIndependentQuantizer_swigregisterr!  IndexIVFPQFastScan_swigregisterr;  r?  rA  rG  rJ  rL  IndexBinary_swigregisterr  IndexBinaryFlat_swigregisterr  IndexBinaryIVF_swigregisterr  &BinaryInvertedListScanner_swigregisterr  !IndexBinaryFromFloat_swigregisterr  IndexBinaryHNSW_swigregisterr9  !IndexBinaryHNSWCagra_swigregisterrI  IndexBinaryHash_swigregisterrh  !IndexBinaryHashStats_swigregisterr{  !IndexBinaryMultiHash_swigregisterr  ThreadedIndexBase_swigregisterr  $ThreadedIndexBaseBinary_swigregisterr  IndexShards_swigregisterr  IndexBinaryShards_swigregisterr  IndexShardsIVF_swigregisterr  IndexReplicas_swigregisterr;   IndexBinaryReplicas_swigregisterrQ  IndexSplitVectors_swigregisterrq  IndexRandom_swigregisterr  #IndexRowwiseMinMaxBase_swigregisterr  #IndexRowwiseMinMaxFP16_swigregisterr  IndexRowwiseMinMax_swigregisterr  Linear_swigregisterr  Embedding_swigregisterr  FFN_swigregisterr  QINCoStep_swigregisterr  NeuralNetCodec_swigregisterr&  QINCo_swigregisterrA  Tensor2D_swigregisterr\  Int32Tensor2D_swigregisterrp   IndexNeuralNetCodec_swigregisterr  IndexQINCo_swigregisterr  RaBitQuantizer_swigregisterr  #RaBitQSearchParameters_swigregisterr  IndexRaBitQ_swigregisterr  &IVFRaBitQSearchParameters_swigregisterr  IndexIVFRaBitQ_swigregisterr  RangeSearchResult_swigregisterr  BufferList_swigregisterr/  RangeQueryResult_swigregisterrB  %RangeSearchPartialResult_swigregisterrb  InterruptCallback_swigregisterrx  TimeoutCallback_swigregisterr  VisitedTable_swigregisterr  IDSelector_swigregisterr  IDSelectorRange_swigregisterr  IDSelectorArray_swigregisterr  IDSelectorBatch_swigregisterr  IDSelectorBitmap_swigregisterr  IDSelectorNot_swigregisterr  IDSelectorAll_swigregisterr  IDSelectorAnd_swigregisterr  IDSelectorOr_swigregisterr)  IDSelectorXOr_swigregisterr7  !IDSelectorTranslated_swigregisterrE  IndexIDMap_swigregisterrv  IndexBinaryIDMap_swigregisterr  IndexIDMap2_swigregisterr  IndexBinaryIDMap2_swigregister
EXACT_TOPKAPPROX_TOPK_BUCKETS_B32_D2APPROX_TOPK_BUCKETS_B8_D3APPROX_TOPK_BUCKETS_B16_D2APPROX_TOPK_BUCKETS_B8_D2r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Cloner_swigregisterIO_FLAG_SKIP_STORAGEIO_FLAG_READ_ONLYIO_FLAG_ONDISK_SAME_DIRIO_FLAG_SKIP_IVF_DATAIO_FLAG_SKIP_PRECOMPUTE_TABLEIO_FLAG_PQ_SKIP_SDC_TABLEIO_FLAG_MMAPIO_FLAG_MMAP_IFCr  r  r  AutoTuneCriterion_swigregisterr1  "OneRecallAtRCriterion_swigregisterr@  "IntersectionCriterion_swigregisterrL  OperatingPoint_swigregisterr^  OperatingPoints_swigregisterr  ParameterRange_swigregisterr  ParameterSpace_swigregisterr  r  r  MatrixStats_swigregisterr    PyCallbackIOWriter_swigregisterr   PyCallbackIOReader_swigregisterr#   !PyCallbackIDSelector_swigregisterr/   'PyCallbackShardingFunction_swigregisterr;   "float_minheap_array_t_swigregisterr    int_minheap_array_t_swigregisterr   "float_maxheap_array_t_swigregisterr    int_maxheap_array_t_swigregisterr   r   r   AlignedTableUint8_swigregisterr!  AlignedTableUint16_swigregisterr1!   AlignedTableFloat32_swigregisterrN!  "MaybeOwnedVectorUInt8_swigregisterr!  "MaybeOwnedVectorInt32_swigregisterr!  $MaybeOwnedVectorFloat32_swigregisterr!  r!  r!  r!  r!  MapLong2Long_swigregisterr!  r!  r"  r"  $PythonInterruptCallback_swigregisterr"  r"  r"  r"  r"  r"  r"  r"  r$   r#   r   <module>rp#     sV+   :#/!"[
L$ L
8V 8v , + +N ;#55 <F << + * *= 9<F << + * *= 99 9< ( ' '
 3:& :< ) ( ( 5:& :< ) ( ( 5:& :< ) ( ( 5:& :< ) ( ( 5;6 ;< * ) ), 7;6 ;< * ) ), 7;6 ;< * ) ), 7B& B< 1 0 01D E@ @< / . ./@ A@ @< / . ./@ A@ @< / . ./@ ADF D< 3 2 23H IC6 C< 2 1 12F GEV E< 4 3 34J K;6 ;< * ) ), 7MV M< < ; ;<Z [C6 C< 2 1 12F GJ& J< 9 8 89T UJ& J< 9 8 89T ULF L< ; : :;X YB& B< 1 0 01D EGH=V = , + +N ;.550B>f > - , ,_ =>f > - , ,_ =F2*G\0[SWNY2646))*0/21)*.(6.=F`"37	?//7O&::0*6f 6 % $ $W -00 %DF %DP 3 2 23H I%DF %DP 3 2 23H I/7,.d\Q(C;YTt1	:=4I+80P$H$K"S"+4ZF,Pm$g$T \p5@ >f  >F - , ,_ =&H &HR 7 6 67P Q2321;4?>7@L =6M[^&;;  #%%	 %%	 )) %%	 1!11 $55 &;;  // E%99  /++
= &99 %99 %99  //

!
!

!
!?`v `" . - -.> ?zHF zHz	 # " "5 )?v ?@ . - -.> ?G/ G0 6 5 56N OH 0 H$ 7 6 67P Q7v 7  & % %h /7v 7  & % %h /=X = , + +N ;
=X 
= , + +N ;A8 A" * ) ), 7A8 A" * ) ), 7?x ?4 . - -.> ??x ?$ . - -.> ?)-3jF j 3 2 23H IB3 B 5 4 45L MA A( 0 / /0B CEx E0 . - -.> ?F=U F=R , + +N ;,8 ,8^ ' & &y 1:) : ) ( ( 5:) :. ) ( ( 5:+ :< ) ( ( 5,C6 ,C^ 2 1 12F GGv G 6 5 56N O<9% <9~ ( ' '
 3;: ;$ * ) ), 7Q)= Q @ ? ?@b ct t 8 7 78R SGA G> 6 5 56N OD&keR(8 (8V ' & &y 1b?y b?J . - -.> ??v ?  . - -.> ?
9 
9 ( ' '
 3
:& 
: ) ( ( 5?v ?" . - -.> ?9 9 ( ' '
 3:& : ) ( ( 5z@	 z@z / . ./@ A :D>,C6 C 2 1 12F G}
Ff 
F 5 4 45L M{UV U D C CDj keUV U D C CDj ken@) n@b / . ./@ AWV, WVt 2 1 12F GT T@ ( ' '
 3	b 	b / . ./@ A7v 70 & % %h /<F <  + * *= 9]e0 ]e@ 6 5 56N OJ": J2 9 8 89T UG7 G2 6 5 56N O9 9> ( ' '
 3=Z =. , + +N ;<>f <>~ - , ,_ =->o ->` - , ,_ =C? C& 2 1 12F G(8 (8V ' & &y 18 82 ' & &y 1;? ;2 * ) ), 78 8@ ' & &y 1'G 'GT 6 5 56N OE_ E, 4 3 34J KA A6 0 / /0B CK#3 K : 9 9:V WY@ Y@x / . ./@ Av"2 v 9 8 89T U3:% 3:l ) ( ( 5>k >$ - , ,_ =-E~ -E` & % %h /K6 K& : 9 9:V WC6 C$ 2 1 12F G!J"6 !JH 9 8 89T UJ"> J. 9 8 89T U,A5 ,A^ 0 / /0B CP6n P6f % $ $W -
A) 
A 0 / /0B C;6 ;( * ) ), 7#B% #BL 1 0 01D EC. C& 2 1 12F GE^ E0 4 3 34J K!E3 !EH 4 3 34J KH 6 H< 7 6 67P Q!L$: !LH ; : :;X Y!O'= !OH > = =>^ _Fe FD 5 4 45L MN.> N E D DEl m0F5 0Ff 5 4 45L MI!8 I6 8 7 78R SLF L. 3 2 23H IEBF EBP + * *= 9#A #AL 0 / /0B CDM D( 3 2 23H I"B/ "BJ 1 0 01D E#A. #AL 0 / /0B C!B/ !BH 1 0 01D E(B/ (BV 1 0 01D E%E2 %EP 4 3 34J K6O& 6Or 1 0 01D E1A 1Ah 0 / /0B C5))68 68r ' & &y 1;6 ;* * ) ), 7%>f %>P - , ,_ =
f* 
f 1 0 01D E@@ @@F / . ./@ AeEu' eEP	 & % %h /DB& DBN 1 0 01D E<F <* + * *= 9F48AFEA A> 0 / /0B C<AssE\	?v 	? . - -.> ?	F. 	F 5 4 45L M<.CP>i P>f - , ,_ ="C> "CJ 2 1 12F G&Fh &FR 5 4 45L M=C8 =C@ 2 1 12F G"H "HJ 7 6 67P QH 9 H0 7 6 67P QK#< K2 : 9 9:V WO'@ O6 > = =>^ _R*C R6 A @ @Ad e	h+ 	h 2 1 12F Gf36 f3R " ! !$ '8 8( ' & &y 1rX\BFE FER ' & &y 1<I < + * *= 9:) :" ) ( ( 5:) : ) ( ( 5>i >$ - , ,_ =!=Y !=H , + +N ;;"@07v 7 & % %h /4F 4$ # " "5 )3q 3ql ' & &y 1:U :D , + +N ;A A 0 / /0B C;8 ;B * ) ), 7%@ %@P / . ./@ A>32& 32l !     %OF O& + * *= 90Ou 0Of & % %h /;8 ; * ) ), 79 9" ( ' '
 39 9 ( ' '
 3	<F 	< + * *= 9ak- akH 1 0 01D E'=V '=T , + +N ;@ @8 / . ./@ A5V 5 $ # #F +6f 64 % $ $W -<N$5 << + * *= 9+?( +?\ . - -.> ??} ?, . - -.> ?;> ;: * ) ), 7D/ D 3 2 23H Ih9 h9V ( ' '
 3M>f >* - , ,_ =(:* (:V ) ( ( 5&H. &HR ) ( ( 5L<E L<^ + * *= 9<F <  + * *= 9B[] B[J < ; ;<Z ["M%C "MJ < ; ;<Z ["P(F "PJ ? > >?` a&T,J &TR C B BCh i&W/M &WR F E EFn o)>m )>X - , ,_ =;6 ; * ) ), 7@ @2 / . ./@ AG0 G* 6 5 56N Od* d* 0 / /0B CA* A2 0 / /0B ClMx lM^ . - -.> ??v ?6 . - -.> ?7q(8 7qt ? > >?` aS+L S B A ABf gP(I P ? > >?` aZ2S Z I H HIt uW/P W F E EFn oK5 K> : 9 9:V W1A) 1Ah 0 / /0B CKTw&CHN& ND ) ( ( 5&>k &>R - , ,_ =pN[ pNf , + +N ;)H )HX 7 6 67P QF; F@ 2 1 12F G$;k $;N - , ,_ =C? C: 2 1 12F G >k  >F - , ,_ =C6 C  2 1 12F GI; I@ 2 1 12F G<R <R~ / . ./@ A<^k <^~ 5 4 45L Mq:# q:h ) ( ( 5q@/ q@h / . ./@ A=[/ =4 , + +N ;[<% [<| + * *= 9[B1 [B| 1 0 01D E"@ "@J / . ./@ A:% :6 ) ( ( 5-PU -P` 4 3 34J KE3 E4 4 3 34J KA/ A4 0 / /0B C5V 5$ $ # #F +8 8( ' & &y 12& 2& !     %8 8: ' & &y 1=V =" , + +N ;4N 4. # " "5 )7v 74 & % %h /<F <4 + * *= 9B. B* 1 0 01D E9$ 9 ( ' '
 3=Y =: , + +N ;E- E 4 3 34J K:. :B ) ( ( 5H 3 H 7 6 67P Q =X  =F , + +N ;@ @: / . ./@ AW W@ ( ' '
 3?v ?$ . - -.> ?"Gz "GJ 6 5 56N O(H (HV / . ./@ A>' >* - , ,_ =;6 ;2 * ) ), 79 9 ( ' '
 3>j >6 - , ,_ =>j >< - , ,_ =>j >D - , ,_ =?z ?2 . - -.> ?<J < + * *= 9ZJ Z + * *= 9<J <& + * *= 9;: ;& * ) ), 7<J <& + * *= 9C: C 2 1 12F G>Y >YB ( ' '
 3>e{ >eB . - -.> ?#[* #[L ) ( ( 5#g( #gL / . ./@ A''
,GG +EE ,GG +EE 1876:2.5-487897@-LV L0 $ # #F +00 ** 66 22  $ B B  ::   (( 25(@ (@V / . ./@ A
D- 
D 3 2 23H I
D- 
D 3 2 23H I=V =, , + +N ;">f ">J - , ,_ =
=V 
= , + +N ;Q=V Q=h , + +N ;0N:& :@ ) ( ( 5A A$ 0 / /0B CA A$ 0 / /0B C
C: 
C 2 1 12F G
y!1 
y 8 7 78R SRDF RDj 3 2 23H IRB& RBj 1 0 01D ERDF RDj 3 2 23H IRB& RBj 1 0 01D EYY!@ !@H / . ./@ A!A !AH 0 / /0B C!B& !BH 1 0 01D E,DF ,D^ 3 2 23H I,DF ,D^ 3 2 23H I,Ff ,F^ 5 4 45L M>>99;6 ;& * ) ), 7<10F/ F  5 4 45L M'/88867*}Q  s   Bm& m&	Bm3m2Bm3