a
    h                     @   s   d dl Zd dlZd dlZd dlT dd ZedjZdddd	ed
krHd	ndddddZe	 D ]4\Z
Zee
d ed  e
dv r^ee
d ed  q^ddddddddddd
dd e	 D Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZdS )+    N)*c                    s:   t     fdd}t fd|i}|t  < dS )a  
    Dynamically construct deprecated classes as wrappers around renamed ones

    The deprecation warning added in their __new__-method will trigger upon
    construction of an instance of the class, but only once per session.

    We do this here (in __init__.py) because the base classes are defined in
    the SWIG interface, making it cumbersome to add the deprecation there.

    Parameters
    ----------
    deprecated_name : string
        Name of the class to be deprecated; _not_ present in SWIG interface.
    base_name : string
        Name of the class that is replacing deprecated_name; must already be
        imported into the current namespace.

    Returns
    -------
    None
        However, the deprecated class gets added to the faiss namespace
    c                    sD   d d d}t j|tdd t | j| g|R i |}|S )NzThe class faiss.z" is deprecated in favour of faiss.!   )
stacklevel)warningswarnDeprecationWarningsuper__new__)clsargskwargsmsginstanceZ
base_class	base_namedeprecated_name S/var/www/html/assistant/venv/lib/python3.9/site-packages/faiss/array_conversions.pynew_meth/   s    z-_make_deprecated_swig_class.<locals>.new_methr
   N)globalstype)r   r   r   Zklazzr   r   r   _make_deprecated_swig_class   s    
r   lFloat32Float64Int8Int32   Int64UInt8UInt64)FloatDoubleCharZIntLongZLongLongByteZUint64Vector)r"   r%   r&   ZVectorVectorZfloat32Zfloat64Zint8Zint16Zint32Zint64uint8uint16Zuint32Zuint64)
r   r   r   ZInt16r   r   r    ZUInt16ZUInt32r!   c                 C   s   i | ]\}}||  qS r   )lower).0kvr   r   r   
<dictcomp>d       r.   c                 C   s   | j j}|drt| S |drrtt|dd  }tj|  |d}|  dkrnt	t
||  |j |S |dsJ tt|dd  }tj|  |d}|  dkrt	t
||  |j |S )	z' convert a C++ vector to a numpy array AlignedTableMaybeOwnedVector   Ndtyper   r'   )	__class____name__
startswithAlignedTable_to_arraynpr4   vector_name_mapemptysizememcpyswig_ptrdatanbytesendswithr-   	classnamer4   ar   r   r   vector_to_arrayh   s    

rF   c                 C   s   t | S )N)rF   )r-   r   r   r   vector_float_to_array|   s    rG   c                 C   s   | j \}|jj}|dr|js(J dtt|dd  }|| jks\J d| j||f || |dkrt	|
 t| | j dS |dsJ tt|dd  }|| jksJ d| j||f || |dkrt	|
 t| | j dS )	z  copy a numpy array to a vector r1   z,cannot copy to an non-owned MaybeOwnedVectorr2   Nz-cannot copy a %s array to a %s (should be %s)r   r'   r5   )shaper6   r7   r8   Zis_ownedr:   r4   r;   resizer>   r@   r?   rA   rB   )rE   r-   nrD   r4   r   r   r   copy_array_to_vector   s0    


rK   c                 C   sF   | j \}| | jksJ || |dkrBt| t| | j d S )Nr   )rH   itemsizerI   r>   getr?   rA   )rE   r-   rJ   r   r   r   copy_array_to_AlignedTable   s
    
rN   c                 C   sB   | j dkrt| j}n| j dkr,t| j}nds4J t| | |S )Nr)   r(   F)r4   ZAlignedTableUint16r=   ZAlignedTableUint8rN   )rE   r-   r   r   r   array_to_AlignedTable   s    


rO   c                 C   s\   | j j}|dsJ |dd  }tj|  |d}|jdkrXtt|| 	 |j
 |S )z* convert an AlignedTable to a numpy array r0      Nr3   r   )r6   r7   r8   r*   r:   r<   r=   r>   r?   r@   rA   rC   r   r   r   r9      s    
r9   )numpyr:   arrayr   Zfaiss.loaderr   rL   Zsizeof_longZdeprecated_name_mapitemsZdepr_prefixbase_prefixr;   rF   rG   rK   rN   rO   r9   r   r   r   r   <module>   sN   +	