o
    Ci                     @   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r$d	ndddddZe	 D ]\Z
Zee
d ed  e
dv rIe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
base_class	base_namedeprecated_name o/var/www/html/fyndo/python/python_agents/rag_suite/venv/lib/python3.10/site-packages/faiss/array_conversions.pynew_meth/   s   z-_make_deprecated_swig_class.<locals>.new_methr
   N)globalstype)r   r   r   klazzr   r   r   _make_deprecated_swig_class   s   
r   lFloat32Float64Int8Int32   Int64UInt8UInt64)FloatDoubleCharIntLongLongLongByteUint64Vector)r$   r(   r*   VectorVectorfloat32float64int8int16int32int64uint8uint16uint32uint64)
r   r   r   Int16r   r!   r"   UInt16UInt32r#   c                 C   s   i | ]	\}}||  qS r   )lower).0kvr   r   r   
<dictcomp>d   s    r?   c                 C   sv   | j j}|drt| S |dsJ tt|dd  }tj| 	 |d}| 	 dkr9t
t||  |j |S )z' convert a C++ vector to a numpy array AlignedTabler,   Ndtyper   )	__class____name__
startswithAlignedTable_to_arrayendswithnprC   vector_name_mapemptysizememcpyswig_ptrdatanbytesr>   	classnamerC   ar   r   r   vector_to_arrayh   s   
rT   c                 C   s   t | S )N)rT   )r>   r   r   r   vector_float_to_arrayu   s   rU   c                 C   s   | j \}|jj}|dsJ tt|dd  }|| jks)J d| j||f || |dkr?t|	 t
| | j dS dS )z  copy a numpy array to a vector r,   NrA   z-cannot copy a %s array to a %s (should be %s)r   )shaperD   rE   rH   rI   rC   rJ   resizerM   rO   rN   rP   )rS   r>   nrR   rC   r   r   r   copy_array_to_vectory   s   
rY   c                 C   sJ   | j \}| | jksJ || |dkr#t| t| | j d S d S )Nr   )rV   itemsizerW   rM   getrN   rP   )rS   r>   rX   r   r   r   copy_array_to_AlignedTable   s   
r\   c                 C   s>   | j dkrt| j}n| j dkrt| j}nJ t| | |S )Nr5   r4   )rC   AlignedTableUint16rL   AlignedTableUint8r\   )rS   r>   r   r   r   array_to_AlignedTable   s   


r_   c                 C   s\   | j j}|dsJ |dd  }tj|  |d}|jdkr,tt|| 	 |j
 |S )z* convert an AlignedTable to a numpy array r@      NrB   r   )rD   rE   rF   r;   rI   rK   rL   rM   rN   rO   rP   rQ   r   r   r   rG      s   
rG   )numpyrI   arrayr   faiss.loaderr   rZ   sizeof_longdeprecated_name_mapitemsdepr_prefixbase_prefixrJ   rT   rU   rY   r\   r_   rG   r   r   r   r   <module>   sR   
+	