�
B�gwe �
�
� d Z ddlZddlZddlmZ ddlmZmZ ddlZ ddl
mZ ddlm
Z
mZ ddlmZ dd lmZ dd
lmZ ddlmZ ddlmZmZmZ dd
lmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZC d� ZDdddddddd �d!�ZEd"� ZF e0d#d$gg d%�d#dgd&gd#dgd'�d�(� � dwdddd)�d*�� � ZGdxd+�ZH e0d#gd#dgd&g e-d�,� � gd&gd-�d�(� � dwde jI dd.�d/�� � ZJdyd0�ZKd1� ZLd2� ZMg d3�ZNe8 e7d4� � k reNd5gz
ZNe8 e7d6� � k reNd7gz
ZNe8 e7d8� � k reNd9gz
ZNd:gZO e0d#d$gd#d$g e.eddh� � g e/ ePeN� � �Q e@jR � � � � � � eSgeTdgd;�d�(� � dd<dd=�d>�� � ZU e0d#d$gd#d$g e.eddh� � g e/ ePeN� � �Q e@jR � � � � � � eSgeTdgd;�d�(� � dd<dd=�d?�� � ZV e0d#d$gg d%�d@�d�(� � dwdA�� � ZW e0d#d$gg d%�d@�d�(� � dwdB�� � ZX e0d#d$gg d%�d@�d�(� � dwdC�� � ZY e0d#d$gd#d$gd@�d�(� � dD� � � ZZ e0d#d$gd#d$gd@�d�(� � dE� � � Z[ e0d#d$gd#d$gd@�d�(� � dF� � � Z\e\eZeZe[e[e[dG�Z] e0d#gd#g e/ ePe]� � � � eSgdH�d�(� � d<dI�dJ�� � Z^ e0d#d$gg d%�d&gdK�d�(� � dzdL�� � Z_ e0d#d$gg d%� e,edddM�N� � g e,edddM�N� � d e+e j` � � g e,edddO�N� � gdP�d�(� � d{dR�� � Za e0d#d$gg d%� e,edddM�N� � d e+e j` � � g e,edddO�N� � gdS�d�(� � d|dT�� � Zb e0d#d$gg d%� e,edddM�N� � d e+e j` � � gdU�d�(� � d}dV�� � Zc e0d#d$gg d%� e,edddO�N� � e+e j` � � dgdU�d�(� � d}dW�� � Zd e0d#d$gg d%�d&gdK�d�(� � dzdX�� � Ze e0d#gd#dgd@�d�(� � dwdY�� � Zf e0d#gd#dg e,edddO�N� � e+e j` � � gdU�d�(� � d~d[�� � ZgeXeYeGeWeGeXeXdeJd\� Zhd]� Zid^� Zjd_� Zkdd`�Zlda� Zmdwdb�Zn e0d#d$gg d%�eSdg e/dch�Q eN� � � � eSgedg e,edddM�N� � dgdd�d�(� � dwdd<ddde�df�� � Zo e0d#d$gg d%� e/ ePeN� � dchz � � eSgedgd& e/dgh� � e+ e/dh� � � � gd& e/dgh� � e+d� � gdh�d�(� � d�ddddi�dj�� � Zpg dk�Zqe8 e7d4� � k reqd5gz
Zqe8 e7d6� � k reqd7gz
Zqe8 e7d8� � k reqd9gz
Zqefege_eaeaecedebeedl� Zrdm� Zsdn etdog� � dndn etg dp�� � etg dp�� � etdog� � etdog� � etdodqg� � dr� Zu e0d#d$gg d%� e/ ePer� � dchz � � eSgd&gedgds�d�(� � d�dddu�dv�� � ZvdS )�z?Metrics for pairwise distances and affinity of sets of samples.� N)�partial)�Integral�Real)�effective_n_jobs)�
csr_matrix�issparse)�distance� )�config_context)�DataConversionWarning)� normalize)�check_array�gen_batches�gen_even_slices)�_fill_or_add_to_diagonal�_find_matching_floating_dtype�_is_numpy_namespace�_max_precision_float_dtype�_modify_in_place_if_numpy�device�
get_namespace�get_namespace_and_device)�get_chunk_n_rows)� _get_mask)�
is_scalar_nan)�Hidden�Interval�
MissingValues�Options�
StrOptions�validate_params)�_deprecate_force_all_finite)� row_norms�safe_sparse_dot)�
parse_version�sp_base_version)�Parallel�delayed)�_num_samples�check_non_negative� )�ArgKmin)�_chi2_kernel_fast�_sparse_manhattanc � � t | � � s.t | t j � � st j | � � } |�| j }nLt |� � s6t |t j � � st j |� � }|j }n|j }| j |cxk rt j k rn n
t j }nt }| ||fS )zq
1. If dtype of X and Y is float32, then dtype float32 is returned.
2. Else dtype float is returned.
)r �
isinstance�np�ndarray�asarray�dtype�float32�float)�X�Y�Y_dtyper4 s �h/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sklearn/metrics/pairwise.py�_return_float_dtyper; 3 s� � �
�A�;�;� �z�!�R�Z�8�8� ��J�q�M�M���y��'���
�a�[�[� ��A�r�z�!:�!:� ��J�q�M�M���'����'���w�'�'�'�'�'�R�Z�'�'�'�'�'��
������a��;�� F�infer_float�csr�
deprecatedT)�precomputedr4 �
accept_sparse�force_all_finite�ensure_all_finite� ensure_2d�copyc �� � t ||� � }t | |� � \ } }
t t | � � t |� � g� � st | � � rt | |� � \ } }}nt
| || �� � }d}|dk r|}|| u s|�t | ||||||�� � x} }n,t | ||||||�� � } t |||||||�� � }|rS| j d |j d k r6t d| j d | j d |j d fz � � �nH|rF| j d |j d k r*t d | j d |j d fz � � �| |fS )
aH Set X and Y appropriately and checks inputs.
If Y is None, it is set as a pointer to X (i.e. not a copy).
If Y is given, this does not happen.
All distance metrics should use this function first to assert that the
given parameters are correct and safe to use.
Specifically, this function first ensures that both X and Y are arrays,
then checks that they are at least two dimensional while ensuring that
their elements are floats (or dtype if provided). Finally, the function
checks that the size of the second dimension of the two arrays is equal, or
the equivalent check for a precomputed distance matrix.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples_X, n_features)
Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features)
precomputed : bool, default=False
True if X is to be treated as precomputed distances to the samples in
Y.
dtype : str, type, list of type or None default="infer_float"
Data type required for X and Y. If "infer_float", the dtype will be an
appropriate float type selected by _return_float_dtype. If None, the
dtype of the input is preserved.
.. versionadded:: 0.18
accept_sparse : str, bool or list/tuple of str, default='csr'
String[s] representing allowed sparse matrix formats, such as 'csc',
'csr', etc. If the input is sparse but not in the allowed format,
it will be converted to the first listed format. True allows the input
to be any format. False means that a sparse matrix input will
raise an error.
force_all_finite : bool or 'allow-nan', default=True
Whether to raise an error on np.inf, np.nan, pd.NA in array. The
possibilities are:
- True: Force all values of array to be finite.
- False: accepts np.inf, np.nan, pd.NA in array.
- 'allow-nan': accepts only np.nan and pd.NA values in array. Values
cannot be infinite.
.. versionadded:: 0.22
``force_all_finite`` accepts the string ``'allow-nan'``.
.. versionchanged:: 0.23
Accepts `pd.NA` and converts it into `np.nan`.
.. deprecated:: 1.6
`force_all_finite` was renamed to `ensure_all_finite` and will be removed
in 1.8.
ensure_all_finite : bool or 'allow-nan', default=True
Whether to raise an error on np.inf, np.nan, pd.NA in array. The
possibilities are:
- True: Force all values of array to be finite.
- False: accepts np.inf, np.nan, pd.NA in array.
- 'allow-nan': accepts only np.nan and pd.NA values in array. Values
cannot be infinite.
.. versionadded:: 1.6
`force_all_finite` was renamed to `ensure_all_finite`.
ensure_2d : bool, default=True
Whether to raise an error when the input arrays are not 2-dimensional. Setting
this to `False` is necessary when using a custom metric with certain
non-numerical inputs (e.g. a list of strings).
.. versionadded:: 1.5
copy : bool, default=False
Whether a forced copy will be triggered. If copy=False, a copy might
be triggered by a conversion.
.. versionadded:: 0.22
Returns
-------
safe_X : {array-like, sparse matrix} of shape (n_samples_X, n_features)
An array equal to X, guaranteed to be a numpy array.
safe_Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features)
An array equal to Y if Y was not None, guaranteed to be a numpy array.
If Y was None, safe_Y will be a pointer to X.
��xp�check_pairwise_arraysr= N)rA r4 rE rC � estimatorrD r+ r zVPrecomputed metric requires shape (n_queries, n_indexed). Got (%d, %d) for %d indexed.zTIncompatible dimension for X and Y matrices: X.shape[1] == %d while Y.shape[1] == %d)
r"