o
    ©CiB= ã                   @   s²+  d dl mZ edk redƒ‚esdev rddlmZ nd dlZzd dlZ	W n e
y2   d dl	Z	Y nw dd	„ Zd
d„ Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZe e¡ ejZG dd„ deƒZe e¡ G dd„ deƒZe e¡ G dd„ deƒZe e¡ G dd„ deƒZe e¡ G dd„ deƒZe e¡ G dd„ deƒZe  e¡ G d d!„ d!eƒZ!e "e!¡ G d"d#„ d#eƒZ#e $e#¡ G d$d%„ d%eƒZ%e &e%¡ G d&d'„ d'eƒZ'e (e'¡ G d(d)„ d)eƒZ)e *e)¡ G d*d+„ d+eƒZ+e ,e+¡ G d,d-„ d-eƒZ-e .e-¡ G d.d/„ d/eƒZ/e 0e/¡ G d0d1„ d1eƒZ1e 2e1¡ G d2d3„ d3eƒZ3e 4e3¡ G d4d5„ d5eƒZ5e 6e5¡ G d6d7„ d7eƒZ7e 8e7¡ G d8d9„ d9eƒZ9e :e9¡ G d:d;„ d;eƒZ;e <e;¡ G d<d=„ d=eƒZ=e >e=¡ d>d?„ Z?d@dA„ Z@G dBdC„ dCeƒZAe BeA¡ dDdE„ ZCdFdG„ ZDdHdI„ ZEdJdK„ ZFdLdM„ ZGG dNdO„ dOeƒZHe IeH¡ ejJZJG dPdQ„ dQeƒZKe LeK¡ dRdS„ ZMdTdU„ ZNdVdW„ ZOdXdY„ ZPdZd[„ ZQd\d]„ ZRd^d_„ ZSd`da„ ZTdNdcdd„ZUdedf„ ZVdgdh„ ZWdidj„ ZXdkdl„ ZYdmdn„ ZZdodp„ Z[dqdr„ Z\dsdt„ Z]dudv„ Z^dwdx„ Z_dydz„ Z`d{d|„ Zad}d~„ Zbdd€„ Zcdd‚„ Zddƒd„„ ZedOd…d†„Zfd‡dˆ„ Zgd‰dŠ„ Zhd‹dŒ„ ZiddŽ„ ZjdPd‘d’„Zkd“d”„ Zld•d–„ Zmd—d˜„ Znd™dš„ Zod›dœ„ Zpddž„ ZqdŸd „ Zrd¡d¢„ ZsdQd¤d¥„Ztd¦d§„ Zud¨d©„ Zvdªd«„ Zwd¬d­„ Zxd®d¯„ Zyd°d±„ Zzd²d³„ Z{d´dµ„ Z|d¶d·„ Z}d¸d¹„ Z~dºd»„ Zd¼d½„ Z€d¾d¿„ ZdÀdÁ„ Z‚dÂdÃ„ ZƒdÄdÅ„ Z„dÆdÇ„ Z…dÈdÉ„ Z†dRdÊdË„Z‡dRdÌdÍ„ZˆdSdÎdÏ„Z‰dSdÐdÑ„ZŠdÒdÓ„ Z‹G dÔdÕ„ dÕeƒZŒe eŒ¡ eJjŽZŽdÖd×„ ZdØdÙ„ ZdÚdÛ„ Z‘dÜdÝ„ Z’dÞdß„ Z“dàdá„ Z”dâdã„ Z•dädå„ Z–dædç„ Z—dTdèdé„Z˜dêdë„ Z™ejšZš	 ej›Z›	 ejœZœ	 ejZ	 ejžZž	 ejŸZŸ	 ej Z ej¡Z¡ej¢Z¢	 dìdí„ Z£ej¤Z¤	 ej¥Z¥ej¦Z¦G dîdï„ dïeƒZ§e ¨e§¡ G dðdñ„ dñeƒZ©e ªe©¡ G dòdó„ dóeƒZ«e ¬e«¡ G dôdõ„ dõe«ƒZ­e ®e­¡ G död÷„ d÷e©ƒZ¯e °e¯¡ G dødù„ dùe¯ƒZ±e ²e±¡ G dúdû„ dûe±ƒZ³e ´e³¡ G düdý„ dýe±ƒZµe ¶eµ¡ G dþdÿ„ dÿeµƒZ·e ¸e·¡ G d d„ deƒZ¹e ºe¹¡ G dd„ deƒZ»e ¼e»¡ G dd„ de¹ƒZ½e ¾e½¡ G dd„ de½ƒZ¿e Àe¿¡ G dd	„ d	e¹ƒZÁe ÂeÁ¡ G d
d„ deƒZÃe ÄeÃ¡ G dd„ deÁƒZÅe ÆeÅ¡ dd„ ZÇdQdd„ZÈdd„ ZÉG dd„ deƒZÊe ËeÊ¡ G dd„ deÊƒZÌe ÍeÌ¡ G dd„ deƒZÎe ÏeÎ¡ G dd„ deƒZÐe ÑeÐ¡ G dd„ deƒZÒe ÓeÒ¡ G dd„ deƒZÔe ÕeÔ¡ G d d!„ d!eƒZÖe ×eÖ¡ G d"d#„ d#eƒZØe ÙeØ¡ G d$d%„ d%eÊƒZÚe ÛeÚ¡ G d&d'„ d'eÚƒZÜe ÝeÜ¡ d(d)„ ZÞd*d+„ ZßG d,d-„ d-eÚƒZàe áeà¡ G d.d/„ d/eƒZâe ãeâ¡ G d0d1„ d1eƒZäe åeä¡ G d2d3„ d3eƒZæe çeæ¡ G d4d5„ d5eƒZèe éeè¡ G d6d7„ d7eÚƒZêe ëeê¡ G d8d9„ d9eêƒZìe íeì¡ G d:d;„ d;eêƒZîe ïeî¡ G d<d=„ d=eƒZðe ñeð¡ G d>d?„ d?eðƒZòe óeò¡ G d@dA„ dAeƒZôe õeô¡ G dBdC„ dCeôƒZöe ÷eö¡ G dDdE„ dEeöƒZøe ùeø¡ G dFdG„ dGeöƒZúe ûeú¡ G dHdI„ dIeöƒZüe ýeü¡ G dJdK„ dKeôƒZþe ÿeþ¡ G dLdM„ dMeöƒZ e e ¡ G dNdO„ dOeôƒZe e¡ G dPdQ„ dQeôƒZe e¡ G dRdS„ dSeôƒZe e¡ G dTdU„ dUe§ƒZe 	e¡ G dVdW„ dWe©ƒZ
e e
¡ G dXdY„ dYe©ƒZe e¡ G dZd[„ d[eƒZe e¡ G d\d]„ d]e¯ƒZe e¡ G d^d_„ d_eƒZe e¡ G d`da„ daeƒZe e¡ G dbdc„ dceƒZe e¡ ddde„ Zdfdg„ ZG dhdi„ dieƒZe e¡ G djdk„ dkeƒZe e¡ G dldm„ dme¯ƒZe e¡ G dndo„ doe§ƒZ e !e ¡ G dpdq„ dqeƒZ"e #e"¡ G drds„ dse©ƒZ$e %e$¡ G dtdu„ due$ƒZ&e 'e&¡ G dvdw„ dwe¯ƒZ(e )e(¡ G dxdy„ dye(ƒZ*e +e*¡ G dzd{„ d{e(ƒZ,e -e,¡ G d|d}„ d}e(ƒZ.e /e.¡ G d~d„ de(ƒZ0e 1e0¡ G d€d„ de©ƒZ2e 3e2¡ G d‚dƒ„ dƒe§ƒZ4e 5e4¡ G d„d…„ d…e2ƒZ6e 7e6¡ G d†d‡„ d‡e2ƒZ8e 9e8¡ G dˆd‰„ d‰eƒZ:e ;e:¡ G dŠd‹„ d‹eƒZ<e =e<¡ G dŒd„ de:ƒZ>e ?e>¡ G dŽd„ de<ƒZ@e Ae@¡ G dd‘„ d‘e:ƒZBe CeB¡ G d’d“„ d“e<ƒZDe EeD¡ G d”d•„ d•e:ƒZFe GeF¡ G d–d—„ d—e<ƒZHe IeH¡ d˜d™„ ZJdšd›„ ZKdœd„ ZLG dždŸ„ dŸeƒZMe NeM¡ G d d¡„ d¡eƒZOe PeO¡ G d¢d£„ d£eOƒZQe ReQ¡ G d¤d¥„ d¥eOƒZSe TeS¡ G d¦d§„ d§eSƒZUe VeU¡ G d¨d©„ d©eSƒZWe XeW¡ G dªd«„ d«eSƒZYe ZeY¡ G d¬d­„ d­eSƒZ[e \e[¡ G d®d¯„ d¯eSƒZ]e ^e]¡ G d°d±„ d±eƒZ_e `e_¡ d²d³„ Zad´dµ„ Zbd¶d·„ Zcd¸d¹„ ZdG dºd»„ d»eOƒZee fee¡ d¼d½„ Zgd¾d¿„ ZhdÀdÁ„ ZiG dÂdÃ„ dÃeƒZje kej¡ G dÄdÅ„ dÅeƒZle mel¡ G dÆdÇ„ dÇeƒZne oen¡ G dÈdÉ„ dÉe§ƒZpe qep¡ G dÊdË„ dËenƒZre ser¡ G dÌdÍ„ dÍe©erƒZte uet¡ G dÎdÏ„ dÏeƒZve wev¡ G dÐdÑ„ dÑeƒZxe yex¡ dÒdÓ„ ZzdÔdÕ„ Z{dÖd×„ Z|dØdÙ„ Z}dÚdÛ„ Z~dÜdÝ„ ZG dÞdß„ dßeƒZ€e e€¡ dàdá„ Z‚dâdã„ ZƒdUdädå„Z„dUdædç„Z…dèdé„ Z†dRdêdë„Z‡G dìdí„ díeÊƒZˆe ‰eˆ¡ G dîdï„ dïe¯ƒZŠe ‹eŠ¡ G dðdñ„ dñetƒZŒe eŒ¡ G dòdó„ dóetƒZŽe eŽ¡ G dôdõ„ dõetƒZe ‘e¡ G död÷„ d÷eƒZ’e “e’¡ G dødù„ dùeƒZ”e •e”¡ G dúdû„ dûeƒZ–e —e–¡ G düdý„ dýeƒZ˜e ™e˜¡ G dþdÿ„ dÿe§ƒZše ›eš¡ G d d„ deƒZœe eœ¡ dd„ ZžG dd„ deƒZŸe  eŸ¡ G dd„ deƒZ¡e ¢e¡¡ G dd	„ d	e©ƒZ£e ¤e£¡ G d
d„ de£ƒZ¥e ¦e¥¡ G dd„ de£ƒZ§e ¨e§¡ G dd„ de£ƒZ©e ªe©¡ G dd„ de£ƒZ«e ¬e«¡ dd„ Z­dd„ Z®G dd„ deƒZ¯e °e¯¡ G dd„ deƒZ±e ²e±¡ G dd„ deƒZ³e ´e³¡ G dd„ de©ƒZµe ¶eµ¡ G dd„ deµƒZ·e ¸e·¡ G d d!„ d!etƒZ¹e ºe¹¡ G d"d#„ d#e¹ƒZ»e ¼e»¡ d$d%„ Z½G d&d'„ d'eƒZ¾e ¿e¾¡ G d(d)„ d)e©ƒZÀe ÁeÀ¡ G d*d+„ d+eÀƒZÂe ÃeÂ¡ G d,d-„ d-eÀƒZÄe ÅeÄ¡ G d.d/„ d/eÀƒZÆe ÇeÆ¡ G d0d1„ d1eƒZÈe ÉeÈ¡ G d2d3„ d3eOƒZÊe ËeÊ¡ G d4d5„ d5eƒZÌe ÍeÌ¡ G d6d7„ d7eƒZÎe ÏeÎ¡ G d8d9„ d9eƒZÐe ÑeÐ¡ G d:d;„ d;eƒZÒe ÓeÒ¡ G d<d=„ d=eÌeÎƒZÔe ÕeÔ¡ G d>d?„ d?eÎƒZÖe ×eÖ¡ G d@dA„ dAeÔƒZØe ÙeØ¡ G dBdC„ dCe©ƒZÚe ÛeÚ¡ G dDdE„ dEepƒZÜe ÝeÜ¡ G dFdG„ dGetƒZÞe ßeÞ¡ dHdI„ ZàG dJdK„ dKeƒZáe âeá¡ G dLdM„ dMeÞƒZãe äeã¡ G dNdO„ dOe¯ƒZåe æeå¡ G dPdQ„ dQe©ƒZçe èeç¡ G dRdS„ dSeƒZée êeé¡ G dTdU„ dUeçƒZëe ìeë¡ G dVdW„ dWeëƒZíe îeí¡ G dXdY„ dYeëƒZïe ðeï¡ G dZd[„ d[eëƒZñe òeñ¡ G d\d]„ d]eëƒZóe ôeó¡ G d^d_„ d_eçƒZõe öeõ¡ G d`da„ daetƒZ÷e øe÷¡ G dbdc„ dceƒZùe úeù¡ G ddde„ dee÷ƒZûe üeû¡ G dfdg„ dgeûƒZýe þeý¡ G dhdi„ dieûƒZÿe  eÿ¡ G djdk„ dkeûƒZe e¡ G dldm„ dmeûƒZe e¡ G dndo„ doe÷ƒZe e¡ dUdpdq„ZdUdrds„ZdUdtdu„Z	dvdw„ Z
dxdy„ ZG dzd{„ d{eƒZe e¡ G d|d}„ d}eƒZe e¡ G d~d„ deƒZe e¡ G d€d„ deƒZe e¡ G d‚dƒ„ dƒeƒZe e¡ G d„d…„ d…eƒZe e¡ G d†d‡„ d‡eƒZe e¡ G dˆd‰„ d‰eƒZe e¡ G dŠd‹„ d‹eƒZe e¡ G dŒd„ de©ƒZe e¡ G dŽd„ deƒZ e !e ¡ G dd‘„ d‘eƒZ"e #e"¡ G d’d“„ d“e ƒZ$e %e$¡ G d”d•„ d•e"enƒZ&e 'e&¡ G d–d—„ d—eƒZ(e )e(¡ G d˜d™„ d™e ƒZ*e +e*¡ G dšd›„ d›e©ƒZ,e -e,¡ G dœd„ de©ƒZ.e /e.¡ G dždŸ„ dŸe©ƒZ0e 1e0¡ G d d¡„ d¡eƒZ2e 3e2¡ G d¢d£„ d£e0ƒZ4e 5e4¡ G d¤d¥„ d¥e2ƒZ6e 7e6¡ G d¦d§„ d§e©ƒZ8e 9e8¡ G d¨d©„ d©e8ƒZ:e ;e:¡ G dªd«„ d«e8ƒZ<e =e<¡ G d¬d­„ d­eƒZ>e ?e>¡ G d®d¯„ d¯eƒZ@e Ae@¡ G d°d±„ d±eƒZBe CeB¡ G d²d³„ d³e@ƒZDe EeD¡ dNd´dµ„ZFG d¶d·„ d·eƒZGe HeG¡ d¸d¹„ ZIdºd»„ ZJd¼d½„ ZKd¾d¿„ ZLG dÀdÁ„ dÁeƒZMe NeM¡ G dÂdÃ„ dÃeƒZOe PeO¡ G dÄdÅ„ dÅeOƒZQe ReQ¡ G dÆdÇ„ dÇeOƒZSe TeS¡ G dÈdÉ„ dÉeOƒZUe VeU¡ G dÊdË„ dËeOƒZWe XeW¡ G dÌdÍ„ dÍeOƒZYe ZeY¡ G dÎdÏ„ dÏeOƒZ[e \e[¡ G dÐdÑ„ dÑeOƒZ]e ^e]¡ G dÒdÓ„ dÓeOƒZ_e `e_¡ G dÔdÕ„ dÕeOƒZae bea¡ ejcZcejdZdejeZeejfZfejgZgdÖd×„ ZhdØdÙ„ ZidÚdÛ„ ZjdÜdÝ„ ZkdÞdß„ Zldàdá„ Zmdâdã„ Zndädå„ Zodædç„ Zpdèdé„ Zqdêdë„ Zrdìdí„ Zsdîdï„ Ztdðdñ„ Zudòdó„ ZvdTdôdõ„Zwdöd÷„ ZxG dødù„ dùeƒZye zey¡ eJj{Z{eJj|Z|eJj}Z}eJj~Z~eJjZdúdû„ Z€G düdý„ dýeƒZe ‚e¡ G dþdÿ„ dÿeƒZƒe „eƒ¡ G d d„ deƒZ…e †e…¡ G dd„ deƒZ‡e ˆe‡¡ G dd„ deƒZ‰e Še‰¡ G dd„ deƒZ‹e Œe‹¡ G dd	„ d	eƒZe Že¡ d
d„ Zdd„ ZG dd„ deƒZ‘e ’e‘¡ G dd„ de<ƒZ“e ”e“¡ G dd„ de:ƒZ•e –e•¡ G dd„ deOƒZ—e ˜e—¡ dd„ Z™dd„ ZšG dd„ deƒZ›e œe›¡ G dd„ deƒZe že¡ G dd„ deƒZŸe  eŸ¡ G d d!„ d!eƒZ¡e ¢e¡¡ d"d#„ Z£d$d%„ Z¤G d&d'„ d'eƒZ¥e ¦e¥¡ d(d)„ Z§G d*d+„ d+eƒZ¨e ©e¨¡ d,d-„ ZªG d.d/„ d/eƒZ«e ¬e«¡ d0d1„ Z­d2d3„ Z®d4d5„ Z¯d6d7„ Z°d8d9„ Z±d:d;„ Z²d<d=„ Z³d>d?„ Z´d@dA„ ZµdBdC„ Z¶dDdE„ Z·dFdG„ Z¸dHdI„ Z¹G dJdK„ dKeƒZºe »eº¡ dLdM„ Z¼dS (V  é    )Úversion_info)é   é   r   zPython 2.7 or later requiredÚ.é   )Ú
_swigfaissNc                 C   sB   z	d| j  ¡  }W n tjy   d}Y nw d| jj| jj|f S )Nz	proxy of Ú z<%s.%s; %s >)ÚthisÚ__repr__Ú__builtin__Ú	ExceptionÚ	__class__Ú
__module__Ú__name__)ÚselfÚstrthis© r   úg/var/www/html/fyndo/python/python_agents/rag_suite/venv/lib/python3.10/site-packages/faiss/swigfaiss.pyÚ
_swig_repr   s   ÿr   c                    ó   ‡ fdd„}|S )Nc                    sj   |dkr| j  |¡ d S |dkrˆ | ||ƒ d S t| |ƒr/ttt| ƒ|ƒtƒr/ˆ | ||ƒ d S td|  ƒ‚)NÚthisownr	   z(You cannot add instance attributes to %s)r	   ÚownÚhasattrÚ
isinstanceÚgetattrÚtypeÚpropertyÚAttributeError)r   ÚnameÚvalue©Úsetr   r   Úset_instance_attr   s   zE_swig_setattr_nondynamic_instance_variable.<locals>.set_instance_attrr   )r!   r"   r   r    r   Ú*_swig_setattr_nondynamic_instance_variable   s   	r#   c                    r   )Nc                    s6   t | |ƒrtt| |ƒtƒsˆ | ||ƒ d S td|  ƒ‚)Nz%You cannot add class attributes to %s)r   r   r   r   r   )Úclsr   r   r    r   r   Úset_class_attr,   s   z?_swig_setattr_nondynamic_class_variable.<locals>.set_class_attrr   )r!   r%   r   r    r   Ú'_swig_setattr_nondynamic_class_variable+   s   r&   c                    r   )zlClass decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclassc                    s   ˆ | j | j| j ¡ ƒS ©N)r   Ú	__bases__Ú__dict__Úcopy)r$   ©Ú	metaclassr   r   Úwrapper6   ó   z$_swig_add_metaclass.<locals>.wrapperr   )r,   r-   r   r+   r   Ú_swig_add_metaclass4   s   r/   c                   @   s   e Zd ZdZeejƒZdS )Ú_SwigNonDynamicMetazKMeta class to enforce nondynamic attributes (no new attributes) for a classN)r   r   Ú__qualname__Ú__doc__r&   r   Ú__setattr__r   r   r   r   r0   ;   s    r0   c                   @   sÀ   e Zd Zedd„ dd„ ddZdd„ ZeZej	Z
dd	„ Zd,dd„Zd,dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+S )-ÚSwigPyIteratorc                 C   ó
   | j  ¡ S r'   ©r	   r   ©Úxr   r   r   Ú<lambda>A   ó   
 zSwigPyIterator.<lambda>c                 C   ó   | j  |¡S r'   r6   ©r8   Úvr   r   r   r9   A   ó    úThe membership flag©Údocc                 O   ó   t dƒ‚©Nz*No constructor defined - class is abstract©r   ©r   ÚargsÚkwargsr   r   r   Ú__init__C   ó   zSwigPyIterator.__init__c                 C   ó
   t  | ¡S r'   )r   ÚSwigPyIterator_value©r   r   r   r   r   H   ó   
zSwigPyIterator.valuer   c                 C   ó   t  | |¡S r'   )r   ÚSwigPyIterator_incr©r   Únr   r   r   ÚincrK   ó   zSwigPyIterator.incrc                 C   rN   r'   )r   ÚSwigPyIterator_decrrP   r   r   r   ÚdecrN   rS   zSwigPyIterator.decrc                 C   rN   r'   )r   ÚSwigPyIterator_distance©r   r8   r   r   r   ÚdistanceQ   rS   zSwigPyIterator.distancec                 C   rN   r'   )r   ÚSwigPyIterator_equalrW   r   r   r   ÚequalT   rS   zSwigPyIterator.equalc                 C   rJ   r'   )r   ÚSwigPyIterator_copyrL   r   r   r   r*   W   rM   zSwigPyIterator.copyc                 C   rJ   r'   )r   ÚSwigPyIterator_nextrL   r   r   r   ÚnextZ   rM   zSwigPyIterator.nextc                 C   rJ   r'   )r   ÚSwigPyIterator___next__rL   r   r   r   Ú__next__]   rM   zSwigPyIterator.__next__c                 C   rJ   r'   )r   ÚSwigPyIterator_previousrL   r   r   r   Úprevious`   rM   zSwigPyIterator.previousc                 C   rN   r'   )r   ÚSwigPyIterator_advancerP   r   r   r   Úadvancec   rS   zSwigPyIterator.advancec                 C   rN   r'   )r   ÚSwigPyIterator___eq__rW   r   r   r   Ú__eq__f   rS   zSwigPyIterator.__eq__c                 C   rN   r'   )r   ÚSwigPyIterator___ne__rW   r   r   r   Ú__ne__i   rS   zSwigPyIterator.__ne__c                 C   rN   r'   )r   ÚSwigPyIterator___iadd__rP   r   r   r   Ú__iadd__l   rS   zSwigPyIterator.__iadd__c                 C   rN   r'   )r   ÚSwigPyIterator___isub__rP   r   r   r   Ú__isub__o   rS   zSwigPyIterator.__isub__c                 C   rN   r'   )r   ÚSwigPyIterator___add__rP   r   r   r   Ú__add__r   rS   zSwigPyIterator.__add__c                 G   ó   t j| g|¢R Ž S r'   )r   ÚSwigPyIterator___sub__©r   rF   r   r   r   Ú__sub__u   ó   zSwigPyIterator.__sub__c                 C   s   | S r'   r   rL   r   r   r   Ú__iter__w   s   zSwigPyIterator.__iter__N©r   )r   r   r1   r   r   rH   r   r
   r   Údelete_SwigPyIteratorÚ__swig_destroy__r   rR   rU   rX   rZ   r*   r]   r_   ra   rc   re   rg   ri   rk   rm   rq   rs   r   r   r   r   r4   @   s,    

r4   c                   @   ól   e Zd Zedd„ dd„ ddZeZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚFloat32Vectorc                 C   r5   r'   r6   r7   r   r   r   r9      r:   zFloat32Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9      r>   r?   r@   c                 C   ó   t  | t  ¡ ¡ d S r'   )r   ÚFloat32Vector_swiginitÚnew_Float32VectorrL   r   r   r   rH   ‚   ó   zFloat32Vector.__init__c                 C   rN   r'   )r   ÚFloat32Vector_push_back©r   Úarg2r   r   r   Ú	push_back…   rS   zFloat32Vector.push_backc                 C   rJ   r'   )r   ÚFloat32Vector_clearrL   r   r   r   Úclearˆ   rM   zFloat32Vector.clearc                 C   rJ   r'   )r   ÚFloat32Vector_datarL   r   r   r   Údata‹   rM   zFloat32Vector.datac                 C   rJ   r'   )r   ÚFloat32Vector_sizerL   r   r   r   ÚsizeŽ   rM   zFloat32Vector.sizec                 C   rN   r'   )r   ÚFloat32Vector_atrP   r   r   r   Úat‘   rS   zFloat32Vector.atc                 C   rN   r'   )r   ÚFloat32Vector_resizerP   r   r   r   Úresize”   rS   zFloat32Vector.resizec                 C   rN   r'   )r   ÚFloat32Vector_swap©r   Úotherr   r   r   Úswap—   rS   zFloat32Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Float32Vectorrv   r   r   r   r   rx   ~   ó    
rx   c                   @   rw   )ÚFloat64Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   Ÿ   r:   zFloat64Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ÿ   r>   r?   r@   c                 C   ry   r'   )r   ÚFloat64Vector_swiginitÚnew_Float64VectorrL   r   r   r   rH   ¢   r|   zFloat64Vector.__init__c                 C   rN   r'   )r   ÚFloat64Vector_push_backr~   r   r   r   r€   ¥   rS   zFloat64Vector.push_backc                 C   rJ   r'   )r   ÚFloat64Vector_clearrL   r   r   r   r‚   ¨   rM   zFloat64Vector.clearc                 C   rJ   r'   )r   ÚFloat64Vector_datarL   r   r   r   r„   «   rM   zFloat64Vector.datac                 C   rJ   r'   )r   ÚFloat64Vector_sizerL   r   r   r   r†   ®   rM   zFloat64Vector.sizec                 C   rN   r'   )r   ÚFloat64Vector_atrP   r   r   r   rˆ   ±   rS   zFloat64Vector.atc                 C   rN   r'   )r   ÚFloat64Vector_resizerP   r   r   r   rŠ   ´   rS   zFloat64Vector.resizec                 C   rN   r'   )r   ÚFloat64Vector_swaprŒ   r   r   r   rŽ   ·   rS   zFloat64Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Float64Vectorrv   r   r   r   r   r‘   ž   r   r‘   c                   @   rw   )Ú
Int8Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   ¿   r:   zInt8Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¿   r>   r?   r@   c                 C   ry   r'   )r   ÚInt8Vector_swiginitÚnew_Int8VectorrL   r   r   r   rH   Â   r|   zInt8Vector.__init__c                 C   rN   r'   )r   ÚInt8Vector_push_backr~   r   r   r   r€   Å   rS   zInt8Vector.push_backc                 C   rJ   r'   )r   ÚInt8Vector_clearrL   r   r   r   r‚   È   rM   zInt8Vector.clearc                 C   rJ   r'   )r   ÚInt8Vector_datarL   r   r   r   r„   Ë   rM   zInt8Vector.datac                 C   rJ   r'   )r   ÚInt8Vector_sizerL   r   r   r   r†   Î   rM   zInt8Vector.sizec                 C   rN   r'   )r   ÚInt8Vector_atrP   r   r   r   rˆ   Ñ   rS   zInt8Vector.atc                 C   rN   r'   )r   ÚInt8Vector_resizerP   r   r   r   rŠ   Ô   rS   zInt8Vector.resizec                 C   rN   r'   )r   ÚInt8Vector_swaprŒ   r   r   r   rŽ   ×   rS   zInt8Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int8Vectorrv   r   r   r   r   rœ   ¾   r   rœ   c                   @   rw   )ÚInt16Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   ß   r:   zInt16Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ß   r>   r?   r@   c                 C   ry   r'   )r   ÚInt16Vector_swiginitÚnew_Int16VectorrL   r   r   r   rH   â   r|   zInt16Vector.__init__c                 C   rN   r'   )r   ÚInt16Vector_push_backr~   r   r   r   r€   å   rS   zInt16Vector.push_backc                 C   rJ   r'   )r   ÚInt16Vector_clearrL   r   r   r   r‚   è   rM   zInt16Vector.clearc                 C   rJ   r'   )r   ÚInt16Vector_datarL   r   r   r   r„   ë   rM   zInt16Vector.datac                 C   rJ   r'   )r   ÚInt16Vector_sizerL   r   r   r   r†   î   rM   zInt16Vector.sizec                 C   rN   r'   )r   ÚInt16Vector_atrP   r   r   r   rˆ   ñ   rS   zInt16Vector.atc                 C   rN   r'   )r   ÚInt16Vector_resizerP   r   r   r   rŠ   ô   rS   zInt16Vector.resizec                 C   rN   r'   )r   ÚInt16Vector_swaprŒ   r   r   r   rŽ   ÷   rS   zInt16Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int16Vectorrv   r   r   r   r   r§   Þ   r   r§   c                   @   rw   )ÚInt32Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   ÿ   r:   zInt32Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ÿ   r>   r?   r@   c                 C   ry   r'   )r   ÚInt32Vector_swiginitÚnew_Int32VectorrL   r   r   r   rH     r|   zInt32Vector.__init__c                 C   rN   r'   )r   ÚInt32Vector_push_backr~   r   r   r   r€     rS   zInt32Vector.push_backc                 C   rJ   r'   )r   ÚInt32Vector_clearrL   r   r   r   r‚     rM   zInt32Vector.clearc                 C   rJ   r'   )r   ÚInt32Vector_datarL   r   r   r   r„     rM   zInt32Vector.datac                 C   rJ   r'   )r   ÚInt32Vector_sizerL   r   r   r   r†     rM   zInt32Vector.sizec                 C   rN   r'   )r   ÚInt32Vector_atrP   r   r   r   rˆ     rS   zInt32Vector.atc                 C   rN   r'   )r   ÚInt32Vector_resizerP   r   r   r   rŠ     rS   zInt32Vector.resizec                 C   rN   r'   )r   ÚInt32Vector_swaprŒ   r   r   r   rŽ     rS   zInt32Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int32Vectorrv   r   r   r   r   r²   þ   r   r²   c                   @   rw   )ÚInt64Vectorc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zInt64Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   ry   r'   )r   ÚInt64Vector_swiginitÚnew_Int64VectorrL   r   r   r   rH   "  r|   zInt64Vector.__init__c                 C   rN   r'   )r   ÚInt64Vector_push_backr~   r   r   r   r€   %  rS   zInt64Vector.push_backc                 C   rJ   r'   )r   ÚInt64Vector_clearrL   r   r   r   r‚   (  rM   zInt64Vector.clearc                 C   rJ   r'   )r   ÚInt64Vector_datarL   r   r   r   r„   +  rM   zInt64Vector.datac                 C   rJ   r'   )r   ÚInt64Vector_sizerL   r   r   r   r†   .  rM   zInt64Vector.sizec                 C   rN   r'   )r   ÚInt64Vector_atrP   r   r   r   rˆ   1  rS   zInt64Vector.atc                 C   rN   r'   )r   ÚInt64Vector_resizerP   r   r   r   rŠ   4  rS   zInt64Vector.resizec                 C   rN   r'   )r   ÚInt64Vector_swaprŒ   r   r   r   rŽ   7  rS   zInt64Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int64Vectorrv   r   r   r   r   r½     r   r½   c                   @   rw   )ÚUInt8Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   ?  r:   zUInt8Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ?  r>   r?   r@   c                 C   ry   r'   )r   ÚUInt8Vector_swiginitÚnew_UInt8VectorrL   r   r   r   rH   B  r|   zUInt8Vector.__init__c                 C   rN   r'   )r   ÚUInt8Vector_push_backr~   r   r   r   r€   E  rS   zUInt8Vector.push_backc                 C   rJ   r'   )r   ÚUInt8Vector_clearrL   r   r   r   r‚   H  rM   zUInt8Vector.clearc                 C   rJ   r'   )r   ÚUInt8Vector_datarL   r   r   r   r„   K  rM   zUInt8Vector.datac                 C   rJ   r'   )r   ÚUInt8Vector_sizerL   r   r   r   r†   N  rM   zUInt8Vector.sizec                 C   rN   r'   )r   ÚUInt8Vector_atrP   r   r   r   rˆ   Q  rS   zUInt8Vector.atc                 C   rN   r'   )r   ÚUInt8Vector_resizerP   r   r   r   rŠ   T  rS   zUInt8Vector.resizec                 C   rN   r'   )r   ÚUInt8Vector_swaprŒ   r   r   r   rŽ   W  rS   zUInt8Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_UInt8Vectorrv   r   r   r   r   rÈ   >  r   rÈ   c                   @   rw   )ÚUInt16Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   _  r:   zUInt16Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   _  r>   r?   r@   c                 C   ry   r'   )r   ÚUInt16Vector_swiginitÚnew_UInt16VectorrL   r   r   r   rH   b  r|   zUInt16Vector.__init__c                 C   rN   r'   )r   ÚUInt16Vector_push_backr~   r   r   r   r€   e  rS   zUInt16Vector.push_backc                 C   rJ   r'   )r   ÚUInt16Vector_clearrL   r   r   r   r‚   h  rM   zUInt16Vector.clearc                 C   rJ   r'   )r   ÚUInt16Vector_datarL   r   r   r   r„   k  rM   zUInt16Vector.datac                 C   rJ   r'   )r   ÚUInt16Vector_sizerL   r   r   r   r†   n  rM   zUInt16Vector.sizec                 C   rN   r'   )r   ÚUInt16Vector_atrP   r   r   r   rˆ   q  rS   zUInt16Vector.atc                 C   rN   r'   )r   ÚUInt16Vector_resizerP   r   r   r   rŠ   t  rS   zUInt16Vector.resizec                 C   rN   r'   )r   ÚUInt16Vector_swaprŒ   r   r   r   rŽ   w  rS   zUInt16Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_UInt16Vectorrv   r   r   r   r   rÓ   ^  r   rÓ   c                   @   rw   )ÚUInt32Vectorc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zUInt32Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   ry   r'   )r   ÚUInt32Vector_swiginitÚnew_UInt32VectorrL   r   r   r   rH   ‚  r|   zUInt32Vector.__init__c                 C   rN   r'   )r   ÚUInt32Vector_push_backr~   r   r   r   r€   …  rS   zUInt32Vector.push_backc                 C   rJ   r'   )r   ÚUInt32Vector_clearrL   r   r   r   r‚   ˆ  rM   zUInt32Vector.clearc                 C   rJ   r'   )r   ÚUInt32Vector_datarL   r   r   r   r„   ‹  rM   zUInt32Vector.datac                 C   rJ   r'   )r   ÚUInt32Vector_sizerL   r   r   r   r†   Ž  rM   zUInt32Vector.sizec                 C   rN   r'   )r   ÚUInt32Vector_atrP   r   r   r   rˆ   ‘  rS   zUInt32Vector.atc                 C   rN   r'   )r   ÚUInt32Vector_resizerP   r   r   r   rŠ   ”  rS   zUInt32Vector.resizec                 C   rN   r'   )r   ÚUInt32Vector_swaprŒ   r   r   r   rŽ   —  rS   zUInt32Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_UInt32Vectorrv   r   r   r   r   rÞ   ~  r   rÞ   c                   @   rw   )ÚUInt64Vectorc                 C   r5   r'   r6   r7   r   r   r   r9   Ÿ  r:   zUInt64Vector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ÿ  r>   r?   r@   c                 C   ry   r'   )r   ÚUInt64Vector_swiginitÚnew_UInt64VectorrL   r   r   r   rH   ¢  r|   zUInt64Vector.__init__c                 C   rN   r'   )r   ÚUInt64Vector_push_backr~   r   r   r   r€   ¥  rS   zUInt64Vector.push_backc                 C   rJ   r'   )r   ÚUInt64Vector_clearrL   r   r   r   r‚   ¨  rM   zUInt64Vector.clearc                 C   rJ   r'   )r   ÚUInt64Vector_datarL   r   r   r   r„   «  rM   zUInt64Vector.datac                 C   rJ   r'   )r   ÚUInt64Vector_sizerL   r   r   r   r†   ®  rM   zUInt64Vector.sizec                 C   rN   r'   )r   ÚUInt64Vector_atrP   r   r   r   rˆ   ±  rS   zUInt64Vector.atc                 C   rN   r'   )r   ÚUInt64Vector_resizerP   r   r   r   rŠ   ´  rS   zUInt64Vector.resizec                 C   rN   r'   )r   ÚUInt64Vector_swaprŒ   r   r   r   rŽ   ·  rS   zUInt64Vector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_UInt64Vectorrv   r   r   r   r   ré   ž  r   ré   c                   @   rw   )ÚFloat32VectorVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ¿  r:   zFloat32VectorVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¿  r>   r?   r@   c                 C   ry   r'   )r   ÚFloat32VectorVector_swiginitÚnew_Float32VectorVectorrL   r   r   r   rH   Â  r|   zFloat32VectorVector.__init__c                 C   rN   r'   )r   ÚFloat32VectorVector_push_backr~   r   r   r   r€   Å  rS   zFloat32VectorVector.push_backc                 C   rJ   r'   )r   ÚFloat32VectorVector_clearrL   r   r   r   r‚   È  rM   zFloat32VectorVector.clearc                 C   rJ   r'   )r   ÚFloat32VectorVector_datarL   r   r   r   r„   Ë  rM   zFloat32VectorVector.datac                 C   rJ   r'   )r   ÚFloat32VectorVector_sizerL   r   r   r   r†   Î  rM   zFloat32VectorVector.sizec                 C   rN   r'   )r   ÚFloat32VectorVector_atrP   r   r   r   rˆ   Ñ  rS   zFloat32VectorVector.atc                 C   rN   r'   )r   ÚFloat32VectorVector_resizerP   r   r   r   rŠ   Ô  rS   zFloat32VectorVector.resizec                 C   rN   r'   )r   ÚFloat32VectorVector_swaprŒ   r   r   r   rŽ   ×  rS   zFloat32VectorVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Float32VectorVectorrv   r   r   r   r   rô   ¾  r   rô   c                   @   rw   )ÚUInt8VectorVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ß  r:   zUInt8VectorVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ß  r>   r?   r@   c                 C   ry   r'   )r   ÚUInt8VectorVector_swiginitÚnew_UInt8VectorVectorrL   r   r   r   rH   â  r|   zUInt8VectorVector.__init__c                 C   rN   r'   )r   ÚUInt8VectorVector_push_backr~   r   r   r   r€   å  rS   zUInt8VectorVector.push_backc                 C   rJ   r'   )r   ÚUInt8VectorVector_clearrL   r   r   r   r‚   è  rM   zUInt8VectorVector.clearc                 C   rJ   r'   )r   ÚUInt8VectorVector_datarL   r   r   r   r„   ë  rM   zUInt8VectorVector.datac                 C   rJ   r'   )r   ÚUInt8VectorVector_sizerL   r   r   r   r†   î  rM   zUInt8VectorVector.sizec                 C   rN   r'   )r   ÚUInt8VectorVector_atrP   r   r   r   rˆ   ñ  rS   zUInt8VectorVector.atc                 C   rN   r'   )r   ÚUInt8VectorVector_resizerP   r   r   r   rŠ   ô  rS   zUInt8VectorVector.resizec                 C   rN   r'   )r   ÚUInt8VectorVector_swaprŒ   r   r   r   rŽ   ÷  rS   zUInt8VectorVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_UInt8VectorVectorrv   r   r   r   r   rÿ   Þ  r   rÿ   c                   @   rw   )ÚInt32VectorVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ÿ  r:   zInt32VectorVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ÿ  r>   r?   r@   c                 C   ry   r'   )r   ÚInt32VectorVector_swiginitÚnew_Int32VectorVectorrL   r   r   r   rH     r|   zInt32VectorVector.__init__c                 C   rN   r'   )r   ÚInt32VectorVector_push_backr~   r   r   r   r€     rS   zInt32VectorVector.push_backc                 C   rJ   r'   )r   ÚInt32VectorVector_clearrL   r   r   r   r‚     rM   zInt32VectorVector.clearc                 C   rJ   r'   )r   ÚInt32VectorVector_datarL   r   r   r   r„     rM   zInt32VectorVector.datac                 C   rJ   r'   )r   ÚInt32VectorVector_sizerL   r   r   r   r†     rM   zInt32VectorVector.sizec                 C   rN   r'   )r   ÚInt32VectorVector_atrP   r   r   r   rˆ     rS   zInt32VectorVector.atc                 C   rN   r'   )r   ÚInt32VectorVector_resizerP   r   r   r   rŠ     rS   zInt32VectorVector.resizec                 C   rN   r'   )r   ÚInt32VectorVector_swaprŒ   r   r   r   rŽ     rS   zInt32VectorVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int32VectorVectorrv   r   r   r   r   r
  þ  r   r
  c                   @   rw   )ÚInt64VectorVectorc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zInt64VectorVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   ry   r'   )r   ÚInt64VectorVector_swiginitÚnew_Int64VectorVectorrL   r   r   r   rH   "  r|   zInt64VectorVector.__init__c                 C   rN   r'   )r   ÚInt64VectorVector_push_backr~   r   r   r   r€   %  rS   zInt64VectorVector.push_backc                 C   rJ   r'   )r   ÚInt64VectorVector_clearrL   r   r   r   r‚   (  rM   zInt64VectorVector.clearc                 C   rJ   r'   )r   ÚInt64VectorVector_datarL   r   r   r   r„   +  rM   zInt64VectorVector.datac                 C   rJ   r'   )r   ÚInt64VectorVector_sizerL   r   r   r   r†   .  rM   zInt64VectorVector.sizec                 C   rN   r'   )r   ÚInt64VectorVector_atrP   r   r   r   rˆ   1  rS   zInt64VectorVector.atc                 C   rN   r'   )r   ÚInt64VectorVector_resizerP   r   r   r   rŠ   4  rS   zInt64VectorVector.resizec                 C   rN   r'   )r   ÚInt64VectorVector_swaprŒ   r   r   r   rŽ   7  rS   zInt64VectorVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_Int64VectorVectorrv   r   r   r   r   r    r   r  c                   @   rw   )ÚVectorTransformVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ?  r:   zVectorTransformVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ?  r>   r?   r@   c                 C   ry   r'   )r   ÚVectorTransformVector_swiginitÚnew_VectorTransformVectorrL   r   r   r   rH   B  r|   zVectorTransformVector.__init__c                 C   rN   r'   )r   ÚVectorTransformVector_push_backr~   r   r   r   r€   E  rS   zVectorTransformVector.push_backc                 C   rJ   r'   )r   ÚVectorTransformVector_clearrL   r   r   r   r‚   H  rM   zVectorTransformVector.clearc                 C   rJ   r'   )r   ÚVectorTransformVector_datarL   r   r   r   r„   K  rM   zVectorTransformVector.datac                 C   rJ   r'   )r   ÚVectorTransformVector_sizerL   r   r   r   r†   N  rM   zVectorTransformVector.sizec                 C   rN   r'   )r   ÚVectorTransformVector_atrP   r   r   r   rˆ   Q  rS   zVectorTransformVector.atc                 C   rN   r'   )r   ÚVectorTransformVector_resizerP   r   r   r   rŠ   T  rS   zVectorTransformVector.resizec                 C   rN   r'   )r   ÚVectorTransformVector_swaprŒ   r   r   r   rŽ   W  rS   zVectorTransformVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_VectorTransformVectorrv   r   r   r   r   r   >  r   r   c                   @   rw   )ÚOperatingPointVectorc                 C   r5   r'   r6   r7   r   r   r   r9   _  r:   zOperatingPointVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   _  r>   r?   r@   c                 C   ry   r'   )r   ÚOperatingPointVector_swiginitÚnew_OperatingPointVectorrL   r   r   r   rH   b  r|   zOperatingPointVector.__init__c                 C   rN   r'   )r   ÚOperatingPointVector_push_backr~   r   r   r   r€   e  rS   zOperatingPointVector.push_backc                 C   rJ   r'   )r   ÚOperatingPointVector_clearrL   r   r   r   r‚   h  rM   zOperatingPointVector.clearc                 C   rJ   r'   )r   ÚOperatingPointVector_datarL   r   r   r   r„   k  rM   zOperatingPointVector.datac                 C   rJ   r'   )r   ÚOperatingPointVector_sizerL   r   r   r   r†   n  rM   zOperatingPointVector.sizec                 C   rN   r'   )r   ÚOperatingPointVector_atrP   r   r   r   rˆ   q  rS   zOperatingPointVector.atc                 C   rN   r'   )r   ÚOperatingPointVector_resizerP   r   r   r   rŠ   t  rS   zOperatingPointVector.resizec                 C   rN   r'   )r   ÚOperatingPointVector_swaprŒ   r   r   r   rŽ   w  rS   zOperatingPointVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_OperatingPointVectorrv   r   r   r   r   r+  ^  r   r+  c                   @   rw   )ÚInvertedListsPtrVectorc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zInvertedListsPtrVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   ry   r'   )r   ÚInvertedListsPtrVector_swiginitÚnew_InvertedListsPtrVectorrL   r   r   r   rH   ‚  r|   zInvertedListsPtrVector.__init__c                 C   rN   r'   )r   Ú InvertedListsPtrVector_push_backr~   r   r   r   r€   …  rS   z InvertedListsPtrVector.push_backc                 C   rJ   r'   )r   ÚInvertedListsPtrVector_clearrL   r   r   r   r‚   ˆ  rM   zInvertedListsPtrVector.clearc                 C   rJ   r'   )r   ÚInvertedListsPtrVector_datarL   r   r   r   r„   ‹  rM   zInvertedListsPtrVector.datac                 C   rJ   r'   )r   ÚInvertedListsPtrVector_sizerL   r   r   r   r†   Ž  rM   zInvertedListsPtrVector.sizec                 C   rN   r'   )r   ÚInvertedListsPtrVector_atrP   r   r   r   rˆ   ‘  rS   zInvertedListsPtrVector.atc                 C   rN   r'   )r   ÚInvertedListsPtrVector_resizerP   r   r   r   rŠ   ”  rS   zInvertedListsPtrVector.resizec                 C   rN   r'   )r   ÚInvertedListsPtrVector_swaprŒ   r   r   r   rŽ   —  rS   zInvertedListsPtrVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_InvertedListsPtrVectorrv   r   r   r   r   r6  ~  r   r6  c                   @   rw   )ÚRepeatVectorc                 C   r5   r'   r6   r7   r   r   r   r9   Ÿ  r:   zRepeatVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ÿ  r>   r?   r@   c                 C   ry   r'   )r   ÚRepeatVector_swiginitÚnew_RepeatVectorrL   r   r   r   rH   ¢  r|   zRepeatVector.__init__c                 C   rN   r'   )r   ÚRepeatVector_push_backr~   r   r   r   r€   ¥  rS   zRepeatVector.push_backc                 C   rJ   r'   )r   ÚRepeatVector_clearrL   r   r   r   r‚   ¨  rM   zRepeatVector.clearc                 C   rJ   r'   )r   ÚRepeatVector_datarL   r   r   r   r„   «  rM   zRepeatVector.datac                 C   rJ   r'   )r   ÚRepeatVector_sizerL   r   r   r   r†   ®  rM   zRepeatVector.sizec                 C   rN   r'   )r   ÚRepeatVector_atrP   r   r   r   rˆ   ±  rS   zRepeatVector.atc                 C   rN   r'   )r   ÚRepeatVector_resizerP   r   r   r   rŠ   ´  rS   zRepeatVector.resizec                 C   rN   r'   )r   ÚRepeatVector_swaprŒ   r   r   r   rŽ   ·  rS   zRepeatVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_RepeatVectorrv   r   r   r   r   rA  ž  r   rA  c                   @   rw   )ÚClusteringIterationStatsVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ¿  r:   z'ClusteringIterationStatsVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¿  r>   r?   r@   c                 C   ry   r'   )r   Ú'ClusteringIterationStatsVector_swiginitÚ"new_ClusteringIterationStatsVectorrL   r   r   r   rH   Â  r|   z'ClusteringIterationStatsVector.__init__c                 C   rN   r'   )r   Ú(ClusteringIterationStatsVector_push_backr~   r   r   r   r€   Å  rS   z(ClusteringIterationStatsVector.push_backc                 C   rJ   r'   )r   Ú$ClusteringIterationStatsVector_clearrL   r   r   r   r‚   È  rM   z$ClusteringIterationStatsVector.clearc                 C   rJ   r'   )r   Ú#ClusteringIterationStatsVector_datarL   r   r   r   r„   Ë  rM   z#ClusteringIterationStatsVector.datac                 C   rJ   r'   )r   Ú#ClusteringIterationStatsVector_sizerL   r   r   r   r†   Î  rM   z#ClusteringIterationStatsVector.sizec                 C   rN   r'   )r   Ú!ClusteringIterationStatsVector_atrP   r   r   r   rˆ   Ñ  rS   z!ClusteringIterationStatsVector.atc                 C   rN   r'   )r   Ú%ClusteringIterationStatsVector_resizerP   r   r   r   rŠ   Ô  rS   z%ClusteringIterationStatsVector.resizec                 C   rN   r'   )r   Ú#ClusteringIterationStatsVector_swaprŒ   r   r   r   rŽ   ×  rS   z#ClusteringIterationStatsVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Ú%delete_ClusteringIterationStatsVectorrv   r   r   r   r   rL  ¾  r   rL  c                   @   rw   )ÚParameterRangeVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ß  r:   zParameterRangeVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ß  r>   r?   r@   c                 C   ry   r'   )r   ÚParameterRangeVector_swiginitÚnew_ParameterRangeVectorrL   r   r   r   rH   â  r|   zParameterRangeVector.__init__c                 C   rN   r'   )r   ÚParameterRangeVector_push_backr~   r   r   r   r€   å  rS   zParameterRangeVector.push_backc                 C   rJ   r'   )r   ÚParameterRangeVector_clearrL   r   r   r   r‚   è  rM   zParameterRangeVector.clearc                 C   rJ   r'   )r   ÚParameterRangeVector_datarL   r   r   r   r„   ë  rM   zParameterRangeVector.datac                 C   rJ   r'   )r   ÚParameterRangeVector_sizerL   r   r   r   r†   î  rM   zParameterRangeVector.sizec                 C   rN   r'   )r   ÚParameterRangeVector_atrP   r   r   r   rˆ   ñ  rS   zParameterRangeVector.atc                 C   rN   r'   )r   ÚParameterRangeVector_resizerP   r   r   r   rŠ   ô  rS   zParameterRangeVector.resizec                 C   rN   r'   )r   ÚParameterRangeVector_swaprŒ   r   r   r   rŽ   ÷  rS   zParameterRangeVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_ParameterRangeVectorrv   r   r   r   r   rW  Þ  r   rW  c                   @   rw   )ÚOnDiskOneListVectorc                 C   r5   r'   r6   r7   r   r   r   r9   ÿ  r:   zOnDiskOneListVector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ÿ  r>   r?   r@   c                 C   ry   r'   )r   ÚOnDiskOneListVector_swiginitÚnew_OnDiskOneListVectorrL   r   r   r   rH     r|   zOnDiskOneListVector.__init__c                 C   rN   r'   )r   ÚOnDiskOneListVector_push_backr~   r   r   r   r€     rS   zOnDiskOneListVector.push_backc                 C   rJ   r'   )r   ÚOnDiskOneListVector_clearrL   r   r   r   r‚     rM   zOnDiskOneListVector.clearc                 C   rJ   r'   )r   ÚOnDiskOneListVector_datarL   r   r   r   r„     rM   zOnDiskOneListVector.datac                 C   rJ   r'   )r   ÚOnDiskOneListVector_sizerL   r   r   r   r†     rM   zOnDiskOneListVector.sizec                 C   rN   r'   )r   ÚOnDiskOneListVector_atrP   r   r   r   rˆ     rS   zOnDiskOneListVector.atc                 C   rN   r'   )r   ÚOnDiskOneListVector_resizerP   r   r   r   rŠ     rS   zOnDiskOneListVector.resizec                 C   rN   r'   )r   ÚOnDiskOneListVector_swaprŒ   r   r   r   rŽ     rS   zOnDiskOneListVector.swapN)r   r   r1   r   r   r   r
   rH   r€   r‚   r„   r†   rˆ   rŠ   rŽ   r   Údelete_OnDiskOneListVectorrv   r   r   r   r   rb  þ  r   rb  c                 C   ó   t  | ||||¡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„   rQ   ÚminÚshiftÚhistr   r   r   rn    ó   rn  c                 C   rm  )z same for 16-bin histogram)r   Úsimd_histogram_16ro  r   r   r   rt  '  ó   rt  c                   @   óX   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZdd„ Zdd	„ ZejZd
S )ÚPartitionStatsc                 C   r5   r'   r6   r7   r   r   r   r9   +  r:   zPartitionStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   +  r>   r?   r@   c                 C   ry   r'   )r   ÚPartitionStats_swiginitÚnew_PartitionStatsrL   r   r   r   rH   0  r|   zPartitionStats.__init__c                 C   rJ   r'   )r   ÚPartitionStats_resetrL   r   r   r   Úreset3  rM   zPartitionStats.resetN)r   r   r1   r   r   r   r
   r   Ú!PartitionStats_bissect_cycles_getÚ!PartitionStats_bissect_cycles_setÚbissect_cyclesÚ"PartitionStats_compress_cycles_getÚ"PartitionStats_compress_cycles_setÚcompress_cyclesrH   r{  Údelete_PartitionStatsrv   r   r   r   r   rw  *  ó    
rw  c                 C   rN   r'   )r   Úbitvec_print)ÚbÚdr   r   r   r„  ;  rS   r„  c                 C   ó   t  | |||¡S r'   )r   Úfvecs2bitvecs)r8   r…  r†  rQ   r   r   r   rˆ  >  ó   rˆ  c                 C   r‡  r'   )r   Úbitvecs2fvecs)r…  r8   r†  rQ   r   r   r   rŠ  A  r‰  rŠ  c                 C   ó   t  | ||¡S r'   )r   Úfvec2bitvec)r8   r…  r†  r   r   r   rŒ  D  ó   rŒ  c                 C   ó   t  | |||||¡S )z0 Shuffle the bits from b(i, j) := a(i, order[j]))r   Úbitvec_shuffle)rQ   ÚdaÚdbÚorderÚar…  r   r   r   r  G  ó   r  c                   @   óf   e Zd Zedd„ d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d	„ ZejZd
S )ÚBitstringWriterc                 C   r5   r'   r6   r7   r   r   r   r9   K  r:   zBitstringWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   K  r>   r?   r@   c                 C   ó   t  | t  ||¡¡ d S r'   )r   ÚBitstringWriter_swiginitÚnew_BitstringWriter©r   ÚcodeÚ	code_sizer   r   r   rH   Q  ó   zBitstringWriter.__init__c                 C   r‹  r'   )r   ÚBitstringWriter_write)r   r8   Únbitr   r   r   ÚwriteT  r  zBitstringWriter.writeN)r   r   r1   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ÚirH   r   Údelete_BitstringWriterrv   r   r   r   r   r–  J  ó    
r–  c                   @   r•  )ÚBitstringReaderc                 C   r5   r'   r6   r7   r   r   r   r9   ]  r:   zBitstringReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ]  r>   r?   r@   c                 C   r—  r'   )r   ÚBitstringReader_swiginitÚnew_BitstringReaderrš  r   r   r   rH   c  r  zBitstringReader.__init__c                 C   rN   r'   )r   ÚBitstringReader_read)r   rŸ  r   r   r   Úreadf  rS   zBitstringReader.readN)r   r   r1   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§  rH   r®  Údelete_BitstringReaderrv   r   r   r   r   rª  \  r©  rª  c                 C   rŽ  )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Údisr   r   r   r¶  n  ó   r¶  c                  G   ó
   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©rF   r   r   r   r½  }  s   
r½  c                 C   rŽ  r'   )r   Úhammings_knn)Úhar“  r…  r¸  ÚncodesÚorderedr   r   r   r¿  ’  r|   r¿  c              
   C   ó   t  | |||||||¡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…  r·  r¸  ÚkrÁ  Ú	distancesÚlabelsr   r   r   rÄ  •  s   rÄ  c              	   C   ó   t  | ||||||¡S )zD same as hammings_knn except we are doing a range search with radius)r   Úhamming_range_search)r“  r…  r·  r¸  ÚradiusrÁ  Úresultr   r   r   rÉ  ­  ó   rÉ  c              	   C   rÈ  r'   )r   Úhamming_count_thres)Úbs1Úbs2Ún1Ún2ÚhtrÁ  Únptrr   r   r   rÍ  ±  r.   rÍ  c              
   C   rÃ  r'   )r   Úmatch_hamming_thres)rÎ  rÏ  rÐ  rÑ  rÒ  rÁ  Úidxrº  r   r   r   rÔ  ´  r  rÔ  c                 C   rm  r'   )r   Úcrosshamming_count_thres)ÚdbsrQ   rÒ  rÁ  rÓ  r   r   r   rÖ  ·  rr   rÖ  Tc                 C   rŽ  )z_
    generalized Hamming distances (= count number of code bytes that
       are the same)
    )r   Úgeneralized_hammings_knn_hc)rÀ  r“  r…  r¸  rœ  rÂ  r   r   r   rØ  º  ó   rØ  c                 C   rJ   r'   )r   Ú
popcount32r7   r   r   r   rÚ  Á  rM   rÚ  c                 C   rJ   r'   )r   Ú
popcount64r7   r   r   r   rÛ  Ä  rM   rÛ  c                   C   ó   t  ¡ S r'   )r   Úget_num_gpusr   r   r   r   rÝ  Ç  rI   rÝ  c                   C   rÜ  r'   )r   Úgpu_profiler_startr   r   r   r   rÞ  Ê  rI   rÞ  c                   C   rÜ  r'   )r   Úgpu_profiler_stopr   r   r   r   rß  Í  rI   rß  c                   C   rÜ  r'   )r   Úgpu_sync_all_devicesr   r   r   r   rà  Ð  rI   rà  c                   C   rÜ  )z get compile options)r   Úget_compile_optionsr   r   r   r   rá  Ó  ó   rá  c                   C   rÜ  )z& ms elapsed since some arbitrary epoch)r   Úgetmillisecsr   r   r   r   rã  ×  râ  rã  c                   C   rÜ  )z get current RSS usage in kB)r   Úget_mem_usage_kbr   r   r   r   rä  Û  râ  rä  c                   C   rÜ  r'   )r   Ú
get_cyclesr   r   r   r   rå  ß  rI   rå  c                 C   rm  )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:   restult table, size n
    )r   Ú	fvec_madd©rQ   r“  Úbfr…  Úcr   r   r   ræ  â  ó   ræ  c                 C   rm  )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ç  r   r   r   rë  ñ  rs  rë  c                 C   rm  r'   )r   Ú
reflection)Úur8   rQ   r†  Únur   r   r   rì  ù  rr   rì  c                 C   r‹  )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)ÚmrQ   r“  r   r   r   rï  ü  ó   rï  c                 C   r‹  )zF distances are supposed to be sorted. Sorts indices with same distance)r   Úranklist_handle_ties)rÅ  rÕ  rº  r   r   r   rò    ó   rò  c                 C   r‡  )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Úv2r   r   r   rô    ó   rô  c              
   C   rÃ  )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)rQ   rÅ  ÚI0ÚD0ÚI1ÚD1Úkeep_minÚtranslationr   r   r   rú    s   rú  c                  G   r¼  )z~
    *Overload 1:*
    a balanced assignment has a IF of 1

    |

    *Overload 2:*
    same, takes a histogram as input
    )r   Úimbalance_factorr¾  r   r   r   r     s   

r  c                 C   r‡  )z compute histogram on v)r   Ú	ivec_hist)rQ   r=   Úvmaxrr  r   r   r   r  ,  ó   r  c                 C   r‡  )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)rQ   ÚnbitsÚcodesrr  r   r   r   r  0  ó   	r  c                 C   rN   )z compute a checksum on a table.)r   Úivec_checksum)rQ   r“  r   r   r   r	  ;  ó   r	  FéÒ  c                 C   rŽ  )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†  rQ   Únmaxr8   ÚverboseÚseedr   r   r   r  ?  s   r  c                 C   r‹  )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_outr   r   r   r  R  ó   r  c                 C   r‹  )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  r   r   r   r  _  ó   r  c                 C   rN   )z A reasonable hashing function)r   Ú
hash_bytes)ÚbytesrQ   r   r   r   r  m  r
  r  c                   C   rÜ  )z+ Whether OpenMP annotations were respected.)r   Úcheck_openmpr   r   r   r   r  q  râ  r  c                 C   r‹  )z( Squared L2 distance between two vectors)r   Ú
fvec_L2sqr©r8   Úyr†  r   r   r   r  u  ró  r  c                 C   r‹  )z inner product)r   Úfvec_inner_productr  r   r   r   r  y  ró  r  c                 C   r‹  )z L1 distance)r   Úfvec_L1r  r   r   r   r  }  ró  r  c                 C   r‹  )z infinity distance)r   Ú	fvec_Linfr  r   r   r   r    ró  r  éÿÿÿÿc	           	      C   ó   t  | ||||||||¡	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†  ÚnqÚxqr¸  Úxbrº  ÚldqÚldbÚlddr   r   r   r"  …  s   r"  c                 C   rm  r'   )r   Úfvec_inner_products_ny)Úipr8   r  r†  Únyr   r   r   r)  ™  rr   r)  c                 C   rm  r'   )r   Úfvec_L2sqr_ny)rº  r8   r  r†  r+  r   r   r   r,  œ  rr   r,  c              	   C   rÈ  r'   )r   Úfvec_L2sqr_ny_transposed)rº  r8   r  Úy_sqlenr†  Úd_offsetr+  r   r   r   r-  Ÿ  r.   r-  c                 C   rm  r'   )r   Úfvec_L2sqr_ny_nearest)Údistances_tmp_bufferr8   r  r†  r+  r   r   r   r0  ¢  rr   r0  c              	   C   rÈ  r'   )r   Ú"fvec_L2sqr_ny_nearest_y_transposed)r1  r8   r  r.  r†  r/  r+  r   r   r   r2  ¥  r.   r2  c                 C   rN   )z squared norm of a vector)r   Úfvec_norm_L2sqr)r8   r†  r   r   r   r3  ¨  r
  r3  c                 C   r‡  )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©Únormsr8   r†  Únxr   r   r   r4  ¬  r  r4  c                 C   r‡  )z2 same as fvec_norms_L2, but computes squared norms)r   Úfvec_norms_L2sqrr5  r   r   r   r8  ·  r  r8  c                 C   r‹  r'   )r   Úfvec_renorm_L2)r†  r7  r8   r   r   r   r9  »  r  r9  c                 C   rm  r'   )r   Úinner_product_to_L2sqr)rº  Únr1Únr2rÐ  rÑ  r   r   r   r:  ¾  rr   r:  c                  G   r¼  )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_addr¾  r   r   r   r=  Á  s   
r=  c                 C   r‡  )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…  ré  r   r   r   r>  Ý  ó   r>  c              	   C   rÈ  r'   )r   Úfvec_inner_products_by_idx)r*  r8   r  Úidsr†  r7  r+  r   r   r   r@  ì  r.   r@  c              	   C   rÈ  r'   )r   Úfvec_L2sqr_by_idx)rº  r8   r  rA  r†  r7  r+  r   r   r   rB  ï  r.   rB  c              	   C   rÈ  )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†  rQ   r8   Úixr  Úiyrº  r   r   r   rC  ò  s   rC  c              	   C   rÈ  r'   )r   Úpairwise_indexed_inner_productrD  r   r   r   rG    r.   rG  c                  G   r¼  )a÷  
    *Overload 1:*
     Return the k nearest neighors 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 neighors 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 neighors 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_productr¾  r   r   r   rH    s   
+rH  c                  G   r¼  )aO	  
    *Overload 1:*
     Return the k nearest neighors 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 neighors 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 neighors 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 neighors 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_L2sqrr¾  r   r   r   rI  3  s   
FrI  c
           
      C   ó   t  | |||||||||	¡
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)
r8   r  Úsubsetr†  r7  ÚnsubsetrÅ  ÚvalsrA  Úld_idsr   r   r   rK  {  ó   rK  c
           
      C   rJ  )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)
r8   r  rL  r†  r7  rM  rÅ  rN  rA  Ú	ld_subsetr   r   r   rQ    rP  rQ  c              
   C   rÃ  )a£  
     Return the k nearest neighors 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©r8   r  r†  r7  r+  rÊ  rË  Úselr   r   r   rS  Ÿ  s   rS  c              
   C   rÃ  )z< same as range_search_L2sqr for the inner product similarity)r   Úrange_search_inner_productrT  r   r   r   rV  ¯  ó   rV  c              	   C   rÈ  )z specialized function for PQ2)r   Úcompute_PQ_dis_tables_dsub2)r†  ÚksubÚ	centroidsr7  r8   Úis_inner_productÚ
dis_tablesr   r   r   rX  ³  rÌ  rX  c                   @   sh   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zdd„ Zdd„ Zddd„ZejZdS )ÚRandomGeneratorz< random generator that can be used in multithreaded contextsc                 C   r5   r'   r6   r7   r   r   r   r9   ¹  r:   zRandomGenerator.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¹  r>   r?   r@   c                 C   rJ   )z random int64_t)r   ÚRandomGenerator_rand_int64rL   r   r   r   Ú
rand_int64½  ó   
zRandomGenerator.rand_int64c                 G   rn   )z•
        *Overload 1:*
        random positive integer

        |

        *Overload 2:*
        generate random integer between 0 and max-1
        )r   ÚRandomGenerator_rand_intrp   r   r   r   Úrand_intÁ  ó   
zRandomGenerator.rand_intc                 C   rJ   )z between 0 and 1)r   ÚRandomGenerator_rand_floatrL   r   r   r   Ú
rand_floatÍ  r`  zRandomGenerator.rand_floatc                 C   rJ   r'   )r   ÚRandomGenerator_rand_doublerL   r   r   r   Úrand_doubleÑ  rM   zRandomGenerator.rand_doubler  c                 C   ó   t  | t  |¡¡ d S r'   )r   ÚRandomGenerator_swiginitÚnew_RandomGenerator©r   r  r   r   r   rH   Ô  r.   zRandomGenerator.__init__N)r  )r   r   r1   r2   r   r   r   r
   r   ÚRandomGenerator_mt_getÚRandomGenerator_mt_setÚmtr_  rb  re  rg  rH   Údelete_RandomGeneratorrv   r   r   r   r   r]  ¶  s    

r]  c                 C   r‹  r'   )r   Ú
float_rand©r8   rQ   r  r   r   r   rp  Ý  r  rp  c                 C   r‹  r'   )r   Úfloat_randnrq  r   r   r   rr  à  r  rr  c                 C   r‹  r'   )r   Ú
int64_randrq  r   r   r   rs  ã  r  rs  c                 C   r‹  r'   )r   Ú	byte_randrq  r   r   r   rt  æ  r  rt  c                 C   r‡  r'   )r   Úint64_rand_max)r8   rQ   Úmaxr  r   r   r   ru  é  r‰  ru  c                 C   r‹  r'   )r   Ú	rand_perm)ÚpermrQ   r  r   r   r   rw  ì  r  rw  c                 C   r‡  r'   )r   Úrand_smooth_vectors)rQ   r†  r8   r  r   r   r   ry  ï  r‰  ry  c                 C   r‹  )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©rQ   rN  rx  r   r   r   rz  ò  r  rz  c                 C   r‹  )z# Same as fvec_argsort, parallelized)r   Úfvec_argsort_parallelr{  r   r   r   r|     ró  r|  c                 C   rŽ  )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)ÚnvalrN  ÚnbucketÚlimsrx  Úntr   r   r   r}    ó   r}  c                  G   r¼  )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_inplacer¾  r   r   r   rƒ    s   
rƒ  c                 C   rJ   )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_typer   r   r   r„  E  ó   
r„  c                   @   sJ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZejZdd	„ Zd
S )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   \  r:   zSearchParameters.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   \  r>   r?   r@   z> if non-null, only these IDs will be considered during search.c                 C   ry   r'   )r   ÚSearchParameters_swiginitÚnew_SearchParametersrL   r   r   r   rH   a  r|   zSearchParameters.__init__N)r   r   r1   r2   r   r   r   r
   r   ÚSearchParameters_sel_getÚSearchParameters_sel_setrU  Údelete_SearchParametersrv   rH   r   r   r   r   r‡  T  s    r‡  c                   @   sN  e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jddZee	je	jddZee	je	jddZee	je	jddZe	jZdd„ Zdd„ Zdd„ Z d:dd„Z!d:dd„Z"d;dd„Z#dd„ Z$dd „ Z%d!d"„ Z&d#d$„ Z'd%d&„ Z(d:d'd(„Z)d)d*„ Z*d+d,„ Z+d-d.„ Z,d/d0„ Z-d1d2„ Z.d3d4„ Z/d<d6d7„Z0d8d9„ Z1dS )=Ú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                 C   r5   r'   r6   r7   r   r   r   r9   o  r:   zIndex.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   o  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   q  rI   zIndex.__init__ú 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                 C   r‹  )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   rQ   r8   r   r   r   Útrain  ó   	zIndex.trainc                 C   r‹  )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 x: float
        :param x:      input matrix, size n * d
        )r   Ú	Index_addr“  r   r   r   ÚaddŠ  ó   
z	Index.addc                 C   r‡  ©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   ÚIndex_add_with_ids©r   rQ   r8   Úxidsr   r   r   Úadd_with_ids–  ó   
zIndex.add_with_idsNc              	   C   rÈ  )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: float
        :param x:           input vectors to search, size n * d
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        :type distances: float
        :param distances:   output pairwise distances, size n*k
        )r   ÚIndex_search©r   rQ   r8   rÅ  rÆ  rÇ  Úparamsr   r   r   Úsearch¢  ó   zIndex.searchc                 C   rŽ  )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 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   rQ   r8   rÊ  rË  r¡  r   r   r   Úrange_search²  ó   zIndex.range_searchr   c                 C   rm  )aQ  
         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 x: float
        :param x:           input vectors to search, size n * d
        :type labels: int
        :param labels:      output labels of the NNs, size n*k
        )r   ÚIndex_assign©r   rQ   r8   rÇ  rÅ  r   r   r   ÚassignÃ  rc  zIndex.assignc                 C   rJ   )z( removes all elements from the database.)r   ÚIndex_resetrL   r   r   r   r{  Ï  r`  zIndex.resetc                 C   rN   )z|
         removes IDs from the index. Not supported by all
        indexes. Returns the number of elements removed.
        )r   ÚIndex_remove_ids©r   rU  r   r   r   Ú
remove_idsÓ  ó   zIndex.remove_idsc                 C   r‹  )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Úreconsr   r   r   ÚreconstructÚ  r˜  zIndex.reconstructc                 C   r‡  )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   rQ   Úkeysr³  r   r   r   Úreconstruct_batchæ  ó   zIndex.reconstruct_batchc                 C   r‡  )zÍ
         Reconstruct vectors i0 to i0 + ni - 1

        this function may not be defined for some indexes
        :type recons: float
        :param recons:      reconstucted vector (size ni * d)
        )r   ÚIndex_reconstruct_n©r   Úi0Únir³  r   r   r   Úreconstruct_nô  ó   zIndex.reconstruct_nc              
   C   rÃ  )ae  
         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 recons: float
        :param recons:      reconstructed vectors size (n, k, d)
        )r   ÚIndex_search_and_reconstruct©r   rQ   r8   rÅ  rÆ  rÇ  r³  r¡  r   r   r   Úsearch_and_reconstructþ  ó   zIndex.search_and_reconstructc                 C   r‡  )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   r8   Úresidualr²  r   r   r   Úcompute_residual  s   zIndex.compute_residualc                 C   rm  )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   rQ   ÚxsÚ	residualsr¶  r   r   r   Úcompute_residual_n  s   zIndex.compute_residual_nc                 C   rJ   )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_computerrL   r   r   r   Úget_distance_computer2  s   
zIndex.get_distance_computerc                 C   rJ   )z$ size of the produced codes in bytes)r   ÚIndex_sa_code_sizerL   r   r   r   Úsa_code_size<  r`  zIndex.sa_code_sizec                 C   r‡  )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   rQ   r8   r  r   r   r   Ú	sa_encode@  ó   zIndex.sa_encodec                 C   r‡  )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   rQ   r  r8   r   r   r   Ú	sa_decodeM  rÑ  zIndex.sa_decoder   c                 C   r‹  ©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_idr   r   r   Ú
merge_fromZ  ó   zIndex.merge_fromc                 C   rN   ©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Ø  r   r   r   Úcheck_compatible_for_mergec  ó   z Index.check_compatible_for_merger'   rt   ©r   )2r   r   r1   r2   r   r   rH   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_Indexrv   r”  r—  r  r¢  r¦  rª  r{  r®  r´  r·  r½  rÁ  rÅ  rÉ  rË  rÍ  rÐ  rÔ  rÚ  rß  r   r   r   r   r  g  s@    






	r  c                   @   óP   e Zd ZdZedd„ dd„ ddZdd„ ZeZd	d
„ Z	dd„ Z
dd„ ZejZdS )ÚDistanceComputerú»
    Copyright (c) Facebook, Inc. and its affiliates.

    This source code is licensed under the MIT license found in the
    LICENSE file in the root directory of this source tree.
    c                 C   r5   r'   r6   r7   r   r   r   r9   v  r:   zDistanceComputer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   v  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   x  rI   zDistanceComputer.__init__c                 C   rN   )zv
        called before computing distances. Pointer x should remain valid
        while operator () is called
        )r   ÚDistanceComputer_set_queryrW   r   r   r   Ú	set_query|  r¯  zDistanceComputer.set_queryc                 C   rN   )z. compute distance of vector i to current query)r   ÚDistanceComputer___call__©r   r§  r   r   r   Ú__call__ƒ  r
  zDistanceComputer.__call__c                 C   r‹  )z, compute distance between two stored vectors)r   ÚDistanceComputer_symmetric_dis©r   r§  Újr   r   r   Úsymmetric_dis‡  ró  zDistanceComputer.symmetric_disN)r   r   r1   r2   r   r   rH   r   r
   rö  rù  rý  r   Údelete_DistanceComputerrv   r   r   r   r   ró  n  s    
ró  c                   @   s`   e Zd Zedd„ dd„ ddZdd„ ZeZeej	ej
ƒZeejejƒZdd	„ Zd
d„ ZejZdS )ÚFlatCodesDistanceComputerc                 C   r5   r'   r6   r7   r   r   r   r9     r:   z"FlatCodesDistanceComputer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ’  rI   z"FlatCodesDistanceComputer.__init__c                 C   rN   r'   )r   Ú"FlatCodesDistanceComputer___call__rø  r   r   r   rù  ˜  rS   z"FlatCodesDistanceComputer.__call__c                 C   rN   )z7 compute distance of current query to an encoded vector)r   Ú*FlatCodesDistanceComputer_distance_to_code©r   r›  r   r   r   Údistance_to_code›  r
  z*FlatCodesDistanceComputer.distance_to_codeN)r   r   r1   r   r   rH   r   r
   r   Ú#FlatCodesDistanceComputer_codes_getÚ#FlatCodesDistanceComputer_codes_setr  Ú'FlatCodesDistanceComputer_code_size_getÚ'FlatCodesDistanceComputer_code_size_setrœ  rù  r  Ú delete_FlatCodesDistanceComputerrv   r   r   r   r   rÿ    s    
rÿ  c                   @   s²   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jƒZee	je	jd	dZd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd"dd „Ze	jZd!S )#ÚIndexFlatCodeszr
     Index that encodes all vectors as fixed-size codes (size code_size). Storage
    is in the codes vector
    c                 C   r5   r'   r6   r7   r   r   r   r9   ©  r:   zIndexFlatCodes.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ©  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   «  rI   zIndexFlatCodes.__init__z) encoded dataset, size ntotal * code_sizec                 C   r‹  )z default add uses sa_encode)r   ÚIndexFlatCodes_addr“  r   r   r   r—  ±  ró  zIndexFlatCodes.addc                 C   rJ   r'   )r   ÚIndexFlatCodes_resetrL   r   r   r   r{  µ  rM   zIndexFlatCodes.resetc                 C   r‡  )z) reconstruction using the codec interface)r   ÚIndexFlatCodes_reconstruct_nrº  r   r   r   r½  ¸  r  zIndexFlatCodes.reconstruct_nc                 C   r‹  r'   )r   ÚIndexFlatCodes_reconstructr±  r   r   r   r´  ¼  r  zIndexFlatCodes.reconstructc                 C   rJ   r'   )r   ÚIndexFlatCodes_sa_code_sizerL   r   r   r   rÍ  ¿  rM   zIndexFlatCodes.sa_code_sizec                 C   rN   )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_idsr­  r   r   r   r®  Â  rà  zIndexFlatCodes.remove_idsc                 C   rJ   )z= a FlatCodesDistanceComputer offers a distance_to_code method)r   Ú,IndexFlatCodes_get_FlatCodesDistanceComputerrL   r   r   r   Úget_FlatCodesDistanceComputerÊ  r`  z,IndexFlatCodes.get_FlatCodesDistanceComputerc                 C   rJ   r'   )r   Ú$IndexFlatCodes_get_distance_computerrL   r   r   r   rË  Î  rM   z$IndexFlatCodes.get_distance_computerc                 C   rJ   r'   )r   ÚIndexFlatCodes_get_CodePackerrL   r   r   r   Úget_CodePackerÑ  rM   zIndexFlatCodes.get_CodePackerc                 C   rN   r'   )r   Ú)IndexFlatCodes_check_compatible_for_mergerÞ  r   r   r   rß  Ô  rS   z)IndexFlatCodes.check_compatible_for_merger   c                 C   r‹  r'   )r   ÚIndexFlatCodes_merge_fromr×  r   r   r   rÚ  ×  r  zIndexFlatCodes.merge_fromNrá  )r   r   r1   r2   r   r   rH   r   r
   r   ÚIndexFlatCodes_code_size_getÚIndexFlatCodes_code_size_setrœ  ÚIndexFlatCodes_codes_getÚIndexFlatCodes_codes_setr  r—  r{  r½  r´  rÍ  r®  r  rË  r  rß  rÚ  Údelete_IndexFlatCodesrv   r   r   r   r   r	  £  s&    

r	  c                   @   s|   e Zd ZdZedd„ dd„ ddZeZddd	„Zdd
d„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )Ú	IndexFlatzB Index that stores the full vectors and performs exhaustive searchc                 C   r5   r'   r6   r7   r   r   r   r9   á  r:   zIndexFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   á  r>   r?   r@   Nc              	   C   rÈ  r'   )r   ÚIndexFlat_searchr   r   r   r   r¢  ä  r.   zIndexFlat.searchc                 C   rŽ  r'   )r   ÚIndexFlat_range_searchr¥  r   r   r   r¦  ç  r|   zIndexFlat.range_searchc                 C   r‹  r'   )r   ÚIndexFlat_reconstructr±  r   r   r   r´  ê  r  zIndexFlat.reconstructc                 C   rŽ  )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   rQ   r8   rÅ  rÆ  rÇ  r   r   r   Úcompute_distance_subsetí  r»  z!IndexFlat.compute_distance_subsetc                 G   rn   r'   )r   ÚIndexFlat_get_xbrp   r   r   r   Úget_xbü  rr   zIndexFlat.get_xbc                 G   ó   t  | t j|Ž ¡ d S r'   )r   ÚIndexFlat_swiginitÚnew_IndexFlatrp   r   r   r   rH   ÿ  r.   zIndexFlat.__init__c                 C   rJ   r'   )r   Ú'IndexFlat_get_FlatCodesDistanceComputerrL   r   r   r   r    rM   z'IndexFlat.get_FlatCodesDistanceComputerc                 C   r‡  r'   )r   ÚIndexFlat_sa_encoderÏ  r   r   r   rÐ    r‰  zIndexFlat.sa_encodec                 C   r‡  r'   )r   ÚIndexFlat_sa_decoderÓ  r   r   r   rÔ    r‰  zIndexFlat.sa_decoder'   )r   r   r1   r2   r   r   r   r
   r¢  r¦  r´  r!  r#  rH   r  rÐ  rÔ  r   Údelete_IndexFlatrv   r   r   r   r   r  Þ  s    


r  c                   @   ó4   e Zd Zedd„ dd„ ddZeZdd„ Zej	Z
dS )	ÚIndexFlatIPc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexFlatIP.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   ÚIndexFlatIP_swiginitÚnew_IndexFlatIPrp   r   r   r   rH     r.   zIndexFlatIP.__init__N)r   r   r1   r   r   r   r
   rH   r   Údelete_IndexFlatIPrv   r   r   r   r   r,    ó
    
r,  c                   @   r+  )	ÚIndexFlatL2c                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexFlatL2.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   ÚIndexFlatL2_swiginitÚnew_IndexFlatL2rp   r   r   r   rH     r.   zIndexFlatL2.__init__N)r   r   r1   r   r   r   r
   rH   r   Údelete_IndexFlatL2rv   r   r   r   r   r1    r0  r1  c                   @   s€   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZdd
d„Zdd„ Zdd„ Zdd„ Zddd„ZejZdS )ÚIndexFlat1Dz$ optimized version for 1D "vectors".c                 C   r5   r'   r6   r7   r   r   r   r9   (  r:   zIndexFlat1D.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   (  r>   r?   r@   z) is the permutation updated continuously?z sorted database indicesTc                 C   rh  r'   )r   ÚIndexFlat1D_swiginitÚnew_IndexFlat1D)r   Úcontinuous_updater   r   r   rH   -  r.   zIndexFlat1D.__init__c                 C   rJ   )zg
        if not continuous_update, call this between the last add and
        the first search
        )r   ÚIndexFlat1D_update_permutationrL   r   r   r   Úupdate_permutation0  r†  zIndexFlat1D.update_permutationc                 C   r‹  r'   )r   ÚIndexFlat1D_addr“  r   r   r   r—  7  r  zIndexFlat1D.addc                 C   rJ   r'   )r   ÚIndexFlat1D_resetrL   r   r   r   r{  :  rM   zIndexFlat1D.resetNc              	   C   rÈ  )z+ Warn: the distances returned are L1 not L2)r   ÚIndexFlat1D_searchr   r   r   r   r¢  =  rÌ  zIndexFlat1D.search©Tr'   )r   r   r1   r2   r   r   r   r
   r   Ú!IndexFlat1D_continuous_update_getÚ!IndexFlat1D_continuous_update_setr8  ÚIndexFlat1D_perm_getÚIndexFlat1D_perm_setrx  rH   r:  r—  r{  r¢  Údelete_IndexFlat1Drv   r   r   r   r   r5  %  s    


r5  c                   @   sú   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejƒZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZ eej!ej"ddZ#eej$ej%ddZ&eej'ej(ddZ)dd„ Z*ej+Z,dS )ÚClusteringParameterszn
     Class for the clustering parameters. Can be passed to the
    constructor of the Clustering object.
    c                 C   r5   r'   r6   r7   r   r   r   r9   K  r:   zClusteringParameters.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   K  r>   r?   r@   z clustering iterationsz. redo clustering this many times and keep bestz! do we want normalized centroids?z' round centroids coordinates to integerz% re-train index after each iteration?zZ
    use the centroids provided as input and do not
    change them during iterations
    z otherwise you get a warningz to limit size of datasetz% seed for the random number generatorz% how many vectors at a time to decodec                 C   s   t  | t  ¡ ¡ dS )z sets reasonable defaultsN)r   ÚClusteringParameters_swiginitÚnew_ClusteringParametersrL   r   r   r   rH   \  r”  zClusteringParameters.__init__N)-r   r   r1   r2   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_centroidsÚ0ClusteringParameters_min_points_per_centroid_getÚ0ClusteringParameters_min_points_per_centroid_setÚmin_points_per_centroidÚ0ClusteringParameters_max_points_per_centroid_getÚ0ClusteringParameters_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_sizerH   Údelete_ClusteringParametersrv   r   r   r   r   rD  E  s"    
rD  c                   @   sŽ   e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZeejejddZeejejd	dZeejejd
dZdd„ ZejZdS )ÚClusteringIterationStatsc                 C   r5   r'   r6   r7   r   r   r   r9   e  r:   z!ClusteringIterationStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   e  r>   r?   r@   z6 objective values (sum of distances reported by index)z seconds for iterationz seconds for just searchz imbalance factor of iterationz number of cluster splitsc                 C   ry   r'   )r   Ú!ClusteringIterationStats_swiginitÚnew_ClusteringIterationStatsrL   r   r   r   rH   m  r|   z!ClusteringIterationStats.__init__N)r   r   r1   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ÚnsplitrH   Údelete_ClusteringIterationStatsrv   r   r   r   r   rg  d  s    
rg  c                   @   sœ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZdd„ Zddd„Zddd„Zdd„ ZejZdS )Ú
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                 C   r5   r'   r6   r7   r   r   r   r9   ‚  r:   zClustering.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ‚  r>   r?   r@   ú 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                 G   r$  r'   )r   ÚClustering_swiginitÚnew_Clusteringrp   r   r   r   rH     r.   zClustering.__init__Nc                 C   rm  )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   rQ   r8   ÚindexÚ	x_weightsr   r   r   r”    ó   zClustering.trainc                 C   rŽ  )aH  
         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   r7  r  Úcodecr€  Úweightsr   r   r   Útrain_encoded  s   zClustering.train_encodedc                 C   rJ   )z
        Post-process the centroids after each centroid update.
        includes optional L2 normalization and nearest integer rounding
        )r   Ú!Clustering_post_process_centroidsrL   r   r   r   Úpost_process_centroidsª  r†  z!Clustering.post_process_centroidsr'   )r   r   r1   r2   r   r   r   r
   r   ÚClustering_d_getÚClustering_d_setr†  ÚClustering_k_getÚClustering_k_setrÅ  ÚClustering_centroids_getÚClustering_centroids_setrZ  ÚClustering_iteration_stats_getÚClustering_iteration_stats_setÚiteration_statsrH   r”  r†  rˆ  Údelete_Clusteringrv   r   r   r   r   ry  t  s    


ry  c                   @   ó@   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	e
jZdS )ÚClustering1Dzw
     Exact 1D clustering algorithm

    Since it does not use an index, it does not overload the train() function
    c                 C   r5   r'   r6   r7   r   r   r   r9   ¼  r:   zClustering1D.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¼  r>   r?   r@   c                 G   r$  r'   )r   ÚClustering1D_swiginitÚnew_Clustering1Drp   r   r   r   rH   ¿  r.   zClustering1D.__init__c                 C   r‹  r'   )r   ÚClustering1D_train_exactr“  r   r   r   Útrain_exactÂ  r  zClustering1D.train_exactN)r   r   r1   r2   r   r   r   r
   rH   r˜  r   Údelete_Clustering1Drv   r   r   r   r   r”  µ  s    
r”  c                   @   sX   e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZdd	„ ZejZd
S )Ú"ProgressiveDimClusteringParametersc                 C   r5   r'   r6   r7   r   r   r   r9   Ê  r:   z+ProgressiveDimClusteringParameters.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ê  r>   r?   r@   z number of incremental stepsz apply PCA on inputc                 C   ry   r'   )r   Ú+ProgressiveDimClusteringParameters_swiginitÚ&new_ProgressiveDimClusteringParametersrL   r   r   r   rH   Ï  r|   z+ProgressiveDimClusteringParameters.__init__N)r   r   r1   r   r   r   r
   r   Ú<ProgressiveDimClusteringParameters_progressive_dim_steps_getÚ<ProgressiveDimClusteringParameters_progressive_dim_steps_setÚprogressive_dim_stepsÚ0ProgressiveDimClusteringParameters_apply_pca_getÚ0ProgressiveDimClusteringParameters_apply_pca_setÚ	apply_pcarH   Ú)delete_ProgressiveDimClusteringParametersrv   r   r   r   r   rš  É  s    
rš  c                   @   ó@   e Zd ZdZedd„ dd„ ddZeZdd„ Ze	j
Zd	d
„ ZdS )ÚProgressiveDimIndexFactoryz7 generates an index suitable for clustering when calledc                 C   r5   r'   r6   r7   r   r   r   r9   Ù  r:   z#ProgressiveDimIndexFactory.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ù  r>   r?   r@   c                 C   rN   )z  ownership transferred to caller)r   Ú#ProgressiveDimIndexFactory___call__)r   Údimr   r   r   rù  Ü  r
  z#ProgressiveDimIndexFactory.__call__c                 C   ry   r'   )r   Ú#ProgressiveDimIndexFactory_swiginitÚnew_ProgressiveDimIndexFactoryrL   r   r   r   rH   á  r|   z#ProgressiveDimIndexFactory.__init__N)r   r   r1   r2   r   r   r   r
   rù  r   Ú!delete_ProgressiveDimIndexFactoryrv   rH   r   r   r   r   r¥  Ö  s    r¥  c                   @   sˆ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ÷  r:   z!ProgressiveDimClustering.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ÷  r>   r?   r@   rz  r{  z centroids (k * d)r|  c                 G   r$  r'   )r   Ú!ProgressiveDimClustering_swiginitÚnew_ProgressiveDimClusteringrp   r   r   r   rH   þ  r.   z!ProgressiveDimClustering.__init__c                 C   r‡  r'   )r   ÚProgressiveDimClustering_train)r   rQ   r8   Úfactoryr   r   r   r”  	  r‰  zProgressiveDimClustering.trainN)r   r   r1   r2   r   r   r   r
   r   ÚProgressiveDimClustering_d_getÚProgressiveDimClustering_d_setr†  ÚProgressiveDimClustering_k_getÚProgressiveDimClustering_k_setrÅ  Ú&ProgressiveDimClustering_centroids_getÚ&ProgressiveDimClustering_centroids_setrZ  Ú,ProgressiveDimClustering_iteration_stats_getÚ,ProgressiveDimClustering_iteration_stats_setr‘  rH   r”  Údelete_ProgressiveDimClusteringrv   r   r   r   r   r«  ç  s    
r«  c                 C   rm  )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†  rQ   rÅ  r8   rZ  r   r   r   r¹  		  ó   r¹  c                 C   ó   t  | |||||||||	|
¡S r'   )r   Úpairwise_extra_distances)r†  r#  r$  r¸  r%  rn  rð  rº  r&  r'  r(  r   r   r   r¼  	  ó   r¼  c                 C   rm  )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†  rn  rð  r¸  r%  r   r   r   r¾  	  ó   r¾  c                   @   st   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZdd„ Zdd„ Zdd„ Ze	jZdS )Ú	Quantizerú2 Product Quantizer. Implemented only for METRIC_L2c                 C   r5   r'   r6   r7   r   r   r   r9   (	  r:   zQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   (	  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   *	  rI   zQuantizer.__init__z size of the input vectorsz bytes per indexed vectorc                 C   r‹  )zs
         Train the quantizer

        :type x: float
        :param x:       training vectors, size n * d
        )r   ÚQuantizer_trainr“  r   r   r   r”  0	  rÛ  zQuantizer.trainc                 C   r‡  )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   r8   r  rQ   r   r   r   Úcompute_codes9	  r  zQuantizer.compute_codesc                 C   r‡  )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›  r8   rQ   r   r   r   ÚdecodeD	  r¾  zQuantizer.decodeN)r   r   r1   r2   r   r   rH   r   r
   r   ÚQuantizer_d_getÚQuantizer_d_setr†  ÚQuantizer_code_size_getÚQuantizer_code_size_setrœ  r”  rÅ  rÈ  Údelete_Quantizerrv   r   r   r   r   rÀ  %	  s    	
	rÀ  c                   @   sÐ  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZejZejZ	 ejZ	 ejZ	 ej Z!	 eej"ej#ƒZ$eej%ej&ddZ'eej(ej)ddZ*eej+ej,ddZ-eej.ej/ddZ0eej1ej2ddZ3dd„ Z4dd„ Z5dd„ Z6dd„ Z7dd„ Z8dd„ Z9dd„ Z:dd „ Z;d!d"„ Z<d#d$„ Z=d%d&„ Z>d'd(„ Z?d)d*„ Z@d+d,„ ZAd<d.d/„ZBd<d0d1„ZCeejDejEd2dZFd3d4„ ZGd<d5d6„ZHd7d8„ ZId9d:„ ZJejKZLd;S )=ÚProductQuantizerrÁ  c                 C   r5   r'   r6   r7   r   r   r   r9   U	  r:   zProductQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   U	  r>   r?   r@   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                 C   r‹  )z1 return the centroids associated with subvector m)r   ÚProductQuantizer_get_centroids)r   rð  r§  r   r   r   Úget_centroidsx	  ró  zProductQuantizer.get_centroidsc                 C   r‹  r'   )r   ÚProductQuantizer_trainr“  r   r   r   r”  |	  r  zProductQuantizer.trainc                 G   r$  r'   )r   ÚProductQuantizer_swiginitÚnew_ProductQuantizerrp   r   r   r   rH   	  r.   zProductQuantizer.__init__c                 C   rJ   )z9 compute derived values when d, M and nbits have been set)r   Ú#ProductQuantizer_set_derived_valuesrL   r   r   r   Úset_derived_values‚	  r`  z#ProductQuantizer.set_derived_valuesc                 C   r‹  )z( Define the centroids for subquantizer m)r   ÚProductQuantizer_set_params)r   rZ  rð  r   r   r   Ú
set_params†	  ró  zProductQuantizer.set_paramsc                 C   r‹  )z/ Quantize one vector with the product quantizer)r   ÚProductQuantizer_compute_code)r   r8   r›  r   r   r   Úcompute_codeŠ	  ró  zProductQuantizer.compute_codec                 C   r‡  )z) same as compute_code for several vectors)r   ÚProductQuantizer_compute_codesrÄ  r   r   r   rÅ  Ž	  r  zProductQuantizer.compute_codesc                 C   r‡  )zn
        speed up code assignment using assign_index
        (non-const because the index is changed)
        )r   Ú0ProductQuantizer_compute_codes_with_assign_indexrÄ  r   r   r   Úcompute_codes_with_assign_index’	  rù  z0ProductQuantizer.compute_codes_with_assign_indexc                 G   rn   r'   )r   ÚProductQuantizer_decoderp   r   r   r   rÈ  ™	  rr   zProductQuantizer.decodec                 C   r‹  )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   Útabr›  r   r   r   Ú compute_code_from_distance_tableœ	  ó   z1ProductQuantizer.compute_code_from_distance_tablec                 C   r‹  )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   r8   Ú	dis_tabler   r   r   Úcompute_distance_table£	  s   z'ProductQuantizer.compute_distance_tablec                 C   r‹  r'   )r   Ú)ProductQuantizer_compute_inner_prod_tablerä  r   r   r   Úcompute_inner_prod_table¶	  r  z)ProductQuantizer.compute_inner_prod_tablec                 C   r‡  )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   r7  r8   r\  r   r   r   Úcompute_distance_tables¹	  r  z(ProductQuantizer.compute_distance_tablesc                 C   r‡  r'   )r   Ú*ProductQuantizer_compute_inner_prod_tablesrê  r   r   r   Úcompute_inner_prod_tablesÄ	  r‰  z*ProductQuantizer.compute_inner_prod_tablesTc              	   C   rÈ  )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   r8   r7  r  rÁ  ÚresÚinit_finalize_heapr   r   r   r¢  Ç	  ó   zProductQuantizer.searchc              	   C   rÈ  )z2 same as search, but with inner product similarity)r   ÚProductQuantizer_search_iprï  r   r   r   Ú	search_ipÙ	  rÌ  zProductQuantizer.search_ipz Symmetric Distance Tablec                 C   rJ   r'   )r   Ú"ProductQuantizer_compute_sdc_tablerL   r   r   r   Úcompute_sdc_tableÞ	  rM   z"ProductQuantizer.compute_sdc_tablec              	   C   rÈ  r'   )r   ÚProductQuantizer_search_sdc)r   Úqcodesr#  ÚbcodesrÁ  rð  rñ  r   r   r   Ú
search_sdcá	  r.   zProductQuantizer.search_sdcc                 C   rJ   )z‚
        Sync transposed centroids with regular centroids. This call
        is needed if centroids were edited directly.
        )r   Ú*ProductQuantizer_sync_transposed_centroidsrL   r   r   r   Úsync_transposed_centroidsä	  r†  z*ProductQuantizer.sync_transposed_centroidsc                 C   rJ   )z= Clear transposed centroids table so ones are no longer used.)r   Ú+ProductQuantizer_clear_transposed_centroidsrL   r   r   r   Úclear_transposed_centroidsë	  r`  z+ProductQuantizer.clear_transposed_centroidsNr>  )Mr   r   r1   r2   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_setrY  Ú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_setrZ  Ú)ProductQuantizer_transposed_centroids_getÚ)ProductQuantizer_transposed_centroids_setÚtransposed_centroidsÚ)ProductQuantizer_centroids_sq_lengths_getÚ)ProductQuantizer_centroids_sq_lengths_setÚcentroids_sq_lengthsrÑ  r”  rH   rÖ  rØ  rÚ  rÅ  rÝ  rÈ  rá  ræ  rè  rë  rí  r¢  rô  ÚProductQuantizer_sdc_table_getÚProductQuantizer_sdc_table_setÚ	sdc_tablerö  rú  rü  rþ  Údelete_ProductQuantizerrv   r   r   r   r   rÎ  R	  s\    



rÎ  c                   @   sz   e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejƒZeejddZeejejƒZdd	d
„Zdd„ ZejZdS )ÚPQEncoderGenericc                 C   r5   r'   r6   r7   r   r   r   r9   ô	  r:   zPQEncoderGeneric.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ô	  r>   r?   r@   z code for this vectorz& number of bits per subquantizer indexr   c                 C   ó   t  | t  |||¡¡ d S r'   )r   ÚPQEncoderGeneric_swiginitÚnew_PQEncoderGeneric)r   r›  r  Úoffsetr   r   r   rH   û	  ó   zPQEncoderGeneric.__init__c                 C   rN   r'   )r   ÚPQEncoderGeneric_encoderW   r   r   r   Úencodeþ	  rS   zPQEncoderGeneric.encodeNrá  )r   r   r1   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ÚregrH   r1  Údelete_PQEncoderGenericrv   r   r   r   r   r*  ó	  s    

r*  c                   @   óJ   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
dd„ Zdd	„ ZejZd
S )Ú
PQEncoder8c                 C   r5   r'   r6   r7   r   r   r   r9   
  r:   zPQEncoder8.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   
  r>   r?   r@   c                 C   r—  r'   )r   ÚPQEncoder8_swiginitÚnew_PQEncoder8©r   r›  r  r   r   r   rH   

  r  zPQEncoder8.__init__c                 C   rN   r'   )r   ÚPQEncoder8_encoderW   r   r   r   r1  
  rS   zPQEncoder8.encodeN)r   r   r1   r   r   r   r
   r   ÚPQEncoder8_code_getÚPQEncoder8_code_setr›  rH   r1  Údelete_PQEncoder8rv   r   r   r   r   r<  
  ó    
r<  c                   @   r;  )ÚPQEncoder16c                 C   r5   r'   r6   r7   r   r   r   r9   
  r:   zPQEncoder16.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   
  r>   r?   r@   c                 C   r—  r'   )r   ÚPQEncoder16_swiginitÚnew_PQEncoder16r?  r   r   r   rH   
  r  zPQEncoder16.__init__c                 C   rN   r'   )r   ÚPQEncoder16_encoderW   r   r   r   r1  
  rS   zPQEncoder16.encodeN)r   r   r1   r   r   r   r
   r   ÚPQEncoder16_code_getÚPQEncoder16_code_setr›  rH   r1  Údelete_PQEncoder16rv   r   r   r   r   rE  
  rD  rE  c                   @   sz   e Zd Zedd„ d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d„ Zdd	„ ZejZd
S )ÚPQDecoderGenericc                 C   r5   r'   r6   r7   r   r   r   r9   $
  r:   zPQDecoderGeneric.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   $
  r>   r?   r@   c                 C   r—  r'   )r   ÚPQDecoderGeneric_swiginitÚnew_PQDecoderGenericr?  r   r   r   rH   ,
  r  zPQDecoderGeneric.__init__c                 C   rJ   r'   )r   ÚPQDecoderGeneric_decoderL   r   r   r   rÈ  /
  rM   zPQDecoderGeneric.decodeN)r   r   r1   r   r   r   r
   r   ÚPQDecoderGeneric_code_getÚPQDecoderGeneric_code_setr›  ÚPQDecoderGeneric_offset_getÚPQDecoderGeneric_offset_setr.  ÚPQDecoderGeneric_nbits_getr  ÚPQDecoderGeneric_mask_getÚmaskÚPQDecoderGeneric_reg_getÚPQDecoderGeneric_reg_setr9  rH   rÈ  Údelete_PQDecoderGenericrv   r   r   r   r   rL  #
  s    


rL  c                   @   óP   e Zd Zedd„ dd„ ddZeZejZ	eej
ejƒZdd„ Zdd	„ ZejZd
S )Ú
PQDecoder8c                 C   r5   r'   r6   r7   r   r   r   r9   7
  r:   zPQDecoder8.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   7
  r>   r?   r@   c                 C   r—  r'   )r   ÚPQDecoder8_swiginitÚnew_PQDecoder8r?  r   r   r   rH   <
  r  zPQDecoder8.__init__c                 C   rJ   r'   )r   ÚPQDecoder8_decoderL   r   r   r   rÈ  ?
  rM   zPQDecoder8.decodeN)r   r   r1   r   r   r   r
   r   ÚPQDecoder8_nbitsr  ÚPQDecoder8_code_getÚPQDecoder8_code_setr›  rH   rÈ  Údelete_PQDecoder8rv   r   r   r   r   r[  6
  ó    
r[  c                   @   rZ  )ÚPQDecoder16c                 C   r5   r'   r6   r7   r   r   r   r9   G
  r:   zPQDecoder16.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   G
  r>   r?   r@   c                 C   r—  r'   )r   ÚPQDecoder16_swiginitÚnew_PQDecoder16r?  r   r   r   rH   L
  r  zPQDecoder16.__init__c                 C   rJ   r'   )r   ÚPQDecoder16_decoderL   r   r   r   rÈ  O
  rM   zPQDecoder16.decodeN)r   r   r1   r   r   r   r
   r   ÚPQDecoder16_nbitsr  ÚPQDecoder16_code_getÚPQDecoder16_code_setr›  rH   rÈ  Údelete_PQDecoder16rv   r   r   r   r   rd  F
  rc  rd  c                   @   s  e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jddZee	je	jƒZee	je	jddZee	je	jddZee	je	jddZee	je	j ddZ!ee	j"e	j#ddZ$ee	j%e	j&ddZ'ee	j(e	j)ddZ*ee	j+e	j,ddZ-ee	j.e	j/ddZ0dd„ Z1dd„ Z2dd„ Z3e	j4Z5	 e	j6Z7	 e	j8Z9	 e	j:Z;	 e	j<Z=	 e	j>Z?e	j@ZA	 e	jBZCe	jDZE	 e	jFZG	 dd„ ZHdd„ ZIdd „ ZJd8d"d#„ZKd9d%d&„ZLd'd(„ ZMd:d)d*„ZNee	jOe	jPd+dZQee	jRe	jSd,dZTee	jUe	jVƒZWd-d.„ ZXd;d0d1„ZYd2d3„ ZZd4d5„ Z[d6d7„ Z\e	j]Z^d!S )<Ú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                 C   r5   r'   r6   r7   r   r   r   r9   _
  r:   zAdditiveQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   _
  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   a
  rI   zAdditiveQuantizer.__init__z number of codebooksz bits for each stepz
 codebooksz' 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 notz store and search normszG
    store norms of codebook entries for 4-bit
    fastscan search
    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                 C   rN   )z" encode a norm into norm_bits bits)r   ÚAdditiveQuantizer_encode_norm)r   Únormr   r   r   Úencode_normx
  r
  zAdditiveQuantizer.encode_normc                 C   rN   )z/ encode norm by non-uniform scalar quantization)r   ÚAdditiveQuantizer_encode_qcintrW   r   r   r   Úencode_qcint|
  r
  zAdditiveQuantizer.encode_qcintc                 C   rN   )z/ decode norm by non-uniform scalar quantization)r   ÚAdditiveQuantizer_decode_qcint©r   ré  r   r   r   Údecode_qcint€
  r
  zAdditiveQuantizer.decode_qcintc                 C   rJ   )z Train the norm quantizer)r   Ú$AdditiveQuantizer_set_derived_valuesrL   r   r   r   rÖ  Ÿ
  r`  z$AdditiveQuantizer.set_derived_valuesc                 C   r‹  r'   )r   ÚAdditiveQuantizer_train_norm)r   rQ   r6  r   r   r   Ú
train_norm£
  r  zAdditiveQuantizer.train_normc                 C   r‡  r'   )r   ÚAdditiveQuantizer_compute_codesrÄ  r   r   r   rÅ  ¦
  r‰  zAdditiveQuantizer.compute_codesNc                 C   rm  ©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   r8   r  rQ   rZ  r   r   r   Úcompute_codes_add_centroids©
  r‚  z-AdditiveQuantizer.compute_codes_add_centroidsr   c              	   C   rÈ  )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   rQ   r  Úpacked_codesÚld_codesr6  rZ  r   r   r   Ú
pack_codes¶
  rò  zAdditiveQuantizer.pack_codesc                 C   r‡  ©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  r8   rQ   r   r   r   rÈ  È
  r  zAdditiveQuantizer.decodec                 C   rm  ©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  r8   rQ   r  r   r   r   Údecode_unpackedÓ
  ó   	z!AdditiveQuantizer.decode_unpackedz$ Also determines what's in the codesz" min/max for quantization of normsc                 C   r‹  )z. decoding function for a code in a 64-bit word)r   ÚAdditiveQuantizer_decode_64bitr“  r   r   r   Údecode_64bitá
  ró  zAdditiveQuantizer.decode_64bitç      ð?c                 C   rŽ  )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   rQ   r$  ÚLUTÚalphaÚld_lutr   r   r   Úcompute_LUTå
  r‚  zAdditiveQuantizer.compute_LUTc                 C   rŽ  )z exact IP search)r   Ú-AdditiveQuantizer_knn_centroids_inner_product)r   rQ   r$  rÅ  rÆ  rÇ  r   r   r   Úknn_centroids_inner_productõ
  r”  z-AdditiveQuantizer.knn_centroids_inner_productc                 C   rN   )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   r6  r   r   r   Úcompute_centroid_normsù
  ó   z(AdditiveQuantizer.compute_centroid_normsc              	   C   rÈ  )z( Exact L2 search, with precomputed norms)r   Ú"AdditiveQuantizer_knn_centroids_L2)r   rQ   r$  rÅ  rÆ  rÇ  Úcentroid_normsr   r   r   Úknn_centroids_L2  rÌ  z"AdditiveQuantizer.knn_centroids_L2r'   )r   NN©r   ©r‹  r   )_r   r   r1   r2   r   r   rH   r   r
   r   ÚAdditiveQuantizer_M_getÚAdditiveQuantizer_M_setr  ÚAdditiveQuantizer_nbits_getÚAdditiveQuantizer_nbits_setr  ÚAdditiveQuantizer_codebooks_getÚAdditiveQuantizer_codebooks_setÚ	codebooksÚ&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_qnorm_getÚAdditiveQuantizer_qnorm_setÚqnormÚAdditiveQuantizer_norm_tabs_getÚAdditiveQuantizer_norm_tabs_setÚ	norm_tabsÚ'AdditiveQuantizer_max_mem_distances_getÚ'AdditiveQuantizer_max_mem_distances_setÚmax_mem_distancesro  rq  rt  Ú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Ö  rw  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_AdditiveQuantizerrv   r   r   r   r   rl  V
  sn    




	
rl  c                   @   sL  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZejZ	 ejZ	 ejZ	 eejejddZejZ	 ejZ	 eejejd	dZeejejd
dZeejej ddZ!eej"ej#ddZ$eej%ej&ddZ'dd„ Z(dd„ Z)d%dd„Z*dd„ Z+d&dd„Z,d'dd„Z-d&dd„Z.d(dd „Z/d!d"„ Z0eej1ej2d#dZ3eej4ej5d$dZ6ej7Z8dS ))Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   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                 G   r$  r'   )r   ÚResidualQuantizer_swiginitÚnew_ResidualQuantizerrp   r   r   r   rH   0  r.   zResidualQuantizer.__init__c                 C   r‹  )z Train the residual quantizer)r   ÚResidualQuantizer_trainr“  r   r   r   r”  3  ró  zResidualQuantizer.trainr   c                 C   r‹  )z< Copy the M codebook levels from other, starting from skip_M)r   Ú!ResidualQuantizer_initialize_from)r   r   Úskip_Mr   r   r   Úinitialize_from7  ró  z!ResidualQuantizer.initialize_fromc                 C   r‹  )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“  r   r   r   Úretrain_AQ_codebook;  s   z%ResidualQuantizer.retrain_AQ_codebookNc                 C   rm  ry  )r   Ú-ResidualQuantizer_compute_codes_add_centroidsr{  r   r   r   r|  J  r‚  z-ResidualQuantizer.compute_codes_add_centroidsc              
   C   rÃ  )aù  
         lower-level encode function

        :type n: int
        :param n:              number of vectors to hanlde
        :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   rQ   Ú	beam_sizerÈ  Únew_beam_sizeÚ	new_codesÚnew_residualsÚnew_distancesr   r   r   Úrefine_beamW  s   zResidualQuantizer.refine_beamc              	   C   rÈ  r'   )r   Ú!ResidualQuantizer_refine_beam_LUT)r   rQ   Úquery_normsÚquery_cpré  rê  rì  r   r   r   Úrefine_beam_LUTl  r.   z!ResidualQuantizer.refine_beam_LUTr   c                 C   rN   )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   rè  r   r   r   Úmemory_per_pointo  ó   z"ResidualQuantizer.memory_per_pointc                 C   rJ   )zu
         Cross products used in codebook tables

        These are used to keep trak of norms of centroids.
        )r   Ú)ResidualQuantizer_compute_codebook_tablesrL   r   r   r   Úcompute_codebook_tablesy  ó   
z)ResidualQuantizer.compute_codebook_tableszq
    dot products of all codebook vectors with each other
    size total_codebook_size * total_codebook_size
    z norms of all vectorsrá  r'   ©NNrš  )9r   r   r1   r2   r   r   r   r
   r   Ú ResidualQuantizer_train_type_getÚ ResidualQuantizer_train_type_setr  ÚResidualQuantizer_Train_defaultr  Ú'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_setr  Ú*ResidualQuantizer_assign_index_factory_getÚ*ResidualQuantizer_assign_index_factory_setÚassign_index_factoryrH   r”  rã  rå  r|  rí  rñ  ró  rö  Ú-ResidualQuantizer_codebook_cross_products_getÚ-ResidualQuantizer_codebook_cross_products_setÚcodebook_cross_productsÚ ResidualQuantizer_cent_norms_getÚ ResidualQuantizer_cent_norms_setÚ
cent_normsÚdelete_ResidualQuantizerrv   r   r   r   r   rÝ  
  sB    






rÝ  c                  G   r¼  )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 hanlde
    :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_stepr¾  r   r   r   r  ‹  s   
 r  c                  G   r¼  )zD Encode a set of vectors using their dot products with the codebooks)r   Úbeam_search_encode_step_tabr¾  r   r   r   r  ­  r`  r  c                   @   sd  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZeejejddZ eej!ej"ddZ#eej$ej%ddZ&eej'ej(ƒZ)eej*ej+ƒZ,dd„ Z-ej.Z/dd„ Z0d*dd„Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5d d!„ Z6d"d#„ Z7d$d%„ Z8d&d'„ Z9d*d(d)„Z:dS )+Ú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                 C   r5   r'   r6   r7   r   r   r   r9   Ã  r:   zLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ã  r>   r?   r@   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                 G   r$  r'   )r   ÚLocalSearchQuantizer_swiginitÚnew_LocalSearchQuantizerrp   r   r   r   rH   Õ  r.   zLocalSearchQuantizer.__init__c                 C   r‹  r'   )r   ÚLocalSearchQuantizer_trainr“  r   r   r   r”  Ù  r  zLocalSearchQuantizer.trainNc                 C   rm  )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{  r   r   r   r|  Ü  rê  z0LocalSearchQuantizer.compute_codes_add_centroidsc                 C   r‡  )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Ä  r   r   r   Úupdate_codebooksë  rÑ  z%LocalSearchQuantizer.update_codebooksc                 C   rŽ  )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  r8   rQ   Ú	ils_itersÚgenr   r   r   Ú
icm_encodeø  r»  zLocalSearchQuantizer.icm_encodec              
   C   rÃ  r'   )r   Ú$LocalSearchQuantizer_icm_encode_impl)r   r  r8   Úunariesr'  rQ   r&  r  r   r   r   Úicm_encode_impl  r  z$LocalSearchQuantizer.icm_encode_implc                 C   rŽ  r'   )r   Ú$LocalSearchQuantizer_icm_encode_step)r   r  r*  ÚbinariesrQ   Ún_itersr   r   r   Úicm_encode_step
  r|   z$LocalSearchQuantizer.icm_encode_stepc                 C   r‡  )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  rQ   r'  r   r   r   Úperturb_codes  r  z"LocalSearchQuantizer.perturb_codesc                 C   r‡  )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'  r   r   r   Úperturb_codebooks  r  z&LocalSearchQuantizer.perturb_codebooksc                 C   rN   )z€
         Compute binary terms

        :type binaries: float
        :param binaries: binary terms, size M * M * K * K
        )r   Ú)LocalSearchQuantizer_compute_binary_terms)r   r-  r   r   r   Úcompute_binary_terms#  r–  z)LocalSearchQuantizer.compute_binary_termsc                 C   r‡  )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   r8   r*  rQ   r   r   r   Úcompute_unary_terms,  rÑ  z(LocalSearchQuantizer.compute_unary_termsc                 C   rm  )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  r8   rQ   Úobjsr   r   r   Úevaluate9  s   zLocalSearchQuantizer.evaluater'   );r   r   r1   r2   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_factoryÚ5LocalSearchQuantizer_update_codebooks_with_double_getÚ5LocalSearchQuantizer_update_codebooks_with_double_setÚupdate_codebooks_with_doublerH   Údelete_LocalSearchQuantizerrv   r”  r|  r$  r(  r+  r/  r1  r5  r7  r9  r<  r   r   r   r   r  °  s:    
	r  c                   @   sn   e Zd Zedd„ d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ejZdd	„ Zd
d„ ZdS )Ú
IcmEncoderc                 C   r5   r'   r6   r7   r   r   r   r9   M  r:   zIcmEncoder.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   M  r>   r?   r@   c                 C   rh  r'   )r   ÚIcmEncoder_swiginitÚnew_IcmEncoder©r   Úlsqr   r   r   rH   S  r.   zIcmEncoder.__init__c                 C   rJ   r'   )r   ÚIcmEncoder_set_binary_termrL   r   r   r   Úset_binary_termW  rM   zIcmEncoder.set_binary_termc                 C   rŽ  )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  r8   r'  rQ   r&  r   r   r   r1  Z  r§  zIcmEncoder.encodeN)r   r   r1   r   r   r   r
   r   ÚIcmEncoder_binaries_getÚIcmEncoder_binaries_setr-  ÚIcmEncoder_verbose_getÚIcmEncoder_verbose_setr  ÚIcmEncoder_lsq_getÚIcmEncoder_lsq_setrf  rH   Údelete_IcmEncoderrv   rh  r1  r   r   r   r   rb  L  s    rb  c                   @   s<   e Zd Zedd„ dd„ ddZeZdd„ Zej	Z
dd	„ Zd
S )ÚIcmEncoderFactoryc                 C   r5   r'   r6   r7   r   r   r   r9   o  r:   zIcmEncoderFactory.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   o  r>   r?   r@   c                 C   rN   r'   )r   ÚIcmEncoderFactory_getre  r   r   r   Úgetr  rS   zIcmEncoderFactory.getc                 C   ry   r'   )r   ÚIcmEncoderFactory_swiginitÚnew_IcmEncoderFactoryrL   r   r   r   rH   v  r|   zIcmEncoderFactory.__init__N)r   r   r1   r   r   r   r
   rs  r   Údelete_IcmEncoderFactoryrv   rH   r   r   r   r   rq  n  s    rq  c                   @   ó^   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zdd„ Zdd„ ZejZdS )ÚLSQTimerz]
    A helper struct to count consuming time during training.
    It is NOT thread-safe.
    c                 C   r5   r'   r6   r7   r   r   r   r9   ‚  r:   zLSQTimer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ‚  r>   r?   r@   c                 C   ry   r'   )r   ÚLSQTimer_swiginitÚnew_LSQTimerrL   r   r   r   rH   †  r|   zLSQTimer.__init__c                 C   rN   r'   )r   ÚLSQTimer_get©r   r   r   r   r   rs  ‰  rS   zLSQTimer.getc                 C   r‹  r'   )r   ÚLSQTimer_add)r   r   Údeltar   r   r   r—  Œ  r  zLSQTimer.addc                 C   rJ   r'   )r   ÚLSQTimer_resetrL   r   r   r   r{    rM   zLSQTimer.resetN)r   r   r1   r2   r   r   r   r
   r   ÚLSQTimer_t_getÚLSQTimer_t_setÚtrH   rs  r—  r{  Údelete_LSQTimerrv   r   r   r   r   rx  |  s    
rx  c                   @   ót   e Zd Zedd„ d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d	„ ZejZd
S )ÚLSQTimerScopec                 C   r5   r'   r6   r7   r   r   r   r9   —  r:   zLSQTimerScope.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   —  r>   r?   r@   c                 C   r—  r'   )r   ÚLSQTimerScope_swiginitÚnew_LSQTimerScope)r   Útimerr   r   r   r   rH   ž  r  zLSQTimerScope.__init__c                 C   rJ   r'   )r   ÚLSQTimerScope_finishrL   r   r   r   Úfinish¡  rM   zLSQTimerScope.finishN)r   r   r1   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ÚfinishedrH   rŠ  Údelete_LSQTimerScoperv   r   r   r   r   r…  –  ó    
r…  c                   @   s    e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejƒZdd	„ ZejZd
d„ Zdd„ Zdd„ Zddd„Zddd„Zddd„Zdd„ Zddd„ZdS ) Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ²  r:   z!ProductAdditiveQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ²  r>   r?   r@   z- number of sub-vectors we split a vector intoc                 G   r$  r'   )r   Ú!ProductAdditiveQuantizer_swiginitÚnew_ProductAdditiveQuantizerrp   r   r   r   rH   ·  r.   z!ProductAdditiveQuantizer.__init__c                 C   r‡  r'   )r   ÚProductAdditiveQuantizer_init)r   r†  ÚaqsrÕ  r   r   r   Úinit»  r‰  zProductAdditiveQuantizer.initc                 C   rN   )z% Train the product additive quantizer)r   Ú%ProductAdditiveQuantizer_subquantizer)r   rð  r   r   r   Úsubquantizer¾  r
  z%ProductAdditiveQuantizer.subquantizerc                 C   r‹  r'   )r   ÚProductAdditiveQuantizer_trainr“  r   r   r   r”  Â  r  zProductAdditiveQuantizer.trainNc                 C   rm  ry  )r   Ú4ProductAdditiveQuantizer_compute_codes_add_centroidsr{  r   r   r   r|  Å  r‚  z4ProductAdditiveQuantizer.compute_codes_add_centroidsc                 C   rm  r'   )r   Ú/ProductAdditiveQuantizer_compute_unpacked_codesr{  r   r   r   Úcompute_unpacked_codesÒ  rr   z/ProductAdditiveQuantizer.compute_unpacked_codesr   c                 C   rm  r„  )r   Ú(ProductAdditiveQuantizer_decode_unpackedr†  r   r   r   r‡  Õ  rˆ  z(ProductAdditiveQuantizer.decode_unpackedc                 C   r‡  r  )r   ÚProductAdditiveQuantizer_decoderƒ  r   r   r   rÈ  à  r  zProductAdditiveQuantizer.decoder‹  c                 C   rŽ  )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  r   r   r   r‘  ë  r»  z$ProductAdditiveQuantizer.compute_LUTr'   rš  r›  )r   r   r1   r2   r   r   r   r
   r   Ú$ProductAdditiveQuantizer_nsplits_getÚ$ProductAdditiveQuantizer_nsplits_setÚnsplitsÚ'ProductAdditiveQuantizer_quantizers_getÚ'ProductAdditiveQuantizer_quantizers_setÚ
quantizersrH   Údelete_ProductAdditiveQuantizerrv   rœ  rž  r”  r|  r¢  r‡  rÈ  r‘  r   r   r   r   r—  ¨  s     	


r—  c                   @   ó8   e Zd ZdZedd„ dd„ ddZeZdd„ Ze	j
Zd	S )
ÚProductLocalSearchQuantizerz Product Local Search Quantizerc                 C   r5   r'   r6   r7   r   r   r   r9      r:   z$ProductLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9      r>   r?   r@   c                 G   r$  r'   )r   Ú$ProductLocalSearchQuantizer_swiginitÚnew_ProductLocalSearchQuantizerrp   r   r   r   rH     r.   z$ProductLocalSearchQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Ú"delete_ProductLocalSearchQuantizerrv   r   r   r   r   r®  ý  ó    
r®  c                   @   r­  )
ÚProductResidualQuantizerz Product Residual Quantizerc                 C   r5   r'   r6   r7   r   r   r   r9     r:   z!ProductResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   Ú!ProductResidualQuantizer_swiginitÚnew_ProductResidualQuantizerrp   r   r   r   rH     r.   z!ProductResidualQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_ProductResidualQuantizerrv   r   r   r   r   r³  
  r²  r³  c                   @   s‚   e Zd ZdZedd„ dd„ ddZ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d„ Zdd„ Zdd„ Ze	jZdS )Ú
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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zCodePacker.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   !  rI   zCodePacker.__init__c                 C   r‡  r'   )r   ÚCodePacker_pack_1©r   Ú	flat_coder.  Úblockr   r   r   Úpack_1(  r‰  zCodePacker.pack_1c                 C   r‡  r'   )r   ÚCodePacker_unpack_1©r   r»  r.  rº  r   r   r   Úunpack_1+  r‰  zCodePacker.unpack_1c                 C   r‹  r'   )r   ÚCodePacker_pack_all©r   Ú
flat_codesr»  r   r   r   Úpack_all.  r  zCodePacker.pack_allc                 C   r‹  r'   )r   ÚCodePacker_unpack_all©r   r»  rÂ  r   r   r   Ú
unpack_all1  r  zCodePacker.unpack_allN)r   r   r1   r2   r   r   rH   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_CodePackerrv   r   r   r   r   r·    s    
r·  c                   @   sX   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZejZdS )ÚCodePackerFlatz6 Trivial code packer where codes are stored one by onec                 C   r5   r'   r6   r7   r   r   r   r9   ;  r:   zCodePackerFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ;  r>   r?   r@   c                 C   rh  r'   )r   ÚCodePackerFlat_swiginitÚnew_CodePackerFlat)r   rœ  r   r   r   rH   >  r.   zCodePackerFlat.__init__c                 C   r‡  r'   )r   ÚCodePackerFlat_pack_1r¹  r   r   r   r¼  A  r‰  zCodePackerFlat.pack_1c                 C   r‡  r'   )r   ÚCodePackerFlat_unpack_1r¾  r   r   r   r¿  D  r‰  zCodePackerFlat.unpack_1c                 C   r‹  r'   )r   ÚCodePackerFlat_pack_allrÁ  r   r   r   rÃ  G  r  zCodePackerFlat.pack_allc                 C   r‹  r'   )r   ÚCodePackerFlat_unpack_allrÅ  r   r   r   rÆ  J  r  zCodePackerFlat.unpack_allN)r   r   r1   r2   r   r   r   r
   rH   r¼  r¿  rÃ  rÆ  r   Údelete_CodePackerFlatrv   r   r   r   r   rÐ  8  s    
rÐ  c                   @   s’   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jƒZee	je	jd	dZee	je	jd
dZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze	jZdS )ÚVectorTransformz/ Any transformation applied on a set of vectorsc                 C   r5   r'   r6   r7   r   r   r   r9   T  r:   zVectorTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   T  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   V  rI   zVectorTransform.__init__zinput dimensionzb
    set if the VectorTransform does not require training, or if
    training is done already
    c                 C   r‹  )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“  r   r   r   r”  `  r˜  zVectorTransform.trainc                 C   r‹  )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“  r   r   r   Úapplyl  r˜  zVectorTransform.applyc                 C   r‡  )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   rQ   r8   Úxtr   r   r   Úapply_noallocx  rž  zVectorTransform.apply_noallocc                 C   r‡  )zi
        reverse transformation. May not be implemented or may return
        approximate result
        )r   Ú!VectorTransform_reverse_transform©r   rQ   rÞ  r8   r   r   r   Úreverse_transform„  rù  z!VectorTransform.reverse_transformc                 C   rN   r'   )r   ÚVectorTransform_check_identicalrŒ   r   r   r   Úcheck_identical‹  rS   zVectorTransform.check_identicalN)r   r   r1   r2   r   r   rH   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_VectorTransformrv   r   r   r   r   rØ  Q  s    
rØ  c                   @   s¼   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZeejejddZeejejd	dZddd„Zdd„ Zdd„ Zdd„ Zdd„ ZeejejƒZdd„ Zdd„ ZejZ dS )ÚLinearTransformz\
     Generic linear transformation, with bias term applied on output
    y = A * x + b
    c                 C   r5   r'   r6   r7   r   r   r   r9   ˜  r:   zLinearTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ˜  r>   r?   r@   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_outr   Fc                 C   ó   t  | t  |||¡¡ dS )z1 both d_in > d_out and d_out < d_in are supportedN)r   ÚLinearTransform_swiginitÚnew_LinearTransform)r   rç  rê  Ú	have_biasr   r   r   rH   ¢  ó   zLinearTransform.__init__c                 C   r‡  )z+ same as apply, but result is pre-allocated)r   ÚLinearTransform_apply_noallocrÝ  r   r   r   rß  ¦  r  zLinearTransform.apply_noallocc                 C   r‡  )zc
        compute x = A^T * (x - b)
        is reverse transform if A has orthonormal lines
        )r   Ú#LinearTransform_transform_transpose)r   rQ   r  r8   r   r   r   Útransform_transposeª  rù  z#LinearTransform.transform_transposec                 C   r‡  )z works only if is_orthonormal)r   Ú!LinearTransform_reverse_transformrá  r   r   r   râ  ±  r  z!LinearTransform.reverse_transformc                 C   rJ   )z/ compute A^T * A to set the is_orthonormal flag)r   Ú"LinearTransform_set_is_orthonormalrL   r   r   r   Úset_is_orthonormalµ  r`  z"LinearTransform.set_is_orthonormalc                 C   rm  r'   )r   Ú LinearTransform_print_if_verbose)r   r   ÚmatrQ   r†  r   r   r   Úprint_if_verboseº  rr   z LinearTransform.print_if_verbosec                 C   rN   r'   )r   ÚLinearTransform_check_identicalrŒ   r   r   r   rä  ½  rS   zLinearTransform.check_identicalN©r   r   F)!r   r   r1   r2   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…  rH   rß  rö  râ  rù  ÚLinearTransform_verbose_getÚLinearTransform_verbose_setr  rü  rä  Údelete_LinearTransformrv   r   r   r   r   rî  ’  s"    

rî  c                   @   sH   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
ejZdS )ÚRandomRotationMatrixz! Randomly rotate a set of vectorsc                 C   r5   r'   r6   r7   r   r   r   r9   Ç  r:   zRandomRotationMatrix.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ç  r>   r?   r@   c                 C   rN   )z, must be called before the transform is used)r   ÚRandomRotationMatrix_initrk  r   r   r   rœ  Ê  r
  zRandomRotationMatrix.initc                 C   r‹  r'   )r   ÚRandomRotationMatrix_trainr“  r   r   r   r”  Î  r  zRandomRotationMatrix.trainc                 G   r$  r'   )r   ÚRandomRotationMatrix_swiginitÚnew_RandomRotationMatrixrp   r   r   r   rH   Ñ  r.   zRandomRotationMatrix.__init__N)r   r   r1   r2   r   r   r   r
   rœ  r”  rH   r   Údelete_RandomRotationMatrixrv   r   r   r   r   r  Ä  s    
r  c                   @   sâ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZeejejddZ ddd„Z!dd„ Z"dd„ Z#dd„ Z$ej%Z&dS )Ú	PCAMatrixzx
    Applies a principal component analysis on a set of vectors,
    with optionally whitening and random rotation.
    c                 C   r5   r'   r6   r7   r   r   r   r9   Þ  r:   zPCAMatrix.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Þ  r>   r?   r@   zŒ
     after transformation the components are multiplied by
    eigenvalues^eigen_power

    =0: no whitening
    =-0.5: full whitening
    zA value added to eigenvalues to avoid division by 0 when whiteningz random rotation after PCAz/ ratio between # training vectors and dimensionz8 try 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_inr   Fc              	   C   ó   t  | t  ||||¡¡ d S r'   )r   ÚPCAMatrix_swiginitÚnew_PCAMatrix)r   rç  rê  Úeigen_powerÚrandom_rotationr   r   r   rH   ï  ó   zPCAMatrix.__init__c                 C   r‹  )zo
        train on n vectors. If n < d_in then the eigenvector matrix
        will be completed with 0s
        )r   ÚPCAMatrix_trainr“  r   r   r   r”  ò  râ  zPCAMatrix.trainc                 C   rN   )z copy pre-trained PCA matrix)r   ÚPCAMatrix_copy_fromrŒ   r   r   r   Ú	copy_fromù  r
  zPCAMatrix.copy_fromc                 C   rJ   )z7 called after mean, PCAMat and eigenvalues are computed)r   ÚPCAMatrix_prepare_AbrL   r   r   r   Ú
prepare_Abý  r`  zPCAMatrix.prepare_AbN)r   r   r   F)'r   r   r1   r2   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_setr  Ú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ÚPCAMatrH   r”  r  r  Údelete_PCAMatrixrv   r   r   r   r   r  Ø  s"    

r  c                   @   sl   e Zd ZdZedd„ d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d	„Zd
d„ ZejZdS )Ú	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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zITQMatrix.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   r   c                 C   rh  r'   )r   ÚITQMatrix_swiginitÚnew_ITQMatrix©r   r†  r   r   r   rH     r.   zITQMatrix.__init__c                 C   r‹  r'   )r   ÚITQMatrix_trainr“  r   r   r   r”    r  zITQMatrix.trainNrá  )r   r   r1   r2   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_rotationrH   r”  Údelete_ITQMatrixrv   r   r   r   r   r5    s    


r5  c                   @   sœ   e Zd ZdZedd„ d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dZeejejƒZdd
d„Zdd„ Zdd„ Zdd„ ZejZdS )ÚITQTransformzH The full ITQ transform, including normalizations and PCA transformationc                 C   r5   r'   r6   r7   r   r   r   r9   #  r:   zITQTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   #  r>   r?   r@   z" max training points per dimensionr   Fc                 C   r+  r'   )r   ÚITQTransform_swiginitÚnew_ITQTransform)r   rç  rê  Údo_pcar   r   r   rH   +  r/  zITQTransform.__init__c                 C   r‹  r'   )r   ÚITQTransform_trainr“  r   r   r   r”  .  r  zITQTransform.trainc                 C   r‡  r'   )r   ÚITQTransform_apply_noallocrÝ  r   r   r   rß  1  r‰  zITQTransform.apply_noallocc                 C   rN   r'   )r   ÚITQTransform_check_identicalrŒ   r   r   r   rä  4  rS   zITQTransform.check_identicalNrþ  )r   r   r1   r2   r   r   r   r
   r   ÚITQTransform_mean_getÚITQTransform_mean_setr-  ÚITQTransform_do_pca_getÚITQTransform_do_pca_setrF  Ú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_itqrH   r”  rß  rä  Údelete_ITQTransformrv   r   r   r   r   rC     s    

rC  c                   @   s¼   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejƒZeejejddZddd„Zdd„ Zej Z!dS )Ú	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                 C   r5   r'   r6   r7   r   r   r   r9   E  r:   zOPQMatrix.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   E  r>   r?   r@   z nb of subquantizersz$ Number of outer training iterationsz) Number of training iterations for the PQz$ same, for the first outer iterationz0 if there are too many training points, resamplezk
    if non-NULL, use this product quantizer for training
    should be constructed with (d_out, M, _)
    r   r   r   c                 C   rï  )z. if d2 != -1, output vectors of this dimensionN)r   ÚOPQMatrix_swiginitÚnew_OPQMatrix)r   r†  r  Úd2r   r   r   rH   R  ró  zOPQMatrix.__init__c                 C   r‹  r'   )r   ÚOPQMatrix_trainr“  r   r   r   r”  V  r  zOPQMatrix.trainN)r   r   r   )"r   r   r1   r2   r   r   r   r
   r   ÚOPQMatrix_M_getÚOPQMatrix_M_setr  ÚOPQMatrix_niter_getÚOPQMatrix_niter_setrI  Ú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ÚpqrH   r”  Údelete_OPQMatrixrv   r   r   r   r   rX  ;  s    	

rX  c                   @   sb   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	„ Zd
d„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   d  r:   z!RemapDimensionsTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   d  r>   r?   r@   zR
    map from output dimension to input, size d_out
    -1 -> set output to 0
    c                 C   r‡  r'   )r   Ú&RemapDimensionsTransform_apply_noallocrÝ  r   r   r   rß  k  r‰  z&RemapDimensionsTransform.apply_noallocc                 C   r‡  )zA reverse transform correct only when the mapping is a permutation)r   Ú*RemapDimensionsTransform_reverse_transformrá  r   r   r   râ  n  r  z*RemapDimensionsTransform.reverse_transformc                 G   r$  r'   )r   Ú!RemapDimensionsTransform_swiginitÚnew_RemapDimensionsTransformrp   r   r   r   rH   r  r.   z!RemapDimensionsTransform.__init__c                 C   rN   r'   )r   Ú(RemapDimensionsTransform_check_identicalrŒ   r   r   r   rä  u  rS   z(RemapDimensionsTransform.check_identicalN)r   r   r1   r2   r   r   r   r
   r   Ú RemapDimensionsTransform_map_getÚ RemapDimensionsTransform_map_setÚmaprß  râ  rH   rä  Údelete_RemapDimensionsTransformrv   r   r   r   r   rp  ]  s    
rp  c                   @   rw  )ÚNormalizationTransformz per-vector normalizationc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zNormalizationTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   ÚNormalizationTransform_swiginitÚnew_NormalizationTransformrp   r   r   r   rH   ƒ  r.   zNormalizationTransform.__init__c                 C   r‡  r'   )r   Ú$NormalizationTransform_apply_noallocrÝ  r   r   r   rß  †  r‰  z$NormalizationTransform.apply_noallocc                 C   r‡  )z0 Identity transform since norm is not revertible)r   Ú(NormalizationTransform_reverse_transformrá  r   r   r   râ  ‰  r  z(NormalizationTransform.reverse_transformc                 C   rN   r'   )r   Ú&NormalizationTransform_check_identicalrŒ   r   r   r   rä    rS   z&NormalizationTransform.check_identicalN)r   r   r1   r2   r   r   r   r
   r   ÚNormalizationTransform_norm_getÚNormalizationTransform_norm_setrn  rH   rß  râ  rä  Údelete_NormalizationTransformrv   r   r   r   r   rz  |  s    
rz  c                   @   sl   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	d
„Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚCenteringTransformz6 Subtract the mean of each component from the vectors.c                 C   r5   r'   r6   r7   r   r   r   r9   —  r:   zCenteringTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   —  r>   r?   r@   z Mean, size d_in = d_outr   c                 C   rh  r'   )r   ÚCenteringTransform_swiginitÚnew_CenteringTransformr8  r   r   r   rH   ›  r.   zCenteringTransform.__init__c                 C   r‹  )z train on n vectors.)r   ÚCenteringTransform_trainr“  r   r   r   r”  ž  ró  zCenteringTransform.trainc                 C   r‡  )z subtract the mean)r   Ú CenteringTransform_apply_noallocrÝ  r   r   r   rß  ¢  r  z CenteringTransform.apply_noallocc                 C   r‡  )z add the mean)r   Ú$CenteringTransform_reverse_transformrá  r   r   r   râ  ¦  r  z$CenteringTransform.reverse_transformc                 C   rN   r'   )r   Ú"CenteringTransform_check_identicalrŒ   r   r   r   rä  ª  rS   z"CenteringTransform.check_identicalNrá  )r   r   r1   r2   r   r   r   r
   r   ÚCenteringTransform_mean_getÚCenteringTransform_mean_setr-  rH   r”  rß  râ  rä  Údelete_CenteringTransformrv   r   r   r   r   rƒ  ”  s    

rƒ  c                   @   óF   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ ZejZd	S )
ÚSearchParametersPreTransformrô  c                 C   r5   r'   r6   r7   r   r   r   r9   ¹  r:   z%SearchParametersPreTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¹  r>   r?   r@   c                 C   ry   r'   )r   Ú%SearchParametersPreTransform_swiginitÚ new_SearchParametersPreTransformrL   r   r   r   rH   ½  r|   z%SearchParametersPreTransform.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú-SearchParametersPreTransform_index_params_getÚ-SearchParametersPreTransform_index_params_setÚindex_paramsrH   Ú#delete_SearchParametersPreTransformrv   r   r   r   r   rŽ  ±  s    
rŽ  c                   @   s
  e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZeejejddZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd3dd„Zd3dd„Zdd„ Zdd„ Zd3d d!„Zd"d#„ Zd$d%„ Zd&d'„ Z d(d)„ Z!d*d+„ Z"d,d-„ Z#d4d/d0„Z$d1d2„ Z%ej&Z'dS )5ÚIndexPreTransformzo
    Index that applies a LinearTransform transform on vectors before
    handing them over to a sub-index
    c                 C   r5   r'   r6   r7   r   r   r   r9   Ê  r:   zIndexPreTransform.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ê  r>   r?   r@   zchain of tranformsúthe sub-indexc                 G   ó   t  | t j|Ž ¡ dS )z«
        *Overload 1:*
        whether pointers are deleted in destructor

        |

        *Overload 2:*
         ltrans is the last transform before the index
        N)r   ÚIndexPreTransform_swiginitÚnew_IndexPreTransformrp   r   r   r   rH   Ð  ó   
zIndexPreTransform.__init__c                 C   rN   r'   )r   Ú#IndexPreTransform_prepend_transform)r   Últransr   r   r   Úprepend_transformÜ  rS   z#IndexPreTransform.prepend_transformc                 C   r‹  r'   )r   ÚIndexPreTransform_trainr“  r   r   r   r”  ß  r  zIndexPreTransform.trainc                 C   r‹  r'   )r   ÚIndexPreTransform_addr“  r   r   r   r—  â  r  zIndexPreTransform.addc                 C   r‡  r'   )r   ÚIndexPreTransform_add_with_idsr›  r   r   r   r  å  r‰  zIndexPreTransform.add_with_idsc                 C   rJ   r'   )r   ÚIndexPreTransform_resetrL   r   r   r   r{  è  rM   zIndexPreTransform.resetc                 C   rN   )z: removes IDs from the index. Not supported by all indexes.)r   ÚIndexPreTransform_remove_idsr­  r   r   r   r®  ë  r
  zIndexPreTransform.remove_idsNc              	   C   rÈ  r'   )r   ÚIndexPreTransform_searchr   r   r   r   r¢  ï  r.   zIndexPreTransform.searchc                 C   rŽ  r'   )r   ÚIndexPreTransform_range_searchr¥  r   r   r   r¦  ò  r|   zIndexPreTransform.range_searchc                 C   r‹  r'   )r   ÚIndexPreTransform_reconstructr±  r   r   r   r´  õ  r  zIndexPreTransform.reconstructc                 C   r‡  r'   )r   ÚIndexPreTransform_reconstruct_nrº  r   r   r   r½  ø  r‰  zIndexPreTransform.reconstruct_nc              
   C   rÃ  r'   )r   Ú(IndexPreTransform_search_and_reconstructrÀ  r   r   r   rÁ  û  r  z(IndexPreTransform.search_and_reconstructc                 C   r‹  )zˆ
        apply the transforms in the chain. The returned float * may be
        equal to x, otherwise it should be deallocated.
        )r   ÚIndexPreTransform_apply_chainr“  r   r   r   Úapply_chainþ  râ  zIndexPreTransform.apply_chainc                 C   r‡  )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á  r   r   r   Úreverse_chain  rù  zIndexPreTransform.reverse_chainc                 C   rJ   r'   )r   Ú'IndexPreTransform_get_distance_computerrL   r   r   r   rË    rM   z'IndexPreTransform.get_distance_computerc                 C   rJ   r'   )r   ÚIndexPreTransform_sa_code_sizerL   r   r   r   rÍ    rM   zIndexPreTransform.sa_code_sizec                 C   r‡  r'   )r   ÚIndexPreTransform_sa_encoderÏ  r   r   r   rÐ    r‰  zIndexPreTransform.sa_encodec                 C   r‡  r'   )r   ÚIndexPreTransform_sa_decoderÓ  r   r   r   rÔ    r‰  zIndexPreTransform.sa_decoder   c                 C   r‹  r'   )r   ÚIndexPreTransform_merge_fromr×  r   r   r   rÚ    r  zIndexPreTransform.merge_fromc                 C   rN   r'   )r   Ú,IndexPreTransform_check_compatible_for_mergerÞ  r   r   r   rß    rS   z,IndexPreTransform.check_compatible_for_merger'   rá  )(r   r   r1   r2   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_fieldsrH   r  r”  r—  r  r{  r®  r¢  r¦  r´  r½  rÁ  r©  r«  rË  rÍ  rÐ  rÔ  rÚ  rß  Údelete_IndexPreTransformrv   r   r   r   r   r•  Ä  s8    




r•  c                   @   sÔ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Z ej!Z"dS ) ÚIndexRefinezŒ
    Index that queries in a base_index (a fast one) and refines the
    results with an exact search, hopefully improving the results.
    c                 C   r5   r'   r6   r7   r   r   r   r9   (  r:   zIndexRefine.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   (  r>   r?   r@   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                 G   r$  r'   )r   ÚIndexRefine_swiginitÚnew_IndexRefinerp   r   r   r   rH   3  r.   zIndexRefine.__init__c                 C   r‹  r'   )r   ÚIndexRefine_trainr“  r   r   r   r”  6  r  zIndexRefine.trainc                 C   r‹  r'   )r   ÚIndexRefine_addr“  r   r   r   r—  9  r  zIndexRefine.addc                 C   rJ   r'   )r   ÚIndexRefine_resetrL   r   r   r   r{  <  rM   zIndexRefine.resetNc              	   C   rÈ  r'   )r   ÚIndexRefine_searchr   r   r   r   r¢  ?  r.   zIndexRefine.searchc                 C   r‹  r'   )r   ÚIndexRefine_reconstructr±  r   r   r   r´  B  r  zIndexRefine.reconstructc                 C   rJ   r'   )r   ÚIndexRefine_sa_code_sizerL   r   r   r   rÍ  E  rM   zIndexRefine.sa_code_sizec                 C   r‡  r'   )r   ÚIndexRefine_sa_encoderÏ  r   r   r   rÐ  H  r‰  zIndexRefine.sa_encodec                 C   r‡  )zk
        The sa_decode decodes from the index_refine, which is assumed to be more
        accurate
        )r   ÚIndexRefine_sa_decoderÓ  r   r   r   rÔ  K  rù  zIndexRefine.sa_decoder'   )#r   r   r1   r2   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_setr¹  Ú IndexRefine_own_refine_index_getÚ IndexRefine_own_refine_index_setÚown_refine_indexÚIndexRefine_k_factor_getÚIndexRefine_k_factor_setÚk_factorrH   r”  r—  r{  r¢  r´  rÍ  rÐ  rÔ  Údelete_IndexRefinerv   r   r   r   r   r»  "  s&    

r»  c                   @   sB   e Zd ZdZedd„ dd„ ddZeZdd„ Zdd
d„Z	e
jZd	S )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ]  r:   zIndexRefineFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ]  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexRefineFlat_swiginitÚnew_IndexRefineFlatrp   r   r   r   rH   `  r.   zIndexRefineFlat.__init__Nc              	   C   rÈ  r'   )r   ÚIndexRefineFlat_searchr   r   r   r   r¢  c  r.   zIndexRefineFlat.searchr'   )r   r   r1   r2   r   r   r   r
   rH   r¢  r   Údelete_IndexRefineFlatrv   r   r   r   r   rÕ  V  s    

rÕ  c                   @   sÄ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZdd„ Zdd„ Zddd„Zdd„ ZejZdd„ Zdd„ Zdd„ Z dS )ÚIndexLSHz? The sign of each vector component is put in a binary signaturec                 C   r5   r'   r6   r7   r   r   r   r9   m  r:   zIndexLSH.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   m  r>   r?   r@   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                 C   r‹  )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“  r   r   r   Úapply_preprocessu  r  zIndexLSH.apply_preprocessc                 C   r‹  r'   )r   ÚIndexLSH_trainr“  r   r   r   r”  ‚  r  zIndexLSH.trainNc              	   C   rÈ  r'   )r   ÚIndexLSH_searchr   r   r   r   r¢  …  r.   zIndexLSH.searchc                 C   rN   )zh
        transfer the thresholds to a pre-processing stage (and unset
        train_thresholds)
        )r   ÚIndexLSH_transfer_thresholds)r   Úvtr   r   r   Útransfer_thresholdsˆ  r¯  zIndexLSH.transfer_thresholdsc                 G   r$  r'   )r   ÚIndexLSH_swiginitÚnew_IndexLSHrp   r   r   r   rH     r.   zIndexLSH.__init__c                 C   r‡  r'   )r   ÚIndexLSH_sa_encoderÏ  r   r   r   rÐ  “  r‰  zIndexLSH.sa_encodec                 C   r‡  r'   )r   ÚIndexLSH_sa_decoderÓ  r   r   r   rÔ  –  r‰  zIndexLSH.sa_decoder'   )!r   r   r1   r2   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_IndexLSHrv   rH   rÐ  rÔ  r   r   r   r   rÚ  j  s"    
rÚ  c                   @   s¨   e Zd ZdZedd„ d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jƒZeejejƒZeejejƒZ dd„ Z!ej"Z#d	S )
ÚSimulatedAnnealingParametersz3 parameters used for the simulated annealing methodc                 C   r5   r'   r6   r7   r   r   r   r9   Ÿ  r:   z%SimulatedAnnealingParameters.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ÿ  r>   r?   r@   c                 C   ry   r'   )r   Ú%SimulatedAnnealingParameters_swiginitÚ new_SimulatedAnnealingParametersrL   r   r   r   rH   ª  r|   z%SimulatedAnnealingParameters.__init__N)$r   r   r1   r2   r   r   r   r
   r   Ú1SimulatedAnnealingParameters_init_temperature_getÚ1SimulatedAnnealingParameters_init_temperature_setÚinit_temperatureÚ2SimulatedAnnealingParameters_temperature_decay_getÚ2SimulatedAnnealingParameters_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_randomrH   Ú#delete_SimulatedAnnealingParametersrv   r   r   r   r   rõ  œ  s    
rõ  c                   @   óV   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jƒZd	d
„ Zdd„ Ze	jZdS )ÚPermutationObjectivez% abstract class for the loss functionc                 C   r5   r'   r6   r7   r   r   r   r9   ´  r:   zPermutationObjective.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ´  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ¶  rI   zPermutationObjective.__init__c                 C   rN   r'   )r   Ú!PermutationObjective_compute_cost©r   rx  r   r   r   Úcompute_cost»  rS   z!PermutationObjective.compute_costc                 C   r‡  r'   )r   Ú PermutationObjective_cost_update©r   rx  ÚiwÚjwr   r   r   Úcost_update¾  r‰  z PermutationObjective.cost_updateN)r   r   r1   r2   r   r   rH   r   r
   r   ÚPermutationObjective_n_getÚPermutationObjective_n_setrQ   r  r  Údelete_PermutationObjectiverv   r   r   r   r   r  ±  s    
r  c                   @   s¸   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
edd„ ƒZdd	„ Zeejejd
dZeejejddZeejejddZdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ ZejZdS )ÚReproduceDistancesObjectivec                 C   r5   r'   r6   r7   r   r   r   r9   Æ  r:   z$ReproduceDistancesObjective.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Æ  r>   r?   r@   c                 C   rJ   r'   ©r   ÚReproduceDistancesObjective_sqrr7   r   r   r   ÚsqrÊ  r`  zReproduceDistancesObjective.sqrc                 C   rN   r'   )r   Ú&ReproduceDistancesObjective_dis_weightrW   r   r   r   Ú
dis_weightÎ  rS   z&ReproduceDistancesObjective.dis_weightz& "real" corrected distances (size n^2)z wanted distances (size n^2)z% weights for each distance (size n^2)c                 C   r‹  r'   )r   Ú*ReproduceDistancesObjective_get_source_disrû  r   r   r   Úget_source_disÔ  r  z*ReproduceDistancesObjective.get_source_disc                 C   rN   r'   )r   Ú(ReproduceDistancesObjective_compute_costr  r   r   r   r  ×  rS   z(ReproduceDistancesObjective.compute_costc                 C   r‡  r'   )r   Ú'ReproduceDistancesObjective_cost_updater  r   r   r   r  Ú  r‰  z'ReproduceDistancesObjective.cost_updatec              	   C   r  r'   )r   Ú$ReproduceDistancesObjective_swiginitÚnew_ReproduceDistancesObjective)r   rQ   Úsource_dis_inÚtarget_dis_inÚdis_weight_factorr   r   r   rH   Ý  r  z$ReproduceDistancesObjective.__init__c                 C   r‡  r'   ©r   Ú.ReproduceDistancesObjective_compute_mean_stdev©rà  rÑ  Úmean_outÚ
stddev_outr   r   r   Úcompute_mean_stdevà  r  z.ReproduceDistancesObjective.compute_mean_stdevc                 C   rN   r'   )r   Ú1ReproduceDistancesObjective_set_affine_target_dis)r   r(  r   r   r   Úset_affine_target_disä  rS   z1ReproduceDistancesObjective.set_affine_target_disN)r   r   r1   r   r   r   r
   r   Ú1ReproduceDistancesObjective_dis_weight_factor_getÚ1ReproduceDistancesObjective_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  rH   r0  r2  Ú"delete_ReproduceDistancesObjectiverv   r   r   r   r   r  Å  s$    


r  c                 C   rJ   r'   r  r7   r   r   r   r  ë  rM   r  c                 C   r‡  r'   r+  r-  r   r   r   r,  î  r‰  r,  c                   @   s–   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZeejejƒZdd	„ ZeejejƒZeejejd
dZdd„ Zdd„ ZejZdS )ÚSimulatedAnnealingOptimizerz= Simulated annealing optimization algorithm for permutations.c                 C   r5   r'   r6   r7   r   r   r   r9   ô  r:   z$SimulatedAnnealingOptimizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ô  r>   r?   r@   z size of the permutationc                 C   ó   t  | t  ||¡¡ dS )z! logs values of the cost functionN)r   Ú$SimulatedAnnealingOptimizer_swiginitÚnew_SimulatedAnnealingOptimizer)r   rl  rN  r   r   r   rH   ú  rW  z$SimulatedAnnealingOptimizer.__init__z& remember initial cost of optimizationc                 C   rN   r'   )r   Ú$SimulatedAnnealingOptimizer_optimizer  r   r   r   Úoptimize   rS   z$SimulatedAnnealingOptimizer.optimizec                 C   rN   r'   )r   Ú,SimulatedAnnealingOptimizer_run_optimization)r   Ú	best_permr   r   r   Úrun_optimization  rS   z,SimulatedAnnealingOptimizer.run_optimizationN)r   r   r1   r2   r   r   r   r
   r   Ú#SimulatedAnnealingOptimizer_obj_getÚ#SimulatedAnnealingOptimizer_obj_setrl  Ú!SimulatedAnnealingOptimizer_n_getÚ!SimulatedAnnealingOptimizer_n_setrQ   Ú'SimulatedAnnealingOptimizer_logfile_getÚ'SimulatedAnnealingOptimizer_logfile_setÚlogfilerH   Ú#SimulatedAnnealingOptimizer_rnd_getÚ#SimulatedAnnealingOptimizer_rnd_setÚrndÚ)SimulatedAnnealingOptimizer_init_cost_getÚ)SimulatedAnnealingOptimizer_init_cost_setÚ	init_costrD  rG  Ú"delete_SimulatedAnnealingOptimizerrv   r   r   r   r   r?  ñ  s    
r?  c                   @   sÀ   e Zd ZdZedd„ d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dZeejejddZeejejd	dZeejejƒZd
d„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"ej#Z$dS )ÚPolysemousTrainingz5 optimizes the order of indices in a ProductQuantizerc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zPolysemousTraining.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   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 losszA refuse to train if it would require more than that amount of RAMc                 C   ry   r'   )r   ÚPolysemousTraining_swiginitÚnew_PolysemousTrainingrL   r   r   r   rH   !  r|   zPolysemousTraining.__init__c                 C   r‡  )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   rn  rQ   r8   r   r   r   Úoptimize_pq_for_hamming$  rù  z*PolysemousTraining.optimize_pq_for_hammingc                 C   r‡  ©z" called by optimize_pq_for_hamming)r   Ú#PolysemousTraining_optimize_rankingrZ  r   r   r   Úoptimize_ranking+  r  z#PolysemousTraining.optimize_rankingc                 C   rN   r\  )r   Ú/PolysemousTraining_optimize_reproduce_distances©r   rn  r   r   r   Úoptimize_reproduce_distances/  r
  z/PolysemousTraining.optimize_reproduce_distancesc                 C   rN   )z& make sure we don't blow up the memory)r   Ú*PolysemousTraining_memory_usage_per_threadr`  r   r   r   Úmemory_usage_per_thread3  r
  z*PolysemousTraining.memory_usage_per_threadN)%r   r   r1   r2   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_patternrH   r[  r^  ra  rc  Údelete_PolysemousTrainingrv   r   r   r   r   rV  
  s(    
rV  c                   @   s  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	„ Zd
d„ Zddd„Zdd„ Zdd„ Zdd„ ZeejejddZeejejddZejZ	 ejZ	 ejZ	 ejZ	 ej Z!	 ej"Z#	 eej$ej%ƒZ&eej'ej(ƒZ)eej*ej+ddZ,dd„ Z-dd„ Z.dd„ Z/ej0Z1dS )ÚIndexPQz_
     Index based on a product quantizer. Stored vectors are
    approximated by PQ codes.
    c                 C   r5   r'   r6   r7   r   r   r   r9   A  r:   zIndexPQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   A  r>   r?   r@   z1 The product quantizer used to encode the vectorsc                 G   r$  r'   )r   ÚIndexPQ_swiginitÚnew_IndexPQrp   r   r   r   rH   E  r.   zIndexPQ.__init__c                 C   r‹  r'   )r   ÚIndexPQ_trainr“  r   r   r   r”  H  r  zIndexPQ.trainNc              	   C   rÈ  r'   )r   ÚIndexPQ_searchr   r   r   r   r¢  K  r.   zIndexPQ.searchc                 C   r‡  r'   )r   ÚIndexPQ_sa_encoderÏ  r   r   r   rÐ  N  r‰  zIndexPQ.sa_encodec                 C   r‡  r'   )r   ÚIndexPQ_sa_decoderÓ  r   r   r   rÔ  Q  r‰  zIndexPQ.sa_decodec                 C   rJ   r'   )r   Ú%IndexPQ_get_FlatCodesDistanceComputerrL   r   r   r   r  T  rM   z%IndexPQ.get_FlatCodesDistanceComputerz false = standard PQz, parameters used for the polysemous trainingz$ Hamming threshold used for polysemyc              
   C   rÃ  r'   )r   ÚIndexPQ_search_core_polysemous)r   rQ   r8   rÅ  rÆ  rÇ  Úpolysemous_htÚgeneralized_hammingr   r   r   Úsearch_core_polysemoush  r  zIndexPQ.search_core_polysemousc                 C   rŽ  )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   rQ   r8   r¸  r%  Údist_histogramr   r   r   Úhamming_distance_histogramk  ó   z"IndexPQ.hamming_distance_histogramc                 C   r‡  )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   rQ   r8   rº  r   r   r   Úhamming_distance_tableu  rÑ  zIndexPQ.hamming_distance_tabler'   )2r   r   r1   r2   r   r   r   r
   r   ÚIndexPQ_pq_getÚIndexPQ_pq_setrn  rH   r”  r¢  rÐ  rÔ  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_setrÕ  ÚIndexPQ_encode_signs_getÚIndexPQ_encode_signs_setÚencode_signsÚIndexPQ_polysemous_ht_getÚIndexPQ_polysemous_ht_setr‚  r„  r‡  rŠ  Údelete_IndexPQrv   r   r   r   r   ry  ;  s@    


ry  c                   @   óT   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ ZejZd	S )
ÚSearchParametersPQz* override search parameters from the classc                 C   r5   r'   r6   r7   r   r   r   r9   ‰  r:   zSearchParametersPQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ‰  r>   r?   r@   c                 C   ry   r'   )r   ÚSearchParametersPQ_swiginitÚnew_SearchParametersPQrL   r   r   r   rH   Ž  r|   zSearchParametersPQ.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú"SearchParametersPQ_search_type_getÚ"SearchParametersPQ_search_type_setrÕ  Ú$SearchParametersPQ_polysemous_ht_getÚ$SearchParametersPQ_polysemous_ht_setr‚  rH   Údelete_SearchParametersPQrv   r   r   r   r   r¨  †  ó    
r¨  c                   @   ój   e Zd ZdZedd„ d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	d
„ ZejZdS )ÚIndexPQStatszs
    statistics are robust to internal threading, but not if
    IndexPQ::search is called by multiple threads
    c                 C   r5   r'   r6   r7   r   r   r   r9   ›  r:   zIndexPQStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ›  r>   r?   r@   c                 C   ry   r'   )r   ÚIndexPQStats_swiginitÚnew_IndexPQStatsrL   r   r   r   rH   ¡  r|   zIndexPQStats.__init__c                 C   rJ   r'   )r   ÚIndexPQStats_resetrL   r   r   r   r{  ¤  rM   zIndexPQStats.resetN)r   r   r1   r2   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_passrH   r{  Údelete_IndexPQStatsrv   r   r   r   r   r²  •  s    
r²  c                   @   sp   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zdd
d„Zdd„ Zdd„ Zdd„ Zdd„ ZejZd	S )ÚMultiIndexQuantizerze
    Quantizer where centroids are virtual: they are the Cartesian
    product of sub-centroids.
    c                 C   r5   r'   r6   r7   r   r   r   r9   ±  r:   zMultiIndexQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ±  r>   r?   r@   c                 C   r‹  r'   )r   ÚMultiIndexQuantizer_trainr“  r   r   r   r”  µ  r  zMultiIndexQuantizer.trainNc              	   C   rÈ  r'   )r   ÚMultiIndexQuantizer_searchr   r   r   r   r¢  ¸  r.   zMultiIndexQuantizer.searchc                 C   r‹  )z$ add and reset will crash at runtime)r   ÚMultiIndexQuantizer_addr“  r   r   r   r—  »  ró  zMultiIndexQuantizer.addc                 C   rJ   r'   )r   ÚMultiIndexQuantizer_resetrL   r   r   r   r{  ¿  rM   zMultiIndexQuantizer.resetc                 G   r$  r'   )r   ÚMultiIndexQuantizer_swiginitÚnew_MultiIndexQuantizerrp   r   r   r   rH   Â  r.   zMultiIndexQuantizer.__init__c                 C   r‹  r'   )r   ÚMultiIndexQuantizer_reconstructr±  r   r   r   r´  Å  r  zMultiIndexQuantizer.reconstructr'   )r   r   r1   r2   r   r   r   r
   r   ÚMultiIndexQuantizer_pq_getÚMultiIndexQuantizer_pq_setrn  r”  r¢  r—  r{  rH   r´  Údelete_MultiIndexQuantizerrv   r   r   r   r   r¿  «  s    

r¿  c                   @   sj   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejƒZdd	„ Zd
d„ Zddd„ZejZdS )ÚMultiIndexQuantizer2zH MultiIndexQuantizer where the PQ assignmnet is performed by sub-indexesc                 C   r5   r'   r6   r7   r   r   r   r9   Ï  r:   zMultiIndexQuantizer2.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ï  r>   r?   r@   z M Indexes on d / M dimensionsc                 G   r$  r'   )r   ÚMultiIndexQuantizer2_swiginitÚnew_MultiIndexQuantizer2rp   r   r   r   rH   Ô  r.   zMultiIndexQuantizer2.__init__c                 C   r‹  r'   )r   ÚMultiIndexQuantizer2_trainr“  r   r   r   r”  ×  r  zMultiIndexQuantizer2.trainNc              	   C   rÈ  r'   )r   ÚMultiIndexQuantizer2_searchr   r   r   r   r¢  Ú  r.   zMultiIndexQuantizer2.searchr'   )r   r   r1   r2   r   r   r   r
   r   Ú'MultiIndexQuantizer2_assign_indexes_getÚ'MultiIndexQuantizer2_assign_indexes_setÚassign_indexesÚ#MultiIndexQuantizer2_own_fields_getÚ#MultiIndexQuantizer2_own_fields_setr¹  rH   r”  r¢  Údelete_MultiIndexQuantizer2rv   r   r   r   r   rÊ  Ì  s    

rÊ  c                   @   sh   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zdd
d„Zdd„ Zdd„ Zdd„ ZejZd	S )ÚIndexAdditiveQuantizerzL Abstract class for additive quantizers. The search functions are in common.c                 C   r5   r'   r6   r7   r   r   r   r9   ä  r:   zIndexAdditiveQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ä  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexAdditiveQuantizer_swiginitÚnew_IndexAdditiveQuantizerrp   r   r   r   rH   è  r.   zIndexAdditiveQuantizer.__init__Nc              	   C   rÈ  r'   )r   ÚIndexAdditiveQuantizer_searchr   r   r   r   r¢  ë  r.   zIndexAdditiveQuantizer.searchc                 C   r‡  r'   )r   Ú IndexAdditiveQuantizer_sa_encoderÏ  r   r   r   rÐ  î  r‰  z IndexAdditiveQuantizer.sa_encodec                 C   r‡  r'   )r   Ú IndexAdditiveQuantizer_sa_decoderÓ  r   r   r   rÔ  ñ  r‰  z IndexAdditiveQuantizer.sa_decodec                 C   rJ   r'   )r   Ú4IndexAdditiveQuantizer_get_FlatCodesDistanceComputerrL   r   r   r   r  ô  rM   z4IndexAdditiveQuantizer.get_FlatCodesDistanceComputerr'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexAdditiveQuantizer_aq_getÚIndexAdditiveQuantizer_aq_setÚaqrH   r¢  rÐ  rÔ  r  Údelete_IndexAdditiveQuantizerrv   r   r   r   r   rÕ  á  s    

rÕ  c                   @   óR   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	„ Zd
d„ ZejZdS )ÚIndexResidualQuantizerú“
     Index based on a residual quantizer. Stored vectors are
    approximated by residual quantization codes.
    Can also be used as a codec
    c                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   ú2 The residual quantizer used to encode the vectorsc                 G   r$  r'   )r   ÚIndexResidualQuantizer_swiginitÚnew_IndexResidualQuantizerrp   r   r   r   rH     r.   zIndexResidualQuantizer.__init__c                 C   r‹  r'   )r   ÚIndexResidualQuantizer_trainr“  r   r   r   r”  	  r  zIndexResidualQuantizer.trainN)r   r   r1   r2   r   r   r   r
   r   ÚIndexResidualQuantizer_rq_getÚIndexResidualQuantizer_rq_setÚrqrH   r”  Údelete_IndexResidualQuantizerrv   r   r   r   r   rá  û  s    
rá  c                   @   r;  )ÚIndexLocalSearchQuantizerc                 C   r5   r'   r6   r7   r   r   r   r9     r:   z"IndexLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   Ú"IndexLocalSearchQuantizer_swiginitÚnew_IndexLocalSearchQuantizerrp   r   r   r   rH     r.   z"IndexLocalSearchQuantizer.__init__c                 C   r‹  r'   )r   ÚIndexLocalSearchQuantizer_trainr“  r   r   r   r”    r  zIndexLocalSearchQuantizer.trainN)r   r   r1   r   r   r   r
   r   Ú!IndexLocalSearchQuantizer_lsq_getÚ!IndexLocalSearchQuantizer_lsq_setrf  rH   r”  Ú delete_IndexLocalSearchQuantizerrv   r   r   r   r   rë    rD  rë  c                   @   rà  )ÚIndexProductResidualQuantizerz- Index based on a product residual quantizer.c                 C   r5   r'   r6   r7   r   r   r   r9   "  r:   z&IndexProductResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   "  r>   r?   r@   ú: The product residual quantizer used to encode the vectorsc                 G   r$  r'   )r   Ú&IndexProductResidualQuantizer_swiginitÚ!new_IndexProductResidualQuantizerrp   r   r   r   rH   &  r.   z&IndexProductResidualQuantizer.__init__c                 C   r‹  r'   )r   Ú#IndexProductResidualQuantizer_trainr“  r   r   r   r”  )  r  z#IndexProductResidualQuantizer.trainN)r   r   r1   r2   r   r   r   r
   r   Ú%IndexProductResidualQuantizer_prq_getÚ%IndexProductResidualQuantizer_prq_setÚprqrH   r”  Ú$delete_IndexProductResidualQuantizerrv   r   r   r   r   rò    ó    
rò  c                   @   rà  )Ú IndexProductLocalSearchQuantizerz1 Index based on a product local search quantizer.c                 C   r5   r'   r6   r7   r   r   r   r9   3  r:   z)IndexProductLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   3  r>   r?   r@   ú> The product local search quantizer used to encode the vectorsc                 G   r$  r'   )r   Ú)IndexProductLocalSearchQuantizer_swiginitÚ$new_IndexProductLocalSearchQuantizerrp   r   r   r   rH   7  r.   z)IndexProductLocalSearchQuantizer.__init__c                 C   r‹  r'   )r   Ú&IndexProductLocalSearchQuantizer_trainr“  r   r   r   r”  :  r  z&IndexProductLocalSearchQuantizer.trainN)r   r   r1   r2   r   r   r   r
   r   Ú)IndexProductLocalSearchQuantizer_plsq_getÚ)IndexProductLocalSearchQuantizer_plsq_setÚplsqrH   r”  Ú'delete_IndexProductLocalSearchQuantizerrv   r   r   r   r   rü  0  rû  rü  c                   @   s‚   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zeejejd	dZd
d„ Zddd„Zdd„ Zdd„ Zdd„ ZejZdS )ÚAdditiveCoarseQuantizerz‘
     A "virtual" index where the elements are the residual quantizer centroids.

    Intended for use as a coarse quantizer in an IndexIVF.
    c                 C   r5   r'   r6   r7   r   r   r   r9   H  r:   z AdditiveCoarseQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   H  r>   r?   r@   c                 G   r$  r'   )r   Ú AdditiveCoarseQuantizer_swiginitÚnew_AdditiveCoarseQuantizerrp   r   r   r   rH   L  r.   z AdditiveCoarseQuantizer.__init__z* norms of centroids, useful for knn-searchc                 C   r‹  ©z N/A)r   ÚAdditiveCoarseQuantizer_addr“  r   r   r   r—  P  ró  zAdditiveCoarseQuantizer.addNc              	   C   rÈ  r'   )r   ÚAdditiveCoarseQuantizer_searchr   r   r   r   r¢  T  r.   zAdditiveCoarseQuantizer.searchc                 C   r‹  r'   )r   Ú#AdditiveCoarseQuantizer_reconstructr±  r   r   r   r´  W  r  z#AdditiveCoarseQuantizer.reconstructc                 C   r‹  r'   )r   ÚAdditiveCoarseQuantizer_trainr“  r   r   r   r”  Z  r  zAdditiveCoarseQuantizer.trainc                 C   rJ   r  )r   ÚAdditiveCoarseQuantizer_resetrL   r   r   r   r{  ]  r`  zAdditiveCoarseQuantizer.resetr'   )r   r   r1   r2   r   r   r   r
   r   ÚAdditiveCoarseQuantizer_aq_getÚAdditiveCoarseQuantizer_aq_setrÞ  rH   Ú*AdditiveCoarseQuantizer_centroid_norms_getÚ*AdditiveCoarseQuantizer_centroid_norms_setr˜  r—  r¢  r´  r”  r{  Údelete_AdditiveCoarseQuantizerrv   r   r   r   r   r  A  s    

r  c                   @   sB   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
ejZdd„ ZdS )	Ú'SearchParametersResidualCoarseQuantizerc                 C   r5   r'   r6   r7   r   r   r   r9   f  r:   z0SearchParametersResidualCoarseQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   f  r>   r?   r@   c                 C   ry   r'   )r   Ú0SearchParametersResidualCoarseQuantizer_swiginitÚ+new_SearchParametersResidualCoarseQuantizerrL   r   r   r   rH   k  r|   z0SearchParametersResidualCoarseQuantizer.__init__N)r   r   r1   r   r   r   r
   r   Ú7SearchParametersResidualCoarseQuantizer_beam_factor_getÚ7SearchParametersResidualCoarseQuantizer_beam_factor_setÚbeam_factorÚ.delete_SearchParametersResidualCoarseQuantizerrv   rH   r   r   r   r   r  e  s    r  c                   @   sv   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZd	d
„ Zddd„Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   x  r:   z ResidualCoarseQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   x  r>   r?   r@   rã  ze
    factor between the beam size and the search k
    if negative, use exact search-to-centroid
    c                 C   rN   )z$ computes centroid norms if required)r   Ú'ResidualCoarseQuantizer_set_beam_factor)r   Únew_beam_factorr   r   r   Úset_beam_factor€  r
  z'ResidualCoarseQuantizer.set_beam_factorNc              	   C   rÈ  r'   )r   ÚResidualCoarseQuantizer_searchr   r   r   r   r¢  „  r.   zResidualCoarseQuantizer.searchc                 C   rN   )z…
         Copy the M first codebook levels from other. Useful to crop a
        ResidualQuantizer to its first M quantizers.
        )r   Ú'ResidualCoarseQuantizer_initialize_fromrŒ   r   r   r   rã  ‡  r¯  z'ResidualCoarseQuantizer.initialize_fromc                 G   r$  r'   )r   Ú ResidualCoarseQuantizer_swiginitÚnew_ResidualCoarseQuantizerrp   r   r   r   rH   Ž  r.   z ResidualCoarseQuantizer.__init__r'   )r   r   r1   r2   r   r   r   r
   r   ÚResidualCoarseQuantizer_rq_getÚResidualCoarseQuantizer_rq_setré  Ú'ResidualCoarseQuantizer_beam_factor_getÚ'ResidualCoarseQuantizer_beam_factor_setr  r  r¢  rã  rH   Údelete_ResidualCoarseQuantizerrv   r   r   r   r   r  q  s    

r  c                   @   sF   e Zd Zedd„ dd„ ddZeZeejej	ddZ
dd„ ZejZd	S )
ÚLocalSearchCoarseQuantizerc                 C   r5   r'   r6   r7   r   r   r   r9   –  r:   z#LocalSearchCoarseQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   –  r>   r?   r@   rã  c                 G   r$  r'   )r   Ú#LocalSearchCoarseQuantizer_swiginitÚnew_LocalSearchCoarseQuantizerrp   r   r   r   rH   š  r.   z#LocalSearchCoarseQuantizer.__init__N)r   r   r1   r   r   r   r
   r   Ú"LocalSearchCoarseQuantizer_lsq_getÚ"LocalSearchCoarseQuantizer_lsq_setrf  rH   Ú!delete_LocalSearchCoarseQuantizerrv   r   r   r   r   r'  •  s    
r'  c                   @   r  )ÚIOReaderrô  c                 C   r5   r'   r6   r7   r   r   r   r9   ©  r:   zIOReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ©  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   «  rI   zIOReader.__init__c                 C   r‡  r'   )r   ÚIOReader___call__©r   Úptrr†   Únitemsr   r   r   rù  °  r‰  zIOReader.__call__c                 C   rJ   r'   )r   ÚIOReader_filenorL   r   r   r   Úfileno³  rM   zIOReader.filenoN)r   r   r1   r2   r   r   rH   r   r
   r   ÚIOReader_name_getÚIOReader_name_setr   rù  r3  Údelete_IOReaderrv   r   r   r   r   r-  ¡  s    
r-  c                   @   sR   e Zd Zedd„ dd„ ddZdd„ ZeZeej	ej
ƒZdd	„ Zd
d„ ZejZdS )ÚIOWriterc                 C   r5   r'   r6   r7   r   r   r   r9   »  r:   zIOWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   »  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ½  rI   zIOWriter.__init__c                 C   r‡  r'   )r   ÚIOWriter___call__r/  r   r   r   rù  Â  r‰  zIOWriter.__call__c                 C   rJ   r'   )r   ÚIOWriter_filenorL   r   r   r   r3  Å  rM   zIOWriter.filenoN)r   r   r1   r   r   rH   r   r
   r   ÚIOWriter_name_getÚIOWriter_name_setr   rù  r3  Údelete_IOWriterrv   r   r   r   r   r7  º  s    
r7  c                   @   rv  )ÚVectorIOReaderc                 C   r5   r'   r6   r7   r   r   r   r9   Í  r:   zVectorIOReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Í  r>   r?   r@   c                 C   r‡  r'   )r   ÚVectorIOReader___call__r/  r   r   r   rù  Ò  r‰  zVectorIOReader.__call__c                 C   ry   r'   )r   ÚVectorIOReader_swiginitÚnew_VectorIOReaderrL   r   r   r   rH   Õ  r|   zVectorIOReader.__init__N)r   r   r1   r   r   r   r
   r   ÚVectorIOReader_data_getÚVectorIOReader_data_setr„   ÚVectorIOReader_rp_getÚVectorIOReader_rp_setÚrprù  rH   Údelete_VectorIOReaderrv   r   r   r   r   r=  Ì  rƒ  r=  c                   @   r;  )ÚVectorIOWriterc                 C   r5   r'   r6   r7   r   r   r   r9   Ý  r:   zVectorIOWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ý  r>   r?   r@   c                 C   r‡  r'   )r   ÚVectorIOWriter___call__r/  r   r   r   rù  á  r‰  zVectorIOWriter.__call__c                 C   ry   r'   )r   ÚVectorIOWriter_swiginitÚnew_VectorIOWriterrL   r   r   r   rH   ä  r|   zVectorIOWriter.__init__N)r   r   r1   r   r   r   r
   r   ÚVectorIOWriter_data_getÚVectorIOWriter_data_setr„   rù  rH   Údelete_VectorIOWriterrv   r   r   r   r   rG  Ü  rD  rG  c                   @   ó`   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZdd„ ZejZdd	„ Zd
d„ ZdS )ÚFileIOReaderc                 C   r5   r'   r6   r7   r   r   r   r9   ì  r:   zFileIOReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ì  r>   r?   r@   c                 G   r$  r'   )r   ÚFileIOReader_swiginitÚnew_FileIOReaderrp   r   r   r   rH   ñ  r.   zFileIOReader.__init__c                 C   r‡  r'   )r   ÚFileIOReader___call__r/  r   r   r   rù  õ  r‰  zFileIOReader.__call__c                 C   rJ   r'   )r   ÚFileIOReader_filenorL   r   r   r   r3  ø  rM   zFileIOReader.filenoN)r   r   r1   r   r   r   r
   r   ÚFileIOReader_f_getÚFileIOReader_f_setÚfÚFileIOReader_need_close_getÚFileIOReader_need_close_setÚ
need_closerH   Údelete_FileIOReaderrv   rù  r3  r   r   r   r   rO  ë  ó    rO  c                   @   rN  )ÚFileIOWriterc                 C   r5   r'   r6   r7   r   r   r   r9   ÿ  r:   zFileIOWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ÿ  r>   r?   r@   c                 G   r$  r'   )r   ÚFileIOWriter_swiginitÚnew_FileIOWriterrp   r   r   r   rH     r.   zFileIOWriter.__init__c                 C   r‡  r'   )r   ÚFileIOWriter___call__r/  r   r   r   rù    r‰  zFileIOWriter.__call__c                 C   rJ   r'   )r   ÚFileIOWriter_filenorL   r   r   r   r3    rM   zFileIOWriter.filenoN)r   r   r1   r   r   r   r
   r   ÚFileIOWriter_f_getÚFileIOWriter_f_setrV  ÚFileIOWriter_need_close_getÚFileIOWriter_need_close_setrY  rH   Údelete_FileIOWriterrv   rù  r3  r   r   r   r   r\  þ  r[  r\  c                   @   s®   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZeejejddZeejejddZeejejd	dZeejejƒZeejejƒZd
d„ Zdd„ Zej Z!dS )ÚBufferedIOReaderzB wraps an ioreader to make buffered reads to avoid too small readsc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zBufferedIOReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   z offset in input streamz# number of bytes returned to callerz' range of available bytes in the bufferc                 G   r—  )z›
        :type bsz: int, optional
        :param bsz:    buffer size (bytes). Reads will be done by batched of
                          this size
        N)r   ÚBufferedIOReader_swiginitÚnew_BufferedIOReaderrp   r   r   r   rH     ó   zBufferedIOReader.__init__c                 C   r‡  r'   )r   ÚBufferedIOReader___call__r/  r   r   r   rù  &  r‰  zBufferedIOReader.__call__N)"r   r   r1   r2   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ÚbufferrH   rù  Údelete_BufferedIOReaderrv   r   r   r   r   rf    s    
rf  c                   @   s˜   e Zd Zedd„ d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dZeejejddZeejejƒZdd	„ Zd
d„ ZejZdS )ÚBufferedIOWriterc                 C   r5   r'   r6   r7   r   r   r   r9   .  r:   zBufferedIOWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   .  r>   r?   r@   z% number of bytes received from callerz amount of data in bufferc                 G   r$  r'   )r   ÚBufferedIOWriter_swiginitÚnew_BufferedIOWriterrp   r   r   r   rH   7  r.   zBufferedIOWriter.__init__c                 C   r‡  r'   )r   ÚBufferedIOWriter___call__r/  r   r   r   rù  :  r‰  zBufferedIOWriter.__call__N)r   r   r1   r   r   r   r
   r   ÚBufferedIOWriter_writer_getÚBufferedIOWriter_writer_setÚwriterÚBufferedIOWriter_bsz_getÚBufferedIOWriter_bsz_setrp  ÚBufferedIOWriter_ofs_getÚBufferedIOWriter_ofs_setrs  ÚBufferedIOWriter_ofs2_getÚBufferedIOWriter_ofs2_setrv  ÚBufferedIOWriter_b0_getÚBufferedIOWriter_b0_setry  ÚBufferedIOWriter_buffer_getÚBufferedIOWriter_buffer_setr  rH   rù  Údelete_BufferedIOWriterrv   r   r   r   r   r  -  s    
r  c                  G   r¼  r'   )r   Úfourccr¾  r   r   r   r“  B  rM   r“  c                  G   r¼  r'   )r   Ú
fourcc_invr¾  r   r   r   r”  E  rM   r”  c                 C   rJ   r'   )r   Úfourcc_inv_printabler7   r   r   r   r•  H  rM   r•  c                   @   sP   e Zd ZdZedd„ dd„ ddZdd„ ZeZe	j
Zd	d
„ Zdd„ Zdd„ ZdS )ÚInvertedListsIteratora  
    Copyright (c) Facebook, Inc. and its affiliates.

    This source code is licensed under the MIT license found in the
    LICENSE file in the root directory of this source tree.

    Definition of inverted lists + a few common classes that implement
    the interface.
    c                 C   r5   r'   r6   r7   r   r   r   r9   U  r:   zInvertedListsIterator.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   U  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   W  rI   zInvertedListsIterator.__init__c                 C   rJ   r'   )r   Ú"InvertedListsIterator_is_availablerL   r   r   r   Úis_available\  rM   z"InvertedListsIterator.is_availablec                 C   rJ   r'   )r   ÚInvertedListsIterator_nextrL   r   r   r   r]   _  rM   zInvertedListsIterator.nextc                 C   rJ   r'   )r   Ú&InvertedListsIterator_get_id_and_codesrL   r   r   r   Úget_id_and_codesb  rM   z&InvertedListsIterator.get_id_and_codesN)r   r   r1   r2   r   r   rH   r   r
   r   Údelete_InvertedListsIteratorrv   r˜  r]   r›  r   r   r   r   r–  J  s    
r–  c                   @   s8  e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jƒZe	jZe	jZ	 dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z dd „ Z!d!d"„ Z"d#d$„ Z#d%d&„ Z$d'd(„ Z%d)d*„ Z&d+d,„ Z'e	j(Z)e	j*Z+e	j,Z-e	j.Z/e	j0Z1d-d.„ Z2d/d0„ Z3d1d2„ Z4d3d4„ Z5d5S )6Ú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                 C   r5   r'   r6   r7   r   r   r   r9   r  r:   zInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   r  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   t  rI   zInvertedLists.__init__ú number of possible key valuesú code size per vector in bytesc                 C   rN   r'   )r   ÚInvertedLists_is_empty©r   Úlist_nor   r   r   Úis_empty  rS   zInvertedLists.is_emptyc                 C   rN   )z get the size of a list)r   ÚInvertedLists_list_sizer¡  r   r   r   Ú	list_size„  r
  zInvertedLists.list_sizec                 C   rN   )z) get iterable for lists that use_iterator)r   ÚInvertedLists_get_iteratorr¡  r   r   r   Úget_iteratorˆ  r
  zInvertedLists.get_iteratorc                 C   rN   )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¡  r   r   r   Ú	get_codesŒ  rô  zInvertedLists.get_codesc                 C   rN   )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¡  r   r   r   Úget_ids–  rô  zInvertedLists.get_idsc                 C   r‹  )zC release codes returned by get_codes (default implementation is nop)r   ÚInvertedLists_release_codes©r   r¢  r  r   r   r   Úrelease_codes   ró  zInvertedLists.release_codesc                 C   r‹  )z  release ids returned by get_ids)r   ÚInvertedLists_release_ids©r   r¢  rA  r   r   r   Úrelease_ids¤  ró  zInvertedLists.release_idsc                 C   r‹  )zN
        :rtype: int
        :return: a single id in an inverted list
        )r   ÚInvertedLists_get_single_id©r   r¢  r.  r   r   r   Úget_single_id¨  râ  zInvertedLists.get_single_idc                 C   r‹  )z‹
        :rtype: uint8_t
        :return: a single code in an inverted list
            (should be deallocated with release_codes)
        )r   ÚInvertedLists_get_single_coder³  r   r   r   Úget_single_code¯  rñ  zInvertedLists.get_single_codec                 C   r‹  )zs
        prepare the following lists (default does nothing)
        a list can be -1 hence the signed long
        )r   ÚInvertedLists_prefetch_lists©r   Úlist_nosÚnlistr   r   r   Úprefetch_lists·  râ  zInvertedLists.prefetch_listsc                 C   r‡  )z" add one entry to an inverted list)r   ÚInvertedLists_add_entry)r   r¢  Útheidr›  r   r   r   Ú	add_entry¾  r  zInvertedLists.add_entryc                 C   rm  r'   )r   ÚInvertedLists_add_entries©r   r¢  Ún_entryrA  r›  r   r   r   Úadd_entriesÂ  rr   zInvertedLists.add_entriesc                 C   rm  r'   )r   ÚInvertedLists_update_entry)r   r¢  r.  Úidr›  r   r   r   Úupdate_entryÅ  rr   zInvertedLists.update_entryc                 C   rŽ  r'   )r   ÚInvertedLists_update_entries©r   r¢  r.  rÁ  rA  r›  r   r   r   Úupdate_entriesÈ  r|   zInvertedLists.update_entriesc                 C   r‹  r'   )r   ÚInvertedLists_resize©r   r¢  Únew_sizer   r   r   rŠ   Ë  r  zInvertedLists.resizec                 C   rJ   r'   )r   ÚInvertedLists_resetrL   r   r   r   r{  Î  rM   zInvertedLists.resetc                 C   r‹  )z- move all entries from oivf (empty on output))r   ÚInvertedLists_merge_from)r   ÚoivfrÙ  r   r   r   rÚ  Ñ  ró  zInvertedLists.merge_fromc                 C   rm  )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Úa2r   r   r   Úcopy_subset_toÚ  rs  zInvertedLists.copy_subset_toc                 C   rJ   )z& 1= perfectly balanced, >1: imbalanced)r   ÚInvertedLists_imbalance_factorrL   r   r   r   r  â  r`  zInvertedLists.imbalance_factorc                 C   rJ   )z, display some stats about the inverted lists)r   ÚInvertedLists_print_statsrL   r   r   r   Úprint_statsæ  r`  zInvertedLists.print_statsc                 C   rJ   )z sum up list sizes)r   ÚInvertedLists_compute_ntotalrL   r   r   r   Úcompute_ntotalê  r`  zInvertedLists.compute_ntotalN)6r   r   r1   r2   r   r   rH   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_InvertedListsrv   Ú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  h  sJ    	

r  c                   @   sˆ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚArrayInvertedListsz> simple (default) implementation as an array of inverted listsc                 C   r5   r'   r6   r7   r   r   r   r9   ô  r:   zArrayInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ô  r>   r?   r@   z Inverted lists for indexesc                 C   r—  r'   )r   ÚArrayInvertedLists_swiginitÚnew_ArrayInvertedLists)r   rº  rœ  r   r   r   rH   ù  r  zArrayInvertedLists.__init__c                 C   rN   r'   )r   ÚArrayInvertedLists_list_sizer¡  r   r   r   r¥  ü  rS   zArrayInvertedLists.list_sizec                 C   rN   r'   )r   ÚArrayInvertedLists_get_codesr¡  r   r   r   r©  ÿ  rS   zArrayInvertedLists.get_codesc                 C   rN   r'   )r   ÚArrayInvertedLists_get_idsr¡  r   r   r   r«    rS   zArrayInvertedLists.get_idsc                 C   rm  r'   )r   ÚArrayInvertedLists_add_entriesrÀ  r   r   r   rÂ    rr   zArrayInvertedLists.add_entriesc                 C   rŽ  r'   )r   Ú!ArrayInvertedLists_update_entriesrÇ  r   r   r   rÈ    r|   z!ArrayInvertedLists.update_entriesc                 C   r‹  r'   )r   ÚArrayInvertedLists_resizerÊ  r   r   r   rŠ     r  zArrayInvertedLists.resizeN)r   r   r1   r2   r   r   r   r
   r   ÚArrayInvertedLists_codes_getÚArrayInvertedLists_codes_setr  ÚArrayInvertedLists_ids_getÚArrayInvertedLists_ids_setrA  rH   r¥  r©  r«  rÂ  rÈ  rŠ   Údelete_ArrayInvertedListsrv   r   r   r   r   rî  ñ  s    
rî  c                   @   rò  )ÚReadOnlyInvertedListsz+ invlists that fail for all write functionsc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zReadOnlyInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH     rI   zReadOnlyInvertedLists.__init__c                 C   rm  r'   )r   Ú!ReadOnlyInvertedLists_add_entriesrÀ  r   r   r   rÂ    rr   z!ReadOnlyInvertedLists.add_entriesc                 C   rŽ  r'   )r   Ú$ReadOnlyInvertedLists_update_entriesrÇ  r   r   r   rÈ    r|   z$ReadOnlyInvertedLists.update_entriesc                 C   r‹  r'   )r   ÚReadOnlyInvertedLists_resizerÊ  r   r   r   rŠ   !  r  zReadOnlyInvertedLists.resizeN)r   r   r1   r2   r   r   rH   r   r
   rÂ  rÈ  rŠ   r   Údelete_ReadOnlyInvertedListsrv   r   r   r   r   rü    s    
rü  c                   @   s†   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚHStackInvertedListsz# Horizontal stack of inverted listsc                 C   r5   r'   r6   r7   r   r   r   r9   +  r:   zHStackInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   +  r>   r?   r@   c                 C   r@  ©z1 build InvertedLists by concatenating nil of themN)r   ÚHStackInvertedLists_swiginitÚnew_HStackInvertedLists©r   ÚnilÚilsr   r   r   rH   /  rW  zHStackInvertedLists.__init__c                 C   rN   r'   )r   ÚHStackInvertedLists_list_sizer¡  r   r   r   r¥  3  rS   zHStackInvertedLists.list_sizec                 C   rN   r'   )r   ÚHStackInvertedLists_get_codesr¡  r   r   r   r©  6  rS   zHStackInvertedLists.get_codesc                 C   rN   r'   )r   ÚHStackInvertedLists_get_idsr¡  r   r   r   r«  9  rS   zHStackInvertedLists.get_idsc                 C   r‹  r'   )r   Ú"HStackInvertedLists_prefetch_listsr¸  r   r   r   r»  <  r  z"HStackInvertedLists.prefetch_listsc                 C   r‹  r'   )r   Ú!HStackInvertedLists_release_codesr­  r   r   r   r®  ?  r  z!HStackInvertedLists.release_codesc                 C   r‹  r'   )r   ÚHStackInvertedLists_release_idsr°  r   r   r   r±  B  r  zHStackInvertedLists.release_idsc                 C   r‹  r'   )r   Ú!HStackInvertedLists_get_single_idr³  r   r   r   r´  E  r  z!HStackInvertedLists.get_single_idc                 C   r‹  r'   )r   Ú#HStackInvertedLists_get_single_coder³  r   r   r   r¶  H  r  z#HStackInvertedLists.get_single_codeN)r   r   r1   r2   r   r   r   r
   r   ÚHStackInvertedLists_ils_getÚHStackInvertedLists_ils_setr	  rH   r¥  r©  r«  r»  r®  r±  r´  r¶  Údelete_HStackInvertedListsrv   r   r   r   r   r	  (  s    
r	  c                   @   s¢   e Zd ZdZedd„ d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	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚSliceInvertedListsz3 vertical slice of indexes in another InvertedListsc                 C   r5   r'   r6   r7   r   r   r   r9   R  r:   zSliceInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   R  r>   r?   r@   c                 C   r+  r'   )r   ÚSliceInvertedLists_swiginitÚnew_SliceInvertedLists)r   Úilr»  Úi1r   r   r   rH   X  r/  zSliceInvertedLists.__init__c                 C   rN   r'   )r   ÚSliceInvertedLists_list_sizer¡  r   r   r   r¥  [  rS   zSliceInvertedLists.list_sizec                 C   rN   r'   )r   ÚSliceInvertedLists_get_codesr¡  r   r   r   r©  ^  rS   zSliceInvertedLists.get_codesc                 C   rN   r'   )r   ÚSliceInvertedLists_get_idsr¡  r   r   r   r«  a  rS   zSliceInvertedLists.get_idsc                 C   r‹  r'   )r   Ú SliceInvertedLists_release_codesr­  r   r   r   r®  d  r  z SliceInvertedLists.release_codesc                 C   r‹  r'   )r   ÚSliceInvertedLists_release_idsr°  r   r   r   r±  g  r  zSliceInvertedLists.release_idsc                 C   r‹  r'   )r   Ú SliceInvertedLists_get_single_idr³  r   r   r   r´  j  r  z SliceInvertedLists.get_single_idc                 C   r‹  r'   )r   Ú"SliceInvertedLists_get_single_coder³  r   r   r   r¶  m  r  z"SliceInvertedLists.get_single_codec                 C   r‹  r'   )r   Ú!SliceInvertedLists_prefetch_listsr¸  r   r   r   r»  p  r  z!SliceInvertedLists.prefetch_listsN)r   r   r1   r2   r   r   r   r
   r   ÚSliceInvertedLists_il_getÚSliceInvertedLists_il_setr	  ÚSliceInvertedLists_i0_getÚSliceInvertedLists_i0_setr»  ÚSliceInvertedLists_i1_getÚSliceInvertedLists_i1_setr	  rH   r¥  r©  r«  r®  r±  r´  r¶  r»  Údelete_SliceInvertedListsrv   r   r   r   r   r	  O  s"    
r	  c                   @   s   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚVStackInvertedListsc                 C   r5   r'   r6   r7   r   r   r   r9   x  r:   zVStackInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   x  r>   r?   r@   c                 C   r@  r	  )r   ÚVStackInvertedLists_swiginitÚnew_VStackInvertedListsr	  r   r   r   rH   }  rW  zVStackInvertedLists.__init__c                 C   rN   r'   )r   ÚVStackInvertedLists_list_sizer¡  r   r   r   r¥    rS   zVStackInvertedLists.list_sizec                 C   rN   r'   )r   ÚVStackInvertedLists_get_codesr¡  r   r   r   r©  „  rS   zVStackInvertedLists.get_codesc                 C   rN   r'   )r   ÚVStackInvertedLists_get_idsr¡  r   r   r   r«  ‡  rS   zVStackInvertedLists.get_idsc                 C   r‹  r'   )r   Ú!VStackInvertedLists_release_codesr­  r   r   r   r®  Š  r  z!VStackInvertedLists.release_codesc                 C   r‹  r'   )r   ÚVStackInvertedLists_release_idsr°  r   r   r   r±    r  zVStackInvertedLists.release_idsc                 C   r‹  r'   )r   Ú!VStackInvertedLists_get_single_idr³  r   r   r   r´    r  z!VStackInvertedLists.get_single_idc                 C   r‹  r'   )r   Ú#VStackInvertedLists_get_single_coder³  r   r   r   r¶  “  r  z#VStackInvertedLists.get_single_codec                 C   r‹  r'   )r   Ú"VStackInvertedLists_prefetch_listsr¸  r   r   r   r»  –  r  z"VStackInvertedLists.prefetch_listsN)r   r   r1   r   r   r   r
   r   ÚVStackInvertedLists_ils_getÚVStackInvertedLists_ils_setr	  ÚVStackInvertedLists_cumsz_getÚVStackInvertedLists_cumsz_setÚcumszrH   r¥  r©  r«  r®  r±  r´  r¶  r»  Údelete_VStackInvertedListsrv   r   r   r   r   r'	  w  s    
r'	  c                   @   ó”   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ¦  r:   zMaskedInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¦  r>   r?   r@   c                 C   r—  r'   )r   ÚMaskedInvertedLists_swiginitÚnew_MaskedInvertedLists)r   Úil0Úil1r   r   r   rH   «  r  zMaskedInvertedLists.__init__c                 C   rN   r'   )r   ÚMaskedInvertedLists_list_sizer¡  r   r   r   r¥  ®  rS   zMaskedInvertedLists.list_sizec                 C   rN   r'   )r   ÚMaskedInvertedLists_get_codesr¡  r   r   r   r©  ±  rS   zMaskedInvertedLists.get_codesc                 C   rN   r'   )r   ÚMaskedInvertedLists_get_idsr¡  r   r   r   r«  ´  rS   zMaskedInvertedLists.get_idsc                 C   r‹  r'   )r   Ú!MaskedInvertedLists_release_codesr­  r   r   r   r®  ·  r  z!MaskedInvertedLists.release_codesc                 C   r‹  r'   )r   ÚMaskedInvertedLists_release_idsr°  r   r   r   r±  º  r  zMaskedInvertedLists.release_idsc                 C   r‹  r'   )r   Ú!MaskedInvertedLists_get_single_idr³  r   r   r   r´  ½  r  z!MaskedInvertedLists.get_single_idc                 C   r‹  r'   )r   Ú#MaskedInvertedLists_get_single_coder³  r   r   r   r¶  À  r  z#MaskedInvertedLists.get_single_codec                 C   r‹  r'   )r   Ú"MaskedInvertedLists_prefetch_listsr¸  r   r   r   r»  Ã  r  z"MaskedInvertedLists.prefetch_listsN)r   r   r1   r2   r   r   r   r
   r   ÚMaskedInvertedLists_il0_getÚMaskedInvertedLists_il0_setr<	  ÚMaskedInvertedLists_il1_getÚMaskedInvertedLists_il1_setr=	  rH   r¥  r©  r«  r®  r±  r´  r¶  r»  Údelete_MaskedInvertedListsrv   r   r   r   r   r9	    s     
r9	  c                   @   r8	  )ÚStopWordsInvertedListszr
    if the inverted list in il is smaller than maxsize then return it,
    otherwise return an empty invlist
    c                 C   r5   r'   r6   r7   r   r   r   r9   Ð  r:   zStopWordsInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ð  r>   r?   r@   c                 C   r—  r'   )r   ÚStopWordsInvertedLists_swiginitÚnew_StopWordsInvertedLists)r   r	  Úmaxsizer   r   r   rH   Õ  r  zStopWordsInvertedLists.__init__c                 C   rN   r'   )r   Ú StopWordsInvertedLists_list_sizer¡  r   r   r   r¥  Ø  rS   z StopWordsInvertedLists.list_sizec                 C   rN   r'   )r   Ú StopWordsInvertedLists_get_codesr¡  r   r   r   r©  Û  rS   z StopWordsInvertedLists.get_codesc                 C   rN   r'   )r   ÚStopWordsInvertedLists_get_idsr¡  r   r   r   r«  Þ  rS   zStopWordsInvertedLists.get_idsc                 C   r‹  r'   )r   Ú$StopWordsInvertedLists_release_codesr­  r   r   r   r®  á  r  z$StopWordsInvertedLists.release_codesc                 C   r‹  r'   )r   Ú"StopWordsInvertedLists_release_idsr°  r   r   r   r±  ä  r  z"StopWordsInvertedLists.release_idsc                 C   r‹  r'   )r   Ú$StopWordsInvertedLists_get_single_idr³  r   r   r   r´  ç  r  z$StopWordsInvertedLists.get_single_idc                 C   r‹  r'   )r   Ú&StopWordsInvertedLists_get_single_coder³  r   r   r   r¶  ê  r  z&StopWordsInvertedLists.get_single_codec                 C   r‹  r'   )r   Ú%StopWordsInvertedLists_prefetch_listsr¸  r   r   r   r»  í  r  z%StopWordsInvertedLists.prefetch_listsN)r   r   r1   r2   r   r   r   r
   r   ÚStopWordsInvertedLists_il0_getÚStopWordsInvertedLists_il0_setr<	  Ú"StopWordsInvertedLists_maxsize_getÚ"StopWordsInvertedLists_maxsize_setrN	  rH   r¥  r©  r«  r®  r±  r´  r¶  r»  Údelete_StopWordsInvertedListsrv   r   r   r   r   rK	  Ê  s     
rK	  c                   @   sœ   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
d	dZee	jd
dZdd„ Zdd„ Zdd„ Ze	jZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zInvertedListsIOHook.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH     rI   zInvertedListsIOHook.__init__z string version of the fourccz typeid.namec                 C   r‹  )z7 write the index to the IOWriter (including the fourcc))r   ÚInvertedListsIOHook_write)r   r	  rV  r   r   r   r   	  ró  zInvertedListsIOHook.writec                 C   r‹  )z3 called when the fourcc matches this class's fourcc)r   ÚInvertedListsIOHook_read)r   rV  Úio_flagsr   r   r   r®    ró  zInvertedListsIOHook.readc                 C   rŽ  )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   rV  r_	  rº  rœ  Úsizesr   r   r   Úread_ArrayInvertedLists  rˆ  z+InvertedListsIOHook.read_ArrayInvertedListsc                 C   rJ   r'   ©r   Ú InvertedListsIOHook_add_callback©Úarg1r   r   r   Úadd_callback  r`  z InvertedListsIOHook.add_callbackc                   C   rÜ  r'   ©r   Ú#InvertedListsIOHook_print_callbacksr   r   r   r   Úprint_callbacks   râ  z#InvertedListsIOHook.print_callbacksc                 C   rJ   r'   ©r   ÚInvertedListsIOHook_lookup©Úhr   r   r   Úlookup$  r`  zInvertedListsIOHook.lookupc                 C   rJ   r'   ©r   Ú$InvertedListsIOHook_lookup_classname©Ú	classnamer   r   r   Úlookup_classname(  r`  z$InvertedListsIOHook.lookup_classnameN)r   r   r1   r2   r   r   rH   r   r
   r   ÚInvertedListsIOHook_key_getr²  Ú!InvertedListsIOHook_classname_getrs	  r   r®  rb	  Údelete_InvertedListsIOHookrv   r5  rg	  rj	  ro	  rt	  r   r   r   r   r\	  ô  s&    	


r\	  c                 C   rJ   r'   rc	  re	  r   r   r   rd	  /  rM   rd	  c                   C   rÜ  r'   rh	  r   r   r   r   ri	  2  rI   ri	  c                 C   rJ   r'   rk	  rm	  r   r   r   rl	  5  rM   rl	  c                 C   rJ   r'   rp	  rr	  r   r   r   rq	  8  rM   rq	  c                   @   s®   e Zd ZdZedd„ d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d„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZ dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   K  r:   zBlockInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   K  r>   r?   r@   c                 G   r$  r'   )r   ÚBlockInvertedLists_swiginitÚnew_BlockInvertedListsrp   r   r   r   rH   S  r.   zBlockInvertedLists.__init__c                 C   rN   r'   )r   ÚBlockInvertedLists_list_sizer¡  r   r   r   r¥  V  rS   zBlockInvertedLists.list_sizec                 C   rN   r'   )r   ÚBlockInvertedLists_get_codesr¡  r   r   r   r©  Y  rS   zBlockInvertedLists.get_codesc                 C   rN   r'   )r   ÚBlockInvertedLists_get_idsr¡  r   r   r   r«  \  rS   zBlockInvertedLists.get_idsc                 C   rm  r'   )r   ÚBlockInvertedLists_add_entriesrÀ  r   r   r   rÂ  _  rr   zBlockInvertedLists.add_entriesc                 C   rŽ  ©z not implemented)r   Ú!BlockInvertedLists_update_entriesrÇ  r   r   r   rÈ  b  r”  z!BlockInvertedLists.update_entriesc                 C   r‹  r'   )r   ÚBlockInvertedLists_resizerÊ  r   r   r   rŠ   f  r  zBlockInvertedLists.resizeN)!r   r   r1   r2   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_setrA  rH   r¥  r©  r«  rÂ  rÈ  rŠ   Údelete_BlockInvertedListsrv   r   r   r   r   rx	  ;  s"    
rx	  c                 C   rN   r'   )r   Úlo_build)Úlist_idr.  r   r   r   r	  n  rS   r	  c                 C   rJ   r'   )r   Ú	lo_listno©Úlor   r   r   r‘	  q  rM   r‘	  c                 C   rJ   r'   )r   Ú	lo_offsetr’	  r   r   r   r”	  t  rM   r”	  c                   @   s¸   e Zd ZdZedd„ d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dZeejejƒZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z ej!Z"dS )Ú	DirectMapz8Direct map: a way to map back from ids to inverted listsc                 C   r5   r'   r6   r7   r   r   r   r9   y  r:   zDirectMap.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   y  r>   r?   r@   zF map for direct access to the elements. Map ids to LO-encoded entries.c                 C   ry   r'   )r   ÚDirectMap_swiginitÚnew_DirectMaprL   r   r   r   rH   ‚  r|   zDirectMap.__init__c                 C   r‡  )z set type and initialize)r   ÚDirectMap_set_type)r   Únew_typeÚinvlistsræ  r   r   r   Úset_type…  r  zDirectMap.set_typec                 C   rN   )z get an entry)r   ÚDirectMap_get©r   rÄ  r   r   r   rs  ‰  r
  zDirectMap.getc                 C   rJ   )z for quick checks)r   ÚDirectMap_norL   r   r   r   Úno  r`  zDirectMap.noc                 C   rN   )zT
        update the direct_map

         throw if Array and ids is not NULL
        )r   ÚDirectMap_check_can_add)r   rA  r   r   r   Úcheck_can_add‘  rà  zDirectMap.check_can_addc                 C   r‡  )z non thread-safe version)r   ÚDirectMap_add_single_id)r   rÄ  r¢  r.  r   r   r   Úadd_single_id™  r  zDirectMap.add_single_idc                 C   rJ   )z remove all entries)r   ÚDirectMap_clearrL   r   r   r   r‚     r`  zDirectMap.clearc                 C   r‹  )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   rU  rš	  r   r   r   r®  ¡  rñ  zDirectMap.remove_idsc                 C   rŽ  )z% update entries, using the direct map)r   ÚDirectMap_update_codes)r   rš	  rQ   rA  r¹  r  r   r   r   Úupdate_codes©  r”  zDirectMap.update_codesN)#r   r   r1   r2   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Ú	hashtablerH   r›	  rs  rŸ	  r¡	  r£	  r‚   r®  r§	  Údelete_DirectMaprv   r   r   r   r   r•	  v  s(    
r•	  c                   @   s”   e Zd ZdZedd„ d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jƒZdd„ Zd	d
„ ZejZdS )ÚDirectMapAddz+ Thread-safe way of updating the direct_mapc                 C   r5   r'   r6   r7   r   r   r   r9   ´  r:   zDirectMapAdd.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ´  r>   r?   r@   c                 C   r+  r'   )r   ÚDirectMapAdd_swiginitÚnew_DirectMapAdd)r   Ú
direct_maprQ   rœ  r   r   r   rH   ½  r/  zDirectMapAdd.__init__c                 C   r‡  )z5 add vector i (with id xids[i]) at list_no and offset)r   ÚDirectMapAdd_add)r   r§  r¢  r.  r   r   r   r—  À  r  zDirectMapAdd.addN)r   r   r1   r2   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_setrQ   ÚDirectMapAdd_xids_getÚDirectMapAdd_xids_setrœ  ÚDirectMapAdd_all_ofs_getÚDirectMapAdd_all_ofs_setÚall_ofsrH   r—  Údelete_DirectMapAddrv   r   r   r   r   r·	  ±  s    
r·	  c                   @   sÄ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zej Z!dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   Ð  r:   zLevel1Quantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ð  r>   r?   r@   ú. 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                 C   rm  ©zF Trains the quantizer and calls train_residual to train sub-quantizers)r   ÚLevel1Quantizer_train_q1)r   rQ   r8   r  r…  r   r   r   Útrain_q1Ý  ru  zLevel1Quantizer.train_q1c                 C   rJ   )z7 compute the number of bytes required to store list ids)r   Ú Level1Quantizer_coarse_code_sizerL   r   r   r   Úcoarse_code_sizeá  r`  z Level1Quantizer.coarse_code_sizec                 C   r‹  r'   )r   ÚLevel1Quantizer_encode_listno)r   r¢  r›  r   r   r   Úencode_listnoå  r  zLevel1Quantizer.encode_listnoc                 C   rN   r'   )r   ÚLevel1Quantizer_decode_listnor  r   r   r   Údecode_listnoè  rS   zLevel1Quantizer.decode_listnoc                 G   r$  r'   )r   ÚLevel1Quantizer_swiginitÚnew_Level1Quantizerrp   r   r   r   rH   ë  r.   zLevel1Quantizer.__init__N)"r   r   r1   r2   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_setr¹  ÚLevel1Quantizer_cp_getÚLevel1Quantizer_cp_setr  Ú$Level1Quantizer_clustering_index_getÚ$Level1Quantizer_clustering_index_setÚclustering_indexrÑ	  rÓ	  rÕ	  r×	  rH   Údelete_Level1Quantizerrv   r   r   r   r   rÊ	  È  s     
rÊ	  c                   @   sf   e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZeejejƒZejZdd	„ Zd
S )ÚSearchParametersIVFc                 C   r5   r'   r6   r7   r   r   r   r9   ó  r:   zSearchParametersIVF.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ó  r>   r?   r@   ú number of probes at query timeú' max nb of codes to visit to do a queryc                 C   ry   r'   )r   ÚSearchParametersIVF_swiginitÚnew_SearchParametersIVFrL   r   r   r   rH   ú  r|   zSearchParametersIVF.__init__N)r   r   r1   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Údelete_SearchParametersIVFrv   rH   r   r   r   r   rê	  ò  s    rê	  c                   @   sl   e Zd Zedd„ dd„ ddZdd„ ZeZeej	ej
ddZeejejd	dZddd„Zddd„ZejZd
S )ÚIndexIVFInterfacec                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexIVFInterface.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH     rI   zIndexIVFInterface.__init__rë	  rì	  Nc                 C   r»  )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   rQ   r8   rÅ  rª  Úcentroid_disrÆ  rÇ  Ústore_pairsr¡  Ústatsr   r   r   Úsearch_preassigned	  s   z$IndexIVFInterface.search_preassignedFc
           
      C   rJ  )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   r7  r8   rÊ  r¶  Ú
coarse_disrË  rý	  r¡  rþ	  r   r   r   Úrange_search_preassigned(  s   z*IndexIVFInterface.range_search_preassignedrø  ©FNN)r   r   r1   r   r   rH   r   r
   r   ÚIndexIVFInterface_nprobe_getÚIndexIVFInterface_nprobe_setrñ	  ÚIndexIVFInterface_max_codes_getÚIndexIVFInterface_max_codes_setrô	  rÿ	  r
  Údelete_IndexIVFInterfacerv   r   r   r   r   rù	     s    


rù	  c                   @   sš  e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jƒZee	je	jd
dZee	je	jddZee	jƒZee	je	jddZdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdLdd„Z dd„ Z!dd„ Z"dMdd „Z#dNd!d"„Z$dOd#d$„Z%dOd%d&„Z&dPd'd(„Z'd)d*„ Z(d+d,„ Z)d-d.„ Z*dOd/d0„Z+d1d2„ Z,d3d4„ Z-d5d6„ Z.d7d8„ Z/d9d:„ Z0d;d<„ Z1e	j2Z3d=d>„ Z4d?d@„ Z5dQdBdC„Z6dDdE„ Z7dLdFdG„Z8dHdI„ Z9dJdK„ Z:dS )RÚ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                 C   r5   r'   r6   r7   r   r   r   r9   \  r:   zIndexIVF.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   \  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ^  rI   zIndexIVF.__init__ú 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()
    c                 C   rJ   r'   )r   ÚIndexIVF_resetrL   r   r   r   r{  u  rM   zIndexIVF.resetc                 C   r‹  rÏ	  )r   ÚIndexIVF_trainr“  r   r   r   r”  x  ró  zIndexIVF.trainc                 C   r‹  )z! Calls add_with_ids with NULL ids)r   ÚIndexIVF_addr“  r   r   r   r—  |  ró  zIndexIVF.addc                 C   r‡  )z1 default implementation that calls encode_vectors)r   ÚIndexIVF_add_with_idsr›  r   r   r   r  €  r  zIndexIVF.add_with_idsc                 C   rm  )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   rQ   r8   rœ  Úprecomputed_idxr   r   r   Úadd_core„  rc  zIndexIVF.add_coreFc                 C   rŽ  )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   rQ   r8   r¹  r  Úinclude_listnor   r   r   Úencode_vectors  r‚  zIndexIVF.encode_vectorsc                 C   r‡  )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   ÚIndexIVF_add_sa_codes)r   rQ   r  rœ  r   r   r   Úadd_sa_codes   r  zIndexIVF.add_sa_codesc                 C   r‹  )zu
        Sub-classes that encode the residuals can train their encoders here
        does nothing by default
        )r   ÚIndexIVF_train_residualr“  r   r   r   Útrain_residual«  râ  zIndexIVF.train_residualNc                 C   r»  r'   )r   ÚIndexIVF_search_preassignedrû	  r   r   r   rÿ	  ²  r½  zIndexIVF.search_preassignedc
           
      C   rJ  r'   )r   Ú!IndexIVF_range_search_preassignedr
  r   r   r   r
  µ  r  z!IndexIVF.range_search_preassignedc              	   C   rÈ  ©z/ assign the vectors, then call search_preassign)r   ÚIndexIVF_searchr   r   r   r   r¢  ¸  rÌ  zIndexIVF.searchc                 C   rŽ  r'   )r   ÚIndexIVF_range_searchr¥  r   r   r   r¦  ¼  r|   zIndexIVF.range_searchc                 C   r‹  )zŸ
         Get a scanner for this index (store_pairs means ignore labels)

        The default search implementation uses this to compute the distances
        )r   Ú IndexIVF_get_InvertedListScanner©r   rý	  rU  r   r   r   Úget_InvertedListScanner¿  rñ  z IndexIVF.get_InvertedListScannerc                 C   r‹  )zI reconstruct a vector. Works only if maintain_direct_map is set to 1 or 2)r   ÚIndexIVF_reconstructr±  r   r   r   r´  Ç  ró  zIndexIVF.reconstructc                 C   r‡  )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   ÚnvrÕ  r=   r   r   r   Úupdate_vectorsË  r?  zIndexIVF.update_vectorsc                 C   r‡  )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_nrº  r   r   r   r½  Ú  ó   zIndexIVF.reconstruct_nc              
   C   rÃ  )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À  r   r   r   rÁ  ê  ó   zIndexIVF.search_and_reconstructc                 C   r‡  ©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.  r³  r   r   r   Úreconstruct_from_offsetø  r  z IndexIVF.reconstruct_from_offsetc                 C   rN   ©z Dataset manipulation functions)r   ÚIndexIVF_remove_idsr­  r   r   r   r®    r
  zIndexIVF.remove_idsc                 C   rN   r'   )r   Ú#IndexIVF_check_compatible_for_mergerÞ  r   r   r   rß    rS   z#IndexIVF.check_compatible_for_mergec                 C   r‹  r'   )r   ÚIndexIVF_merge_fromr×  r   r   r   rÚ  
  r  zIndexIVF.merge_fromc                 C   rJ   r'   )r   ÚIndexIVF_get_CodePackerrL   r   r   r   r    rM   zIndexIVF.get_CodePackerc                 C   rm  )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Ð  r   r   r   rÔ    r¿  zIndexIVF.copy_subset_toc                 C   rN   r'   )r   ÚIndexIVF_get_list_sizer¡  r   r   r   Úget_list_size  rS   zIndexIVF.get_list_sizec                 C   rJ   )z are the ids sorted?)r   ÚIndexIVF_check_ids_sortedrL   r   r   r   Úcheck_ids_sorted  r`  zIndexIVF.check_ids_sortedTc                 C   rN   ©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_mapr   r   r   Úmake_direct_map  rô  zIndexIVF.make_direct_mapc                 C   rN   r'   )r   ÚIndexIVF_set_direct_map_type©r   r   r   r   r   Úset_direct_map_type)  rS   zIndexIVF.set_direct_map_typec                 C   r‹  )zC replace the inverted lists, old one is deallocated if own_invlists)r   ÚIndexIVF_replace_invlists©r   r	  r   r   r   r   Úreplace_invlists,  ró  zIndexIVF.replace_invlistsc                 C   rJ   r'   )r   ÚIndexIVF_sa_code_sizerL   r   r   r   rÍ  0  rM   zIndexIVF.sa_code_sizec                 C   r‡  r'   )r   ÚIndexIVF_sa_encoderÏ  r   r   r   rÐ  3  r‰  zIndexIVF.sa_encode©Frø  r
  r'   )FNr>  );r   r   r1   r2   r   r   rH   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º	  r{  r”  r—  r  r
  r
  r
  r
  rÿ	  r
  r¢  r¦  r#
  r´  r(
  r½  rÁ  r0
  r®  rß  rÚ  r  rÔ  Údelete_IndexIVFrv   r8
  r:
  r?
  rB
  rE
  rÍ  rÐ  r   r   r   r   r

  E  sT    










r

  c                   @   sÊ   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jddZee	je	jddZee	je	jddZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze	j Z!dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   A  r:   zInvertedListScanner.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   A  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   C  rI   zInvertedListScanner.__init__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                 C   rN   ©z" from now on we handle this query.)r   ÚInvertedListScanner_set_query©r   Úquery_vectorr   r   r   rö  L  r
  zInvertedListScanner.set_queryc                 C   r‹  ©z- following codes come from this inverted list)r   ÚInvertedListScanner_set_list©r   r¢  r
  r   r   r   Úset_listP  ró  zInvertedListScanner.set_listc                 C   rN   ©z( compute a single query-to-code distance)r   Ú$InvertedListScanner_distance_to_coder  r   r   r   r  T  r
  z$InvertedListScanner.distance_to_codec              	   C   rÈ  )aÁ  
         scan a set of codes, compute distances to current query and
        update heap of results if necessary. Default implemetation
        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   rQ   r  rA  rÆ  rÇ  rÅ  r   r   r   Ú
scan_codesX  s   zInvertedListScanner.scan_codesc                 C   rŽ  r'   )r   Ú!InvertedListScanner_iterate_codes)r   ÚiteratorrÆ  rÇ  rÅ  r¥  r   r   r   Úiterate_codeso  r|   z!InvertedListScanner.iterate_codesc                 C   rŽ  )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   rQ   r  rA  rÊ  rË  r   r   r   Úscan_codes_ranger  ó   z$InvertedListScanner.scan_codes_rangec                 C   rm  r'   )r   Ú'InvertedListScanner_iterate_codes_range)r   rg
  rÊ  rË  r¥  r   r   r   Úiterate_codes_range{  rr   z'InvertedListScanner.iterate_codes_rangeN)"r   r   r1   r2   r   r   rH   r   r
   r   ÚInvertedListScanner_list_no_getÚInvertedListScanner_list_no_setr¢  Ú InvertedListScanner_keep_max_getÚ InvertedListScanner_keep_max_setÚkeep_maxÚ#InvertedListScanner_store_pairs_getÚ#InvertedListScanner_store_pairs_setrý	  ÚInvertedListScanner_sel_getÚInvertedListScanner_sel_setrU  Ú!InvertedListScanner_code_size_getÚ!InvertedListScanner_code_size_setrœ  rö  r`
  r  re
  rh
  rk
  rn
  Údelete_InvertedListScannerrv   r   r   r   r   rX
  9  s$    	
rX
  c                   @   s˜   e Zd Zedd„ d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jƒZdd„ Zdd	„ Zd
d„ ZejZdS )ÚIndexIVFStatsc                 C   r5   r'   r6   r7   r   r   r   r9   ƒ  r:   zIndexIVFStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ƒ  r>   r?   r@   c                 C   ry   r'   )r   ÚIndexIVFStats_swiginitÚnew_IndexIVFStatsrL   r   r   r   rH   Œ  r|   zIndexIVFStats.__init__c                 C   rJ   r'   )r   ÚIndexIVFStats_resetrL   r   r   r   r{    rM   zIndexIVFStats.resetc                 C   rN   r'   )r   ÚIndexIVFStats_addrŒ   r   r   r   r—  ’  rS   zIndexIVFStats.addN)r   r   r1   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_timerH   r{  r—  Údelete_IndexIVFStatsrv   r   r   r   r   r{
  ‚  s    
r{
  c                 C   rN   )zn
     check if two indexes have the same parameters and are trained in
    the same way, otherwise throw.
    )r   rß  )Úindex1Úindex2r   r   r   rß  š  r¯  rß  c                  G   r¼  r'   )r   Úextract_index_ivfr¾  r   r   r   r“
  ¡  rM   r“
  c                  G   r¼  r'   )r   Útry_extract_index_ivfr¾  r   r   r   r”
  ¤  rM   r”
  c                 C   r‹  )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)Úindex0r‘
  Ú	shift_idsr   r   r   r•
  §  ó   r•
  c                 C   r‡  r'   )r   Úsearch_centroid)r€  r8   rQ   Úcentroid_idsr   r   r   r™
  ±  r‰  r™
  c              
   C   rÃ  r'   )r   Úsearch_and_return_centroids)r€  rQ   ÚxinrÅ  rÆ  rÇ  Úquery_centroid_idsÚresult_centroid_idsr   r   r   r›
  ´  r  r›
  c                   @   sš   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ¼  r:   zSlidingIndexWindow.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¼  r>   r?   r@   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                 C   ó   t  | t  |¡¡ dS )z, index should be initially empty and trainedN)r   ÚSlidingIndexWindow_swiginitÚnew_SlidingIndexWindow©r   r€  r   r   r   rH   Ä  rÌ  zSlidingIndexWindow.__init__c                 C   r‹  )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_oldestr   r   r   ÚstepÈ  r•  zSlidingIndexWindow.stepN)r   r   r1   r2   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_setra	  rH   r§
  Údelete_SlidingIndexWindowrv   r   r   r   r   rŸ
  ¶  s    

rŸ
  c                 C   r‹  )z( Get a subset of inverted lists [i0, i1))r   Úget_invlist_range)r€  r»  r	  r   r   r   r´
  Ø  ró  r´
  c                 C   r‡  )z Set a subset of inverted lists)r   Úset_invlist_range)r€  r»  r	  Úsrcr   r   r   rµ
  Ü  r  rµ
  c	           	      C   r!  )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€  rQ   r8   rÅ  rÆ  rÇ  r¡  Únb_disÚms_per_stager   r   r   r·
  à  s   r·
  c              
   C   rÃ  )z4 same as search_with_parameters but for range search)r   Úrange_search_with_parameters)r€  rQ   r8   rÊ  rË  r¡  r¸
  r¹
  r   r   r   rº
  î  rW  rº
  c                 C   rN   )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)rf	  Únlevelr   r   r   r»
  ò  r¯  r»
  c                 C   r‡  )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œ  r   r   r   r½
  ù  r?  r½
  c                   @   s  e Zd ZdZedd„ d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ejejƒZejZ	 ejZ	 ejZ	 ej Z!	 eej"ej#ƒZ$eej%ej&ƒZ'eej(ej)ddZ*eej+ej,ddZ-d	d
„ Z.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5ddd„Z6ej7Z8dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zScalarQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   z bits per scalar codez% trained values (including the range)c                 G   r$  r'   )r   ÚScalarQuantizer_swiginitÚnew_ScalarQuantizerrp   r   r   r   rH   *  r.   zScalarQuantizer.__init__c                 C   rJ   )z- updates internal values based on qtype and d)r   Ú!ScalarQuantizer_set_derived_sizesrL   r   r   r   Úset_derived_sizes-  r`  z!ScalarQuantizer.set_derived_sizesc                 C   r‹  r'   )r   ÚScalarQuantizer_trainr“  r   r   r   r”  1  r  zScalarQuantizer.trainc                 C   rŽ  )z5 Used by an IVF index to train based on the residuals)r   ÚScalarQuantizer_train_residual)r   rQ   r8   rÜ	  Úby_residualr  r   r   r   r
  4  r”  zScalarQuantizer.train_residualc                 C   r‡  )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Ä  r   r   r   rÅ  8  r  zScalarQuantizer.compute_codesc                 C   r‡  )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Ç  r   r   r   rÈ  C  r¾  zScalarQuantizer.decodec                 C   rJ   r'   )r   Ú ScalarQuantizer_select_quantizerrL   r   r   r   Úselect_quantizerM  rM   z ScalarQuantizer.select_quantizerc                 G   rn   r'   )r   Ú%ScalarQuantizer_get_distance_computerrp   r   r   r   rË  P  rr   z%ScalarQuantizer.get_distance_computerFc                 C   rŽ  r'   )r   Ú*ScalarQuantizer_select_InvertedListScanner)r   rn  rÜ	  rý	  rU  rÆ
  r   r   r   Úselect_InvertedListScannerS  r|   z*ScalarQuantizer.select_InvertedListScannerNrH
  )9r   r   r1   r2   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_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ÚtrainedrH   rÃ
  r”  r
  rÅ  rÈ  rÊ
  rË  rÍ
  Údelete_ScalarQuantizerrv   r   r   r   r   r¿
    sN    


r¿
  c                   @   st   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	„ Zd
d„ Zddd„Zdd„ Zdd„ Zdd„ ZejZdS )ÚIndexScalarQuantizerz'Flat index built on a scalar quantizer.c                 C   r5   r'   r6   r7   r   r   r   r9   ]  r:   zIndexScalarQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ]  r>   r?   r@   z Used to encode the vectorsc                 G   r$  r'   )r   ÚIndexScalarQuantizer_swiginitÚnew_IndexScalarQuantizerrp   r   r   r   rH   a  r.   zIndexScalarQuantizer.__init__c                 C   r‹  r'   )r   ÚIndexScalarQuantizer_trainr“  r   r   r   r”  d  r  zIndexScalarQuantizer.trainNc              	   C   rÈ  r'   )r   ÚIndexScalarQuantizer_searchr   r   r   r   r¢  g  r.   zIndexScalarQuantizer.searchc                 C   rJ   r'   )r   Ú2IndexScalarQuantizer_get_FlatCodesDistanceComputerrL   r   r   r   r  j  rM   z2IndexScalarQuantizer.get_FlatCodesDistanceComputerc                 C   r‡  r'   )r   ÚIndexScalarQuantizer_sa_encoderÏ  r   r   r   rÐ  m  r‰  zIndexScalarQuantizer.sa_encodec                 C   r‡  r'   )r   ÚIndexScalarQuantizer_sa_decoderÓ  r   r   r   rÔ  p  r‰  zIndexScalarQuantizer.sa_decoder'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexScalarQuantizer_sq_getÚIndexScalarQuantizer_sq_setÚsqrH   r”  r¢  r  rÐ  rÔ  Údelete_IndexScalarQuantizerrv   r   r   r   r   rô
  Z  s    

rô
  c                   @   s†   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ Zd	d
„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   z IndexIVFScalarQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   Ú IndexIVFScalarQuantizer_swiginitÚnew_IndexIVFScalarQuantizerrp   r   r   r   rH   „  r.   z IndexIVFScalarQuantizer.__init__c                 C   r‹  r'   )r   Ú&IndexIVFScalarQuantizer_train_residualr“  r   r   r   r
  ‡  r  z&IndexIVFScalarQuantizer.train_residualFc                 C   rŽ  r'   )r   Ú&IndexIVFScalarQuantizer_encode_vectors©r   rQ   r8   r¹  r  Úinclude_listnosr   r   r   r
  Š  r|   z&IndexIVFScalarQuantizer.encode_vectorsc                 C   rm  r'   )r   Ú IndexIVFScalarQuantizer_add_corer
  r   r   r   r
    rr   z IndexIVFScalarQuantizer.add_corec                 C   r‹  r'   )r   Ú/IndexIVFScalarQuantizer_get_InvertedListScannerr"
  r   r   r   r#
    r  z/IndexIVFScalarQuantizer.get_InvertedListScannerc                 C   r‡  r'   )r   Ú/IndexIVFScalarQuantizer_reconstruct_from_offsetr/
  r   r   r   r0
  “  r‰  z/IndexIVFScalarQuantizer.reconstruct_from_offsetc                 C   r‡  r'   )r   Ú!IndexIVFScalarQuantizer_sa_decoderÓ  r   r   r   rÔ  –  r‰  z!IndexIVFScalarQuantizer.sa_decodeNrH
  )r   r   r1   r2   r   r   r   r
   r   ÚIndexIVFScalarQuantizer_sq_getÚIndexIVFScalarQuantizer_sq_setrþ
  Ú'IndexIVFScalarQuantizer_by_residual_getÚ'IndexIVFScalarQuantizer_by_residual_setrÆ
  rH   r
  r
  r
  r#
  r0
  rÔ  Údelete_IndexIVFScalarQuantizerrv   r   r   r   r   r   w  s    

r   c                   @   sâ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZejZ	 ejZ	 ejZ	 ejZ	 eejejƒZeej ej!ddZ"dd„ Z#dd„ Z$ddd„Z%dd„ Z&dd„ Z'ej(Z)dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ¨  r:   zIndexIVFSpectralHash.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¨  r>   r?   r@   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                 G   r$  r'   )r   ÚIndexIVFSpectralHash_swiginitÚnew_IndexIVFSpectralHashrp   r   r   r   rH   ¼  r.   zIndexIVFSpectralHash.__init__c                 C   r‹  r'   )r   Ú#IndexIVFSpectralHash_train_residualr“  r   r   r   r
  ¿  r  z#IndexIVFSpectralHash.train_residualFc                 C   rŽ  r'   )r   Ú#IndexIVFSpectralHash_encode_vectorsr  r   r   r   r
  Â  r|   z#IndexIVFSpectralHash.encode_vectorsc                 C   r‹  r'   )r   Ú,IndexIVFSpectralHash_get_InvertedListScannerr"
  r   r   r   r#
  Å  r  z,IndexIVFSpectralHash.get_InvertedListScannerc                 G   rn   )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_vtrp   r   r   r   Ú
replace_vtÈ  rº  zIndexIVFSpectralHash.replace_vtNrH
  )*r   r   r1   r2   r   r   r   r
   r   ÚIndexIVFSpectralHash_vt_getÚIndexIVFSpectralHash_vt_setrà  Ú#IndexIVFSpectralHash_own_fields_getÚ#IndexIVFSpectralHash_own_fields_setr¹  Ú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ò
  rH   r
  r
  r#
  r  Údelete_IndexIVFSpectralHashrv   r   r   r   r   r    s0    


r  c                   @   s„   e Zd ZdZedd„ d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	d
„ Zddd„Zdd„ Zdd„ ZejZdS )ÚIndexIVFAdditiveQuantizerz]
    Abstract class for IVF additive quantizers.
    The search functions are in common.
    c                 C   r5   r'   r6   r7   r   r   r   r9   å  r:   z"IndexIVFAdditiveQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   å  r>   r?   r@   c                 G   r$  r'   )r   Ú"IndexIVFAdditiveQuantizer_swiginitÚnew_IndexIVFAdditiveQuantizerrp   r   r   r   rH   ë  r.   z"IndexIVFAdditiveQuantizer.__init__c                 C   r‹  r'   )r   Ú(IndexIVFAdditiveQuantizer_train_residualr“  r   r   r   r
  î  r  z(IndexIVFAdditiveQuantizer.train_residualFc                 C   rŽ  r'   )r   Ú(IndexIVFAdditiveQuantizer_encode_vectorsr  r   r   r   r
  ñ  r|   z(IndexIVFAdditiveQuantizer.encode_vectorsc                 C   r‹  r'   )r   Ú1IndexIVFAdditiveQuantizer_get_InvertedListScannerr"
  r   r   r   r#
  ô  r  z1IndexIVFAdditiveQuantizer.get_InvertedListScannerc                 C   r‡  r'   )r   Ú#IndexIVFAdditiveQuantizer_sa_decode)r   rQ   r  r8   r   r   r   rÔ  ÷  r‰  z#IndexIVFAdditiveQuantizer.sa_decodeNrH
  )r   r   r1   r2   r   r   r   r
   r   Ú IndexIVFAdditiveQuantizer_aq_getÚ IndexIVFAdditiveQuantizer_aq_setrÞ  Ú)IndexIVFAdditiveQuantizer_by_residual_getÚ)IndexIVFAdditiveQuantizer_by_residual_setrÆ
  Ú3IndexIVFAdditiveQuantizer_use_precomputed_table_getÚ3IndexIVFAdditiveQuantizer_use_precomputed_table_setÚuse_precomputed_tablerH   r
  r
  r#
  rÔ  Ú delete_IndexIVFAdditiveQuantizerrv   r   r   r   r   r/  ß  s    

r/  c                   @   óJ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZdd	„ ZejZd
S )ÚIndexIVFResidualQuantizerúv
     IndexIVF based on a residual quantizer. Stored vectors are
    approximated by residual quantization codes.
    c                 C   r5   r'   r6   r7   r   r   r   r9     r:   z"IndexIVFResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   rã  c                 G   r$  r'   )r   Ú"IndexIVFResidualQuantizer_swiginitÚnew_IndexIVFResidualQuantizerrp   r   r   r   rH     r.   z"IndexIVFResidualQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú IndexIVFResidualQuantizer_rq_getÚ IndexIVFResidualQuantizer_rq_setré  rH   Ú delete_IndexIVFResidualQuantizerrv   r   r   r   r   r?  þ  ó    
r?  c                   @   r>  )ÚIndexIVFLocalSearchQuantizerr@  c                 C   r5   r'   r6   r7   r   r   r   r9     r:   z%IndexIVFLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   z- The LSQ quantizer used to encode the vectorsc                 G   r$  r'   )r   Ú%IndexIVFLocalSearchQuantizer_swiginitÚ new_IndexIVFLocalSearchQuantizerrp   r   r   r   rH     r.   z%IndexIVFLocalSearchQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú$IndexIVFLocalSearchQuantizer_lsq_getÚ$IndexIVFLocalSearchQuantizer_lsq_setrf  rH   Ú#delete_IndexIVFLocalSearchQuantizerrv   r   r   r   r   rG    rF  rG  c                   @   r>  )Ú IndexIVFProductResidualQuantizerz†
     IndexIVF based on a product residual quantizer. Stored vectors are
    approximated by product residual quantization codes.
    c                 C   r5   r'   r6   r7   r   r   r   r9   &  r:   z)IndexIVFProductResidualQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   &  r>   r?   r@   ró  c                 G   r$  r'   )r   Ú)IndexIVFProductResidualQuantizer_swiginitÚ$new_IndexIVFProductResidualQuantizerrp   r   r   r   rH   *  r.   z)IndexIVFProductResidualQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú(IndexIVFProductResidualQuantizer_prq_getÚ(IndexIVFProductResidualQuantizer_prq_setrù  rH   Ú'delete_IndexIVFProductResidualQuantizerrv   r   r   r   r   rM     rF  rM  c                   @   r>  )Ú#IndexIVFProductLocalSearchQuantizerzŽ
     IndexIVF based on a product local search quantizer. Stored vectors are
    approximated by product local search quantization codes.
    c                 C   r5   r'   r6   r7   r   r   r   r9   7  r:   z,IndexIVFProductLocalSearchQuantizer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   7  r>   r?   r@   rý  c                 G   r$  r'   )r   Ú,IndexIVFProductLocalSearchQuantizer_swiginitÚ'new_IndexIVFProductLocalSearchQuantizerrp   r   r   r   rH   ;  r.   z,IndexIVFProductLocalSearchQuantizer.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú,IndexIVFProductLocalSearchQuantizer_plsq_getÚ,IndexIVFProductLocalSearchQuantizer_plsq_setr  rH   Ú*delete_IndexIVFProductLocalSearchQuantizerrv   r   r   r   r   rS  1  rF  rS  c                   @   sP   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZejZdd„ ZdS )	ÚSearchParametersHNSWc                 C   r5   r'   r6   r7   r   r   r   r9   C  r:   zSearchParametersHNSW.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   C  r>   r?   r@   c                 C   ry   r'   )r   ÚSearchParametersHNSW_swiginitÚnew_SearchParametersHNSWrL   r   r   r   rH   I  r|   zSearchParametersHNSW.__init__N)r   r   r1   r   r   r   r
   r   Ú!SearchParametersHNSW_efSearch_getÚ!SearchParametersHNSW_efSearch_setÚefSearchÚ0SearchParametersHNSW_check_relative_distance_getÚ0SearchParametersHNSW_check_relative_distance_setÚcheck_relative_distanceÚdelete_SearchParametersHNSWrv   rH   r   r   r   r   rY  B  s    rY  c                   @   s¤  e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZeejejddZeejejd	dZeejejd
dZeejejddZeejejƒZeejejddZeej ej!ddZ"eej#ej$ddZ%eej&ej'ddZ(eej)ej*ddZ+eej,ej-ddZ.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3d7dd„Z4dd „ Z5d!d"„ Z6d#d$„ Z7d%d&„ Z8d8d(d)„Z9d*d+„ Z:d,d-„ Z;d.d/„ Z<d0d1„ Z=d9d3d4„Z>e?d5d6„ ƒZ@ejAZBd'S ):ÚHNSWc                 C   r5   r'   r6   r7   r   r   r   r9   P  r:   zHNSW.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   P  r>   r?   r@   z- assignment probability to each layer (sum=1)zf
    number of neighbors stored per layer (cumulative), should not
    be changed after first add
    z5 level 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& number of entry points in levels > 0.z% use bounded queue during explorationc                 C   r‹  )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   r  Ú	levelMultr   r   r   Úset_default_probaso  râ  zHNSW.set_default_probasc                 C   r‹  )z< set nb of neighbors for this level (before adding anything))r   ÚHNSW_set_nb_neighbors)r   Úlevel_norQ   r   r   r   Úset_nb_neighborsv  ró  zHNSW.set_nb_neighborsc                 C   rN   )z nb of neighbors for this level)r   ÚHNSW_nb_neighbors©r   Úlayer_nor   r   r   Únb_neighborsz  r
  zHNSW.nb_neighborsc                 C   rN   )z0 cumumlative nb up to (and excluding) this level)r   ÚHNSW_cum_nb_neighborsrk  r   r   r   Úcum_nb_neighbors~  r
  zHNSW.cum_nb_neighborsc                 C   rm  )zA range of entries in the neighbors table of vertex no at layer_no)r   ÚHNSW_neighbor_range)r   rŸ	  rl  ÚbeginÚendr   r   r   Úneighbor_range‚  ru  zHNSW.neighbor_rangeé    c                 C   r 
  )z* only mandatory parameter: nb of neighborsN)r   ÚHNSW_swiginitÚnew_HNSW)r   r  r   r   r   rH   †  rÌ  zHNSW.__init__c                 C   rJ   )z$ pick a random level for a new point)r   ÚHNSW_random_levelrL   r   r   r   Úrandom_levelŠ  r`  zHNSW.random_levelc                 C   rN   )z0 add n random levels to table (for debugging...))r   ÚHNSW_fill_with_random_linksrP   r   r   r   Úfill_with_random_linksŽ  r
  zHNSW.fill_with_random_linksc              
   C   rÃ  r'   )r   ÚHNSW_add_links_starting_from)r   ÚptdisÚpt_idÚnearestÚ	d_nearestÚlevelÚlocksrà  r   r   r   Úadd_links_starting_from’  r  zHNSW.add_links_starting_fromc                 C   rŽ  )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   r   r   Úadd_with_locks•  rÙ  zHNSW.add_with_locksNc              	   C   rÈ  )z, search interface for 1 point, single thread)r   ÚHNSW_search)r   ÚqdisrÅ  ÚIÚDrà  r¡  r   r   r   r¢  œ  rÌ  zHNSW.searchc                 C   r»  )z+ search only in level 0 from a given vertex)r   ÚHNSW_search_level_0)r   r‡  rÅ  ÚidxiÚsimirñ	  Ú	nearest_iÚ	nearest_drÕ  Úsearch_statsrà  r   r   r   Úsearch_level_0   s   zHNSW.search_level_0c                 C   rJ   r'   )r   Ú
HNSW_resetrL   r   r   r   r{  ¤  rM   z
HNSW.resetc                 C   rN   r'   )r   ÚHNSW_clear_neighbor_tables©r   r€  r   r   r   Úclear_neighbor_tables§  rS   zHNSW.clear_neighbor_tablesc                 C   rN   r'   )r   ÚHNSW_print_neighbor_statsr“  r   r   r   Úprint_neighbor_statsª  rS   zHNSW.print_neighbor_statsFc                 C   r‹  r'   )r   ÚHNSW_prepare_level_tab)r   rQ   Úpreset_levelsr   r   r   Úprepare_level_tab­  r  zHNSW.prepare_level_tabc                 C   r‡  r'   ©r   ÚHNSW_shrink_neighbor_list©r‡  ÚinputÚoutputÚmax_sizer   r   r   Úshrink_neighbor_list°  r  zHNSW.shrink_neighbor_list©rt  r'   rH
  )Cr   r   r1   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_setra  ÚHNSW_upper_beam_getÚHNSW_upper_beam_setÚ
upper_beamÚHNSW_search_bounded_queue_getÚHNSW_search_bounded_queue_setÚsearch_bounded_queuerf  ri  rm  ro  rs  rH   rx  rz  r‚  r…  r¢  r  r{  r”  r–  r™  r5  r   Údelete_HNSWrv   r   r   r   r   rc  O  sF    




rc  c                 C   r‡  r'   rš  rœ  r   r   r   r›  ¸  r‰  r›  c                   @   sŒ   e Zd Zedd„ d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dd„Zd	d
„ Zdd„ ZejZdS )Ú	HNSWStatsc                 C   r5   r'   r6   r7   r   r   r   r9   ¼  r:   zHNSWStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¼  r>   r?   r@   r   c              
   C   s   t  | t  |||||¡¡ d S r'   )r   ÚHNSWStats_swiginitÚnew_HNSWStats)r   rÐ  rÑ  Ún3r†
  Únreorderr   r   r   rH   Ä  r½  zHNSWStats.__init__c                 C   rJ   r'   )r   ÚHNSWStats_resetrL   r   r   r   r{  Ç  rM   zHNSWStats.resetc                 C   rN   r'   )r   ÚHNSWStats_combinerŒ   r   r   r   ÚcombineÊ  rS   zHNSWStats.combineN)r   r   r   r   r   )r   r   r1   r   r   r   r
   r   ÚHNSWStats_n1_getÚHNSWStats_n1_setrÐ  ÚHNSWStats_n2_getÚHNSWStats_n2_setrÑ  ÚHNSWStats_n3_getÚHNSWStats_n3_setrË  ÚHNSWStats_ndis_getÚHNSWStats_ndis_setr†
  ÚHNSWStats_nreorder_getÚHNSWStats_nreorder_setrÌ  rH   r{  rÏ  Údelete_HNSWStatsrv   r   r   r   r   rÈ  »  s    

rÈ  c                   @   sü   e Zd Zedd„ dd„ ddZeZe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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j&ƒZ'ddd	„Z(d
d„ Z)dd„ Z*dd„ Z+dd„ Z,dd„ Z-dd„ Z.ej/Z0dS )ÚReconstructFromNeighborsc                 C   r5   r'   r6   r7   r   r   r   r9   Ò  r:   z!ReconstructFromNeighbors.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ò  r>   r?   r@   é   r   c                 C   r+  r'   )r   Ú!ReconstructFromNeighbors_swiginitÚnew_ReconstructFromNeighbors)r   r€  rÅ  Únsqr   r   r   rH   à  r/  z!ReconstructFromNeighbors.__init__c                 C   r‹  )zq
        codes must be added in the correct order and the IndexHNSW
        must be populated and sorted
        )r   Ú"ReconstructFromNeighbors_add_codesr“  r   r   r   Ú	add_codesã  râ  z"ReconstructFromNeighbors.add_codesc                 C   rm  r'   )r   Ú*ReconstructFromNeighbors_compute_distances)r   rQ   Ú	shortlistÚqueryrÆ  r   r   r   Úcompute_distancesê  rr   z*ReconstructFromNeighbors.compute_distancesc                 C   r‡  )z called by add_codes)r   Ú&ReconstructFromNeighbors_estimate_code)r   r8   r§  r›  r   r   r   Úestimate_codeí  r  z&ReconstructFromNeighbors.estimate_codec                 C   r‡  )z called by compute_distances)r   Ú$ReconstructFromNeighbors_reconstruct)r   r§  r8   Útmpr   r   r   r´  ñ  r  z$ReconstructFromNeighbors.reconstructc                 C   r‡  r'   )r   Ú&ReconstructFromNeighbors_reconstruct_n)r   Ún0r¼  r8   r   r   r   r½  õ  r‰  z&ReconstructFromNeighbors.reconstruct_nc                 C   r‹  )z> get the M+1 -by-d table for neighbor coordinates for vector i)r   Ú+ReconstructFromNeighbors_get_neighbor_table)r   r§  Úoutr   r   r   Úget_neighbor_tableø  ró  z+ReconstructFromNeighbors.get_neighbor_tableN)rÜ  r   )1r   r   r1   r   r   r   r
   r   Ú"ReconstructFromNeighbors_index_getr€  ÚReconstructFromNeighbors_M_getÚReconstructFromNeighbors_M_setr  ÚReconstructFromNeighbors_k_getÚReconstructFromNeighbors_k_setrÅ  Ú ReconstructFromNeighbors_nsq_getÚ ReconstructFromNeighbors_nsq_setrß  Ú&ReconstructFromNeighbors_code_size_getÚ&ReconstructFromNeighbors_code_size_setrœ  Ú&ReconstructFromNeighbors_k_reorder_getÚ&ReconstructFromNeighbors_k_reorder_setÚ	k_reorderÚ%ReconstructFromNeighbors_codebook_getÚ%ReconstructFromNeighbors_codebook_setÚcodebookÚ"ReconstructFromNeighbors_codes_getÚ"ReconstructFromNeighbors_codes_setr  Ú#ReconstructFromNeighbors_ntotal_getÚ#ReconstructFromNeighbors_ntotal_setræ  ÚReconstructFromNeighbors_d_getÚReconstructFromNeighbors_d_setr†  Ú!ReconstructFromNeighbors_dsub_getÚ!ReconstructFromNeighbors_dsub_setr  rH   rá  rå  rç  r´  r½  rî  Údelete_ReconstructFromNeighborsrv   r   r   r   r   rÛ  Ñ  s,    


rÛ  c                   @   sÌ   e Zd ZdZedd„ d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ejZd	d
„ Zdd„ Zd!dd„Zdd„ Zdd„ Zdd„ Zd"dd„Zdd„ Zdd„ Z dd„ Z!dd „ Z"dS )#Ú	IndexHNSWúe
     The HNSW index is a normal random-access index with a HNSW
    link structure built on top
    c                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexHNSW.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   ÚIndexHNSW_swiginitÚnew_IndexHNSWrp   r   r   r   rH     r.   zIndexHNSW.__init__c                 C   r‹  r'   )r   ÚIndexHNSW_addr“  r   r   r   r—    r  zIndexHNSW.addc                 C   r‹  ©z Trains the storage if needed)r   ÚIndexHNSW_trainr“  r   r   r   r”    ró  zIndexHNSW.trainNc              	   C   rÈ  ©z entry point for search)r   ÚIndexHNSW_searchr   r   r   r   r¢    rÌ  zIndexHNSW.searchc                 C   r‹  r'   )r   ÚIndexHNSW_reconstructr±  r   r   r   r´    r  zIndexHNSW.reconstructc                 C   rJ   r'   )r   ÚIndexHNSW_resetrL   r   r   r   r{    rM   zIndexHNSW.resetc                 C   rN   r'   )r   Ú"IndexHNSW_shrink_level_0_neighbors©r   r†   r   r   r   Úshrink_level_0_neighbors"  rS   z"IndexHNSW.shrink_level_0_neighborsr   c
           
      C   rJ  )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   rQ   r8   rÅ  r~  rŽ  rÆ  rÇ  rñ	  rÕ  r   r   r   r  %  s   	zIndexHNSW.search_level_0c                 C   r‡  ©z alternative graph building)r   Ú$IndexHNSW_init_level_0_from_knngraph)r   rÅ  r‰  rˆ  r   r   r   Úinit_level_0_from_knngraph0  r  z$IndexHNSW.init_level_0_from_knngraphc                 C   r‡  r  )r   Ú(IndexHNSW_init_level_0_from_entry_points)r   ÚnptÚpointsÚnearestsr   r   r   Úinit_level_0_from_entry_points4  r  z(IndexHNSW.init_level_0_from_entry_pointsc                 C   rJ   r'   )r   ÚIndexHNSW_reorder_linksrL   r   r   r   Úreorder_links8  rM   zIndexHNSW.reorder_linksc                 C   rJ   r'   )r   ÚIndexHNSW_link_singletonsrL   r   r   r   Úlink_singletons;  rM   zIndexHNSW.link_singletonsr'   )r   r   )#r   r   r1   r2   r   r   r   r
   r   ÚIndexHNSW_hnsw_getÚIndexHNSW_hnsw_setÚhnswÚIndexHNSW_own_fields_getÚIndexHNSW_own_fields_setr¹  ÚIndexHNSW_storage_getÚIndexHNSW_storage_setÚstorageÚ(IndexHNSW_reconstruct_from_neighbors_getÚ(IndexHNSW_reconstruct_from_neighbors_setÚreconstruct_from_neighborsrH   Údelete_IndexHNSWrv   r—  r”  r¢  r´  r{  r  r  r  r  r  r!  r   r   r   r   r     s*    

r  c                   @   r­  )
ÚIndexHNSWFlatz_
    Flat index topped with with a HNSW structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9   G  r:   zIndexHNSWFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   G  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexHNSWFlat_swiginitÚnew_IndexHNSWFlatrp   r   r   r   rH   J  r.   zIndexHNSWFlat.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_IndexHNSWFlatrv   r   r   r   r   r.  A  ó    
r.  c                   @   r“  )ÚIndexHNSWPQz]
    PQ index topped with with a HNSW structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9   W  r:   zIndexHNSWPQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   W  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexHNSWPQ_swiginitÚnew_IndexHNSWPQrp   r   r   r   rH   Z  r.   zIndexHNSWPQ.__init__c                 C   r‹  r'   )r   ÚIndexHNSWPQ_trainr“  r   r   r   r”  ]  r  zIndexHNSWPQ.trainN)r   r   r1   r2   r   r   r   r
   rH   r”  r   Údelete_IndexHNSWPQrv   r   r   r   r   r3  Q  ó    
r3  c                   @   r­  )
ÚIndexHNSWSQz]
    SQ index topped with with a HNSW structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9   j  r:   zIndexHNSWSQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   j  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexHNSWSQ_swiginitÚnew_IndexHNSWSQrp   r   r   r   rH   m  r.   zIndexHNSWSQ.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_IndexHNSWSQrv   r   r   r   r   r9  d  r2  r9  c                   @   sJ   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	ddd„Z
ejZdS )ÚIndexHNSW2Levelz/ 2-level code structure with fast random accessc                 C   r5   r'   r6   r7   r   r   r   r9   w  r:   zIndexHNSW2Level.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   w  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexHNSW2Level_swiginitÚnew_IndexHNSW2Levelrp   r   r   r   rH   z  r.   zIndexHNSW2Level.__init__c                 C   rJ   r'   )r   ÚIndexHNSW2Level_flip_to_ivfrL   r   r   r   Úflip_to_ivf}  rM   zIndexHNSW2Level.flip_to_ivfNc              	   C   rÈ  r  )r   ÚIndexHNSW2Level_searchr   r   r   r   r¢  €  rÌ  zIndexHNSW2Level.searchr'   )r   r   r1   r2   r   r   r   r
   rH   rA  r¢  r   Údelete_IndexHNSW2Levelrv   r   r   r   r   r=  t  s    

r=  c                 C   r‡  )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Úncolsr8   Úargminsr   r   r   rD  ‰  s   rD  c                 C   r‡  )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)r8   rQ   Ú	nclustersrZ  r   r   r   rH  š  s   rH  c                   @   r•  )ÚNeighborc                 C   r5   r'   r6   r7   r   r   r   r9   ³  r:   zNeighbor.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ³  r>   r?   r@   c                 G   r$  r'   )r   ÚNeighbor_swiginitÚnew_Neighborrp   r   r   r   rH   ¹  r.   zNeighbor.__init__c                 C   rN   r'   )r   ÚNeighbor___lt__rŒ   r   r   r   Ú__lt__¼  rS   zNeighbor.__lt__N)r   r   r1   r   r   r   r
   r   ÚNeighbor_id_getÚNeighbor_id_setrÄ  ÚNeighbor_distance_getÚNeighbor_distance_setrX   ÚNeighbor_flag_getÚNeighbor_flag_setÚflagrH   rN  Údelete_Neighborrv   r   r   r   r   rJ  ²  r©  rJ  c                   @   s   e Zd Zedd„ d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jƒZdd„ Zdd	„ ZejZd
S )ÚNhoodc                 C   r5   r'   r6   r7   r   r   r   r9   Ä  r:   zNhood.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ä  r>   r?   r@   c                 G   r$  r'   )r   ÚNhood_swiginitÚ	new_Nhoodrp   r   r   r   rH   Í  r.   zNhood.__init__c                 C   r‹  r'   )r   ÚNhood_insert)r   rÄ  Údistr   r   r   ÚinsertÐ  r  zNhood.insertN)r   r   r1   r   r   r   r
   r   ÚNhood_pool_getÚNhood_pool_setÚpoolÚNhood_M_getÚNhood_M_setr  Ú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_newrH   r\  Údelete_Nhoodrv   r   r   r   r   rW  Ã  s    
rW  c                   @   s$  e Zd Zedd„ dd„ ddZeZdd„ Zej	Z
dd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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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ƒZ1eej2ej3ƒZ4eej5ej6ƒZ7dS )Ú	NNDescentc                 C   r5   r'   r6   r7   r   r   r   r9   Ø  r:   zNNDescent.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ø  r>   r?   r@   c                 C   r—  r'   )r   ÚNNDescent_swiginitÚnew_NNDescent)r   r†  r?  r   r   r   rH   Û  r  zNNDescent.__init__c                 C   r‡  r'   )r   ÚNNDescent_build)r   r‡  rQ   r  r   r   r   Úbuildß  r‰  zNNDescent.buildc                 C   rŽ  r'   )r   ÚNNDescent_search)r   r‡  ÚtopkÚindicesÚdistsrà  r   r   r   r¢  â  r|   zNNDescent.searchc                 C   rJ   r'   )r   ÚNNDescent_resetrL   r   r   r   r{  å  rM   zNNDescent.resetc                 C   rN   )z" Initialize the KNN graph randomly)r   ÚNNDescent_init_graph©r   r‡  r   r   r   Ú
init_graphè  r
  zNNDescent.init_graphc                 C   r‹  )z Perform NNDescent algorithm)r   ÚNNDescent_nndescent)r   r‡  r  r   r   r   Ú	nndescentì  ró  zNNDescent.nndescentc                 C   rN   )z  Perform local join on each node)r   ÚNNDescent_joinrz  r   r   r   Újoinð  r
  zNNDescent.joinc                 C   rJ   )z> Sample new neighbors for each node to peform local join later)r   ÚNNDescent_updaterL   r   r   r   Úupdateô  r`  zNNDescent.updatec                 C   rm  )zF Sample a small number of points to evaluate the quality of KNNG built)r   ÚNNDescent_generate_eval_set)r   r‡  ré  r=   ÚNr   r   r   Úgenerate_eval_setø  ru  zNNDescent.generate_eval_setc                 C   r‹  )z# Evaluate the quality of KNNG built)r   ÚNNDescent_eval_recall)r   Úctrl_pointsÚacc_eval_setr   r   r   Úeval_recallü  ró  zNNDescent.eval_recallN)8r   r   r1   r   r   r   r
   rH   r   Údelete_NNDescentrv   rs  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_setrW  ÚNNDescent_K_getÚNNDescent_K_setr?  Ú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   ro  ×  s4    ro  c                   @   s   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejƒZeejejƒZdd	„ ZejZd
d„ Zdd„ Zddd„Zdd„ Zdd„ ZdS )ÚIndexNNDescentzp
     The NNDescent index is a normal random-access index with an NNDescent
    link structure built on top
    c                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexNNDescent.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   z Faiss results are 64-bitc                 G   r$  r'   )r   ÚIndexNNDescent_swiginitÚnew_IndexNNDescentrp   r   r   r   rH     r.   zIndexNNDescent.__init__c                 C   r‹  r'   )r   ÚIndexNNDescent_addr“  r   r   r   r—    r  zIndexNNDescent.addc                 C   r‹  r  )r   ÚIndexNNDescent_trainr“  r   r   r   r”  "  ró  zIndexNNDescent.trainNc              	   C   rÈ  r  )r   ÚIndexNNDescent_searchr   r   r   r   r¢  &  rÌ  zIndexNNDescent.searchc                 C   r‹  r'   )r   ÚIndexNNDescent_reconstructr±  r   r   r   r´  *  r  zIndexNNDescent.reconstructc                 C   rJ   r'   )r   ÚIndexNNDescent_resetrL   r   r   r   r{  -  rM   zIndexNNDescent.resetr'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexNNDescent_nndescent_getÚIndexNNDescent_nndescent_setr}  ÚIndexNNDescent_own_fields_getÚIndexNNDescent_own_fields_setr¹  ÚIndexNNDescent_storage_getÚIndexNNDescent_storage_setr)  rH   Údelete_IndexNNDescentrv   r—  r”  r¢  r´  r{  r   r   r   r   rª    s    
rª  c                   @   r­  )
ÚIndexNNDescentFlatzd
    Flat index topped with with a NNDescent structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9   9  r:   zIndexNNDescentFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   9  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexNNDescentFlat_swiginitÚnew_IndexNNDescentFlatrp   r   r   r   rH   <  r.   zIndexNNDescentFlat.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_IndexNNDescentFlatrv   r   r   r   r   r¹  3  r2  r¹  c                   @   sb   e Zd ZdZedd„ dd„ ddZeZdd„ Zdd
d„Z	dd„ Z
dd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   J  r:   zIndexIVFFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   J  r>   r?   r@   c                 C   rm  r'   )r   ÚIndexIVFFlat_add_corer
  r   r   r   r
  M  rr   zIndexIVFFlat.add_coreFc                 C   rŽ  r'   )r   ÚIndexIVFFlat_encode_vectorsr  r   r   r   r
  P  r|   zIndexIVFFlat.encode_vectorsc                 C   r‹  r'   )r   Ú$IndexIVFFlat_get_InvertedListScannerr"
  r   r   r   r#
  S  r  z$IndexIVFFlat.get_InvertedListScannerc                 C   r‡  r'   )r   Ú$IndexIVFFlat_reconstruct_from_offsetr/
  r   r   r   r0
  V  r‰  z$IndexIVFFlat.reconstruct_from_offsetc                 C   r‡  r'   )r   ÚIndexIVFFlat_sa_decoderÓ  r   r   r   rÔ  Y  r‰  zIndexIVFFlat.sa_decodec                 G   r$  r'   )r   ÚIndexIVFFlat_swiginitÚnew_IndexIVFFlatrp   r   r   r   rH   \  r.   zIndexIVFFlat.__init__NrH
  )r   r   r1   r2   r   r   r   r
   r
  r
  r#
  r0
  rÔ  rH   r   Údelete_IndexIVFFlatrv   r   r   r   r   r½  C  s    

r½  c                   @   s‚   e Zd Zedd„ dd„ ddZeZeejej	ddZ
dd„ Zd	d
„ Zddd„Zdd„ Zddd„Zdd„ Zdd„ Zdd„ ZejZdS )ÚIndexIVFFlatDedupc                 C   r5   r'   r6   r7   r   r   r   r9   d  r:   zIndexIVFFlatDedup.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   d  r>   r?   r@   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                 C   r‹  )z also dedups the training set)r   ÚIndexIVFFlatDedup_trainr“  r   r   r   r”  l  ró  zIndexIVFFlatDedup.trainc                 C   r‡  )z& implemented for all IndexIVF* classes)r   ÚIndexIVFFlatDedup_add_with_idsr›  r   r   r   r  p  r  zIndexIVFFlatDedup.add_with_idsNc                 C   r»  r'   )r   Ú$IndexIVFFlatDedup_search_preassignedrû	  r   r   r   rÿ	  t  r½  z$IndexIVFFlatDedup.search_preassignedc                 C   rN   r'   )r   ÚIndexIVFFlatDedup_remove_idsr­  r   r   r   r®  w  rS   zIndexIVFFlatDedup.remove_idsc                 C   rŽ  r	  )r   ÚIndexIVFFlatDedup_range_searchr¥  r   r   r   r¦  z  r”  zIndexIVFFlatDedup.range_searchc                 C   r‡  r	  )r   Ú IndexIVFFlatDedup_update_vectorsr&
  r   r   r   r(
  ~  r  z IndexIVFFlatDedup.update_vectorsc                 C   r‡  r	  )r   Ú)IndexIVFFlatDedup_reconstruct_from_offsetr/
  r   r   r   r0
  ‚  r  z)IndexIVFFlatDedup.reconstruct_from_offsetc                 G   r$  r'   )r   ÚIndexIVFFlatDedup_swiginitÚnew_IndexIVFFlatDeduprp   r   r   r   rH   †  r.   zIndexIVFFlatDedup.__init__rø  r'   )r   r   r1   r   r   r   r
   r   ÚIndexIVFFlatDedup_instances_getÚIndexIVFFlatDedup_instances_setÚ	instancesr”  r  rÿ	  r®  r¦  r(
  r0
  rH   Údelete_IndexIVFFlatDeduprv   r   r   r   r   rÆ  c  s    


rÆ  c                 C   rJ   r'   )r   Ústorage_distance_computer)r)  r   r   r   rÔ  Ž  rM   rÔ  c                   @   s0  e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZeej ej!ddZ"d)dd„Z#dd„ Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*d d!„ Z+d"d#„ Z,d$d%„ Z-d&d'„ Z.ej/Z0d(S )*ÚNSGc                 C   r5   r'   r6   r7   r   r   r   r9   ‘  r:   zNSG.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ‘  r>   r?   r@   z nb of nodesz nb of neighbors per nodez/ length of the search path at construction timez) candidate pool size at construction timez length of the search pathz enterpointz NSG graph structurez NSG is built or notz random generatorrt  c                 C   rh  r'   )r   ÚNSG_swiginitÚnew_NSG)r   r’  r   r   r   rH     r.   zNSG.__init__c                 C   rm  r'   )r   Ú	NSG_build)r   r)  rQ   Ú	knn_graphr  r   r   r   rs     rr   z	NSG.buildc                 C   rJ   r'   )r   Ú	NSG_resetrL   r   r   r   r{  £  rM   z	NSG.resetc                 C   rŽ  r'   )r   Ú
NSG_search)r   rº  rÅ  rˆ  r‰  rà  r   r   r   r¢  ¦  r|   z
NSG.searchc                 C   r‹  r'   )r   ÚNSG_init_graph)r   r)  rÙ  r   r   r   r{  ©  r  zNSG.init_graphc                 C   rm  r'   )r   ÚNSG_add_reverse_links)r   Úqr  rº  r¦  r   r   r   Úadd_reverse_links¬  rr   zNSG.add_reverse_linksc              	   C   rÈ  r'   )r   ÚNSG_sync_prune)r   rÞ  r_  rº  rà  rÙ  r¦  r   r   r   Ú
sync_prune¯  r.   zNSG.sync_prunec                 C   rm  r'   )r   ÚNSG_link)r   r)  rÙ  r¦  r  r   r   r   Úlink²  rr   zNSG.linkc                 C   r‹  r'   )r   ÚNSG_tree_grow)r   r)  Údegreesr   r   r   Ú	tree_growµ  r  zNSG.tree_growc                 C   r‡  r'   )r   ÚNSG_dfs)r   rà  ÚrootÚcntr   r   r   Údfs¸  r‰  zNSG.dfsc                 C   rm  r'   )r   ÚNSG_attach_unlinked)r   r)  rà  Úvt2rå  r   r   r   Úattach_unlinked»  rr   zNSG.attach_unlinkedc                 C   rJ   r'   )r   ÚNSG_check_graphrL   r   r   r   Úcheck_graph¾  rM   zNSG.check_graphNr¡  )1r   r   r1   r   r   r   r
   r   ÚNSG_ntotal_getÚNSG_ntotal_setræ  Ú	NSG_R_getÚ	NSG_R_setr’  Ú	NSG_L_getÚ	NSG_L_setr¡  Ú	NSG_C_getÚ	NSG_C_setÚCÚNSG_search_L_getÚNSG_search_L_setr˜  ÚNSG_enterpoint_getÚNSG_enterpoint_setÚ
enterpointÚNSG_final_graph_getÚNSG_final_graph_setr©  ÚNSG_is_built_getÚNSG_is_built_setÚis_builtÚNSG_rng_getÚNSG_rng_setr¶  rH   rs  r{  r¢  r{  rß  rá  rã  ræ  rê  rí  rï  Ú
delete_NSGrv   r   r   r   r   rÕ    s2    

rÕ  c                   @   s  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejƒZeejejd	dZeejejd
dZeejejddZeejejddZeejejƒZ eej!ej"ƒZ#eej$ej%ƒZ&dd„ Z'ej(Z)dd„ Z*dd„ Z+dd„ Z,ddd„Z-dd„ Z.dd„ Z/dd„ Z0dS )ÚIndexNSGzc
     The NSG index is a normal random-access index with a NSG
    link structure built on top
    c                 C   r5   r'   r6   r7   r   r   r   r9   Ë  r:   zIndexNSG.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ë  r>   r?   r@   z the link strcuturez 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                 G   r$  r'   )r   ÚIndexNSG_swiginitÚnew_IndexNSGrp   r   r   r   rH   Ü  r.   zIndexNSG.__init__c                 C   rm  r'   )r   ÚIndexNSG_build)r   rQ   r8   rÙ  ÚGKr   r   r   rs  à  rr   zIndexNSG.buildc                 C   r‹  r'   )r   ÚIndexNSG_addr“  r   r   r   r—  ã  r  zIndexNSG.addc                 C   r‹  r  )r   ÚIndexNSG_trainr“  r   r   r   r”  æ  ró  zIndexNSG.trainNc              	   C   rÈ  r  )r   ÚIndexNSG_searchr   r   r   r   r¢  ê  rÌ  zIndexNSG.searchc                 C   r‹  r'   )r   ÚIndexNSG_reconstructr±  r   r   r   r´  î  r  zIndexNSG.reconstructc                 C   rJ   r'   )r   ÚIndexNSG_resetrL   r   r   r   r{  ñ  rM   zIndexNSG.resetc                 C   r‡  r'   )r   ÚIndexNSG_check_knn_graph)r   rÙ  rQ   r?  r   r   r   Úcheck_knn_graphô  r‰  zIndexNSG.check_knn_graphr'   )1r   r   r1   r2   r   r   r   r
   r   ÚIndexNSG_nsg_getÚIndexNSG_nsg_setÚnsgÚIndexNSG_own_fields_getÚIndexNSG_own_fields_setr¹  Ú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_iterrH   Údelete_IndexNSGrv   rs  r—  r”  r¢  r´  r{  r  r   r   r   r   r  Å  s.    
r  c                   @   r­  )
ÚIndexNSGFlatz^
    Flat index topped with with a NSG structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9      r:   zIndexNSGFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9      r>   r?   r@   c                 G   r$  r'   )r   ÚIndexNSGFlat_swiginitÚnew_IndexNSGFlatrp   r   r   r   rH     r.   zIndexNSGFlat.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_IndexNSGFlatrv   r   r   r   r   r-  ú  r2  r-  c                   @   r“  )Ú
IndexNSGPQz\
    PQ index topped with with a NSG structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndexNSGPQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   r$  r'   )r   ÚIndexNSGPQ_swiginitÚnew_IndexNSGPQrp   r   r   r   rH     r.   zIndexNSGPQ.__init__c                 C   r‹  r'   )r   ÚIndexNSGPQ_trainr“  r   r   r   r”    r  zIndexNSGPQ.trainN)r   r   r1   r2   r   r   r   r
   rH   r”  r   Údelete_IndexNSGPQrv   r   r   r   r   r1  
  r8  r1  c                   @   r­  )
Ú
IndexNSGSQz\
    SQ index topped with with a NSG structure to access elements
    more efficiently.
    c                 C   r5   r'   r6   r7   r   r   r   r9   #  r:   zIndexNSGSQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   #  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexNSGSQ_swiginitÚnew_IndexNSGSQrp   r   r   r   rH   &  r.   zIndexNSGSQ.__init__N)r   r   r1   r2   r   r   r   r
   rH   r   Údelete_IndexNSGSQrv   r   r   r   r   r6    r2  r6  c                   @   s^   e Zd Zedd„ d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ejZdS )	ÚOnDiskOneListc                 C   r5   r'   r6   r7   r   r   r   r9   .  r:   zOnDiskOneList.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   .  r>   r?   r@   c                 C   ry   r'   )r   ÚOnDiskOneList_swiginitÚnew_OnDiskOneListrL   r   r   r   rH   4  r|   zOnDiskOneList.__init__N)r   r   r1   r   r   r   r
   r   ÚOnDiskOneList_size_getÚOnDiskOneList_size_setr†   ÚOnDiskOneList_capacity_getÚOnDiskOneList_capacity_setÚcapacityÚOnDiskOneList_offset_getÚOnDiskOneList_offset_setr.  rH   Údelete_OnDiskOneListrv   r   r   r   r   r:  -  s    
r:  c                   @   s:  e Zd ZdZedd„ d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jƒZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Z d+dd„Z!d+dd„Z"dd„ Z#dd„ Z$ej%Z&eej'ej(ƒZ)eej*ej+ƒZ,eej-ej.ƒZ/dd„ Z0dd„ Z1d d!„ Z2d"d#„ Z3d$d%„ Z4d&d'„ Z5d(d)„ Z6d*S ),Ú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                 C   r5   r'   r6   r7   r   r   r   r9   Z  r:   zOnDiskInvertedLists.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Z  r>   r?   r@   c                 C   rN   r'   )r   ÚOnDiskInvertedLists_list_sizer¡  r   r   r   r¥  c  rS   zOnDiskInvertedLists.list_sizec                 C   rN   r'   )r   ÚOnDiskInvertedLists_get_codesr¡  r   r   r   r©  f  rS   zOnDiskInvertedLists.get_codesc                 C   rN   r'   )r   ÚOnDiskInvertedLists_get_idsr¡  r   r   r   r«  i  rS   zOnDiskInvertedLists.get_idsc                 C   rm  r'   )r   ÚOnDiskInvertedLists_add_entriesrÀ  r   r   r   rÂ  l  rr   zOnDiskInvertedLists.add_entriesc                 C   rŽ  r'   )r   Ú"OnDiskInvertedLists_update_entriesrÇ  r   r   r   rÈ  o  r|   z"OnDiskInvertedLists.update_entriesc                 C   r‹  r'   )r   ÚOnDiskInvertedLists_resizerÊ  r   r   r   rŠ   r  r  zOnDiskInvertedLists.resizeFc                 C   r‡  r'   )r   ÚOnDiskInvertedLists_merge_from)r   r	  Ún_ilr  r   r   r   rÚ  u  r‰  zOnDiskInvertedLists.merge_fromc                 C   r‹  )z( same as merge_from for a single invlist)r   Ú OnDiskInvertedLists_merge_from_1)r   r	  r  r   r   r   Úmerge_from_1x  ró  z OnDiskInvertedLists.merge_from_1c                 C   r‹  )zI restrict the inverted lists to l0:l1 without touching the mmapped region)r   Ú!OnDiskInvertedLists_crop_invlists)r   Úl0Úl1r   r   r   Úcrop_invlists|  ró  z!OnDiskInvertedLists.crop_invlistsc                 C   r‹  r'   )r   Ú"OnDiskInvertedLists_prefetch_listsr¸  r   r   r   r»  €  r  z"OnDiskInvertedLists.prefetch_listsc                 C   rJ   r'   )r   ÚOnDiskInvertedLists_do_mmaprL   r   r   r   Údo_mmap‡  rM   zOnDiskInvertedLists.do_mmapc                 C   rN   r'   )r   Ú"OnDiskInvertedLists_update_totsize)r   Únew_totsizer   r   r   Úupdate_totsizeŠ  rS   z"OnDiskInvertedLists.update_totsizec                 C   r‹  r'   )r   Ú!OnDiskInvertedLists_resize_lockedrÊ  r   r   r   Úresize_locked  r  z!OnDiskInvertedLists.resize_lockedc                 C   rN   r'   )r   Ú!OnDiskInvertedLists_allocate_slot)r   rA  r   r   r   Úallocate_slot  rS   z!OnDiskInvertedLists.allocate_slotc                 C   r‹  r'   )r   ÚOnDiskInvertedLists_free_slot)r   r.  rA  r   r   r   Ú	free_slot“  r  zOnDiskInvertedLists.free_slotc                 C   rN   )z2 override all list sizes and make a packed storage)r   Ú'OnDiskInvertedLists_set_all_lists_sizes)r   ra	  r   r   r   Úset_all_lists_sizes–  r
  z'OnDiskInvertedLists.set_all_lists_sizesc                 G   r$  r'   )r   ÚOnDiskInvertedLists_swiginitÚnew_OnDiskInvertedListsrp   r   r   r   rH   š  r.   zOnDiskInvertedLists.__init__NrH
  )7r   r   r1   r2   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_setr0  Ú!OnDiskInvertedLists_read_only_getÚ!OnDiskInvertedLists_read_only_setÚ	read_onlyr¥  r©  r«  rÂ  rÈ  rŠ   rÚ  rO  rS  r»  Údelete_OnDiskInvertedListsrv   ÚOnDiskInvertedLists_locks_getÚOnDiskInvertedLists_locks_setr  ÚOnDiskInvertedLists_pf_getÚOnDiskInvertedLists_pf_setÚpfÚ(OnDiskInvertedLists_prefetch_nthread_getÚ(OnDiskInvertedLists_prefetch_nthread_setÚprefetch_nthreadrV  rY  r[  r]  r_  ra  rH   r   r   r   r   rE  ;  s>    

rE  c                   @   s„   e Zd ZdZedd„ d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dZdd	„ Zd
d„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ª  r:   zZnSphereSearch.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ª  r>   r?   r@   z size dim * ntatomc                 C   r—  r'   )r   ÚZnSphereSearch_swiginitÚnew_ZnSphereSearch©r   r§  Úr2r   r   r   rH   ±  r  zZnSphereSearch.__init__c                 G   rn   )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_searchrp   r   r   r   r¢  ´  s   zZnSphereSearch.searchc                 C   rm  r'   )r   ÚZnSphereSearch_search_multi)r   rQ   r8   Úc_outÚdp_outr   r   r   Úsearch_multiÅ  rr   zZnSphereSearch.search_multiN)r   r   r1   r2   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ÚvocrH   r¢  r‡  Údelete_ZnSphereSearchrv   r   r   r   r   r~     s    	
r~  c                   @   s|   e Zd Zedd„ dd„ ddZdd„ ZeZeej	ej
ddZeejejƒZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚEnumeratedVectorsc                 C   r5   r'   r6   r7   r   r   r   r9   Í  r:   zEnumeratedVectors.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Í  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   Ï  rI   zEnumeratedVectors.__init__z size of the collectionc                 C   rN   )z" encode a vector from a collection)r   ÚEnumeratedVectors_encoderW   r   r   r   r1  Õ  r
  zEnumeratedVectors.encodec                 C   r‹  )z
 decode it)r   ÚEnumeratedVectors_decode©r   r›  ré  r   r   r   rÈ  Ù  ró  zEnumeratedVectors.decodec                 C   r‡  r'   )r   ÚEnumeratedVectors_encode_multi)r   Úncré  r  r   r   r   Úencode_multiÝ  r‰  zEnumeratedVectors.encode_multic                 C   r‡  r'   )r   ÚEnumeratedVectors_decode_multi)r   r™  r  ré  r   r   r   Údecode_multià  r‰  zEnumeratedVectors.decode_multic              	   C   rÈ  r'   )r   ÚEnumeratedVectors_find_nn)r   rQ   r  r#  r$  rÕ  rº  r   r   r   Úfind_nnã  r.   zEnumeratedVectors.find_nnN)r   r   r1   r   r   rH   r   r
   r   ÚEnumeratedVectors_nv_getÚEnumeratedVectors_nv_setr'
  ÚEnumeratedVectors_dim_getÚEnumeratedVectors_dim_setr§  r1  rÈ  rš  rœ  rž  Údelete_EnumeratedVectorsrv   r   r   r   r   r”  Ì  s    
r”  c                   @   sP   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZdd„ ZejZdS )	ÚRepeatc                 C   r5   r'   r6   r7   r   r   r   r9   ë  r:   zRepeat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ë  r>   r?   r@   c                 C   ry   r'   )r   ÚRepeat_swiginitÚ
new_RepeatrL   r   r   r   rH   ð  r|   zRepeat.__init__N)r   r   r1   r   r   r   r
   r   ÚRepeat_val_getÚRepeat_val_setÚvalÚRepeat_n_getÚRepeat_n_setrQ   rH   Údelete_Repeatrv   r   r   r   r   r¤  ê  s    
r¤  c                   @   sn   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd	d
„Zdd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   þ  r:   zRepeats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   þ  r>   r?   r@   r   Nc                 C   r—  r'   )r   ÚRepeats_swiginitÚnew_Repeats)r   r§  ré  r   r   r   rH     r  zRepeats.__init__c                 C   rJ   r'   )r   ÚRepeats_countrL   r   r   r   Úcount  rM   zRepeats.countc                 C   rN   r'   )r   ÚRepeats_encoders  r   r   r   r1  	  rS   zRepeats.encodec                 C   r‹  r'   )r   ÚRepeats_decoder—  r   r   r   rÈ    r  zRepeats.decode)r   N)r   r   r1   r2   r   r   r   r
   r   ÚRepeats_dim_getÚRepeats_dim_setr§  ÚRepeats_repeats_getÚRepeats_repeats_setÚrepeatsrH   r±  r1  rÈ  Údelete_Repeatsrv   r   r   r   r   r­  ÷  s    

r­  c                   @   sz   e Zd ZdZedd„ d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	d
„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zZnSphereCodec.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   r—  r'   )r   ÚZnSphereCodec_swiginitÚnew_ZnSphereCodecr  r   r   r   rH   "  r  zZnSphereCodec.__init__c                 C   rN   r'   )r   ÚZnSphereCodec_search_and_encoderW   r   r   r   Úsearch_and_encode%  rS   zZnSphereCodec.search_and_encodec                 C   r‹  r'   )r   ÚZnSphereCodec_decoder—  r   r   r   rÈ  (  r  zZnSphereCodec.decodec                 C   rN   )z/ takes vectors that do not need to be centroids)r   ÚZnSphereCodec_encoderW   r   r   r   r1  +  r
  zZnSphereCodec.encodeN)r   r   r1   r2   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œ  rH   r¾  rÈ  r1  Údelete_ZnSphereCodecrv   r   r   r   r   rº    s    
rº  c                   @   sÊ   e Zd ZdZedd„ d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	d
„ Zdd„ Zd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!dd„ Z"dd„ Z#dd„ Z$ej%Z&dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   <  r:   zZnSphereCodecRec.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   <  r>   r?   r@   c                 C   r—  r'   )r   ÚZnSphereCodecRec_swiginitÚnew_ZnSphereCodecRecr  r   r   r   rH   B  r  zZnSphereCodecRec.__init__c                 C   rN   r'   )r   Ú ZnSphereCodecRec_encode_centroidrs  r   r   r   Úencode_centroidE  rS   z ZnSphereCodecRec.encode_centroidc                 C   r‹  r'   )r   ÚZnSphereCodecRec_decoder—  r   r   r   rÈ  H  r  zZnSphereCodecRec.decodec                 C   rN   )z[
        vectors need to be centroids (does not work on arbitrary
        vectors)
        )r   ÚZnSphereCodecRec_encoderW   r   r   r   r1  K  r¯  zZnSphereCodecRec.encodec                 C   r‹  r'   )r   ÚZnSphereCodecRec_get_nv)r   ÚldÚr2ar   r   r   Úget_nvV  r  zZnSphereCodecRec.get_nvc                 C   r‡  r'   )r   ÚZnSphereCodecRec_get_nv_cum)r   rÑ  Úr2trÒ  r   r   r   Ú
get_nv_cumY  r‰  zZnSphereCodecRec.get_nv_cumc                 C   rm  r'   )r   ÚZnSphereCodecRec_set_nv_cum)r   rÑ  rÕ  rÒ  r=   r   r   r   Ú
set_nv_cum\  rr   zZnSphereCodecRec.set_nv_cumN)'r   r   r1   r2   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œ  rH   rÍ  rÈ  r1  Ú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_ZnSphereCodecRecrv   r   r   r   r   rÉ  3  s&    
rÉ  c                   @   sd   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ Zd	d
„ Zdd„ ZejZdS )ÚZnSphereCodecAltzg
     Codec that uses the recursive codec if dim is a power of 2 and
    the regular one otherwise
    c                 C   r5   r'   r6   r7   r   r   r   r9   i  r:   zZnSphereCodecAlt.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   i  r>   r?   r@   c                 C   r—  r'   )r   ÚZnSphereCodecAlt_swiginitÚnew_ZnSphereCodecAltr  r   r   r   rH   n  r  zZnSphereCodecAlt.__init__c                 C   rN   r'   )r   ÚZnSphereCodecAlt_encoderW   r   r   r   r1  q  rS   zZnSphereCodecAlt.encodec                 C   r‹  r'   )r   ÚZnSphereCodecAlt_decoder—  r   r   r   rÈ  t  r  zZnSphereCodecAlt.decodeN)r   r   r1   r2   r   r   r   r
   r   ÚZnSphereCodecAlt_use_rec_getÚZnSphereCodecAlt_use_rec_setÚuse_recÚZnSphereCodecAlt_znc_rec_getÚZnSphereCodecAlt_znc_rec_setÚznc_recrH   r1  rÈ  Údelete_ZnSphereCodecAltrv   r   r   r   r   rí  c  s    
rí  c                   @   sì   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejƒZeejejddZeejejddZdd„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#ddd„Z$dd„ Z%ej&Z'dS )ÚIndexLatticezC Index that encodes a vector with a series of Zn lattice quantizersc                 C   r5   r'   r6   r7   r   r   r   r9   ~  r:   zIndexLattice.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ~  r>   r?   r@   z number of sub-vectorsz dimension of sub-vectorsz the lattice quantizerz0 nb bits used to encode the scale, per subvectorz total, in bytesz5 mins and maxes of the vector norms, per subquantizerc              	   C   r  r'   )r   ÚIndexLattice_swiginitÚnew_IndexLattice)r   r†  rß  Ú
scale_nbitr‚  r   r   r   rH   ˆ  r  zIndexLattice.__init__c                 C   r‹  r'   )r   ÚIndexLattice_trainr“  r   r   r   r”  ‹  r  zIndexLattice.trainc                 C   rJ   r'   )r   ÚIndexLattice_sa_code_sizerL   r   r   r   rÍ  Ž  rM   zIndexLattice.sa_code_sizec                 C   r‡  r'   )r   ÚIndexLattice_sa_encoderÏ  r   r   r   rÐ  ‘  r‰  zIndexLattice.sa_encodec                 C   r‡  r'   )r   ÚIndexLattice_sa_decoderÓ  r   r   r   rÔ  ”  r‰  zIndexLattice.sa_decodec                 C   r‹  r	  )r   ÚIndexLattice_addr“  r   r   r   r—  —  ró  zIndexLattice.addNc              	   C   rÈ  r'   )r   ÚIndexLattice_searchr   r   r   r   r¢  ›  r.   zIndexLattice.searchc                 C   rJ   r'   )r   ÚIndexLattice_resetrL   r   r   r   r{  ž  rM   zIndexLattice.resetr'   )(r   r   r1   r2   r   r   r   r
   r   ÚIndexLattice_nsq_getÚIndexLattice_nsq_setrß  Ú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_setrü  ÚIndexLattice_lattice_nbit_getÚIndexLattice_lattice_nbit_setÚlattice_nbitÚIndexLattice_code_size_getÚIndexLattice_code_size_setrœ  ÚIndexLattice_trained_getÚIndexLattice_trained_setrò
  rH   r”  rÍ  rÐ  rÔ  r—  r¢  r{  Údelete_IndexLatticerv   r   r   r   r   rù  {  s(    

rù  c                   @   s\   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZd	d
„ ZejZdS )ÚIVFPQSearchParametersrô  c                 C   r5   r'   r6   r7   r   r   r   r9   ­  r:   zIVFPQSearchParameters.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ­  r>   r?   r@   ú% use table computation or on-the-fly?ú( Hamming thresh for polysemous filteringc                 C   ry   r'   )r   ÚIVFPQSearchParameters_swiginitÚnew_IVFPQSearchParametersrL   r   r   r   rH   ²  r|   zIVFPQSearchParameters.__init__N)r   r   r1   r2   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_setr‚  rH   Údelete_IVFPQSearchParametersrv   r   r   r   r   r  ¥  s    
r  c                   @   s6  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZeejejddZ d-dd„Z!dd„ Z"dd„ Z#d.dd„Z$dd„ Z%dd„ Z&dd„ Z'dd „ Z(d!d"„ Z)d-d#d$„Z*d%d&„ Z+d'd(„ Z,d)d*„ Z-d+d,„ Z.ej/Z0dS )/Ú
IndexIVFPQzz
     Inverted file with Product Quantizer encoding. Each residual
    vector is encoded as a product quantizer code.
    c                 C   r5   r'   r6   r7   r   r   r   r9   ¿  r:   zIndexIVFPQ.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¿  r>   r?   r@   z! Encode residual or plain vector?ú produces the codesz% reorder PQ centroids after training?z if NULL, use defaultr  r  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
    Fc                 C   rŽ  r'   )r   ÚIndexIVFPQ_encode_vectorsr  r   r   r   r
  Ð  r|   zIndexIVFPQ.encode_vectorsc                 C   r‡  r'   )r   ÚIndexIVFPQ_sa_decoderÓ  r   r   r   rÔ  Ó  r‰  zIndexIVFPQ.sa_decodec                 C   rm  r'   )r   ÚIndexIVFPQ_add_corer
  r   r   r   r
  Ö  rr   zIndexIVFPQ.add_coreNc                 C   rŽ  )z‘
        same as add_core, also:
        - output 2nd level residuals if residuals_2 != NULL
        - accepts precomputed_idx = nullptr
        )r   ÚIndexIVFPQ_add_core_o)r   rQ   r8   rœ  Úresiduals_2r
  r   r   r   Ú
add_core_oÙ  s   zIndexIVFPQ.add_core_oc                 C   r‹  )z trains the product quantizer)r   ÚIndexIVFPQ_train_residualr“  r   r   r   r
  á  ró  zIndexIVFPQ.train_residualc                 C   r‡  )z8 same as train_residual, also output 2nd level residuals)r   ÚIndexIVFPQ_train_residual_o)r   rQ   r8   r'  r   r   r   Útrain_residual_oå  r  zIndexIVFPQ.train_residual_oc                 C   r‡  r'   )r   Ú"IndexIVFPQ_reconstruct_from_offsetr/
  r   r   r   r0
  é  r‰  z"IndexIVFPQ.reconstruct_from_offsetc                 C   r‹  )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   rA  r€  r   r   r   Úfind_duplicatesì  s   zIndexIVFPQ.find_duplicatesc                 C   r‡  r'   )r   ÚIndexIVFPQ_encode)r   r²  r8   r›  r   r   r   r1  þ  r‰  zIndexIVFPQ.encodec                 C   rŽ  )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   rQ   r¶  r8   r  Úcompute_keysr   r   r   Úencode_multiple  s   zIndexIVFPQ.encode_multiplec                 C   rm  )z inverse of encode_multiple)r   ÚIndexIVFPQ_decode_multiple)r   rQ   r¶  Úxcodesr8   r   r   r   Údecode_multiple  ru  zIndexIVFPQ.decode_multiplec                 C   r‹  r'   )r   Ú"IndexIVFPQ_get_InvertedListScannerr"
  r   r   r   r#
    r  z"IndexIVFPQ.get_InvertedListScannerc                 C   rJ   )z build precomputed table)r   ÚIndexIVFPQ_precompute_tablerL   r   r   r   Úprecompute_table  r`  zIndexIVFPQ.precompute_tablec                 G   r$  r'   )r   ÚIndexIVFPQ_swiginitÚnew_IndexIVFPQrp   r   r   r   rH     r.   zIndexIVFPQ.__init__rH
  r'   )1r   r   r1   r2   r   r   r   r
   r   ÚIndexIVFPQ_by_residual_getÚIndexIVFPQ_by_residual_setrÆ
  ÚIndexIVFPQ_pq_getÚIndexIVFPQ_pq_setrn  Ú%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_setr‚  Ú$IndexIVFPQ_use_precomputed_table_getÚ$IndexIVFPQ_use_precomputed_table_setr<  Ú IndexIVFPQ_precomputed_table_getÚ IndexIVFPQ_precomputed_table_setÚprecomputed_tabler
  rÔ  r
  r(  r
  r+  r0
  r.  r1  r2  r5  r#
  r8  rH   Údelete_IndexIVFPQrv   r   r   r   r   r!  ¹  s6    



r!  c                 C   rŽ  )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)r<  rÜ	  rn  rK  rÆ
  r  r   r   r   rM  &  r‚  rM  c                   @   s„   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejƒZeejejd	dZd
d„ Zdd„ ZejZdS )ÚIndexIVFPQStatsz‚
    statistics are robust to internal threading, but not if
    IndexIVFPQ::search_preassigned is called by multiple threads
    c                 C   r5   r'   r6   r7   r   r   r   r9   ;  r:   zIndexIVFPQStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ;  r>   r?   r@   z nb of refines (IVFPQR)z5 nb of passed Hamming distance tests (for polysemous)z only for IVFPQRc                 C   ry   r'   )r   ÚIndexIVFPQStats_swiginitÚnew_IndexIVFPQStatsrL   r   r   r   rH   B  r|   zIndexIVFPQStats.__init__c                 C   rJ   r'   )r   ÚIndexIVFPQStats_resetrL   r   r   r   r{  E  rM   zIndexIVFPQStats.resetN)r   r   r1   r2   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_cyclesrH   r{  Údelete_IndexIVFPQStatsrv   r   r   r   r   rN  5  s    
rN  c                   @   s°   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZejZdS )ÚIndexIVFPQRz0 Index with an additional level of PQ refinementc                 C   r5   r'   r6   r7   r   r   r   r9   O  r:   zIndexIVFPQR.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   O  r>   r?   r@   z 3rd level quantizerz corresponding codeszH factor between k requested in search and the k requested from the IVFPQc                 C   rJ   r'   )r   ÚIndexIVFPQR_resetrL   r   r   r   r{  U  rM   zIndexIVFPQR.resetc                 C   rN   r'   )r   ÚIndexIVFPQR_remove_idsr­  r   r   r   r®  X  rS   zIndexIVFPQR.remove_idsc                 C   r‹  )z" trains the two product quantizers)r   ÚIndexIVFPQR_train_residualr“  r   r   r   r
  [  ró  zIndexIVFPQR.train_residualc                 C   r‡  r'   )r   ÚIndexIVFPQR_add_with_idsr›  r   r   r   r  _  r‰  zIndexIVFPQR.add_with_idsc                 C   rm  )zB same as add_with_ids, but optionally use the precomputed list ids)r   ÚIndexIVFPQR_add_corer
  r   r   r   r
  b  ru  zIndexIVFPQR.add_corec                 C   r‡  r'   )r   Ú#IndexIVFPQR_reconstruct_from_offsetr/
  r   r   r   r0
  f  r‰  z#IndexIVFPQR.reconstruct_from_offsetc                 C   r‹  r'   )r   ÚIndexIVFPQR_merge_fromr×  r   r   r   rÚ  i  r  zIndexIVFPQR.merge_fromNc                 C   r»  r'   )r   ÚIndexIVFPQR_search_preassignedrû	  r   r   r   rÿ	  l  r½  zIndexIVFPQR.search_preassignedc                 G   r$  r'   )r   ÚIndexIVFPQR_swiginitÚnew_IndexIVFPQRrp   r   r   r   rH   o  r.   zIndexIVFPQR.__init__rø  )r   r   r1   r2   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_setrÓ  r{  r®  r
  r  r
  r0
  rÚ  rÿ	  rH   Údelete_IndexIVFPQRrv   r   r   r   r   r^  L  s"    

r^  c                   @   s²   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZdd„ ZejZdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIndex2Layer.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   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                 G   r$  r'   )r   ÚIndex2Layer_swiginitÚnew_Index2Layerrp   r   r   r   rH   †  r.   zIndex2Layer.__init__c                 C   r‹  r'   )r   ÚIndex2Layer_trainr“  r   r   r   r”  Š  r  zIndex2Layer.trainNc              	   C   rÈ  r	  )r   ÚIndex2Layer_searchr   r   r   r   r¢    rÌ  zIndex2Layer.searchc                 C   rJ   r'   )r   Ú!Index2Layer_get_distance_computerrL   r   r   r   rË  ‘  rM   z!Index2Layer.get_distance_computerc                 C   rN   )z* transfer the flat codes to an IVFPQ index)r   ÚIndex2Layer_transfer_to_IVFPQrŒ   r   r   r   Útransfer_to_IVFPQ”  r
  zIndex2Layer.transfer_to_IVFPQc                 C   r‡  r'   )r   ÚIndex2Layer_sa_encoderÏ  r   r   r   rÐ  ˜  r‰  zIndex2Layer.sa_encodec                 C   r‡  r'   )r   ÚIndex2Layer_sa_decoderÓ  r   r   r   rÔ  ›  r‰  zIndex2Layer.sa_decoder'   )r   r   r1   r2   r   r   r   r
   r   ÚIndex2Layer_q1_getÚIndex2Layer_q1_setÚq1ÚIndex2Layer_pq_getÚIndex2Layer_pq_setrn  Ú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_2rH   Údelete_Index2Layerrv   r”  r¢  rË  ry  rÐ  rÔ  r   r   r   r   rr  v  s     
rr  c                   @   sD  e Zd ZdZedd„ dd„ ddZ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	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	j)ƒZ*ee	j+e	j,ƒZ-d	d
„ Z.dd„ Z/d#dd„Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5dd„ Z6dd„ Z7d$dd „Z8d!d"„ Z9e	j:Z;dS )%Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ±  r:   zIndexFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ±  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ³  rI   zIndexFastScan.__init__c                 C   rŽ  r'   )r   ÚIndexFastScan_init_fastscan)r   r†  r  r  ÚmetricÚbbsr   r   r   Úinit_fastscanÃ  r|   zIndexFastScan.init_fastscanc                 C   rJ   r'   )r   ÚIndexFastScan_resetrL   r   r   r   r{  Æ  rM   zIndexFastScan.resetNc              	   C   rÈ  r'   )r   ÚIndexFastScan_searchr   r   r   r   r¢  É  r.   zIndexFastScan.searchc                 C   r‹  r'   )r   ÚIndexFastScan_addr“  r   r   r   r—  Ì  r  zIndexFastScan.addc                 C   r‡  r'   )r   ÚIndexFastScan_compute_codes©r   r  rQ   r8   r   r   r   rÅ  Ï  r‰  zIndexFastScan.compute_codesc                 C   r‡  r'   )r   ÚIndexFastScan_compute_float_LUT©r   ÚlutrQ   r8   r   r   r   Úcompute_float_LUTÒ  r‰  zIndexFastScan.compute_float_LUTc                 C   rm  r'   )r   Ú#IndexFastScan_compute_quantized_LUT)r   rQ   r8   r”  Únormalizersr   r   r   Úcompute_quantized_LUTÕ  rr   z#IndexFastScan.compute_quantized_LUTc                 C   r‹  r'   )r   ÚIndexFastScan_reconstructr±  r   r   r   r´  Ø  r  zIndexFastScan.reconstructc                 C   rN   r'   )r   ÚIndexFastScan_remove_idsr­  r   r   r   r®  Û  rS   zIndexFastScan.remove_idsc                 C   rJ   r'   )r   ÚIndexFastScan_get_CodePackerrL   r   r   r   r  Þ  rM   zIndexFastScan.get_CodePackerr   c                 C   r‹  r'   )r   ÚIndexFastScan_merge_fromr×  r   r   r   rÚ  á  r  zIndexFastScan.merge_fromc                 C   rN   r'   )r   Ú(IndexFastScan_check_compatible_for_mergerÞ  r   r   r   rß  ä  rS   z(IndexFastScan.check_compatible_for_merger'   rá  )<r   r   r1   r2   r   r   rH   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_setr  ÚIndexFastScan_nbits_getÚIndexFastScan_nbits_setr  ÚIndexFastScan_ksub_getÚIndexFastScan_ksub_setrY  Ú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Å  r•  r˜  r´  r®  r  rÚ  rß  Údelete_IndexFastScanrv   r   r   r   r   rˆ  ¡  s<    


rˆ  c                   @   r„  )ÚFastScanStatsc                 C   r5   r'   r6   r7   r   r   r   r9   ì  r:   zFastScanStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ì  r>   r?   r@   c                 C   ry   r'   )r   ÚFastScanStats_swiginitÚnew_FastScanStatsrL   r   r   r   rH   ó  r|   zFastScanStats.__init__c                 C   rJ   r'   )r   ÚFastScanStats_resetrL   r   r   r   r{  ö  rM   zFastScanStats.resetN)r   r   r1   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Út3rH   r{  Údelete_FastScanStatsrv   r   r   r   r   r½  ë  r–  r½  c                   @   sª   e Zd ZdZedd„ d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ejZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9     r:   z'IndexAdditiveQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 G   rn   r'   )r   Ú#IndexAdditiveQuantizerFastScan_initrp   r   r   r   rœ    rr   z#IndexAdditiveQuantizerFastScan.initc                 G   r—  )z
        *Overload 1:*
        build from an existing IndexAQ

        |

        *Overload 2:*
        build from an existing IndexAQ
        N)r   Ú'IndexAdditiveQuantizerFastScan_swiginitÚ"new_IndexAdditiveQuantizerFastScanrp   r   r   r   rH     rš  z'IndexAdditiveQuantizerFastScan.__init__c                 C   r‹  r'   )r   Ú$IndexAdditiveQuantizerFastScan_trainr“  r   r   r   r”  "  r  z$IndexAdditiveQuantizerFastScan.trainc                 C   r‹  r'   )r   Ú2IndexAdditiveQuantizerFastScan_estimate_norm_scaler“  r   r   r   Úestimate_norm_scale%  r  z2IndexAdditiveQuantizerFastScan.estimate_norm_scalec                 C   r‡  r'   )r   Ú,IndexAdditiveQuantizerFastScan_compute_codesr‘  r   r   r   rÅ  (  r‰  z,IndexAdditiveQuantizerFastScan.compute_codesc                 C   r‡  r'   )r   Ú0IndexAdditiveQuantizerFastScan_compute_float_LUTr“  r   r   r   r•  +  r‰  z0IndexAdditiveQuantizerFastScan.compute_float_LUTNc              	   C   rÈ  r'   )r   Ú%IndexAdditiveQuantizerFastScan_searchr   r   r   r   r¢  .  r.   z%IndexAdditiveQuantizerFastScan.searchc                 C   r‡  )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_decoderÓ  r   r   r   rÔ  1  r*
  z(IndexAdditiveQuantizerFastScan.sa_decoder'   )r   r   r1   r2   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_scaleÚ3IndexAdditiveQuantizerFastScan_max_train_points_getÚ3IndexAdditiveQuantizerFastScan_max_train_points_setri  rœ  Ú%delete_IndexAdditiveQuantizerFastScanrv   rH   r”  rÓ  rÅ  r•  r¢  rÔ  r   r   r   r   rÍ  ý  s"    
rÍ  c                   @   r>  )ÚIndexResidualQuantizerFastScanrâ  c                 C   r5   r'   r6   r7   r   r   r   r9   K  r:   z'IndexResidualQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   K  r>   r?   r@   rã  c                 G   r$  r'   )r   Ú'IndexResidualQuantizerFastScan_swiginitÚ"new_IndexResidualQuantizerFastScanrp   r   r   r   rH   O  r.   z'IndexResidualQuantizerFastScan.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú%IndexResidualQuantizerFastScan_rq_getÚ%IndexResidualQuantizerFastScan_rq_setré  rH   Ú%delete_IndexResidualQuantizerFastScanrv   r   r   r   r   rã  D  ó    
rã  c                   @   r  )
Ú!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                 C   r5   r'   r6   r7   r   r   r   r9   ]  r:   z*IndexLocalSearchQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ]  r>   r?   r@   c                 G   r$  r'   )r   Ú*IndexLocalSearchQuantizerFastScan_swiginitÚ%new_IndexLocalSearchQuantizerFastScanrp   r   r   r   rH   a  r.   z*IndexLocalSearchQuantizerFastScan.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú)IndexLocalSearchQuantizerFastScan_lsq_getÚ)IndexLocalSearchQuantizerFastScan_lsq_setrf  rH   Ú(delete_IndexLocalSearchQuantizerFastScanrv   r   r   r   r   rê  V  s    
rê  c                   @   r>  )Ú%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                 C   r5   r'   r6   r7   r   r   r   r9   o  r:   z.IndexProductResidualQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   o  r>   r?   r@   ró  c                 G   r$  r'   )r   Ú.IndexProductResidualQuantizerFastScan_swiginitÚ)new_IndexProductResidualQuantizerFastScanrp   r   r   r   rH   s  r.   z.IndexProductResidualQuantizerFastScan.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú-IndexProductResidualQuantizerFastScan_prq_getÚ-IndexProductResidualQuantizerFastScan_prq_setrù  rH   Ú,delete_IndexProductResidualQuantizerFastScanrv   r   r   r   r   rð  h  ré  rð  c                   @   r>  )Ú(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                 C   r5   r'   r6   r7   r   r   r   r9     r:   z1IndexProductLocalSearchQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   rý  c                 G   r$  r'   )r   Ú1IndexProductLocalSearchQuantizerFastScan_swiginitÚ,new_IndexProductLocalSearchQuantizerFastScanrp   r   r   r   rH   …  r.   z1IndexProductLocalSearchQuantizerFastScan.__init__N)r   r   r1   r2   r   r   r   r
   r   Ú1IndexProductLocalSearchQuantizerFastScan_plsq_getÚ1IndexProductLocalSearchQuantizerFastScan_plsq_setr  rH   Ú/delete_IndexProductLocalSearchQuantizerFastScanrv   r   r   r   r   rö  z  ré  rö  c                   @   sf   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   š  r:   zIndexPQFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   š  r>   r?   r@   c                 G   r—  )z
        *Overload 1:*
        build from an existing IndexPQ

        |

        *Overload 2:*
        build from an existing IndexPQ
        N)r   ÚIndexPQFastScan_swiginitÚnew_IndexPQFastScanrp   r   r   r   rH   ž  rš  zIndexPQFastScan.__init__c                 C   r‹  r'   )r   ÚIndexPQFastScan_trainr“  r   r   r   r”  ª  r  zIndexPQFastScan.trainc                 C   r‡  r'   )r   ÚIndexPQFastScan_compute_codesr‘  r   r   r   rÅ  ­  r‰  zIndexPQFastScan.compute_codesc                 C   r‡  r'   )r   Ú!IndexPQFastScan_compute_float_LUTr“  r   r   r   r•  °  r‰  z!IndexPQFastScan.compute_float_LUTc                 C   r‡  )a¥  
         Decode a set of vectors.

         NOTE: The codes in the IndexPQFastScan 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   ÚIndexPQFastScan_sa_decoderÓ  r   r   r   rÔ  ³  r*
  zIndexPQFastScan.sa_decodeN)r   r   r1   r2   r   r   r   r
   r   ÚIndexPQFastScan_pq_getÚIndexPQFastScan_pq_setrn  rH   r”  rÅ  r•  rÔ  Údelete_IndexPQFastScanrv   r   r   r   r   rü  Œ  s    
rü  c                   @   s2  e Zd ZdZedd„ dd„ ddZ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	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	d
„ Z(dd„ Z)e	j*Z+ee	j,e	j-ddZ.dd„ Z/dd„ Z0dd„ Z1dd„ Z2d!dd„Z3d!dd„Z4dd„ Z5dd„ Z6dd „ Z7dS )"Ú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
    c                 C   r5   r'   r6   r7   r   r   r   r9   Ù  r:   zIndexIVFFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ù  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   Û  rI   zIndexIVFFastScan.__init__c                 C   rŽ  r'   )r   ÚIndexIVFFastScan_init_fastscan)r   r  r  rº  rŠ  r‹  r   r   r   rŒ  é  r|   zIndexIVFFastScan.init_fastscanc                 C   rJ   r'   )r   Ú!IndexIVFFastScan_init_code_packerrL   r   r   r   Úinit_code_packerì  rM   z!IndexIVFFastScan.init_code_packerz& orig's inverted lists (for debugging)c                 C   r‡  r'   )r   ÚIndexIVFFastScan_add_with_idsr›  r   r   r   r  ñ  r‰  zIndexIVFFastScan.add_with_idsc                 C   rJ   r'   )r   Ú#IndexIVFFastScan_lookup_table_is_3drL   r   r   r   Úlookup_table_is_3dô  rM   z#IndexIVFFastScan.lookup_table_is_3dc              	   C   rÈ  r'   )r   ÚIndexIVFFastScan_compute_LUT©r   rQ   r8   Ú
coarse_idsr
  r\  Úbiasesr   r   r   r‘  ÷  r.   zIndexIVFFastScan.compute_LUTc              
   C   rÃ  r'   )r   Ú"IndexIVFFastScan_compute_LUT_uint8)r   rQ   r8   r  r
  r\  r  r—  r   r   r   Úcompute_LUT_uint8ú  r  z"IndexIVFFastScan.compute_LUT_uint8Nc              	   C   rÈ  r'   )r   ÚIndexIVFFastScan_searchr   r   r   r   r¢  ý  r.   zIndexIVFFastScan.searchc                 C   rŽ  )z will just fail)r   ÚIndexIVFFastScan_range_searchr¥  r   r   r   r¦     r”  zIndexIVFFastScan.range_searchc                 C   r‡  r'   )r   Ú(IndexIVFFastScan_reconstruct_from_offsetr/
  r   r   r   r0
    r‰  z(IndexIVFFastScan.reconstruct_from_offsetc                 C   rJ   r'   )r   ÚIndexIVFFastScan_get_CodePackerrL   r   r   r   r    rM   zIndexIVFFastScan.get_CodePackerc                 C   rJ   r'   )r   Ú*IndexIVFFastScan_reconstruct_orig_invlistsrL   r   r   r   Úreconstruct_orig_invlists
  rM   z*IndexIVFFastScan.reconstruct_orig_invlistsr'   )8r   r   r1   r2   r   r   rH   r   r
   r   ÚIndexIVFFastScan_bbs_getÚIndexIVFFastScan_bbs_setr‹  ÚIndexIVFFastScan_M_getÚIndexIVFFastScan_M_setr  ÚIndexIVFFastScan_nbits_getÚIndexIVFFastScan_nbits_setr  ÚIndexIVFFastScan_ksub_getÚIndexIVFFastScan_ksub_setrY  ÚIndexIVFFastScan_M2_getÚIndexIVFFastScan_M2_setr¶  ÚIndexIVFFastScan_implem_getÚIndexIVFFastScan_implem_setr   ÚIndexIVFFastScan_skip_getÚIndexIVFFastScan_skip_setr£  Ú IndexIVFFastScan_by_residual_getÚ IndexIVFFastScan_by_residual_setrÆ
  ÚIndexIVFFastScan_qbs_getÚIndexIVFFastScan_qbs_setr¨  ÚIndexIVFFastScan_qbs2_getÚIndexIVFFastScan_qbs2_setÚqbs2rŒ  r	  Údelete_IndexIVFFastScanrv   Ú"IndexIVFFastScan_orig_invlists_getÚ"IndexIVFFastScan_orig_invlists_setÚorig_invlistsr  r  r‘  r  r¢  r¦  r0
  r  r  r   r   r   r   r  Ç  s8    

r  c                   @   sÊ   e Zd Zedd„ d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jƒZeejejƒZeejejƒZeej ej!ƒZ"dd„ Z#dd	„ Z$d
d„ Z%dd„ Z&ej'Z(dS )ÚIVFFastScanStatsc                 C   r5   r'   r6   r7   r   r   r   r9     r:   zIVFFastScanStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9     r>   r?   r@   c                 C   rN   r'   )r   ÚIVFFastScanStats_Mcy_atrø  r   r   r   ÚMcy_at  rS   zIVFFastScanStats.Mcy_atc                 C   rN   r'   )r   Ú!IVFFastScanStats_Mcy_reservoir_atrø  r   r   r   ÚMcy_reservoir_at   rS   z!IVFFastScanStats.Mcy_reservoir_atc                 C   ry   r'   )r   ÚIVFFastScanStats_swiginitÚnew_IVFFastScanStatsrL   r   r   r   rH   #  r|   zIVFFastScanStats.__init__c                 C   rJ   r'   )r   ÚIVFFastScanStats_resetrL   r   r   r   r{  &  rM   zIVFFastScanStats.resetN))r   r   r1   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_encoder4  r6  rH   r{  Údelete_IVFFastScanStatsrv   r   r   r   r   r2    s"    
r2  c                   @   s´   e Zd ZdZedd„ d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ejZd	d
„ Zdd„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ Zdd„ ZdS )Ú!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                 C   r5   r'   r6   r7   r   r   r   r9   ?  r:   z*IndexIVFAdditiveQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ?  r>   r?   r@   c                 C   rm  r'   )r   Ú&IndexIVFAdditiveQuantizerFastScan_init)r   rÞ  rº  rŠ  r‹  r   r   r   rœ  F  rr   z&IndexIVFAdditiveQuantizerFastScan.initc                 G   r$  r'   )r   Ú*IndexIVFAdditiveQuantizerFastScan_swiginitÚ%new_IndexIVFAdditiveQuantizerFastScanrp   r   r   r   rH   J  r.   z*IndexIVFAdditiveQuantizerFastScan.__init__c                 C   r‹  r'   )r   Ú0IndexIVFAdditiveQuantizerFastScan_train_residualr“  r   r   r   r
  M  r  z0IndexIVFAdditiveQuantizerFastScan.train_residualc                 C   r‹  r'   )r   Ú5IndexIVFAdditiveQuantizerFastScan_estimate_norm_scaler“  r   r   r   rÓ  P  r  z5IndexIVFAdditiveQuantizerFastScan.estimate_norm_scaleFc                 C   rŽ  )zq
        same as the regular IVFAQ encoder. The codes are not reorganized by
        blocks a that point
        )r   Ú0IndexIVFAdditiveQuantizerFastScan_encode_vectorsr
  r   r   r   r
  S  rÙ  z0IndexIVFAdditiveQuantizerFastScan.encode_vectorsNc              	   C   rÈ  r'   )r   Ú(IndexIVFAdditiveQuantizerFastScan_searchr   r   r   r   r¢  Z  r.   z(IndexIVFAdditiveQuantizerFastScan.searchc                 C   rJ   r'   )r   Ú4IndexIVFAdditiveQuantizerFastScan_lookup_table_is_3drL   r   r   r   r  ]  rM   z4IndexIVFAdditiveQuantizerFastScan.lookup_table_is_3dc              	   C   rÈ  r'   )r   Ú-IndexIVFAdditiveQuantizerFastScan_compute_LUTr  r   r   r   r‘  `  r.   z-IndexIVFAdditiveQuantizerFastScan.compute_LUTc                 C   r‡  r'   )r   Ú+IndexIVFAdditiveQuantizerFastScan_sa_decoderÓ  r   r   r   rÔ  c  r‰  z+IndexIVFAdditiveQuantizerFastScan.sa_decoderH
  r'   ) r   r   r1   r2   r   r   r   r
   r   Ú(IndexIVFAdditiveQuantizerFastScan_aq_getÚ(IndexIVFAdditiveQuantizerFastScan_aq_setrÞ  Ú2IndexIVFAdditiveQuantizerFastScan_rescale_norm_getÚ2IndexIVFAdditiveQuantizerFastScan_rescale_norm_setrÜ  Ú0IndexIVFAdditiveQuantizerFastScan_norm_scale_getÚ0IndexIVFAdditiveQuantizerFastScan_norm_scale_setrß  Ú6IndexIVFAdditiveQuantizerFastScan_max_train_points_getÚ6IndexIVFAdditiveQuantizerFastScan_max_train_points_setri  rœ  Ú(delete_IndexIVFAdditiveQuantizerFastScanrv   rH   r
  rÓ  r
  r¢  r  r‘  rÔ  r   r   r   r   rV  -  s$    

rV  c                   @   óB   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
dd„ ZejZdS )	Ú$IndexIVFLocalSearchQuantizerFastScanc                 C   r5   r'   r6   r7   r   r   r   r9   j  r:   z-IndexIVFLocalSearchQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   j  r>   r?   r@   c                 G   r$  r'   )r   Ú-IndexIVFLocalSearchQuantizerFastScan_swiginitÚ(new_IndexIVFLocalSearchQuantizerFastScanrp   r   r   r   rH   n  r.   z-IndexIVFLocalSearchQuantizerFastScan.__init__N)r   r   r1   r   r   r   r
   r   Ú,IndexIVFLocalSearchQuantizerFastScan_lsq_getÚ,IndexIVFLocalSearchQuantizerFastScan_lsq_setrf  rH   Ú+delete_IndexIVFLocalSearchQuantizerFastScanrv   r   r   r   r   rk  i  ó    
rk  c                   @   rj  )	Ú!IndexIVFResidualQuantizerFastScanc                 C   r5   r'   r6   r7   r   r   r   r9   v  r:   z*IndexIVFResidualQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   v  r>   r?   r@   c                 G   r$  r'   )r   Ú*IndexIVFResidualQuantizerFastScan_swiginitÚ%new_IndexIVFResidualQuantizerFastScanrp   r   r   r   rH   z  r.   z*IndexIVFResidualQuantizerFastScan.__init__N)r   r   r1   r   r   r   r
   r   Ú(IndexIVFResidualQuantizerFastScan_rq_getÚ(IndexIVFResidualQuantizerFastScan_rq_setré  rH   Ú(delete_IndexIVFResidualQuantizerFastScanrv   r   r   r   r   rr  u  rq  rr  c                   @   rj  )	Ú+IndexIVFProductLocalSearchQuantizerFastScanc                 C   r5   r'   r6   r7   r   r   r   r9   ‚  r:   z4IndexIVFProductLocalSearchQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ‚  r>   r?   r@   c                 G   r$  r'   )r   Ú4IndexIVFProductLocalSearchQuantizerFastScan_swiginitÚ/new_IndexIVFProductLocalSearchQuantizerFastScanrp   r   r   r   rH   †  r.   z4IndexIVFProductLocalSearchQuantizerFastScan.__init__N)r   r   r1   r   r   r   r
   r   Ú4IndexIVFProductLocalSearchQuantizerFastScan_plsq_getÚ4IndexIVFProductLocalSearchQuantizerFastScan_plsq_setr  rH   Ú2delete_IndexIVFProductLocalSearchQuantizerFastScanrv   r   r   r   r   rx    rq  rx  c                   @   rj  )	Ú(IndexIVFProductResidualQuantizerFastScanc                 C   r5   r'   r6   r7   r   r   r   r9   Ž  r:   z1IndexIVFProductResidualQuantizerFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ž  r>   r?   r@   c                 G   r$  r'   )r   Ú1IndexIVFProductResidualQuantizerFastScan_swiginitÚ,new_IndexIVFProductResidualQuantizerFastScanrp   r   r   r   rH   ’  r.   z1IndexIVFProductResidualQuantizerFastScan.__init__N)r   r   r1   r   r   r   r
   r   Ú0IndexIVFProductResidualQuantizerFastScan_prq_getÚ0IndexIVFProductResidualQuantizerFastScan_prq_setrù  rH   Ú/delete_IndexIVFProductResidualQuantizerFastScanrv   r   r   r   r   r~    rq  r~  c                   @   s    e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZd
d„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   «  r:   zIndexIVFPQFastScan.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   «  r>   r?   r@   r"  z precomputed tables managementz4 if use_precompute_table size (nlist, pq.M, pq.ksub)c                 G   r$  r'   )r   ÚIndexIVFPQFastScan_swiginitÚnew_IndexIVFPQFastScanrp   r   r   r   rH   ±  r.   zIndexIVFPQFastScan.__init__c                 C   r‹  r'   )r   Ú!IndexIVFPQFastScan_train_residualr“  r   r   r   r
  ´  r  z!IndexIVFPQFastScan.train_residualc                 C   rJ   )zA build precomputed table, possibly updating use_precomputed_table)r   Ú#IndexIVFPQFastScan_precompute_tablerL   r   r   r   r8  ·  r`  z#IndexIVFPQFastScan.precompute_tableFc                 C   rŽ  )zq
        same as the regular IVFPQ encoder. The codes are not reorganized by
        blocks a that point
        )r   Ú!IndexIVFPQFastScan_encode_vectorsr
  r   r   r   r
  »  rÙ  z!IndexIVFPQFastScan.encode_vectorsc                 C   rJ   r'   )r   Ú%IndexIVFPQFastScan_lookup_table_is_3drL   r   r   r   r  Â  rM   z%IndexIVFPQFastScan.lookup_table_is_3dc              	   C   rÈ  r'   )r   ÚIndexIVFPQFastScan_compute_LUTr  r   r   r   r‘  Å  r.   zIndexIVFPQFastScan.compute_LUTc                 C   r‡  r'   )r   ÚIndexIVFPQFastScan_sa_decoderÓ  r   r   r   rÔ  È  r‰  zIndexIVFPQFastScan.sa_decodeNrH
  )r   r   r1   r2   r   r   r   r
   r   ÚIndexIVFPQFastScan_pq_getÚIndexIVFPQFastScan_pq_setrn  Ú,IndexIVFPQFastScan_use_precomputed_table_getÚ,IndexIVFPQFastScan_use_precomputed_table_setr<  Ú(IndexIVFPQFastScan_precomputed_table_getÚ(IndexIVFPQFastScan_precomputed_table_setrK  rH   r
  r8  r
  r  r‘  rÔ  Údelete_IndexIVFPQFastScanrv   r   r   r   r   r„  ™  s    

r„  c                 C   rm  )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à  rQ   r†  Úa_outÚb_outr   r   r   r”  Ð  s   r”  c                 C   rŽ  r'   )r   Úround_uint8_per_column_multi)rà  rð  rQ   r†  r•  r–  r   r   r   r—  Þ  r|   r—  c                 C   r»  )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ñ	  r  rY  Ú	lut_is_3drŽ  ÚbiasÚLUTqr¶  Úbiasqr•  r–  r   r   r   r˜  á  s   r˜  c                 C   s    t  | |||||||||	|
|¡S r'   )r   Úaq_quantize_LUT_and_bias)rñ	  r  rY  rŽ  rš  ÚM_normrß  r›  r¶  rœ  r•  r–  r   r   r   r  ô  s    r  c                 C   r‡  r'   )r   Úaq_estimate_norm_scale)r  rY  rž  rŽ  r   r   r   rŸ  ÷  r‰  rŸ  c                   @   s  e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jddZee	je	jddZee	je	jddZee	je	jddZe	jZdd„ Zdd„ Zdd„ Z d.dd„Z!d.dd„Z"d/dd„Z#dd„ Z$dd „ Z%d!d"„ Z&d#d$„ Z'd.d%d&„Z(d'd(„ Z)d0d*d+„Z*d,d-„ Z+dS )1Ú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                 C   r5   r'   r6   r7   r   r   r   r9      r:   zIndexBinary.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9      r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH      rI   zIndexBinary.__init__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                 C   r‹  )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“  r   r   r   r”     r•  zIndexBinary.trainc                 C   r‹  )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“  r   r   r   r—     r˜
  zIndexBinary.addc                 C   r‡  r™  )r   ÚIndexBinary_add_with_idsr›  r   r   r   r  (   rž  zIndexBinary.add_with_idsNc              	   C   rÈ  )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_searchr   r   r   r   r¢  4   r£  zIndexBinary.searchc                 C   rŽ  )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_searchr¥  r   r   r   r¦  D   s   zIndexBinary.range_searchr   c                 C   rm  )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_assignr©  r   r   r   rª  Y   r‚  zIndexBinary.assignc                 C   rJ   )z( Removes all elements from the database.)r   ÚIndexBinary_resetrL   r   r   r   r{  f   r`  zIndexBinary.resetc                 C   rN   )z: Removes IDs from the index. Not supported by all indexes.)r   ÚIndexBinary_remove_idsr­  r   r   r   r®  j   r
  zIndexBinary.remove_idsc                 C   r‹  )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_reconstructr±  r   r   r   r´  n   r˜  zIndexBinary.reconstructc                 C   r‡  )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_nrº  r   r   r   r½  z   r¾  zIndexBinary.reconstruct_nc              
   C   rÃ  )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À  r   r   r   rÁ  „   rÂ  z"IndexBinary.search_and_reconstructc                 C   rJ   )z2 Display the actual class name and some more info.)r   ÚIndexBinary_displayrL   r   r   r   Údisplay‘   r`  zIndexBinary.displayr   c                 C   r‹  rÕ  )r   ÚIndexBinary_merge_fromr×  r   r   r   rÚ  •   rÛ  zIndexBinary.merge_fromc                 C   rN   rÜ  )r   Ú&IndexBinary_check_compatible_for_mergerÞ  r   r   r   rß  ž   rà  z&IndexBinary.check_compatible_for_merger'   rt   rá  ),r   r   r1   r2   r   r   rH   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_IndexBinaryrv   r”  r—  r  r¢  r¦  rª  r{  r®  r´  r½  rÁ  r­  rÚ  rß  r   r   r   r   r   ù  s4    	






	r   c                   @   s¬   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejƒZeejejƒZd	d
„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ Zdd„ ZejZdS )ÚIndexBinaryFlatzC Index that stores the full vectors and performs exhaustive search.c                 C   r5   r'   r6   r7   r   r   r   r9   ¬   r:   zIndexBinaryFlat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¬   r>   r?   r@   z& database vectors, size ntotal * d / 8út
     Select between using a heap or counting to select the k smallest values
    when scanning inverted lists.
    c                 C   r‹  r'   )r   ÚIndexBinaryFlat_addr“  r   r   r   r—  ¶   r  zIndexBinaryFlat.addc                 C   rJ   r'   )r   ÚIndexBinaryFlat_resetrL   r   r   r   r{  ¹   rM   zIndexBinaryFlat.resetNc              	   C   rÈ  r'   )r   ÚIndexBinaryFlat_searchr   r   r   r   r¢  ¼   r.   zIndexBinaryFlat.searchc                 C   rŽ  r'   )r   ÚIndexBinaryFlat_range_searchr¥  r   r   r   r¦  ¿   r|   zIndexBinaryFlat.range_searchc                 C   r‹  r'   )r   ÚIndexBinaryFlat_reconstructr±  r   r   r   r´  Â   r  zIndexBinaryFlat.reconstructc                 C   rN   )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_idsr­  r   r   r   r®  Å   rà  zIndexBinaryFlat.remove_idsc                 G   r$  r'   )r   ÚIndexBinaryFlat_swiginitÚnew_IndexBinaryFlatrp   r   r   r   rH   Í   r.   zIndexBinaryFlat.__init__r'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryFlat_xb_getÚIndexBinaryFlat_xb_setr%  Ú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¢  r¦  r´  r®  rH   Údelete_IndexBinaryFlatrv   r   r   r   r   r½  ©   s     


r½  c                   @   sÂ  e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejƒZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZeejejddZ eej!ej"ddZ#eej$ej%ddZ&eej'ej(ddZ)eej*ej+ddZ,dd„ Z-ej.Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4dAdd „Z5dBd"d#„Z6dAd$d%„Z7dAd&d'„Z8d(d)„ Z9d*d+„ Z:d,d-„ Z;dAd.d/„Z<d0d1„ Z=d2d3„ Z>d4d5„ Z?d6d7„ Z@d8d9„ ZAdCd;d<„ZBd=d>„ ZCdBd?d@„ZDdS )DÚ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                 C   r5   r'   r6   r7   r   r   r   r9   à   r:   zIndexBinaryIVF.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   à   r>   r?   r@   r
  rë	  rì	  r¾  z collect computations per batchz> map for direct access to the elements. Enables reconstruct().rË	  rž  rÌ	  rÍ	  rÎ	  c                 G   r$  r'   )r   ÚIndexBinaryIVF_swiginitÚnew_IndexBinaryIVFrp   r   r   r   rH   ò   r.   zIndexBinaryIVF.__init__c                 C   rJ   r'   )r   ÚIndexBinaryIVF_resetrL   r   r   r   r{  ö   rM   zIndexBinaryIVF.resetc                 C   r‹  )z Trains the quantizer)r   ÚIndexBinaryIVF_trainr“  r   r   r   r”  ù   ró  zIndexBinaryIVF.trainc                 C   r‹  r'   )r   ÚIndexBinaryIVF_addr“  r   r   r   r—  ý   r  zIndexBinaryIVF.addc                 C   r‡  r'   )r   ÚIndexBinaryIVF_add_with_idsr›  r   r   r   r   !  r‰  zIndexBinaryIVF.add_with_idsc                 C   rm  )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_corer
  r   r   r   r
  !  rˆ  zIndexBinaryIVF.add_coreNc
           
      C   rJ  )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   rQ   r8   rÅ  rª  rü	  rÆ  rÇ  rý	  r¡  r   r   r   rÿ	  !  s   z!IndexBinaryIVF.search_preassignedFc                 C   rN   r'   )r   Ú&IndexBinaryIVF_get_InvertedListScanner)r   rý	  r   r   r   r#
  *!  rS   z&IndexBinaryIVF.get_InvertedListScannerc              	   C   rÈ  r
  )r   ÚIndexBinaryIVF_searchr   r   r   r   r¢  -!  rÌ  zIndexBinaryIVF.searchc                 C   rŽ  r'   )r   ÚIndexBinaryIVF_range_searchr¥  r   r   r   r¦  1!  r|   zIndexBinaryIVF.range_searchc              	   C   rÈ  r'   )r   Ú'IndexBinaryIVF_range_search_preassigned)r   rQ   r8   rÊ  rª  rü	  rË  r   r   r   r
  4!  r.   z'IndexBinaryIVF.range_search_preassignedc                 C   r‹  r'   )r   ÚIndexBinaryIVF_reconstructr±  r   r   r   r´  7!  r  zIndexBinaryIVF.reconstructc                 C   r‡  )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_nrº  r   r   r   r½  :!  r*
  zIndexBinaryIVF.reconstruct_nc              
   C   rÃ  )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À  r   r   r   rÁ  J!  r,
  z%IndexBinaryIVF.search_and_reconstructc                 C   r‡  r-
  )r   Ú&IndexBinaryIVF_reconstruct_from_offsetr/
  r   r   r   r0
  X!  r  z&IndexBinaryIVF.reconstruct_from_offsetc                 C   rN   r1
  )r   ÚIndexBinaryIVF_remove_idsr­  r   r   r   r®  c!  r
  zIndexBinaryIVF.remove_idsc                 C   r‹  r'   )r   ÚIndexBinaryIVF_merge_from)r   r   rÙ  r   r   r   rÚ  g!  r  zIndexBinaryIVF.merge_fromc                 C   rN   r'   )r   Ú)IndexBinaryIVF_check_compatible_for_mergerÞ  r   r   r   rß  j!  rS   z)IndexBinaryIVF.check_compatible_for_mergec                 C   rN   r'   )r   ÚIndexBinaryIVF_get_list_sizer¡  r   r   r   r8
  m!  rS   zIndexBinaryIVF.get_list_sizeTc                 C   rN   r;
  )r   ÚIndexBinaryIVF_make_direct_mapr=
  r   r   r   r?
  p!  rô  zIndexBinaryIVF.make_direct_mapc                 C   rN   r'   )r   Ú"IndexBinaryIVF_set_direct_map_typerA
  r   r   r   rB
  z!  rS   z"IndexBinaryIVF.set_direct_map_typec                 C   r‹  r'   )r   ÚIndexBinaryIVF_replace_invlistsrD
  r   r   r   rE
  }!  r  zIndexBinaryIVF.replace_invlistsr'   rH
  r>  )Er   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryIVF_invlists_getÚIndexBinaryIVF_invlists_setrš	  ÚIndexBinaryIVF_own_invlists_getÚIndexBinaryIVF_own_invlists_setrM
  Ú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_setrÜ	  ÚIndexBinaryIVF_nlist_getÚIndexBinaryIVF_nlist_setrº  ÚIndexBinaryIVF_own_fields_getÚIndexBinaryIVF_own_fields_setr¹  ÚIndexBinaryIVF_cp_getÚIndexBinaryIVF_cp_setr  Ú#IndexBinaryIVF_clustering_index_getÚ#IndexBinaryIVF_clustering_index_setrè	  rH   Údelete_IndexBinaryIVFrv   r{  r”  r—  r  r
  rÿ	  r#
  r¢  r¦  r
  r´  r½  rÁ  r0
  r®  rÚ  rß  r8
  r?
  rB
  rE
  r   r   r   r   rÒ  Ô   sN    






rÒ  c                   @   s\   e Zd Zedd„ dd„ ddZdd„ ZeZdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZejZdS )ÚBinaryInvertedListScannerc                 C   r5   r'   r6   r7   r   r   r   r9   „!  r:   z"BinaryInvertedListScanner.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   „!  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   †!  rI   z"BinaryInvertedListScanner.__init__c                 C   rN   rY
  )r   Ú#BinaryInvertedListScanner_set_queryr[
  r   r   r   rö  Š!  r
  z#BinaryInvertedListScanner.set_queryc                 C   r‹  r]
  )r   Ú"BinaryInvertedListScanner_set_listr_
  r   r   r   r`
  Ž!  ró  z"BinaryInvertedListScanner.set_listc                 C   rN   ra
  )r   Ú*BinaryInvertedListScanner_distance_to_coder  r   r   r   r  ’!  r
  z*BinaryInvertedListScanner.distance_to_codec              	   C   rÈ  )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_codesrd
  r   r   r   re
  –!  s   z$BinaryInvertedListScanner.scan_codesc                 C   rŽ  r'   )r   Ú*BinaryInvertedListScanner_scan_codes_rangerj
  r   r   r   rk
  ª!  r|   z*BinaryInvertedListScanner.scan_codes_rangeN)r   r   r1   r   r   rH   r   r
   rö  r`
  r  re
  rk
  r   Ú delete_BinaryInvertedListScannerrv   r   r   r   r   r  ƒ!  s    
r  c                   @   sz   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZdd	„ ZejZd
d„ Zdd„ Zddd„Zdd„ ZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   »!  r:   zIndexBinaryFromFloat.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   »!  r>   r?   r@   z' Whether object owns the index pointer.c                 G   r$  r'   )r   ÚIndexBinaryFromFloat_swiginitÚnew_IndexBinaryFromFloatrp   r   r   r   rH   À!  r.   zIndexBinaryFromFloat.__init__c                 C   r‹  r'   )r   ÚIndexBinaryFromFloat_addr“  r   r   r   r—  Ä!  r  zIndexBinaryFromFloat.addc                 C   rJ   r'   )r   ÚIndexBinaryFromFloat_resetrL   r   r   r   r{  Ç!  rM   zIndexBinaryFromFloat.resetNc              	   C   rÈ  r'   )r   ÚIndexBinaryFromFloat_searchr   r   r   r   r¢  Ê!  r.   zIndexBinaryFromFloat.searchc                 C   r‹  r'   )r   ÚIndexBinaryFromFloat_trainr“  r   r   r   r”  Í!  r  zIndexBinaryFromFloat.trainr'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryFromFloat_index_getÚIndexBinaryFromFloat_index_setr€  Ú#IndexBinaryFromFloat_own_fields_getÚ#IndexBinaryFromFloat_own_fields_setr¹  rH   Údelete_IndexBinaryFromFloatrv   r—  r{  r¢  r”  r   r   r   r   r  ±!  s    	
r  c                   @   s”   e Zd ZdZedd„ d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ejZd	d
„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ ZdS )ÚIndexBinaryHNSWr  c                 C   r5   r'   r6   r7   r   r   r   r9   Ù!  r:   zIndexBinaryHNSW.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ù!  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexBinaryHNSW_swiginitÚnew_IndexBinaryHNSWrp   r   r   r   rH   ß!  r.   zIndexBinaryHNSW.__init__c                 C   rJ   r'   )r   Ú%IndexBinaryHNSW_get_distance_computerrL   r   r   r   rË  ã!  rM   z%IndexBinaryHNSW.get_distance_computerc                 C   r‹  r'   )r   ÚIndexBinaryHNSW_addr“  r   r   r   r—  æ!  r  zIndexBinaryHNSW.addc                 C   r‹  r  )r   ÚIndexBinaryHNSW_trainr“  r   r   r   r”  é!  ró  zIndexBinaryHNSW.trainNc              	   C   rÈ  r  )r   ÚIndexBinaryHNSW_searchr   r   r   r   r¢  í!  rÌ  zIndexBinaryHNSW.searchc                 C   r‹  r'   )r   ÚIndexBinaryHNSW_reconstructr±  r   r   r   r´  ñ!  r  zIndexBinaryHNSW.reconstructc                 C   rJ   r'   )r   ÚIndexBinaryHNSW_resetrL   r   r   r   r{  ô!  rM   zIndexBinaryHNSW.resetr'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryHNSW_hnsw_getÚIndexBinaryHNSW_hnsw_setr$  ÚIndexBinaryHNSW_own_fields_getÚIndexBinaryHNSW_own_fields_setr¹  ÚIndexBinaryHNSW_storage_getÚIndexBinaryHNSW_storage_setr)  rH   Údelete_IndexBinaryHNSWrv   rË  r—  r”  r¢  r´  r{  r   r   r   r   r  Ó!  s    
r  c                   @   sž   e Zd ZdZedd„ d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	d
„ Zdd„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ ZejZdS )ÚIndexBinaryHashú+ just uses the b first bits as a hash valuec                 C   r5   r'   r6   r7   r   r   r   r9   ý!  r:   zIndexBinaryHash.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ý!  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexBinaryHash_swiginitÚnew_IndexBinaryHashrp   r   r   r   rH   "  r.   zIndexBinaryHash.__init__c                 C   rJ   r'   )r   ÚIndexBinaryHash_resetrL   r   r   r   r{  "  rM   zIndexBinaryHash.resetc                 C   r‹  r'   )r   ÚIndexBinaryHash_addr“  r   r   r   r—  	"  r  zIndexBinaryHash.addc                 C   r‡  r'   )r   ÚIndexBinaryHash_add_with_idsr›  r   r   r   r  "  r‰  zIndexBinaryHash.add_with_idsNc                 C   rŽ  r'   )r   ÚIndexBinaryHash_range_searchr¥  r   r   r   r¦  "  r|   zIndexBinaryHash.range_searchc              	   C   rÈ  r'   )r   ÚIndexBinaryHash_searchr   r   r   r   r¢  "  r.   zIndexBinaryHash.searchc                 C   rJ   r'   )r   ÚIndexBinaryHash_displayrL   r   r   r   r­  "  rM   zIndexBinaryHash.displayc                 C   rJ   r'   )r   ÚIndexBinaryHash_hashtable_sizerL   r   r   r   Úhashtable_size"  rM   zIndexBinaryHash.hashtable_sizer'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryHash_invlists_getÚIndexBinaryHash_invlists_setrš	  ÚIndexBinaryHash_b_getÚIndexBinaryHash_b_setr…  ÚIndexBinaryHash_nflip_getÚIndexBinaryHash_nflip_setÚnfliprH   r{  r—  r  r¦  r¢  r­  r2  Údelete_IndexBinaryHashrv   r   r   r   r   r'  ú!  s     


r'  c                   @   r„  )ÚIndexBinaryHashStatsc                 C   r5   r'   r6   r7   r   r   r   r9    "  r:   zIndexBinaryHashStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9    "  r>   r?   r@   c                 C   ry   r'   )r   ÚIndexBinaryHashStats_swiginitÚnew_IndexBinaryHashStatsrL   r   r   r   rH   '"  r|   zIndexBinaryHashStats.__init__c                 C   rJ   r'   )r   ÚIndexBinaryHashStats_resetrL   r   r   r   r{  *"  rM   zIndexBinaryHashStats.resetN)r   r   r1   r   r   r   r
   r   ÚIndexBinaryHashStats_nq_getÚIndexBinaryHashStats_nq_setr#  ÚIndexBinaryHashStats_n0_getÚIndexBinaryHashStats_n0_setrë  ÚIndexBinaryHashStats_nlist_getÚIndexBinaryHashStats_nlist_setrº  ÚIndexBinaryHashStats_ndis_getÚIndexBinaryHashStats_ndis_setr†
  rH   r{  Údelete_IndexBinaryHashStatsrv   r   r   r   r   r;  "  r–  r;  c                   @   sÄ   e Zd ZdZedd„ d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dZeejejddZeejejd	dZd
d„ ZejZdd„ Zdd„ Zddd„Z ddd„Z!dd„ Z"dS )ÚIndexBinaryMultiHashr(  c                 C   r5   r'   r6   r7   r   r   r   r9   4"  r:   zIndexBinaryMultiHash.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   4"  r>   r?   r@   z nb of hash mapsz nb bits per hash mapz# nb bit flips to use at search timec                 G   r$  r'   )r   ÚIndexBinaryMultiHash_swiginitÚnew_IndexBinaryMultiHashrp   r   r   r   rH   ="  r.   zIndexBinaryMultiHash.__init__c                 C   rJ   r'   )r   ÚIndexBinaryMultiHash_resetrL   r   r   r   r{  A"  rM   zIndexBinaryMultiHash.resetc                 C   r‹  r'   )r   ÚIndexBinaryMultiHash_addr“  r   r   r   r—  D"  r  zIndexBinaryMultiHash.addNc                 C   rŽ  r'   )r   Ú!IndexBinaryMultiHash_range_searchr¥  r   r   r   r¦  G"  r|   z!IndexBinaryMultiHash.range_searchc              	   C   rÈ  r'   )r   ÚIndexBinaryMultiHash_searchr   r   r   r   r¢  J"  r.   zIndexBinaryMultiHash.searchc                 C   rJ   r'   )r   Ú#IndexBinaryMultiHash_hashtable_sizerL   r   r   r   r2  M"  rM   z#IndexBinaryMultiHash.hashtable_sizer'   )#r   r   r1   r2   r   r   r   r
   r   Ú IndexBinaryMultiHash_storage_getÚ IndexBinaryMultiHash_storage_setr)  Ú#IndexBinaryMultiHash_own_fields_getÚ#IndexBinaryMultiHash_own_fields_setr¹  Ú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_setr9  rH   Údelete_IndexBinaryMultiHashrv   r{  r—  r¦  r¢  r2  r   r   r   r   rH  1"  s"    

rH  c                   @   óz   e Zd ZdZedd„ dd„ ddZdd„ ZeZe	j
Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zee	je	jddZdS )ÚThreadedIndexBaseúr
    A holder of indices in a collection of threads
    The interface to this class itself is not thread safe
    c                 C   r5   r'   r6   r7   r   r   r   r9   Y"  r:   zThreadedIndexBase.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Y"  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   ["  rI   zThreadedIndexBase.__init__c                 C   rN   ©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£
  r   r   r   ÚaddIndex`"  r–  zThreadedIndexBase.addIndexc                 C   rN   ©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£
  r   r   r   ÚremoveIndexi"  rà  zThreadedIndexBase.removeIndexc                 G   rn   r'   )r   ÚThreadedIndexBase_runOnIndexrp   r   r   r   Ú
runOnIndexq"  rr   zThreadedIndexBase.runOnIndexc                 C   rJ   ©zL
        faiss::Index API
        All indices receive the same call
        )r   ÚThreadedIndexBase_resetrL   r   r   r   r{  t"  r†  zThreadedIndexBase.resetc                 C   rJ   ©z" Returns the number of sub-indices)r   ÚThreadedIndexBase_countrL   r   r   r   r±  {"  r`  zThreadedIndexBase.countc                 G   rn   ©z—
        *Overload 1:*
        Returns the i-th sub-index

        |

        *Overload 2:*
        Returns the i-th sub-index (const version)
        )r   ÚThreadedIndexBase_atrp   r   r   r   rˆ   "  rc  zThreadedIndexBase.atúE Whether or not we are responsible for deleting our contained indicesN)r   r   r1   r2   r   r   rH   r   r
   r   Údelete_ThreadedIndexBaserv   rd  rg  ri  r{  r±  rˆ   Ú!ThreadedIndexBase_own_indices_getÚ!ThreadedIndexBase_own_indices_setÚown_indicesr   r   r   r   r`  S"  ó    	r`  c                   @   r_  )ÚThreadedIndexBaseBinaryra  c                 C   r5   r'   r6   r7   r   r   r   r9   •"  r:   z ThreadedIndexBaseBinary.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   •"  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   —"  rI   z ThreadedIndexBaseBinary.__init__c                 C   rN   rb  )r   Ú ThreadedIndexBaseBinary_addIndexr£
  r   r   r   rd  œ"  r–  z ThreadedIndexBaseBinary.addIndexc                 C   rN   re  )r   Ú#ThreadedIndexBaseBinary_removeIndexr£
  r   r   r   rg  ¥"  rà  z#ThreadedIndexBaseBinary.removeIndexc                 G   rn   r'   )r   Ú"ThreadedIndexBaseBinary_runOnIndexrp   r   r   r   ri  ­"  rr   z"ThreadedIndexBaseBinary.runOnIndexc                 C   rJ   rj  )r   ÚThreadedIndexBaseBinary_resetrL   r   r   r   r{  °"  r†  zThreadedIndexBaseBinary.resetc                 C   rJ   rl  )r   ÚThreadedIndexBaseBinary_countrL   r   r   r   r±  ·"  r`  zThreadedIndexBaseBinary.countc                 G   rn   rn  )r   ÚThreadedIndexBaseBinary_atrp   r   r   r   rˆ   »"  rc  zThreadedIndexBaseBinary.atrp  N)r   r   r1   r2   r   r   rH   r   r
   r   Údelete_ThreadedIndexBaseBinaryrv   rd  rg  ri  r{  r±  rˆ   Ú'ThreadedIndexBaseBinary_own_indices_getÚ'ThreadedIndexBaseBinary_own_indices_setrt  r   r   r   r   rv  "  ru  rv  c                   @   ó€   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zddd„Zdd„ ZeejejƒZdd„ ZejZdS )ÚIndexShardsú<Index that concatenates the results from several sub-indexesc                 C   r5   r'   r6   r7   r   r   r   r9   Î"  r:   zIndexShards.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Î"  r>   r?   r@   c                 G   r—  ©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_IndexShardsrp   r   r   r   rH   Ñ"  ó   BzIndexShards.__init__c                 C   rN   ©z Alias for addIndex())r   ÚIndexShards_add_shardr£
  r   r   r   Ú	add_shard#  r
  zIndexShards.add_shardc                 C   rN   ©z Alias for removeIndex())r   ÚIndexShards_remove_shardr£
  r   r   r   Úremove_shard#  r
  zIndexShards.remove_shardc                 C   r‹  ©z; supported only for sub-indices that implement add_with_ids)r   ÚIndexShards_addr“  r   r   r   r—  #  ró  zIndexShards.addc                 C   r‡  ©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›  r   r   r   r  !#  r¸  zIndexShards.add_with_idsNc              	   C   rÈ  r'   )r   ÚIndexShards_searchr   r   r   r   r¢  /#  r.   zIndexShards.searchc                 C   r‹  r'   )r   ÚIndexShards_trainr“  r   r   r   r”  2#  r  zIndexShards.trainc                 C   rJ   ©zd
        Synchronize the top-level index (IndexShards) with data in the
        sub-indices
        )r   ÚIndexShards_syncWithSubIndexesrL   r   r   r   ÚsyncWithSubIndexes6#  r†  zIndexShards.syncWithSubIndexesr'   )r   r   r1   r2   r   r   r   r
   rH   r‰  rŒ  r—  r  r¢  r”  r   ÚIndexShards_successive_ids_getÚIndexShards_successive_ids_setÚsuccessive_idsr•  Údelete_IndexShardsrv   r   r   r   r   r  Ë"  ó    D

r  c                   @   r€  )ÚIndexBinaryShardsr‚  c                 C   r5   r'   r6   r7   r   r   r   r9   D#  r:   zIndexBinaryShards.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   D#  r>   r?   r@   c                 G   r—  rƒ  )r   ÚIndexBinaryShards_swiginitÚnew_IndexBinaryShardsrp   r   r   r   rH   G#  r†  zIndexBinaryShards.__init__c                 C   rN   r‡  )r   ÚIndexBinaryShards_add_shardr£
  r   r   r   r‰  ‹#  r
  zIndexBinaryShards.add_shardc                 C   rN   rŠ  )r   ÚIndexBinaryShards_remove_shardr£
  r   r   r   rŒ  #  r
  zIndexBinaryShards.remove_shardc                 C   r‹  r  )r   ÚIndexBinaryShards_addr“  r   r   r   r—  “#  ró  zIndexBinaryShards.addc                 C   r‡  r  )r   ÚIndexBinaryShards_add_with_idsr›  r   r   r   r  —#  r¸  zIndexBinaryShards.add_with_idsNc              	   C   rÈ  r'   )r   ÚIndexBinaryShards_searchr   r   r   r   r¢  ¥#  r.   zIndexBinaryShards.searchc                 C   r‹  r'   )r   ÚIndexBinaryShards_trainr“  r   r   r   r”  ¨#  r  zIndexBinaryShards.trainc                 C   rJ   r“  )r   Ú$IndexBinaryShards_syncWithSubIndexesrL   r   r   r   r•  ¬#  r†  z$IndexBinaryShards.syncWithSubIndexesr'   )r   r   r1   r2   r   r   r   r
   rH   r‰  rŒ  r—  r  r¢  r”  r   Ú$IndexBinaryShards_successive_ids_getÚ$IndexBinaryShards_successive_ids_setr˜  r•  Údelete_IndexBinaryShardsrv   r   r   r   r   r›  A#  rš  r›  c                   @   s\   e Zd ZdZedd„ dd„ ddZeZdd	d
„Zdd„ Z	dd„ Z
dd„ Zddd„ZejZdS )ÚIndexShardsIVFz¡
    IndexShards with a common coarse quantizer. All the indexes added should be
    IndexIVFInterface indexes so that the search_precomputed can be called.
    c                 C   r5   r'   r6   r7   r   r   r   r9   ½#  r:   zIndexShardsIVF.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ½#  r>   r?   r@   FTc              	   C   r  r'   )r   ÚIndexShardsIVF_swiginitÚnew_IndexShardsIVF)r   rÜ	  rº  Úthreadedr˜  r   r   r   rH   À#  r  zIndexShardsIVF.__init__c                 C   rN   r'   )r   ÚIndexShardsIVF_addIndexr£
  r   r   r   rd  Ã#  rS   zIndexShardsIVF.addIndexc                 C   r‡  r'   )r   ÚIndexShardsIVF_add_with_idsr›  r   r   r   r  Æ#  r‰  zIndexShardsIVF.add_with_idsc                 C   r‹  r'   )r   ÚIndexShardsIVF_trainr“  r   r   r   r”  É#  r  zIndexShardsIVF.trainNc              	   C   rÈ  r'   )r   ÚIndexShardsIVF_searchr   r   r   r   r¢  Ì#  r.   zIndexShardsIVF.search)FTr'   )r   r   r1   r2   r   r   r   r
   rH   rd  r  r”  r¢  r   Údelete_IndexShardsIVFrv   r   r   r   r   r¨  ·#  s    


r¨  c                   @   ór   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zddd„Zdd„ Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   Û#  r:   zIndexReplicas.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Û#  r>   r?   r@   c                 G   r—  ©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_IndexReplicasrp   r   r   r   rH   Þ#  ó   &zIndexReplicas.__init__c                 C   rN   r‡  )r   ÚIndexReplicas_add_replicar£
  r   r   r   Úadd_replica$  r
  zIndexReplicas.add_replicac                 C   rN   rŠ  )r   ÚIndexReplicas_remove_replicar£
  r   r   r   Úremove_replica
$  r
  zIndexReplicas.remove_replicac                 C   r‹  rj  )r   ÚIndexReplicas_trainr“  r   r   r   r”  $  râ  zIndexReplicas.trainc                 C   r‹  rj  )r   ÚIndexReplicas_addr“  r   r   r   r—  $  râ  zIndexReplicas.addNc              	   C   rÈ  ©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_searchr   r   r   r   r¢  $  ri  zIndexReplicas.searchc                 C   r‹  ©z" reconstructs from the first index)r   ÚIndexReplicas_reconstruct©r   r   r=   r   r   r   r´  $$  ró  zIndexReplicas.reconstructc                 C   rJ   r“  )r   Ú IndexReplicas_syncWithSubIndexesrL   r   r   r   r•  ($  r†  z IndexReplicas.syncWithSubIndexesr'   )r   r   r1   r2   r   r   r   r
   rH   r¹  r»  r”  r—  r¢  r´  r•  r   Údelete_IndexReplicasrv   r   r   r   r   r²  Ó#  ó    (

r²  c                   @   r±  )ÚIndexBinaryReplicasr³  c                 C   r5   r'   r6   r7   r   r   r   r9   ;$  r:   zIndexBinaryReplicas.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ;$  r>   r?   r@   c                 G   r—  r´  )r   ÚIndexBinaryReplicas_swiginitÚnew_IndexBinaryReplicasrp   r   r   r   rH   >$  r·  zIndexBinaryReplicas.__init__c                 C   rN   r‡  )r   ÚIndexBinaryReplicas_add_replicar£
  r   r   r   r¹  f$  r
  zIndexBinaryReplicas.add_replicac                 C   rN   rŠ  )r   Ú"IndexBinaryReplicas_remove_replicar£
  r   r   r   r»  j$  r
  z"IndexBinaryReplicas.remove_replicac                 C   r‹  rj  )r   ÚIndexBinaryReplicas_trainr“  r   r   r   r”  n$  râ  zIndexBinaryReplicas.trainc                 C   r‹  rj  )r   ÚIndexBinaryReplicas_addr“  r   r   r   r—  u$  râ  zIndexBinaryReplicas.addNc              	   C   rÈ  r¾  )r   ÚIndexBinaryReplicas_searchr   r   r   r   r¢  |$  ri  zIndexBinaryReplicas.searchc                 C   r‹  rÀ  )r   ÚIndexBinaryReplicas_reconstructrÂ  r   r   r   r´  „$  ró  zIndexBinaryReplicas.reconstructc                 C   rJ   r“  )r   Ú&IndexBinaryReplicas_syncWithSubIndexesrL   r   r   r   r•  ˆ$  r†  z&IndexBinaryReplicas.syncWithSubIndexesr'   )r   r   r1   r2   r   r   r   r
   rH   r¹  r»  r”  r—  r¢  r´  r•  r   Údelete_IndexBinaryReplicasrv   r   r   r   r   rÆ  3$  rÅ  rÆ  c                   @   s¤   e Zd ZdZedd„ d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d	„Zd
d„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ ZejZdS )ÚIndexSplitVectorsz€
     splits input vectors in segments and assigns each segment to a sub-index
    used to distribute a MultiIndexQuantizer
    c                 C   r5   r'   r6   r7   r   r   r   r9   ™$  r:   zIndexSplitVectors.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ™$  r>   r?   r@   Fc                 C   r@  )z sum of dimensions seen so farN)r   ÚIndexSplitVectors_swiginitÚnew_IndexSplitVectors)r   r†  r«  r   r   r   rH    $  rW  zIndexSplitVectors.__init__c                 C   rN   r'   )r   ÚIndexSplitVectors_add_sub_indexr~   r   r   r   Úadd_sub_index¤$  rS   zIndexSplitVectors.add_sub_indexc                 C   rJ   r'   )r   Ú'IndexSplitVectors_sync_with_sub_indexesrL   r   r   r   Úsync_with_sub_indexes§$  rM   z'IndexSplitVectors.sync_with_sub_indexesc                 C   r‹  r'   )r   ÚIndexSplitVectors_addr“  r   r   r   r—  ª$  r  zIndexSplitVectors.addNc              	   C   rÈ  r'   )r   ÚIndexSplitVectors_searchr   r   r   r   r¢  ­$  r.   zIndexSplitVectors.searchc                 C   r‹  r'   )r   ÚIndexSplitVectors_trainr“  r   r   r   r”  °$  r  zIndexSplitVectors.trainc                 C   rJ   r'   )r   ÚIndexSplitVectors_resetrL   r   r   r   r{  ³$  rM   zIndexSplitVectors.resetrH
  r'   )r   r   r1   r2   r   r   r   r
   r   Ú IndexSplitVectors_own_fields_getÚ IndexSplitVectors_own_fields_setr¹  Ú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_drH   rÕ  r×  r—  r¢  r”  r{  Údelete_IndexSplitVectorsrv   r   r   r   r   rÑ  “$  s     


rÑ  c                   @   sh   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zddd„Zdd„ Zdd„ ZejZdS )ÚIndexRandomzQ
     index that returns random results.
    used mainly for time benchmarks
    c                 C   r5   r'   r6   r7   r   r   r   r9   À$  r:   zIndexRandom.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   À$  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexRandom_swiginitÚnew_IndexRandomrp   r   r   r   rH   Ä$  r.   zIndexRandom.__init__c                 C   r‹  r'   )r   ÚIndexRandom_addr“  r   r   r   r—  Ç$  r  zIndexRandom.addNc              	   C   rÈ  r'   )r   ÚIndexRandom_searchr   r   r   r   r¢  Ê$  r.   zIndexRandom.searchc                 C   r‹  r'   )r   ÚIndexRandom_reconstructr±  r   r   r   r´  Í$  r  zIndexRandom.reconstructc                 C   rJ   r'   )r   ÚIndexRandom_resetrL   r   r   r   r{  Ð$  rM   zIndexRandom.resetr'   )r   r   r1   r2   r   r   r   r
   r   ÚIndexRandom_seed_getÚIndexRandom_seed_setr  rH   r—  r¢  r´  r{  Údelete_IndexRandomrv   r   r   r   r   rç  º$  s    

rç  c                   @   ó¸   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejddZeejejddZd	d
„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zddd„Zd dd„Zdd„ ZejZdd„ ZdS )!Ú
IndexIDMapú, Index that translates search results to idsc                 C   r5   r'   r6   r7   r   r   r   r9   Ú$  r:   zIndexIDMap.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ú$  r>   r?   r@   r–  ú)whether pointers are deleted in destructoc                 C   r‡  ©zi
        :type xids: int
        :param xids: if non-null, ids to store for the vectors (size n)
        )r   ÚIndexIDMap_add_with_idsr›  r   r   r   r  à$  rù  zIndexIDMap.add_with_idsc                 C   r‹  ©z! this will fail. Use add_with_ids)r   ÚIndexIDMap_addr“  r   r   r   r—  ç$  ró  zIndexIDMap.addNc              	   C   rÈ  r'   )r   ÚIndexIDMap_searchr   r   r   r   r¢  ë$  r.   zIndexIDMap.searchc                 C   r‹  r'   )r   ÚIndexIDMap_trainr“  r   r   r   r”  î$  r  zIndexIDMap.trainc                 C   rJ   r'   )r   ÚIndexIDMap_resetrL   r   r   r   r{  ñ$  rM   zIndexIDMap.resetc                 C   rN   ©z  remove ids adapted to IndexFlat)r   ÚIndexIDMap_remove_idsr­  r   r   r   r®  ô$  r
  zIndexIDMap.remove_idsc                 C   rŽ  r'   )r   ÚIndexIDMap_range_searchr¥  r   r   r   r¦  ø$  r|   zIndexIDMap.range_searchr   c                 C   r‹  r'   )r   ÚIndexIDMap_merge_fromr×  r   r   r   rÚ  û$  r  zIndexIDMap.merge_fromc                 C   rN   r'   )r   Ú%IndexIDMap_check_compatible_for_mergerÞ  r   r   r   rß  þ$  rS   z%IndexIDMap.check_compatible_for_mergec                 G   r$  r'   )r   ÚIndexIDMap_swiginitÚnew_IndexIDMaprp   r   r   r   rH   %  r.   zIndexIDMap.__init__r'   rá  )r   r   r1   r2   r   r   r   r
   r   ÚIndexIDMap_index_getÚIndexIDMap_index_setr€  ÚIndexIDMap_own_fields_getÚIndexIDMap_own_fields_setr¹  ÚIndexIDMap_id_map_getÚIndexIDMap_id_map_setÚid_mapr  r—  r¢  r”  r{  r®  r¦  rÚ  rß  Údelete_IndexIDMaprv   rH   r   r   r   r   rò  ×$  ó$    


rò  c                   @   rñ  )!ÚIndexBinaryIDMapró  c                 C   r5   r'   r6   r7   r   r   r   r9   %  r:   zIndexBinaryIDMap.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   %  r>   r?   r@   r–  rô  c                 C   r‡  rõ  )r   ÚIndexBinaryIDMap_add_with_idsr›  r   r   r   r  %  rù  zIndexBinaryIDMap.add_with_idsc                 C   r‹  r÷  )r   ÚIndexBinaryIDMap_addr“  r   r   r   r—  %  ró  zIndexBinaryIDMap.addNc              	   C   rÈ  r'   )r   ÚIndexBinaryIDMap_searchr   r   r   r   r¢  %  r.   zIndexBinaryIDMap.searchc                 C   r‹  r'   )r   ÚIndexBinaryIDMap_trainr“  r   r   r   r”  %  r  zIndexBinaryIDMap.trainc                 C   rJ   r'   )r   ÚIndexBinaryIDMap_resetrL   r   r   r   r{  "%  rM   zIndexBinaryIDMap.resetc                 C   rN   rü  )r   ÚIndexBinaryIDMap_remove_idsr­  r   r   r   r®  %%  r
  zIndexBinaryIDMap.remove_idsc                 C   rŽ  r'   )r   ÚIndexBinaryIDMap_range_searchr¥  r   r   r   r¦  )%  r|   zIndexBinaryIDMap.range_searchr   c                 C   r‹  r'   )r   ÚIndexBinaryIDMap_merge_fromr×  r   r   r   rÚ  ,%  r  zIndexBinaryIDMap.merge_fromc                 C   rN   r'   )r   Ú+IndexBinaryIDMap_check_compatible_for_mergerÞ  r   r   r   rß  /%  rS   z+IndexBinaryIDMap.check_compatible_for_mergec                 G   r$  r'   )r   ÚIndexBinaryIDMap_swiginitÚnew_IndexBinaryIDMaprp   r   r   r   rH   3%  r.   zIndexBinaryIDMap.__init__r'   rá  )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryIDMap_index_getÚIndexBinaryIDMap_index_setr€  ÚIndexBinaryIDMap_own_fields_getÚIndexBinaryIDMap_own_fields_setr¹  ÚIndexBinaryIDMap_id_map_getÚIndexBinaryIDMap_id_map_setr	  r  r—  r¢  r”  r{  r®  r¦  rÚ  rß  Údelete_IndexBinaryIDMaprv   rH   r   r   r   r   r  %  r  r  c                   @   óx   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zddd„ZejZdd„ ZdS )ÚIndexIDMap2úo
    same as IndexIDMap but also provides an efficient reconstruction
    implementation via a 2-way index
    c                 C   r5   r'   r6   r7   r   r   r   r9   ?%  r:   zIndexIDMap2.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ?%  r>   r?   r@   c                 C   rJ   ©z make the rev_map from scratch)r   ÚIndexIDMap2_construct_rev_maprL   r   r   r   Úconstruct_rev_mapC%  r`  zIndexIDMap2.construct_rev_mapc                 C   r‡  r'   )r   ÚIndexIDMap2_add_with_idsr›  r   r   r   r  G%  r‰  zIndexIDMap2.add_with_idsc                 C   rN   r'   )r   ÚIndexIDMap2_remove_idsr­  r   r   r   r®  J%  rS   zIndexIDMap2.remove_idsc                 C   r‹  r'   )r   ÚIndexIDMap2_reconstructr±  r   r   r   r´  M%  r  zIndexIDMap2.reconstructc                 C   rJ   ©z2 check that the rev_map and the id_map are in sync)r   ÚIndexIDMap2_check_consistencyrL   r   r   r   Úcheck_consistencyP%  r`  zIndexIDMap2.check_consistencyr   c                 C   r‹  r'   )r   ÚIndexIDMap2_merge_fromr×  r   r   r   rÚ  T%  r  zIndexIDMap2.merge_fromc                 G   r$  r'   )r   ÚIndexIDMap2_swiginitÚnew_IndexIDMap2rp   r   r   r   rH   X%  r.   zIndexIDMap2.__init__Nrá  )r   r   r1   r2   r   r   r   r
   r   ÚIndexIDMap2_rev_map_getÚIndexIDMap2_rev_map_setÚrev_mapr$  r  r®  r´  r*  rÚ  Údelete_IndexIDMap2rv   rH   r   r   r   r   r   9%  ó    
r   c                   @   r  )ÚIndexBinaryIDMap2r!  c                 C   r5   r'   r6   r7   r   r   r   r9   d%  r:   zIndexBinaryIDMap2.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   d%  r>   r?   r@   c                 C   rJ   r"  )r   Ú#IndexBinaryIDMap2_construct_rev_maprL   r   r   r   r$  h%  r`  z#IndexBinaryIDMap2.construct_rev_mapc                 C   r‡  r'   )r   ÚIndexBinaryIDMap2_add_with_idsr›  r   r   r   r  l%  r‰  zIndexBinaryIDMap2.add_with_idsc                 C   rN   r'   )r   ÚIndexBinaryIDMap2_remove_idsr­  r   r   r   r®  o%  rS   zIndexBinaryIDMap2.remove_idsc                 C   r‹  r'   )r   ÚIndexBinaryIDMap2_reconstructr±  r   r   r   r´  r%  r  zIndexBinaryIDMap2.reconstructc                 C   rJ   r(  )r   Ú#IndexBinaryIDMap2_check_consistencyrL   r   r   r   r*  u%  r`  z#IndexBinaryIDMap2.check_consistencyr   c                 C   r‹  r'   )r   ÚIndexBinaryIDMap2_merge_fromr×  r   r   r   rÚ  y%  r  zIndexBinaryIDMap2.merge_fromc                 G   r$  r'   )r   ÚIndexBinaryIDMap2_swiginitÚnew_IndexBinaryIDMap2rp   r   r   r   rH   }%  r.   zIndexBinaryIDMap2.__init__Nrá  )r   r   r1   r2   r   r   r   r
   r   ÚIndexBinaryIDMap2_rev_map_getÚIndexBinaryIDMap2_rev_map_setr0  r$  r  r®  r´  r*  rÚ  Údelete_IndexBinaryIDMap2rv   rH   r   r   r   r   r3  ^%  r2  r3  c                   @   s~   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZe	jZdd„ Zddd„Zdd„ Zdd„ ZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   %  r:   zIndexRowwiseMinMaxBase.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   %  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   Ÿ%  rI   zIndexRowwiseMinMaxBase.__init__z
 sub-indexz: whether the subindex needs to be freed in the destructor.c                 C   r‹  r'   )r   ÚIndexRowwiseMinMaxBase_addr“  r   r   r   r—  ¦%  r  zIndexRowwiseMinMaxBase.addNc              	   C   rÈ  r'   )r   ÚIndexRowwiseMinMaxBase_searchr   r   r   r   r¢  ©%  r.   zIndexRowwiseMinMaxBase.searchc                 C   rJ   r'   )r   ÚIndexRowwiseMinMaxBase_resetrL   r   r   r   r{  ¬%  rM   zIndexRowwiseMinMaxBase.resetc                 C   r‹  r'   )r   Ú$IndexRowwiseMinMaxBase_train_inplacer“  r   r   r   Útrain_inplace¯%  r  z$IndexRowwiseMinMaxBase.train_inplacer'   )r   r   r1   r2   r   r   rH   r   r
   r   Ú IndexRowwiseMinMaxBase_index_getÚ IndexRowwiseMinMaxBase_index_setr€  Ú%IndexRowwiseMinMaxBase_own_fields_getÚ%IndexRowwiseMinMaxBase_own_fields_setr¹  Údelete_IndexRowwiseMinMaxBaserv   r—  r¢  r{  rD  r   r   r   r   r?  ƒ%  s    
r?  c                   @   ó`   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZejZdS )ÚIndexRowwiseMinMaxFP16z, Stores scaling coefficients as fp16 values.c                 C   r5   r'   r6   r7   r   r   r   r9   ¸%  r:   zIndexRowwiseMinMaxFP16.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¸%  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexRowwiseMinMaxFP16_swiginitÚnew_IndexRowwiseMinMaxFP16rp   r   r   r   rH   »%  r.   zIndexRowwiseMinMaxFP16.__init__c                 C   r‹  r'   )r   ÚIndexRowwiseMinMaxFP16_trainr“  r   r   r   r”  ¾%  r  zIndexRowwiseMinMaxFP16.trainc                 C   r‹  r'   )r   Ú$IndexRowwiseMinMaxFP16_train_inplacer“  r   r   r   rD  Á%  r  z$IndexRowwiseMinMaxFP16.train_inplacec                 C   rJ   r'   )r   Ú#IndexRowwiseMinMaxFP16_sa_code_sizerL   r   r   r   rÍ  Ä%  rM   z#IndexRowwiseMinMaxFP16.sa_code_sizec                 C   r‡  r'   )r   Ú IndexRowwiseMinMaxFP16_sa_encoderÏ  r   r   r   rÐ  Ç%  r‰  z IndexRowwiseMinMaxFP16.sa_encodec                 C   r‡  r'   )r   Ú IndexRowwiseMinMaxFP16_sa_decoderÓ  r   r   r   rÔ  Ê%  r‰  z IndexRowwiseMinMaxFP16.sa_decodeN)r   r   r1   r2   r   r   r   r
   rH   r”  rD  rÍ  rÐ  rÔ  r   Údelete_IndexRowwiseMinMaxFP16rv   r   r   r   r   rK  µ%  ó    
rK  c                   @   rJ  )ÚIndexRowwiseMinMaxz, Stores scaling coefficients as fp32 values.c                 C   r5   r'   r6   r7   r   r   r   r9   Ô%  r:   zIndexRowwiseMinMax.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ô%  r>   r?   r@   c                 G   r$  r'   )r   ÚIndexRowwiseMinMax_swiginitÚnew_IndexRowwiseMinMaxrp   r   r   r   rH   ×%  r.   zIndexRowwiseMinMax.__init__c                 C   r‹  r'   )r   ÚIndexRowwiseMinMax_trainr“  r   r   r   r”  Ú%  r  zIndexRowwiseMinMax.trainc                 C   r‹  r'   )r   Ú IndexRowwiseMinMax_train_inplacer“  r   r   r   rD  Ý%  r  z IndexRowwiseMinMax.train_inplacec                 C   rJ   r'   )r   ÚIndexRowwiseMinMax_sa_code_sizerL   r   r   r   rÍ  à%  rM   zIndexRowwiseMinMax.sa_code_sizec                 C   r‡  r'   )r   ÚIndexRowwiseMinMax_sa_encoderÏ  r   r   r   rÐ  ã%  r‰  zIndexRowwiseMinMax.sa_encodec                 C   r‡  r'   )r   ÚIndexRowwiseMinMax_sa_decoderÓ  r   r   r   rÔ  æ%  r‰  zIndexRowwiseMinMax.sa_decodeN)r   r   r1   r2   r   r   r   r
   rH   r”  rD  rÍ  rÐ  rÔ  r   Údelete_IndexRowwiseMinMaxrv   r   r   r   r   rU  Ñ%  rT  rU  c                   @   sœ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZddd„Zdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   õ%  r:   zRangeSearchResult.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   õ%  r>   r?   r@   z nb of queriesz size (nq + 1)z0 result for query i is labels[lims[i]:lims[i+1]]z% corresponding distances (not sorted)z  size of the result buffers usedTc                 C   r@  )z1 lims must be allocated on input to range_search.N)r   ÚRangeSearchResult_swiginitÚnew_RangeSearchResult)r   r#  Ú
alloc_limsr   r   r   rH   ý%  rW  zRangeSearchResult.__init__c                 C   rJ   )zd
        called when lims contains the nb of elements result entries
        for each query
        )r   ÚRangeSearchResult_do_allocationrL   r   r   r   Údo_allocation&  r†  zRangeSearchResult.do_allocationNr>  )r   r   r1   r2   r   r   r   r
   r   ÚRangeSearchResult_nq_getÚRangeSearchResult_nq_setr#  ÚRangeSearchResult_lims_getÚRangeSearchResult_lims_setr€  ÚRangeSearchResult_labels_getÚRangeSearchResult_labels_setrÇ  ÚRangeSearchResult_distances_getÚRangeSearchResult_distances_setrÆ  Ú!RangeSearchResult_buffer_size_getÚ!RangeSearchResult_buffer_size_setÚbuffer_sizerH   rc  Údelete_RangeSearchResultrv   r   r   r   r   r^  í%  s    

r^  c                   @   s~   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZeejejddZdd	„ ZejZd
d„ Zdd„ Zdd„ ZdS )Ú
BufferListzu
    List of temporary buffers used to store results before they are
    copied to the RangeSearchResult object.
    c                 C   r5   r'   r6   r7   r   r   r   r9   &  r:   zBufferList.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   &  r>   r?   r@   z" write pointer in the last buffer.c                 C   rh  r'   )r   ÚBufferList_swiginitÚnew_BufferList)r   rn  r   r   r   rH   &  r.   zBufferList.__init__c                 C   rJ   )z create a new buffer)r   ÚBufferList_append_bufferrL   r   r   r   Úappend_buffer&  r`  zBufferList.append_bufferc                 C   r‹  )z: add one result, possibly appending a new buffer if needed)r   ÚBufferList_add)r   rÄ  rº  r   r   r   r—   &  ró  zBufferList.addc                 C   rm  )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   rs  rQ   Údest_idsÚdest_disr   r   r   Ú
copy_range$&  r¿  zBufferList.copy_rangeN)r   r   r1   r2   r   r   r   r
   r   ÚBufferList_buffer_size_getÚBufferList_buffer_size_setrn  ÚBufferList_buffers_getÚBufferList_buffers_setÚbuffersÚBufferList_wp_getÚBufferList_wp_setÚwprH   Údelete_BufferListrv   rt  r—  ry  r   r   r   r   rp  &  s    rp  c                   @   r±  )ÚRangeQueryResultz$ result structure for a single queryc                 C   r5   r'   r6   r7   r   r   r   r9   1&  r:   zRangeQueryResult.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   1&  r>   r?   r@   c                 C   r‹  )z1 called by search function to report a new result)r   ÚRangeQueryResult_add)r   rº  rÄ  r   r   r   r—  7&  ró  zRangeQueryResult.addc                 C   ry   r'   )r   ÚRangeQueryResult_swiginitÚnew_RangeQueryResultrL   r   r   r   rH   ;&  r|   zRangeQueryResult.__init__N)r   r   r1   r2   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—  rH   Údelete_RangeQueryResultrv   r   r   r   r   rƒ  .&  s    
rƒ  c                   @   sˆ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zeejejd	dZd
d„ Zdd„ Zdd„ Zddd„Zeddd„ƒZejZdS )ÚRangeSearchPartialResultz/ the entries in the buffers are split per queryc                 C   r5   r'   r6   r7   r   r   r   r9   E&  r:   z!RangeSearchPartialResult.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   E&  r>   r?   r@   c                 C   r 
  )z/ eventually the result will be stored in res_inN)r   Ú!RangeSearchPartialResult_swiginitÚnew_RangeSearchPartialResult)r   Úres_inr   r   r   rH   I&  rÌ  z!RangeSearchPartialResult.__init__z% query ids + nb of results per query.c                 C   rN   )z begin a new result)r   Ú#RangeSearchPartialResult_new_result)r   r‰  r   r   r   Ú
new_resultN&  r
  z#RangeSearchPartialResult.new_resultc                 C   rJ   r'   )r   Ú!RangeSearchPartialResult_finalizerL   r   r   r   ÚfinalizeR&  rM   z!RangeSearchPartialResult.finalizec                 C   rJ   )z, called by range_search before do_allocation)r   Ú!RangeSearchPartialResult_set_limsrL   r   r   r   Úset_limsU&  r`  z!RangeSearchPartialResult.set_limsFc                 C   rN   )z+ called by range_search after do_allocation)r   Ú$RangeSearchPartialResult_copy_result)r   Úincrementalr   r   r   Úcopy_resultY&  r
  z$RangeSearchPartialResult.copy_resultTc                 C   rN   )z{
        merge a set of PartialResult's into one RangeSearchResult
        on ouptut the partialresults are empty!
        ©r   ÚRangeSearchPartialResult_merge©Úpartial_resultsÚ	do_deleter   r   r   Úmerge]&  rà  zRangeSearchPartialResult.mergeNrH
  r>  )r   r   r1   r2   r   r   r   r
   r   Ú RangeSearchPartialResult_res_getÚ RangeSearchPartialResult_res_setrð  rH   Ú$RangeSearchPartialResult_queries_getÚ$RangeSearchPartialResult_queries_setÚqueriesr–  r˜  rš  r  r5  r£  Údelete_RangeSearchPartialResultrv   r   r   r   r   r‘  B&  s    

r‘  c                 C   rN   )zo
    merge a set of PartialResult's into one RangeSearchResult
    on ouptut the partialresults are empty!
    rž  r   r   r   r   rŸ  i&  r¯  rŸ  c                   @   sl   e Zd Zedd„ dd„ ddZdd„ ZeZdd	„ Ze	j
Zed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )ÚInterruptCallbackc                 C   r5   r'   r6   r7   r   r   r   r9   q&  r:   zInterruptCallback.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   q&  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   s&  rI   zInterruptCallback.__init__c                 C   rJ   r'   )r   Ú InterruptCallback_want_interruptrL   r   r   r   Úwant_interruptw&  rM   z InterruptCallback.want_interruptc                   C   rÜ  r'   ©r   Ú InterruptCallback_clear_instancer   r   r   r   Úclear_instance{&  râ  z InterruptCallback.clear_instancec                   C   rÜ  )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   r   Úcheck&  s   	zInterruptCallback.checkc                   C   rÜ  )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   r   Úis_interruptedŠ&  s   z InterruptCallback.is_interruptedc                 C   rJ   )zŠ
         assuming each iteration takes a certain number of flops, what
        is a reasonable interval to check for interrupts?
        ©r   Ú!InterruptCallback_get_period_hint©Úflopsr   r   r   Úget_period_hint’&  r÷  z!InterruptCallback.get_period_hintN)r   r   r1   r   r   rH   r   r
   r¬  r   Údelete_InterruptCallbackrv   r5  r¯  r²  rµ  rº  r   r   r   r   rª  p&  s    



rª  c                   C   rÜ  r'   r­  r   r   r   r   r®  &  rI   r®  c                   C   rÜ  )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°  r   r   r   r   r±   &  s   r±  c                   C   rÜ  )zy
    same as check() but return true if is interrupted instead of
    throwing. Can be called from multiple threads.
    r³  r   r   r   r   r´  ª&  s   r´  c                 C   rJ   )z~
     assuming each iteration takes a certain number of flops, what
    is a reasonable interval to check for interrupts?
    r¶  r¸  r   r   r   r·  ±&  r†  r·  c                   @   sl   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ Zd	d
„ Zdd„ Zdd„ ZejZdS )ÚVisitedTablez. set implementation optimized for fast access.c                 C   r5   r'   r6   r7   r   r   r   r9   »&  r:   zVisitedTable.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   »&  r>   r?   r@   c                 C   rh  r'   )r   ÚVisitedTable_swiginitÚnew_VisitedTabler  r   r   r   rH   À&  r.   zVisitedTable.__init__c                 C   rN   )z set flag #no to true)r   ÚVisitedTable_set©r   rŸ	  r   r   r   r!   Ã&  r
  zVisitedTable.setc                 C   rN   )z get flag #no)r   ÚVisitedTable_getrÀ  r   r   r   rs  Ç&  r
  zVisitedTable.getc                 C   rJ   )z reset all flags to false)r   ÚVisitedTable_advancerL   r   r   r   rc   Ë&  r`  zVisitedTable.advanceN)r   r   r1   r2   r   r   r   r
   r   ÚVisitedTable_visited_getÚVisitedTable_visited_setÚvisitedÚVisitedTable_visno_getÚVisitedTable_visno_setÚvisnorH   r!   rs  rc   Údelete_VisitedTablerv   r   r   r   r   r¼  ¸&  s    
r¼  c                   @   s@   e Zd ZdZedd„ dd„ ddZdd„ ZeZd	d
„ Z	e
jZdS )Ú
IDSelectorz% Encapsulates a set of ids to handle.c                 C   r5   r'   r6   r7   r   r   r   r9   Ö&  r:   zIDSelector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Ö&  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   Ø&  rI   zIDSelector.__init__c                 C   rN   r'   )r   ÚIDSelector_is_memberr	  r   r   r   Ú	is_memberÜ&  rS   zIDSelector.is_memberN)r   r   r1   r2   r   r   rH   r   r
   rÌ  r   Údelete_IDSelectorrv   r   r   r   r   rÊ  Ó&  s    
rÊ  c                   @   sx   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZeejejddZdd	d
„Zdd„ Zdd„ ZejZdS )ÚIDSelectorRangez ids between [imin, imax)c                 C   r5   r'   r6   r7   r   r   r   r9   æ&  r:   zIDSelectorRange.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   æ&  r>   r?   r@   zb
    Assume that the ids to handle are sorted. In some cases this can speed
    up processing
    Fc                 C   r+  r'   )r   ÚIDSelectorRange_swiginitÚnew_IDSelectorRange)r   ÚiminÚimaxÚassume_sortedr   r   r   rH   ï&  r/  zIDSelectorRange.__init__c                 C   rN   r'   )r   ÚIDSelectorRange_is_memberr	  r   r   r   rÌ  ò&  rS   zIDSelectorRange.is_memberc                 C   rm  )zg
        for sorted ids, find the range of list indices where the valid ids are
        stored
        )r   Ú&IDSelectorRange_find_sorted_ids_bounds)r   r¥  rA  ÚjminÚjmaxr   r   r   Úfind_sorted_ids_boundsõ&  r¿  z&IDSelectorRange.find_sorted_ids_boundsNrH
  )r   r   r1   r2   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Ó  rH   rÌ  rØ  Údelete_IDSelectorRangerv   r   r   r   r   rÎ  ã&  s    

rÎ  c                   @   ó\   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZeejejƒZdd„ Zd	d
„ ZejZdS )ÚIDSelectorArrayz€
     Simple array of elements

    is_member calls are very inefficient, but some operations can use the ids
    directly.
    c                 C   r5   r'   r6   r7   r   r   r   r9   '  r:   zIDSelectorArray.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   '  r>   r?   r@   c                 C   r@  )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   rQ   rA  r   r   r   rH   '  ó   
zIDSelectorArray.__init__c                 C   rN   r'   )r   ÚIDSelectorArray_is_memberr	  r   r   r   rÌ  '  rS   zIDSelectorArray.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorArray_n_getÚIDSelectorArray_n_setrQ   ÚIDSelectorArray_ids_getÚIDSelectorArray_ids_setrA  rH   rÌ  Údelete_IDSelectorArrayrv   r   r   r   r   rá   '  s    
rá  c                   @   rà  )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   -'  r:   zIDSelectorBatch.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   -'  r>   r?   r@   c                 C   r@  )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   rQ   rv  r   r   r   rH   2'  s   	zIDSelectorBatch.__init__c                 C   rN   r'   )r   ÚIDSelectorBatch_is_memberr	  r   r   r   rÌ  ='  rS   zIDSelectorBatch.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorBatch_nbits_getÚIDSelectorBatch_nbits_setr  ÚIDSelectorBatch_mask_getÚIDSelectorBatch_mask_setrV  rH   rÌ  Údelete_IDSelectorBatchrv   r   r   r   r   rë   '  s    
rë  c                   @   rà  )ÚIDSelectorBitmapzB One bit per element. Constructed with a bitmap, size ceil(n / 8).c                 C   r5   r'   r6   r7   r   r   r   r9   G'  r:   zIDSelectorBitmap.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   G'  r>   r?   r@   c                 C   r@  )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   rQ   Úbitmapr   r   r   rH   L'  rä  zIDSelectorBitmap.__init__c                 C   rN   r'   )r   ÚIDSelectorBitmap_is_memberr	  r   r   r   rÌ  X'  rS   zIDSelectorBitmap.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorBitmap_n_getÚIDSelectorBitmap_n_setrQ   ÚIDSelectorBitmap_bitmap_getÚIDSelectorBitmap_bitmap_setr÷  rH   rÌ  Údelete_IDSelectorBitmaprv   r   r   r   r   rô  D'  s    
rô  c                   @   sN   e Zd ZdZedd„ dd„ ddZeZeej	ej
ƒZdd„ Zd	d
„ ZejZdS )ÚIDSelectorNotz0 reverts the membership test of another selectorc                 C   r5   r'   r6   r7   r   r   r   r9   b'  r:   zIDSelectorNot.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   b'  r>   r?   r@   c                 C   rh  r'   )r   ÚIDSelectorNot_swiginitÚnew_IDSelectorNotr­  r   r   r   rH   f'  r.   zIDSelectorNot.__init__c                 C   rN   r'   )r   ÚIDSelectorNot_is_memberr	  r   r   r   rÌ  i'  rS   zIDSelectorNot.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorNot_sel_getÚIDSelectorNot_sel_setrU  rH   rÌ  Údelete_IDSelectorNotrv   r   r   r   r   rþ  _'  s    
rþ  c                   @   r¤  )ÚIDSelectorAllz. selects all entries (useful for benchmarking)c                 C   r5   r'   r6   r7   r   r   r   r9   s'  r:   zIDSelectorAll.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   s'  r>   r?   r@   c                 C   rN   r'   )r   ÚIDSelectorAll_is_memberr	  r   r   r   rÌ  v'  rS   zIDSelectorAll.is_memberc                 C   ry   r'   )r   ÚIDSelectorAll_swiginitÚnew_IDSelectorAllrL   r   r   r   rH   z'  r|   zIDSelectorAll.__init__N)r   r   r1   r2   r   r   r   r
   rÌ  r   Údelete_IDSelectorAllrv   rH   r   r   r   r   r  p'  s    r  c                   @   rà  )ÚIDSelectorAndz\
    does an AND operation on the the two given IDSelector's is_membership
    results.
    c                 C   r5   r'   r6   r7   r   r   r   r9   †'  r:   zIDSelectorAnd.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   †'  r>   r?   r@   c                 C   r—  r'   )r   ÚIDSelectorAnd_swiginitÚnew_IDSelectorAnd©r   ÚlhsÚrhsr   r   r   rH   ‹'  r  zIDSelectorAnd.__init__c                 C   rN   r'   )r   ÚIDSelectorAnd_is_memberr	  r   r   r   rÌ  Ž'  rS   zIDSelectorAnd.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorAnd_lhs_getÚIDSelectorAnd_lhs_setr  ÚIDSelectorAnd_rhs_getÚIDSelectorAnd_rhs_setr  rH   rÌ  Údelete_IDSelectorAndrv   r   r   r   r   r
  €'  ó    
r
  c                   @   rà  )ÚIDSelectorOrz[
    does an OR operation on the the two given IDSelector's is_membership
    results.
    c                 C   r5   r'   r6   r7   r   r   r   r9   ›'  r:   zIDSelectorOr.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ›'  r>   r?   r@   c                 C   r—  r'   )r   ÚIDSelectorOr_swiginitÚnew_IDSelectorOrr  r   r   r   rH    '  r  zIDSelectorOr.__init__c                 C   rN   r'   )r   ÚIDSelectorOr_is_memberr	  r   r   r   rÌ  £'  rS   zIDSelectorOr.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorOr_lhs_getÚIDSelectorOr_lhs_setr  ÚIDSelectorOr_rhs_getÚIDSelectorOr_rhs_setr  rH   rÌ  Údelete_IDSelectorOrrv   r   r   r   r   r  •'  r  r  c                   @   rà  )ÚIDSelectorXOrz\
    does an XOR operation on the the two given IDSelector's is_membership
    results.
    c                 C   r5   r'   r6   r7   r   r   r   r9   °'  r:   zIDSelectorXOr.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   °'  r>   r?   r@   c                 C   r—  r'   )r   ÚIDSelectorXOr_swiginitÚnew_IDSelectorXOrr  r   r   r   rH   µ'  r  zIDSelectorXOr.__init__c                 C   rN   r'   )r   ÚIDSelectorXOr_is_memberr	  r   r   r   rÌ  ¸'  rS   zIDSelectorXOr.is_memberN)r   r   r1   r2   r   r   r   r
   r   ÚIDSelectorXOr_lhs_getÚIDSelectorXOr_lhs_setr  ÚIDSelectorXOr_rhs_getÚIDSelectorXOr_rhs_setr  rH   rÌ  Údelete_IDSelectorXOrrv   r   r   r   r   r   ª'  r  r   c                 C   rJ   r'   )r   Údowncast_index©r€  r   r   r   r)  Å'  rM   r)  c                 C   rJ   r'   )r   Údowncast_VectorTransform)rà  r   r   r   r+  È'  rM   r+  c                 C   rJ   r'   )r   Údowncast_IndexBinaryr*  r   r   r   r,  Ë'  rM   r,  c                 C   rJ   r'   )r   Údowncast_InvertedLists)r	  r   r   r   r-  Î'  rM   r-  c                 C   rJ   r'   )r   Údowncast_AdditiveQuantizer©rÞ  r   r   r   r.  Ñ'  rM   r.  c                 C   rJ   r'   )r   Údowncast_Quantizerr/  r   r   r   r0  Ô'  rM   r0  c                  G   r¼  r'   )r   Úwrite_indexr¾  r   r   r   r1  ×'  rM   r1  c                  G   r¼  r'   )r   Úwrite_index_binaryr¾  r   r   r   r2  Ú'  rM   r2  c                  G   r¼  r'   )r   Ú
read_indexr¾  r   r   r   r3  Ý'  rM   r3  c                  G   r¼  r'   )r   Úread_index_binaryr¾  r   r   r   r4  à'  rM   r4  c                  G   r¼  r'   )r   Úwrite_VectorTransformr¾  r   r   r   r5  ã'  rM   r5  c                  G   r¼  r'   )r   Úread_VectorTransformr¾  r   r   r   r6  æ'  rM   r6  c                  G   r¼  r'   )r   Úread_ProductQuantizerr¾  r   r   r   r7  é'  rM   r7  c                  G   r¼  r'   )r   Úwrite_ProductQuantizerr¾  r   r   r   r8  ì'  rM   r8  c                 C   rN   r'   )r   Úwrite_InvertedLists)r	  rV  r   r   r   r9  ï'  rS   r9  c                 C   rN   r'   )r   Úread_InvertedLists)rm  r_	  r   r   r   r:  ò'  rS   r:  c                 C   rJ   r'   )r   Úclone_indexre	  r   r   r   r;  õ'  rM   r;  c                   @   sP   e Zd ZdZedd„ dd„ ddZeZdd„ Zd	d
„ Z	dd„ Z
ejZdd„ ZdS )ÚClonerz”
     Cloner class, useful to override classes with other cloning
    functions. The cloning function above just calls
    Cloner::clone_Index.
    c                 C   r5   r'   r6   r7   r   r   r   r9   þ'  r:   zCloner.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   þ'  r>   r?   r@   c                 C   rN   r'   )r   ÚCloner_clone_VectorTransformr~   r   r   r   Úclone_VectorTransform(  rS   zCloner.clone_VectorTransformc                 C   rN   r'   )r   ÚCloner_clone_Indexr~   r   r   r   Úclone_Index(  rS   zCloner.clone_Indexc                 C   rN   r'   )r   ÚCloner_clone_IndexIVFr~   r   r   r   Úclone_IndexIVF(  rS   zCloner.clone_IndexIVFc                 C   ry   r'   )r   ÚCloner_swiginitÚ
new_ClonerrL   r   r   r   rH   (  r|   zCloner.__init__N)r   r   r1   r2   r   r   r   r
   r>  r@  rB  r   Údelete_Clonerrv   rH   r   r   r   r   r<  ÷'  s    r<  c                 C   rJ   r'   )r   Úclone_Quantizer)Úquantr   r   r   rF  (  rM   rF  c                   @   s¢   e Zd ZdZedd„ dd„ ddZdd„ ZeZee	j
e	jd	dZee	je	jd
dZee	je	jddZee	je	jddZee	je	jddZdd„ Zdd„ Ze	jZdS )ÚAutoTuneCriterionz]
    Evaluation criterion. Returns a performance measure in [0,1],
    higher is better.
    c                 C   r5   r'   r6   r7   r   r   r   r9   (  r:   zAutoTuneCriterion.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   (  r>   r?   r@   c                 O   rB   rC   rD   rE   r   r   r   rH   !(  rI   zAutoTuneCriterion.__init__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                 C   r‡  )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_inr   r   r   Úset_groundtruth*(  r  z!AutoTuneCriterion.set_groundtruthc                 C   r‹  )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ˆ  r   r   r   r<  5(  r  zAutoTuneCriterion.evaluateN)r   r   r1   r2   r   r   rH   r   r
   r   ÚAutoTuneCriterion_nq_getÚAutoTuneCriterion_nq_setr#  ÚAutoTuneCriterion_nnn_getÚAutoTuneCriterion_nnn_setÚnnnÚAutoTuneCriterion_gt_nnn_getÚAutoTuneCriterion_gt_nnn_setrJ  ÚAutoTuneCriterion_gt_D_getÚAutoTuneCriterion_gt_D_setÚgt_DÚAutoTuneCriterion_gt_I_getÚAutoTuneCriterion_gt_I_setÚgt_IrM  r<  Údelete_AutoTuneCriterionrv   r   r   r   r   rH  (  s    
rH  c                   @   r;  )ÚOneRecallAtRCriterionc                 C   r5   r'   r6   r7   r   r   r   r9   G(  r:   zOneRecallAtRCriterion.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   G(  r>   r?   r@   c                 C   r—  r'   )r   ÚOneRecallAtRCriterion_swiginitÚnew_OneRecallAtRCriterion©r   r#  r’  r   r   r   rH   K(  r  zOneRecallAtRCriterion.__init__c                 C   r‹  r'   )r   ÚOneRecallAtRCriterion_evaluaterO  r   r   r   r<  N(  r  zOneRecallAtRCriterion.evaluateN)r   r   r1   r   r   r   r
   r   ÚOneRecallAtRCriterion_R_getÚOneRecallAtRCriterion_R_setr’  rH   r<  Údelete_OneRecallAtRCriterionrv   r   r   r   r   r^  F(  rD  r^  c                   @   r;  )ÚIntersectionCriterionc                 C   r5   r'   r6   r7   r   r   r   r9   V(  r:   zIntersectionCriterion.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   V(  r>   r?   r@   c                 C   r—  r'   )r   ÚIntersectionCriterion_swiginitÚnew_IntersectionCriterionra  r   r   r   rH   Z(  r  zIntersectionCriterion.__init__c                 C   r‹  r'   )r   ÚIntersectionCriterion_evaluaterO  r   r   r   r<  ](  r  zIntersectionCriterion.evaluateN)r   r   r1   r   r   r   r
   r   ÚIntersectionCriterion_R_getÚIntersectionCriterion_R_setr’  rH   r<  Údelete_IntersectionCriterionrv   r   r   r   r   rf  U(  rD  rf  c                   @   s€   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZdd„ ZejZdS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   n(  r:   zOperatingPoint.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   n(  r>   r?   r@   z, performance measure (output of a Criterion)z" corresponding execution time (ms)z key that identifies this op ptz integer identiferc                 C   ry   r'   )r   ÚOperatingPoint_swiginitÚnew_OperatingPointrL   r   r   r   rH   u(  r|   zOperatingPoint.__init__N)r   r   r1   r2   r   r   r   r
   r   ÚOperatingPoint_perf_getÚOperatingPoint_perf_setÚperfÚOperatingPoint_t_getÚOperatingPoint_t_setr‚  ÚOperatingPoint_key_getÚOperatingPoint_key_setr²  ÚOperatingPoint_cno_getÚOperatingPoint_cno_setÚcnorH   Údelete_OperatingPointrv   r   r   r   r   rm  d(  s    	
rm  c                   @   s”   e Zd Zedd„ dd„ ddZeZeejej	ddZ
eejejddZdd	„ Zd
d„ Zdd„ Zddd„Zdd„ Zddd„Zdd„ Zdd„ ZejZdS )ÚOperatingPointsc                 C   r5   r'   r6   r7   r   r   r   r9   }(  r:   zOperatingPoints.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   }(  r>   r?   r@   z all operating pointsz) optimal operating points, sorted by perfc                 C   ry   r'   )r   ÚOperatingPoints_swiginitÚnew_OperatingPointsrL   r   r   r   rH   ‚(  r|   zOperatingPoints.__init__c                 G   rn   )zC add operating points from other to this, with a prefix to the keys)r   ÚOperatingPoints_merge_withrp   r   r   r   Ú
merge_with…(  ru  zOperatingPoints.merge_withc                 C   rJ   r'   )r   ÚOperatingPoints_clearrL   r   r   r   r‚   ‰(  rM   zOperatingPoints.clearr   c                 C   rm  )zA add a performance measure. Return whether it is an optimal point)r   ÚOperatingPoints_add)r   rr  r‚  r²  ry  r   r   r   r—  Œ(  ru  zOperatingPoints.addc                 C   rN   )z8 get time required to obtain a given performance measure)r   ÚOperatingPoints_t_for_perf)r   rr  r   r   r   Ú
t_for_perf(  r
  zOperatingPoints.t_for_perfTc                 C   rN   )z easy-to-read output)r   ÚOperatingPoints_display)r   Úonly_optimalr   r   r   r­  ”(  r
  zOperatingPoints.displayc                 C   rN   )z- output to a format easy to digest by gnuplot)r   ÚOperatingPoints_all_to_gnuplot©r   Úfnamer   r   r   Úall_to_gnuplot˜(  r
  zOperatingPoints.all_to_gnuplotc                 C   rN   r'   )r   Ú"OperatingPoints_optimal_to_gnuplotr‡  r   r   r   Úoptimal_to_gnuplotœ(  rS   z"OperatingPoints.optimal_to_gnuplotNrá  r>  )r   r   r1   r   r   r   r
   r   ÚOperatingPoints_all_pts_getÚOperatingPoints_all_pts_setÚall_ptsÚOperatingPoints_optimal_pts_getÚOperatingPoints_optimal_pts_setÚoptimal_ptsrH   r  r‚   r—  rƒ  r­  r‰  r‹  Údelete_OperatingPointsrv   r   r   r   r   r{  |(  s    


r{  c                   @   r§  )
ÚParameterRangezM possible values of a parameter, sorted from least to most expensive/accuratec                 C   r5   r'   r6   r7   r   r   r   r9   ¦(  r:   zParameterRange.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ¦(  r>   r?   r@   c                 C   ry   r'   )r   ÚParameterRange_swiginitÚnew_ParameterRangerL   r   r   r   rH   «(  r|   zParameterRange.__init__N)r   r   r1   r2   r   r   r   r
   r   ÚParameterRange_name_getÚParameterRange_name_setr   ÚParameterRange_values_getÚParameterRange_values_setÚvaluesrH   Údelete_ParameterRangerv   r   r   r   r   r“  £(  r°  r“  c                   @   sô   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZeejejddZeejejddZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#dd „ Z$d!d"„ Z%ej&Z'd#S )$ÚParameterSpacezL Uses a-priori knowledge on the Faiss indexes to extract tunable parameters.c                 C   r5   r'   r6   r7   r   r   r   r9   µ(  r:   zParameterSpace.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   µ(  r>   r?   r@   z all tunable parametersz verbosity during explorationzA 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                 C   ry   r'   )r   ÚParameterSpace_swiginitÚnew_ParameterSpacerL   r   r   r   rH   Ä(  r|   zParameterSpace.__init__c                 C   rJ   )z. nb of combinations, = product of values sizes)r   ÚParameterSpace_n_combinationsrL   r   r   r   Ún_combinationsÇ(  r`  zParameterSpace.n_combinationsc                 C   r‹  )z9 returns whether combinations c1 >= c2 in the tuple sense)r   ÚParameterSpace_combination_ge)r   Úc1Úc2r   r   r   Úcombination_geË(  ró  zParameterSpace.combination_gec                 C   rN   )z- get string representation of the combination)r   ÚParameterSpace_combination_name)r   ry  r   r   r   Úcombination_nameÏ(  r
  zParameterSpace.combination_namec                 C   rJ   )z print a description on stdout)r   ÚParameterSpace_displayrL   r   r   r   r­  Ó(  r`  zParameterSpace.displayc                 C   rN   )z0 add a new parameter (or return it if it exists))r   ÚParameterSpace_add_ranger|  r   r   r   Ú	add_range×(  r
  zParameterSpace.add_rangec                 C   rN   )z4 initialize with reasonable parameters for the index)r   ÚParameterSpace_initializer£
  r   r   r   Ú
initializeÛ(  r
  zParameterSpace.initializec                 G   rn   )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_parametersrp   r   r   r   Úset_index_parametersß(  rc  z#ParameterSpace.set_index_parametersc                 C   r‡  )zB set one of the parameters, returns whether setting was successful)r   Ú"ParameterSpace_set_index_parameter)r   r€  r   r©  r   r   r   Úset_index_parameterë(  r  z"ParameterSpace.set_index_parameterc                 C   rm  )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   ry  ÚopÚupper_bound_perfÚlower_bound_tr   r   r   Úupdate_boundsï(  r¿  zParameterSpace.update_boundsc                 C   rŽ  )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#  r$  ÚcritÚopsr   r   r   Úexploreö(  s   zParameterSpace.exploreN)(r   r   r1   r2   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_durationrH   r   r¤  r¦  r­  r©  r«  r­  r¯  r´  r¸  Údelete_ParameterSpacerv   r   r   r   r   rœ  ²(  s,    
rœ  c                  G   r¼  )z\
    Build and index with the sequence of processing steps described in
    the string.
    )r   Úindex_factoryr¾  r   r   r   rË  	)  r†  rË  c                 C   rN   r'   )r   Úindex_binary_factory)r†  Údescriptionr   r   r   rÌ  )  rS   rÌ  c                   @   sè   e Zd ZdZedd„ dd„ ddZeZd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	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	j)ƒZ*ee	j+e	j,ƒZ-d	d
„ Z.e	j/Z0dS )Ú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                 C   r5   r'   r6   r7   r   r   r   r9   )  r:   zMatrixStats.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   )  r>   r?   r@   c                 C   r+  r'   )r   ÚMatrixStats_swiginitÚnew_MatrixStats)r   rQ   r†  r8   r   r   r   rH   )  r/  zMatrixStats.__init__c                 C   rN   r'   )r   ÚMatrixStats_do_comment)r   Úfmtr   r   r   Ú
do_comment,)  rS   zMatrixStats.do_commentN)1r   r   r1   r2   r   r   r   r
   rH   r   ÚMatrixStats_comments_getÚMatrixStats_comments_setÚcommentsÚMatrixStats_n_getÚMatrixStats_n_setrQ   Ú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_setrë  ÚMatrixStats_min_norm2_getÚMatrixStats_min_norm2_setÚ	min_norm2ÚMatrixStats_max_norm2_getÚMatrixStats_max_norm2_setÚ	max_norm2Ú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_MatrixStatsrv   r   r   r   r   rÎ  )  s&    
rÎ  c                   @   rà  )ÚPyCallbackIOWriterrô  c                 C   r5   r'   r6   r7   r   r   r   r9   ;)  r:   zPyCallbackIOWriter.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ;)  r>   r?   r@   c                 G   r—  )zƒ
        Callback: Python function that takes a bytes object and
        returns the number of bytes successfully written.
        N)r   ÚPyCallbackIOWriter_swiginitÚnew_PyCallbackIOWriterrp   r   r   r   rH   @)  ó   zPyCallbackIOWriter.__init__c                 C   r‡  r'   )r   ÚPyCallbackIOWriter___call__©r   Úptrvr†   r1  r   r   r   rù  G)  r‰  zPyCallbackIOWriter.__call__N)r   r   r1   r2   r   r   r   r
   r   ÚPyCallbackIOWriter_callback_getÚPyCallbackIOWriter_callback_setÚcallbackÚPyCallbackIOWriter_bs_getÚPyCallbackIOWriter_bs_setÚbsrH   rù  Údelete_PyCallbackIOWriterrv   r   r   r   r   rö  3)  s    
rö  c                   @   rv  )ÚPyCallbackIOReaderc                 C   r5   r'   r6   r7   r   r   r   r9   O)  r:   zPyCallbackIOReader.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   O)  r>   r?   r@   c                 G   r—  )zy
         Callback: Python function that takes a size and returns a
        bytes object with the resulting read
        N)r   ÚPyCallbackIOReader_swiginitÚnew_PyCallbackIOReaderrp   r   r   r   rH   T)  rù  zPyCallbackIOReader.__init__c                 C   r‡  r'   )r   ÚPyCallbackIOReader___call__rû  r   r   r   rù  [)  r‰  zPyCallbackIOReader.__call__N)r   r   r1   r   r   r   r
   r   ÚPyCallbackIOReader_callback_getÚPyCallbackIOReader_callback_setrÿ  ÚPyCallbackIOReader_bs_getÚPyCallbackIOReader_bs_setr  rH   rù  Údelete_PyCallbackIOReaderrv   r   r   r   r   r  N)  s    
r  c                   @   r;  )ÚPyCallbackIDSelectorc                 C   r5   r'   r6   r7   r   r   r   r9   c)  r:   zPyCallbackIDSelector.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   c)  r>   r?   r@   c                 C   rh  r'   )r   ÚPyCallbackIDSelector_swiginitÚnew_PyCallbackIDSelector)r   rÿ  r   r   r   rH   g)  r.   zPyCallbackIDSelector.__init__c                 C   rN   r'   )r   ÚPyCallbackIDSelector_is_memberr	  r   r   r   rÌ  j)  rS   zPyCallbackIDSelector.is_memberN)r   r   r1   r   r   r   r
   r   Ú!PyCallbackIDSelector_callback_getÚ!PyCallbackIDSelector_callback_setrÿ  rH   rÌ  Údelete_PyCallbackIDSelectorrv   r   r   r   r   r  b)  rD  r  c                 C   rJ   r'   )r   Úswig_ptr)r“  r   r   r   r  r)  rM   r  c                  G   r¼  r'   )r   Úrev_swig_ptrr¾  r   r   r   r  u)  rM   r  c                   @   óÆ   e Zd ZdZedd„ dd„ ddZeZeej	ej
ddZeejejddZeejejd	dZeejejd
dZdd„ Zdd„ Zdd„ Zd dd„Zd!dd„Zd"dd„Zdd„ Zdd„ Zdd„ ZejZdS )#Ú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                 C   r5   r'   r6   r7   r   r   r   r9   ~)  r:   zfloat_minheap_array_t.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ~)  r>   r?   r@   ú number of heapsú allocated size per heapú identifiers (size nh * k)ú0 values (distances or similarities), size nh * kc                 C   rN   ©z% Return the list of values for a heap)r   Úfloat_minheap_array_t_get_val©r   r²  r   r   r   Úget_val…)  r
  zfloat_minheap_array_t.get_valc                 C   rN   ©z Correspponding identifiers)r   Úfloat_minheap_array_t_get_idsr  r   r   r   r«  ‰)  r
  zfloat_minheap_array_t.get_idsc                 C   rJ   ©z$ prepare all the heaps before adding)r   Úfloat_minheap_array_t_heapifyrL   r   r   r   Úheapify)  r`  zfloat_minheap_array_t.heapifyr   r   c                 C   rŽ  ©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ÚvinÚj0r»  r¼  r   r   r   Úaddn‘)  r§  zfloat_minheap_array_t.addnNc              	   C   rÈ  ©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   r)  r*  Úid_inÚ	id_strider»  r¼  r   r   r   Úaddn_with_ids¢)  ó   	z#float_minheap_array_t.addn_with_idsc              	   C   rÈ  ©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   rM  rL  r)  r*  r0  r1  r   r   r   Úaddn_query_subset_with_ids­)  r3  z0float_minheap_array_t.addn_query_subset_with_idsc                 C   rJ   ©z reorder all the heaps)r   Úfloat_minheap_array_t_reorderrL   r   r   r   Úreorder¸)  r`  zfloat_minheap_array_t.reorderc                 C   r‹  ©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_outr   r   r   Úper_line_extrema¼)  r•  z&float_minheap_array_t.per_line_extremac                 C   ry   r'   )r   Úfloat_minheap_array_t_swiginitÚnew_float_minheap_array_trL   r   r   r   rH   Ç)  r|   zfloat_minheap_array_t.__init__©r   r   r   ©Nr   r   r   ©Nr   ) r   r   r1   r2   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_setrÅ  Úfloat_minheap_array_t_ids_getÚfloat_minheap_array_t_ids_setrA  Úfloat_minheap_array_t_val_getÚfloat_minheap_array_t_val_setr©  r   r«  r%  r,  r2  r7  r:  r@  rH   Údelete_float_minheap_array_trv   r   r   r   r   r  w)  ó$    



r  c                   @   r  )#Úint_minheap_array_tr  c                 C   r5   r'   r6   r7   r   r   r   r9   Õ)  r:   zint_minheap_array_t.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   Õ)  r>   r?   r@   r  r  r  r  c                 C   rN   r  )r   Úint_minheap_array_t_get_valr  r   r   r   r   Ü)  r
  zint_minheap_array_t.get_valc                 C   rN   r!  )r   Úint_minheap_array_t_get_idsr  r   r   r   r«  à)  r
  zint_minheap_array_t.get_idsc                 C   rJ   r#  )r   Úint_minheap_array_t_heapifyrL   r   r   r   r%  ä)  r`  zint_minheap_array_t.heapifyr   r   c                 C   rŽ  ©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_addnr(  r   r   r   r,  è)  r§  zint_minheap_array_t.addnNc              	   C   rÈ  r-  )r   Ú!int_minheap_array_t_addn_with_idsr/  r   r   r   r2  ù)  r3  z!int_minheap_array_t.addn_with_idsc              	   C   rÈ  r4  )r   Ú.int_minheap_array_t_addn_query_subset_with_idsr6  r   r   r   r7  *  r3  z.int_minheap_array_t.addn_query_subset_with_idsc                 C   rJ   r8  )r   Úint_minheap_array_t_reorderrL   r   r   r   r:  *  r`  zint_minheap_array_t.reorderc                 C   r‹  ©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_extremar=  r   r   r   r@  *  r•  z$int_minheap_array_t.per_line_extremac                 C   ry   r'   )r   Úint_minheap_array_t_swiginitÚnew_int_minheap_array_trL   r   r   r   rH   *  r|   zint_minheap_array_t.__init__rC  rD  rE  ) r   r   r1   r2   r   r   r   r
   r   Úint_minheap_array_t_nh_getÚint_minheap_array_t_nh_setrH  Úint_minheap_array_t_k_getÚint_minheap_array_t_k_setrÅ  Úint_minheap_array_t_ids_getÚint_minheap_array_t_ids_setrA  Úint_minheap_array_t_val_getÚint_minheap_array_t_val_setr©  r   r«  r%  r,  r2  r7  r:  r@  rH   Údelete_int_minheap_array_trv   r   r   r   r   rQ  Î)  rP  rQ  c                   @   r  )#Úfloat_maxheap_array_tr  c                 C   r5   r'   r6   r7   r   r   r   r9   ,*  r:   zfloat_maxheap_array_t.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ,*  r>   r?   r@   r  r  r  r  c                 C   rN   r  )r   Úfloat_maxheap_array_t_get_valr  r   r   r   r   3*  r
  zfloat_maxheap_array_t.get_valc                 C   rN   r!  )r   Úfloat_maxheap_array_t_get_idsr  r   r   r   r«  7*  r
  zfloat_maxheap_array_t.get_idsc                 C   rJ   r#  )r   Úfloat_maxheap_array_t_heapifyrL   r   r   r   r%  ;*  r`  zfloat_maxheap_array_t.heapifyr   r   c                 C   rŽ  r&  )r   Úfloat_maxheap_array_t_addnr(  r   r   r   r,  ?*  r§  zfloat_maxheap_array_t.addnNc              	   C   rÈ  r-  )r   Ú#float_maxheap_array_t_addn_with_idsr/  r   r   r   r2  P*  r3  z#float_maxheap_array_t.addn_with_idsc              	   C   rÈ  r4  )r   Ú0float_maxheap_array_t_addn_query_subset_with_idsr6  r   r   r   r7  [*  r3  z0float_maxheap_array_t.addn_query_subset_with_idsc                 C   rJ   r8  )r   Úfloat_maxheap_array_t_reorderrL   r   r   r   r:  f*  r`  zfloat_maxheap_array_t.reorderc                 C   r‹  r;  )r   Ú&float_maxheap_array_t_per_line_extremar=  r   r   r   r@  j*  r•  z&float_maxheap_array_t.per_line_extremac                 C   ry   r'   )r   Úfloat_maxheap_array_t_swiginitÚnew_float_maxheap_array_trL   r   r   r   rH   u*  r|   zfloat_maxheap_array_t.__init__rC  rD  rE  ) r   r   r1   r2   r   r   r   r
   r   Úfloat_maxheap_array_t_nh_getÚfloat_maxheap_array_t_nh_setrH  Úfloat_maxheap_array_t_k_getÚfloat_maxheap_array_t_k_setrÅ  Úfloat_maxheap_array_t_ids_getÚfloat_maxheap_array_t_ids_setrA  Úfloat_maxheap_array_t_val_getÚfloat_maxheap_array_t_val_setr©  r   r«  r%  r,  r2  r7  r:  r@  rH   Údelete_float_maxheap_array_trv   r   r   r   r   rg  %*  rP  rg  c                   @   r  )#Úint_maxheap_array_tr  c                 C   r5   r'   r6   r7   r   r   r   r9   ƒ*  r:   zint_maxheap_array_t.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   ƒ*  r>   r?   r@   r  r  r  r  c                 C   rN   r  )r   Úint_maxheap_array_t_get_valr  r   r   r   r   Š*  r
  zint_maxheap_array_t.get_valc                 C   rN   r!  )r   Úint_maxheap_array_t_get_idsr  r   r   r   r«  Ž*  r
  zint_maxheap_array_t.get_idsc                 C   rJ   r#  )r   Úint_maxheap_array_t_heapifyrL   r   r   r   r%  ’*  r`  zint_maxheap_array_t.heapifyr   r   c                 C   rŽ  rU  )r   Úint_maxheap_array_t_addnr(  r   r   r   r,  –*  r§  zint_maxheap_array_t.addnNc              	   C   rÈ  r-  )r   Ú!int_maxheap_array_t_addn_with_idsr/  r   r   r   r2  §*  r3  z!int_maxheap_array_t.addn_with_idsc              	   C   rÈ  r4  )r   Ú.int_maxheap_array_t_addn_query_subset_with_idsr6  r   r   r   r7  ²*  r3  z.int_maxheap_array_t.addn_query_subset_with_idsc                 C   rJ   r8  )r   Úint_maxheap_array_t_reorderrL   r   r   r   r:  ½*  r`  zint_maxheap_array_t.reorderc                 C   r‹  rZ  )r   Ú$int_maxheap_array_t_per_line_extremar=  r   r   r   r@  Á*  r•  z$int_maxheap_array_t.per_line_extremac                 C   ry   r'   )r   Úint_maxheap_array_t_swiginitÚnew_int_maxheap_array_trL   r   r   r   rH   Ì*  r|   zint_maxheap_array_t.__init__rC  rD  rE  ) r   r   r1   r2   r   r   r   r
   r   Úint_maxheap_array_t_nh_getÚint_maxheap_array_t_nh_setrH  Úint_maxheap_array_t_k_getÚint_maxheap_array_t_k_setrÅ  Úint_maxheap_array_t_ids_getÚint_maxheap_array_t_ids_setrA  Úint_maxheap_array_t_val_getÚint_maxheap_array_t_val_setr©  r   r«  r%  r,  r2  r7  r:  r@  rH   Údelete_int_maxheap_array_trv   r   r   r   r   r{  |*  rP  r{  c                 C   rŽ  ©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©rN  rA  rQ   Úq_minÚq_maxÚq_outr   r   r   r  Ô*  rl
  r  c                 C   rŽ  r  )r   ÚCMax_float_partition_fuzzyr‘  r   r   r   r•  Ý*  rl
  r•  c                   @   ó”   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
eejejƒZedd„ ƒZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZejZdS )ÚAlignedTableUint8c                 C   r5   r'   r6   r7   r   r   r   r9   æ*  r:   zAlignedTableUint8.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   æ*  r>   r?   r@   c                 C   rJ   r'   ©r   Ú AlignedTableUint8_round_capacity©rQ   r   r   r   Úround_capacityë*  r`  z AlignedTableUint8.round_capacityc                 G   r$  r'   )r   ÚAlignedTableUint8_swiginitÚnew_AlignedTableUint8rp   r   r   r   rH   ï*  r.   zAlignedTableUint8.__init__c                 C   rJ   r'   )r   ÚAlignedTableUint8_itemsizerL   r   r   r   Úitemsizeò*  rM   zAlignedTableUint8.itemsizec                 C   rN   r'   )r   ÚAlignedTableUint8_resizerP   r   r   r   rŠ   õ*  rS   zAlignedTableUint8.resizec                 C   rJ   r'   )r   ÚAlignedTableUint8_clearrL   r   r   r   r‚   ø*  rM   zAlignedTableUint8.clearc                 C   rJ   r'   )r   ÚAlignedTableUint8_sizerL   r   r   r   r†   û*  rM   zAlignedTableUint8.sizec                 C   rJ   r'   )r   ÚAlignedTableUint8_nbytesrL   r   r   r   Únbytesþ*  rM   zAlignedTableUint8.nbytesc                 G   rn   r'   )r   ÚAlignedTableUint8_getrp   r   r   r   rs  +  rr   zAlignedTableUint8.getc                 G   rn   r'   )r   ÚAlignedTableUint8_datarp   r   r   r   r„   +  rr   zAlignedTableUint8.dataN)r   r   r1   r   r   r   r
   r   ÚAlignedTableUint8_tab_getÚAlignedTableUint8_tab_setrà  ÚAlignedTableUint8_numel_getÚAlignedTableUint8_numel_setÚnumelr5  r›  rH   rŸ  rŠ   r‚   r†   r¤  rs  r„   Údelete_AlignedTableUint8rv   r   r   r   r   r—  å*  ó     

r—  c                 C   rJ   r'   r˜  rš  r   r   r   r™  +  rM   r™  c                   @   r–  )ÚAlignedTableUint16c                 C   r5   r'   r6   r7   r   r   r   r9   +  r:   zAlignedTableUint16.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   +  r>   r?   r@   c                 C   rJ   r'   ©r   Ú!AlignedTableUint16_round_capacityrš  r   r   r   r›  +  r`  z!AlignedTableUint16.round_capacityc                 G   r$  r'   )r   ÚAlignedTableUint16_swiginitÚnew_AlignedTableUint16rp   r   r   r   rH   +  r.   zAlignedTableUint16.__init__c                 C   rJ   r'   )r   ÚAlignedTableUint16_itemsizerL   r   r   r   rŸ  +  rM   zAlignedTableUint16.itemsizec                 C   rN   r'   )r   ÚAlignedTableUint16_resizerP   r   r   r   rŠ   +  rS   zAlignedTableUint16.resizec                 C   rJ   r'   )r   ÚAlignedTableUint16_clearrL   r   r   r   r‚   !+  rM   zAlignedTableUint16.clearc                 C   rJ   r'   )r   ÚAlignedTableUint16_sizerL   r   r   r   r†   $+  rM   zAlignedTableUint16.sizec                 C   rJ   r'   )r   ÚAlignedTableUint16_nbytesrL   r   r   r   r¤  '+  rM   zAlignedTableUint16.nbytesc                 G   rn   r'   )r   ÚAlignedTableUint16_getrp   r   r   r   rs  *+  rr   zAlignedTableUint16.getc                 G   rn   r'   )r   ÚAlignedTableUint16_datarp   r   r   r   r„   -+  rr   zAlignedTableUint16.dataN)r   r   r1   r   r   r   r
   r   ÚAlignedTableUint16_tab_getÚAlignedTableUint16_tab_setrà  ÚAlignedTableUint16_numel_getÚAlignedTableUint16_numel_setr«  r5  r›  rH   rŸ  rŠ   r‚   r†   r¤  rs  r„   Údelete_AlignedTableUint16rv   r   r   r   r   r®  +  r­  r®  c                 C   rJ   r'   r¯  rš  r   r   r   r°  4+  rM   r°  c                   @   r–  )ÚAlignedTableFloat32c                 C   r5   r'   r6   r7   r   r   r   r9   8+  r:   zAlignedTableFloat32.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   8+  r>   r?   r@   c                 C   rJ   r'   ©r   Ú"AlignedTableFloat32_round_capacityrš  r   r   r   r›  =+  r`  z"AlignedTableFloat32.round_capacityc                 G   r$  r'   )r   ÚAlignedTableFloat32_swiginitÚnew_AlignedTableFloat32rp   r   r   r   rH   A+  r.   zAlignedTableFloat32.__init__c                 C   rJ   r'   )r   ÚAlignedTableFloat32_itemsizerL   r   r   r   rŸ  D+  rM   zAlignedTableFloat32.itemsizec                 C   rN   r'   )r   ÚAlignedTableFloat32_resizerP   r   r   r   rŠ   G+  rS   zAlignedTableFloat32.resizec                 C   rJ   r'   )r   ÚAlignedTableFloat32_clearrL   r   r   r   r‚   J+  rM   zAlignedTableFloat32.clearc                 C   rJ   r'   )r   ÚAlignedTableFloat32_sizerL   r   r   r   r†   M+  rM   zAlignedTableFloat32.sizec                 C   rJ   r'   )r   ÚAlignedTableFloat32_nbytesrL   r   r   r   r¤  P+  rM   zAlignedTableFloat32.nbytesc                 G   rn   r'   )r   ÚAlignedTableFloat32_getrp   r   r   r   rs  S+  rr   zAlignedTableFloat32.getc                 G   rn   r'   )r   ÚAlignedTableFloat32_datarp   r   r   r   r„   V+  rr   zAlignedTableFloat32.dataN)r   r   r1   r   r   r   r
   r   ÚAlignedTableFloat32_tab_getÚAlignedTableFloat32_tab_setrà  ÚAlignedTableFloat32_numel_getÚAlignedTableFloat32_numel_setr«  r5  r›  rH   rŸ  rŠ   r‚   r†   r¤  rs  r„   Údelete_AlignedTableFloat32rv   r   r   r   r   r¿  7+  r­  r¿  c                 C   rJ   r'   rÀ  rš  r   r   r   rÁ  ]+  rM   rÁ  c                  G   r¼  r'   )r   ÚCMin_uint16_partition_fuzzyr¾  r   r   r   rÐ  a+  rM   rÐ  c                  G   r¼  r'   )r   ÚCMax_uint16_partition_fuzzyr¾  r   r   r   rÑ  d+  rM   rÑ  c                  G   r¼  r'   )r   Úmerge_knn_results_CMinr¾  r   r   r   rÒ  g+  rM   rÒ  c                  G   r¼  r'   )r   Úmerge_knn_results_CMaxr¾  r   r   r   rÓ  j+  rM   rÓ  c                 C   rJ   r'   )r   Úomp_set_num_threads)Únum_threadsr   r   r   rÔ  m+  rM   rÔ  c                   C   rÜ  r'   )r   Úomp_get_max_threadsr   r   r   r   rÖ  p+  rI   rÖ  c                 C   r‹  r'   )r   Úmemcpy)Údestr¶
  rQ   r   r   r   r×  s+  r  r×  c                 C   rJ   r'   )r   Úcast_integer_to_uint8_ptrr7   r   r   r   rÙ  v+  rM   rÙ  c                 C   rJ   r'   )r   Úcast_integer_to_float_ptrr7   r   r   r   rÚ  y+  rM   rÚ  c                 C   rJ   r'   )r   Úcast_integer_to_idx_t_ptrr7   r   r   r   rÛ  |+  rM   rÛ  c                 C   rJ   r'   )r   Úcast_integer_to_int_ptrr7   r   r   r   rÜ  +  rM   rÜ  c                 C   rJ   r'   )r   Úcast_integer_to_void_ptrr7   r   r   r   rÝ  ‚+  rM   rÝ  c                   @   sZ   e Zd Zedd„ dd„ ddZeZeejej	ƒZ
dd„ Zdd	„ Zd
d„ Zdd„ ZejZdS )ÚMapLong2Longc                 C   r5   r'   r6   r7   r   r   r   r9   …+  r:   zMapLong2Long.<lambda>c                 C   r;   r'   r6   r<   r   r   r   r9   …+  r>   r?   r@   c                 C   r‡  r'   )r   ÚMapLong2Long_add©r   rQ   r¶  rN  r   r   r   r—  ‰+  r‰  zMapLong2Long.addc                 C   rN   r'   )r   ÚMapLong2Long_searchr  r   r   r   r¢  Œ+  rS   zMapLong2Long.searchc                 C   r‡  r'   )r   ÚMapLong2Long_search_multiplerà  r   r   r   Úsearch_multiple+  r‰  zMapLong2Long.search_multiplec                 C   ry   r'   )r   ÚMapLong2Long_swiginitÚnew_MapLong2LongrL   r   r   r   rH   ’+  r|   zMapLong2Long.__init__N)r   r   r1   r   r   r   r
   r   ÚMapLong2Long_map_getÚMapLong2Long_map_setrx  r—  r¢  rã  rH   Údelete_MapLong2Longrv   r   r   r   r   rÞ  „+  s    
rÞ  c                   C   rÜ  r'   )r   Úwaitr   r   r   r   ré  š+  rI   ré  r>  )Tr   )Fr  )r   r   r   rš  r'   rá  rø  (½  Úsysr   Ú_swig_python_version_infoÚRuntimeErrorÚ__package__r   r   r   Úbuiltinsr   ÚImportErrorr   r#   r&   r/   r   r0   Úobjectr4   ÚSwigPyIterator_swigregisterÚSHARED_PTR_DISOWNrx   ÚFloat32Vector_swigregisterr‘   ÚFloat64Vector_swigregisterrœ   ÚInt8Vector_swigregisterr§   ÚInt16Vector_swigregisterr²   ÚInt32Vector_swigregisterr½   ÚInt64Vector_swigregisterrÈ   ÚUInt8Vector_swigregisterrÓ   ÚUInt16Vector_swigregisterrÞ   ÚUInt32Vector_swigregisterré   ÚUInt64Vector_swigregisterrô   Ú Float32VectorVector_swigregisterrÿ   ÚUInt8VectorVector_swigregisterr
  ÚInt32VectorVector_swigregisterr  ÚInt64VectorVector_swigregisterr   Ú"VectorTransformVector_swigregisterr+  Ú!OperatingPointVector_swigregisterr6  Ú#InvertedListsPtrVector_swigregisterrA  ÚRepeatVector_swigregisterrL  Ú+ClusteringIterationStatsVector_swigregisterrW  Ú!ParameterRangeVector_swigregisterrb  Ú OnDiskOneListVector_swigregisterrn  rt  rw  ÚPartitionStats_swigregisterr„  rˆ  rŠ  rŒ  r  r–  ÚBitstringWriter_swigregisterÚcvarrª  ÚBitstringReader_swigregisterr¶  r½  r¿  rÄ  rÉ  rÍ  rÔ  rÖ  rØ  rÚ  rÛ  rÝ  rÞ  rß  rà  rá  rã  rä  rå  ræ  rë  rì  rï  rò  rô  rú  r  r  r  r	  r  r  r  r  r  r  r  r  r  r"  r)  r,  r-  r0  r2  r3  r4  r8  r9  r:  r=  r>  r@  rB  rC  rG  rH  rI  rK  rQ  rS  rV  rX  r]  ÚRandomGenerator_swigregisterÚhamdis_tab_ham_bytesrp  rr  rs  rt  ru  rw  ry  rz  r|  r}  rƒ  ÚMETRIC_INNER_PRODUCTÚ	METRIC_L2Ú	METRIC_L1ÚMETRIC_LinfÚ	METRIC_LpÚMETRIC_CanberraÚMETRIC_BrayCurtisÚMETRIC_JensenShannonÚMETRIC_Jaccardr„  ÚFAISS_VERSION_MAJORÚFAISS_VERSION_MINORÚFAISS_VERSION_PATCHr‡  ÚSearchParameters_swigregisterr  ÚIndex_swigregisterró  ÚDistanceComputer_swigregisterrÿ  Ú&FlatCodesDistanceComputer_swigregisterr	  ÚIndexFlatCodes_swigregisterr  ÚIndexFlat_swigregisterr,  ÚIndexFlatIP_swigregisterr1  ÚIndexFlatL2_swigregisterr5  ÚIndexFlat1D_swigregisterrD  Ú!ClusteringParameters_swigregisterrg  Ú%ClusteringIterationStats_swigregisterry  ÚClustering_swigregisterr”  ÚClustering1D_swigregisterrš  Ú/ProgressiveDimClusteringParameters_swigregisterr¥  Ú'ProgressiveDimIndexFactory_swigregisterr«  Ú%ProgressiveDimClustering_swigregisterr¹  r¼  r¾  rÀ  ÚQuantizer_swigregisterrÎ  ÚProductQuantizer_swigregisterr*  ÚPQEncoderGeneric_swigregisterr<  ÚPQEncoder8_swigregisterrE  ÚPQEncoder16_swigregisterrL  ÚPQDecoderGeneric_swigregisterr[  ÚPQDecoder8_swigregisterrd  ÚPQDecoder16_swigregisterrl  ÚAdditiveQuantizer_swigregisterrÝ  ÚResidualQuantizer_swigregisterr  r  r  Ú!LocalSearchQuantizer_swigregisterrb  ÚIcmEncoder_swigregisterrq  ÚIcmEncoderFactory_swigregisterrx  ÚLSQTimer_swigregisterr…  ÚLSQTimerScope_swigregisterr—  Ú%ProductAdditiveQuantizer_swigregisterr®  Ú(ProductLocalSearchQuantizer_swigregisterr³  Ú%ProductResidualQuantizer_swigregisterr·  ÚCodePacker_swigregisterrÐ  ÚCodePackerFlat_swigregisterrØ  ÚVectorTransform_swigregisterrî  ÚLinearTransform_swigregisterr  Ú!RandomRotationMatrix_swigregisterr  ÚPCAMatrix_swigregisterr5  ÚITQMatrix_swigregisterrC  ÚITQTransform_swigregisterrX  ÚOPQMatrix_swigregisterrp  Ú%RemapDimensionsTransform_swigregisterrz  Ú#NormalizationTransform_swigregisterrƒ  ÚCenteringTransform_swigregisterrŽ  Ú)SearchParametersPreTransform_swigregisterr•  ÚIndexPreTransform_swigregisterr»  ÚIndexRefine_swigregisterrÕ  ÚIndexRefineFlat_swigregisterrÚ  ÚIndexLSH_swigregisterrõ  Ú)SimulatedAnnealingParameters_swigregisterr  Ú!PermutationObjective_swigregisterr  Ú(ReproduceDistancesObjective_swigregisterr  r,  r?  Ú(SimulatedAnnealingOptimizer_swigregisterrV  ÚPolysemousTraining_swigregisterry  ÚIndexPQ_swigregisterr¨  ÚSearchParametersPQ_swigregisterr²  ÚIndexPQStats_swigregisterr¿  Ú MultiIndexQuantizer_swigregisterrÊ  Ú!MultiIndexQuantizer2_swigregisterrÕ  Ú#IndexAdditiveQuantizer_swigregisterrá  Ú#IndexResidualQuantizer_swigregisterrë  Ú&IndexLocalSearchQuantizer_swigregisterrò  Ú*IndexProductResidualQuantizer_swigregisterrü  Ú-IndexProductLocalSearchQuantizer_swigregisterr  Ú$AdditiveCoarseQuantizer_swigregisterr  Ú4SearchParametersResidualCoarseQuantizer_swigregisterr  Ú$ResidualCoarseQuantizer_swigregisterr'  Ú'LocalSearchCoarseQuantizer_swigregisterr-  ÚIOReader_swigregisterr7  ÚIOWriter_swigregisterr=  ÚVectorIOReader_swigregisterrG  ÚVectorIOWriter_swigregisterrO  ÚFileIOReader_swigregisterr\  ÚFileIOWriter_swigregisterrf  ÚBufferedIOReader_swigregisterr  ÚBufferedIOWriter_swigregisterr“  r”  r•  r–  Ú"InvertedListsIterator_swigregisterr  ÚInvertedLists_swigregisterrî  ÚArrayInvertedLists_swigregisterrü  Ú"ReadOnlyInvertedLists_swigregisterr	  Ú HStackInvertedLists_swigregisterr	  ÚSliceInvertedLists_swigregisterr'	  Ú VStackInvertedLists_swigregisterr9	  Ú MaskedInvertedLists_swigregisterrK	  Ú#StopWordsInvertedLists_swigregisterr\	  Ú InvertedListsIOHook_swigregisterrd	  ri	  rl	  rq	  rx	  ÚBlockInvertedLists_swigregisterr	  r‘	  r”	  r•	  ÚDirectMap_swigregisterr·	  ÚDirectMapAdd_swigregisterrÊ	  ÚLevel1Quantizer_swigregisterrê	  Ú SearchParametersIVF_swigregisterrù	  ÚIndexIVFInterface_swigregisterr

  ÚIndexIVF_swigregisterrX
  Ú InvertedListScanner_swigregisterr{
  ÚIndexIVFStats_swigregisterrß  r“
  r”
  r•
  r™
  r›
  rŸ
  ÚSlidingIndexWindow_swigregisterr´
  rµ
  r·
  rº
  r»
  r½
  r¿
  ÚScalarQuantizer_swigregisterrô
  Ú!IndexScalarQuantizer_swigregisterr   Ú$IndexIVFScalarQuantizer_swigregisterr  Ú!IndexIVFSpectralHash_swigregisterr/  Ú&IndexIVFAdditiveQuantizer_swigregisterr?  Ú&IndexIVFResidualQuantizer_swigregisterrG  Ú)IndexIVFLocalSearchQuantizer_swigregisterrM  Ú-IndexIVFProductResidualQuantizer_swigregisterrS  Ú0IndexIVFProductLocalSearchQuantizer_swigregisterrY  Ú!SearchParametersHNSW_swigregisterrc  ÚHNSW_swigregisterr›  rÈ  ÚHNSWStats_swigregisterrÛ  Ú%ReconstructFromNeighbors_swigregisterr  ÚIndexHNSW_swigregisterr.  ÚIndexHNSWFlat_swigregisterr3  ÚIndexHNSWPQ_swigregisterr9  ÚIndexHNSWSQ_swigregisterr=  ÚIndexHNSW2Level_swigregisterrD  rH  rJ  ÚNeighbor_swigregisterrW  ÚNhood_swigregisterro  ÚNNDescent_swigregisterrª  ÚIndexNNDescent_swigregisterr¹  ÚIndexNNDescentFlat_swigregisterr½  ÚIndexIVFFlat_swigregisterrÆ  ÚIndexIVFFlatDedup_swigregisterrÔ  rÕ  ÚNSG_swigregisterr  ÚIndexNSG_swigregisterr-  ÚIndexNSGFlat_swigregisterr1  ÚIndexNSGPQ_swigregisterr6  ÚIndexNSGSQ_swigregisterr:  ÚOnDiskOneList_swigregisterrE  Ú OnDiskInvertedLists_swigregisterr~  ÚZnSphereSearch_swigregisterr”  ÚEnumeratedVectors_swigregisterr¤  ÚRepeat_swigregisterr­  ÚRepeats_swigregisterrº  ÚZnSphereCodec_swigregisterrÉ  ÚZnSphereCodecRec_swigregisterrí  ÚZnSphereCodecAlt_swigregisterrù  ÚIndexLattice_swigregisterr  Ú"IVFPQSearchParameters_swigregisterr!  ÚIndexIVFPQ_swigregisterrM  rN  ÚIndexIVFPQStats_swigregisterr^  ÚIndexIVFPQR_swigregisterrr  ÚIndex2Layer_swigregisterrˆ  ÚIndexFastScan_swigregisterr½  ÚFastScanStats_swigregisterrÍ  Ú+IndexAdditiveQuantizerFastScan_swigregisterrã  Ú+IndexResidualQuantizerFastScan_swigregisterrê  Ú.IndexLocalSearchQuantizerFastScan_swigregisterrð  Ú2IndexProductResidualQuantizerFastScan_swigregisterrö  Ú5IndexProductLocalSearchQuantizerFastScan_swigregisterrü  ÚIndexPQFastScan_swigregisterr  ÚIndexIVFFastScan_swigregisterr2  ÚIVFFastScanStats_swigregisterrV  Ú.IndexIVFAdditiveQuantizerFastScan_swigregisterrk  Ú1IndexIVFLocalSearchQuantizerFastScan_swigregisterrr  Ú.IndexIVFResidualQuantizerFastScan_swigregisterrx  Ú8IndexIVFProductLocalSearchQuantizerFastScan_swigregisterr~  Ú5IndexIVFProductResidualQuantizerFastScan_swigregisterr„  ÚIndexIVFPQFastScan_swigregisterr”  r—  r˜  r  rŸ  r   ÚIndexBinary_swigregisterr½  ÚIndexBinaryFlat_swigregisterrÒ  ÚIndexBinaryIVF_swigregisterr  Ú&BinaryInvertedListScanner_swigregisterr  Ú!IndexBinaryFromFloat_swigregisterr  ÚIndexBinaryHNSW_swigregisterr'  ÚIndexBinaryHash_swigregisterr;  Ú!IndexBinaryHashStats_swigregisterrH  Ú!IndexBinaryMultiHash_swigregisterr`  ÚThreadedIndexBase_swigregisterrv  Ú$ThreadedIndexBaseBinary_swigregisterr  ÚIndexShards_swigregisterr›  ÚIndexBinaryShards_swigregisterr¨  ÚIndexShardsIVF_swigregisterr²  ÚIndexReplicas_swigregisterrÆ  Ú IndexBinaryReplicas_swigregisterrÑ  ÚIndexSplitVectors_swigregisterrç  ÚIndexRandom_swigregisterrò  ÚIndexIDMap_swigregisterr  ÚIndexBinaryIDMap_swigregisterr   ÚIndexIDMap2_swigregisterr3  ÚIndexBinaryIDMap2_swigregisterr?  Ú#IndexRowwiseMinMaxBase_swigregisterrK  Ú#IndexRowwiseMinMaxFP16_swigregisterrU  ÚIndexRowwiseMinMax_swigregisterr^  ÚRangeSearchResult_swigregisterrp  ÚBufferList_swigregisterrƒ  ÚRangeQueryResult_swigregisterr‘  Ú%RangeSearchPartialResult_swigregisterrŸ  rª  ÚInterruptCallback_swigregisterr®  r±  r´  r·  r¼  ÚVisitedTable_swigregisterrÊ  ÚIDSelector_swigregisterrÎ  ÚIDSelectorRange_swigregisterrá  ÚIDSelectorArray_swigregisterrë  ÚIDSelectorBatch_swigregisterrô  ÚIDSelectorBitmap_swigregisterrþ  ÚIDSelectorNot_swigregisterr  ÚIDSelectorAll_swigregisterr
  ÚIDSelectorAnd_swigregisterr  ÚIDSelectorOr_swigregisterr   ÚIDSelectorXOr_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.  r0  r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  ÚCloner_swigregisterÚIO_FLAG_READ_ONLYÚIO_FLAG_ONDISK_SAME_DIRÚIO_FLAG_SKIP_IVF_DATAÚIO_FLAG_SKIP_PRECOMPUTE_TABLEÚIO_FLAG_MMAPrF  rH  ÚAutoTuneCriterion_swigregisterr^  Ú"OneRecallAtRCriterion_swigregisterrf  Ú"IntersectionCriterion_swigregisterrm  ÚOperatingPoint_swigregisterr{  ÚOperatingPoints_swigregisterr“  ÚParameterRange_swigregisterrœ  ÚParameterSpace_swigregisterrË  rÌ  rÎ  ÚMatrixStats_swigregisterrö  ÚPyCallbackIOWriter_swigregisterr  ÚPyCallbackIOReader_swigregisterr  Ú!PyCallbackIDSelector_swigregisterr  r  r  Ú"float_minheap_array_t_swigregisterrQ  Ú int_minheap_array_t_swigregisterrg  Ú"float_maxheap_array_t_swigregisterr{  Ú int_maxheap_array_t_swigregisterr  r•  r—  ÚAlignedTableUint8_swigregisterr™  r®  ÚAlignedTableUint16_swigregisterr°  r¿  Ú AlignedTableFloat32_swigregisterrÁ  rÐ  rÑ  rÒ  rÓ  rÔ  rÖ  r×  rÙ  rÚ  rÛ  rÜ  rÝ  rÞ  ÚMapLong2Long_swigregisterré  r   r   r   r   Ú<module>   s˜  ÿ	
;























-H
#
  



9
/
	
	



?




+ 
 





 
3
~" 

 



S




?
0

+

 \20$/I"
"
 %&$+(909(C sG
Q$@g-?6"(33c*.(j()HE9G:



4 /) ., %# ::tt^^%//##0 %+
"









+%TUUUU	$$$