�
K�g@X � �� � d Z ddlZddlmZ ddlmZ ddlm Z m
Z
ddlmZ ddl
mZ dd l
mZ dd
l
mZ d� Zd� Zd
� Zd� Zdd�Zdd�d�Zd� Zd� Zd� Zd� Zd� Zd� Zd d�Z d!d�Z!d� Z"d� Z#d� Z$d� Z%dS )"zBA collection of utilities to work with sparse matrices and arrays.� N)�LinearOperator� )�_sparse_min_max�_sparse_nan_min_max)�_check_sample_weight� )�csc_mean_variance_axis0)�csr_mean_variance_axis0)�incr_mean_variance_axis0c �~ � t j | � � r| j nt | � � }d|z }t |� � �)z2Raises a TypeError if X is not a CSR or CSC matrixz,Expected a CSR or CSC sparse matrix, got %s.)�sp�issparse�format�type� TypeError)�X�
input_type�errs �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sklearn/utils/sparsefuncs.py�_raise_typeerrorr s6 � ��[��^�^�8�����a���J�
8�:�
E�C�
�C�.�.�� c �2 � | dvrt d| z � � �d S )N)r r z8Unknown axis value: %d. Use 0 for rows, or 1 for columns)�
ValueError��axiss r �_raise_error_wrong_axisr s/ � ��6����F��M�
�
�
� �r c � � |j d | j d k sJ �| xj |� | j d�� � z c_ dS )a� Inplace column scaling of a CSR matrix.
Scale each feature of the data matrix by multiplying with specific scale
provided by the caller assuming a (n_samples, n_features) shape.
Parameters
----------
X : sparse matrix of shape (n_samples, n_features)
Matrix to normalize using the variance of the features.
It should be of CSR format.
scale : ndarray of shape (n_features,), dtype={np.float32, np.float64}
Array of precomputed feature-wise values to use for scaling.
Examples
--------
>>> from sklearn.utils import sparsefuncs
>>> from scipy import sparse
>>> import numpy as np
>>> indptr = np.array([0, 3, 4, 4, 4])
>>> indices = np.array([0, 1, 2, 2])
>>> data = np.array([8, 1, 2, 5])
>>> scale = np.array([2, 3, 2])
>>> csr = sparse.csr_matrix((data, indices, indptr))
>>> csr.todense()
matrix([[8, 1, 2],
[0, 0, 5],
[0, 0, 0],
[0, 0, 0]])
>>> sparsefuncs.inplace_csr_column_scale(csr, scale)
>>> csr.todense()
matrix([[16, 3, 4],
[ 0, 0, 10],
[ 0, 0, 0],
[ 0, 0, 0]])
r r �clip)�modeN)�shape�data�take�indices�r �scales r �inplace_csr_column_scaler&