a
    ]g                     @   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 e/var/www/html/cobodadashboardai.evdpl.com/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   sv   | j j}|drt| S |ds(J tt|dd  }tj| 	 |d}| 	 dkrrt
t||  |j |S )z' convert a C++ vector to a numpy array AlignedTabler'   Ndtyper   )	__class____name__
startswithAlignedTable_to_arrayendswithnpr3   vector_name_mapemptysizememcpyswig_ptrdatanbytesr-   	classnamer3   ar   r   r   vector_to_arrayh   s    
rD   c                 C   s   t | S )N)rD   )r-   r   r   r   vector_float_to_arrayu   s    rE   c                 C   s~   | j \}|jj}|dsJ tt|dd  }|| jksRJ d| j||f || |dkrzt|	 t
| | j dS )z  copy a numpy array to a vector r'   Nr1   z-cannot copy a %s array to a %s (should be %s)r   )shaper4   r5   r8   r9   r3   r:   resizer=   r?   r>   r@   )rC   r-   nrB   r3   r   r   r   copy_array_to_vectory   s    
rI   c                 C   sF   | j \}| | jksJ || |dkrBt| t| | j d S )Nr   )rF   itemsizerG   r=   getr>   r@   )rC   r-   rH   r   r   r   copy_array_to_AlignedTable   s
    
rL   c                 C   sB   | j dkrt| j}n| j dkr,t| j}nds4J t| | |S )Nr)   r(   F)r3   ZAlignedTableUint16r<   ZAlignedTableUint8rL   )rC   r-   r   r   r   array_to_AlignedTable   s    


rM   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      Nr2   r   )r4   r5   r6   r*   r9   r;   r<   r=   r>   r?   r@   rA   r   r   r   r7      s    
r7   )numpyr9   arrayr   Zfaiss.loaderr   rJ   Zsizeof_longZdeprecated_name_mapitemsZdepr_prefixbase_prefixr:   rD   rE   rI   rL   rM   r7   r   r   r   r   <module>   sN   +	