Ë
    »dæjù  ã                   ó€   — d Z ddlZddlmZ ej
                  Zdej                  dej                  fd„Zdedede	fd„Z
y)	zCosine similarity utilities.é    N)Úembedding_resultÚuÚvc                 ó  — t        | «      dk  rt        d«      ‚t        j                  j	                  | «      }t        j                  j	                  |«      }|dk  s|dk  rt        d«      ‚| j                  |«      ||z  z  S )z2Computes cosine similarity between two embeddings.r   z5Cannot compute cosing similarity on empty embeddings.z:Cannot compute cosine similarity on embedding with 0 norm.)ÚlenÚ
ValueErrorÚnpÚlinalgÚnormÚdot)r   r   Únorm_uÚnorm_vs       ú|/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/components/utils/cosine_similarity.pyÚ_compute_cosine_similarityr      sw   € ô 	ˆƒVˆq‚[Ü
ÐLÓ
MÐMä�9‰9�>‰>˜!Ó€&Ü�9‰9�>‰>˜!Ó€&àˆq‚[�F˜a’KÜ
ØDóFð Fð 
�‰ˆq‹�V˜f‘_Ñ	%Ð%ó    Úreturnc                 óæ  — t        | j                  «      t        |j                  «      k7  r8t        dt        | j                  «      › dt        |j                  «      › d�«      ‚| j                  j                  t        k(  r=|j                  j                  t        k(  r t        | j                  |j                  «      S | j                  j                  t        j                  k(  rƒ|j                  j                  t        j                  k(  r\t        | j                  j                  d«      j                  d«      |j                  j                  d«      j                  d«      «      S t        d«      ‚)aF  Utility function to compute cosine similarity between two embedding.

  May return an InvalidArgumentError if e.g. the feature vectors are of
  different types (quantized vs. float), have different sizes, or have an
  L2-norm of 0.

  Args:
    u: An embedding.
    v: An embedding.

  Returns:
    Cosine similarity value.
  zHCannot compute cosine similarity between embeddings of different sizes (z vs. z).Úint8ÚfloatzHCannot compute cosine similarity between quantized and float embeddings.)
r   Ú	embeddingr   Údtyper   r   r	   Úuint8ÚviewÚastype)r   r   s     r   Úcosine_similarityr   '   s  € ô 	ˆ�‰Óœ˜QŸ[™[Ó)Ò)Ü
ð ä˜QŸ[™[Ó)Ð*¨%´°A·K±KÓ0@Ð/AÀðEó Fð Fð ‡[�[×Ñœ%Ò A§K¡K×$5Ñ$5¼Ò$>Ü% a§k¡k°1·;±;Ó?Ð?à‡[�[×Ñœ"Ÿ(™(Ò" q§{¡{×'8Ñ'8¼B¿H¹HÒ'DÜ%Ø	�‰×Ñ˜Ó ×'Ñ'¨Ó0Ø	�‰×Ñ˜Ó ×'Ñ'¨Ó0óð ô
 	ð 'ó 	(ð (r   )Ú__doc__Únumpyr	   Ú,mediapipe.tasks.python.components.containersr   Ú	EmbeddingÚ
_EmbeddingÚndarrayr   r   r   © r   r   ú<module>r#      sP   ðñ #ã å Ià×'Ñ'€
ð& "§*¡*ð &°·±ó &ð (˜ð (¨
ð (°uô (r   