§
    ¦˜ºh¶K  ã                   óÚ   — d dl Zd dlmZ ddlmZ ddlmZ	 ddlm
Z ddlmZ d„ Zd	„ Zd
„ Zd„ Zd d„Zddœd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd!d„Zd"d„Z d„ Z!d„ Z"d„ Z#dS )#é    Né   )Ú_check_sample_weighté   )Úcsc_mean_variance_axis0)Úcsr_mean_variance_axis0)Úincr_mean_variance_axis0c                 ó~   — t          j        | ¦  «        r| j        nt          | ¦  «        }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      úa/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/sklearn/utils/sparsefuncs.pyÚ_raise_typeerrorr      s6   € åœ[¨™^œ^Ð8�”�µ°a±´€JØ
8¸:Ñ
E€CÝ
�C‰.Œ.Ðó    c                 ó2   — | dvrt          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    sJ ‚| xj        |                     | j        d¬¦  «        z  c_        dS )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.
    r   r   Úclip)ÚmodeN)ÚshapeÚdataÚtakeÚindices©r   Úscales     r   Úinplace_csr_column_scaler#   #   sG   € ð Œ;�qŒ>˜QœW QœZÒ'Ð'Ð'Ð'Ø€F„Fˆe�jŠj˜œ¨ˆjÑ0Ô0Ñ0€F„F€F€Fr   c                 ó¶   — |j         d         | j         d         k    sJ ‚| xj        t          j        |t          j        | j        ¦  «        ¦  «        z  c_        dS )aÂ  Inplace row scaling of a CSR matrix.

    Scale each sample 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 be scaled. It should be of CSR format.

    scale : ndarray of float of shape (n_samples,)
        Array of precomputed sample-wise values to use for scaling.
    r   N)r   r   ÚnpÚrepeatÚdiffÚindptrr!   s     r   Úinplace_csr_row_scaler)   6   sM   € ð Œ;�qŒ>˜QœW QœZÒ'Ð'Ð'Ð'Ø€F„F�bŒi˜�rœw q¤xÑ0Ô0Ñ1Ô1Ñ1€F„F€F€Fr   Fc                 óz  — t          |¦  «         t          j        | ¦  «        r:| j        dk    r/|dk    rt	          | ||¬¦  «        S t          | j        ||¬¦  «        S t          j        | ¦  «        r:| j        dk    r/|dk    rt          | ||¬¦  «        S t	          | j        ||¬¦  «        S t          | ¦  «         dS )a4  Compute mean and variance along an axis on a CSR or CSC matrix.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Input data. It can be of CSR or CSC format.

    axis : {0, 1}
        Axis along which the axis should be computed.

    weights : ndarray of shape (n_samples,) or (n_features,), default=None
        If axis is set to 0 shape is (n_samples,) or
        if axis is set to 1 shape is (n_features,).
        If it is set to None, then samples are equally weighted.

        .. versionadded:: 0.24

    return_sum_weights : bool, default=False
        If True, returns the sum of weights seen for each feature
        if `axis=0` or each sample if `axis=1`.

        .. versionadded:: 0.24

    Returns
    -------

    means : ndarray of shape (n_features,), dtype=floating
        Feature-wise means.

    variances : ndarray of shape (n_features,), dtype=floating
        Feature-wise variances.

    sum_weights : ndarray of shape (n_features,), dtype=floating
        Returned if `return_sum_weights` is `True`.
    Úcsrr   )ÚweightsÚreturn_sum_weightsÚcscN)r   r
   r   r   Ú_csr_mean_var_axis0Ú_csc_mean_var_axis0ÚTr   )r   r   r,   r-   s       r   Úmean_variance_axisr2   H   sù   € õH ˜DÑ!Ô!Ð!å	„{�1�~„~ð ˜!œ( eÒ+Ð+Ø�1Š9ˆ9Ý&Ø˜7Ð7Iðñ ô ð õ 'Ø”˜WÐ9Kðñ ô ð õ 
Œ�Q‰Œð 
˜AœH¨Ò-Ð-Ø�1Š9ˆ9Ý&Ø˜7Ð7Iðñ ô ð õ 'Ø”˜WÐ9Kðñ ô ð õ 	˜ÑÔÐÐÐr   )r,   c                óp  — t          |¦  «         t          j        | ¦  «        r	| j        dv st	          | ¦  «         t          j        |¦  «        dk    r!t          j        |j        ||j	        ¬¦  «        }t          j        |¦  «        t          j        |¦  «        cxk    rt          j        |¦  «        k    sn t          d¦  «        ‚|dk    rWt          j        |¦  «        | j        d         k    r3t          d| j        d         › dt          j        |¦  «        › d�¦  «        ‚nVt          j        |¦  «        | j        d         k    r3t          d	| j        d         › dt          j        |¦  «        › d�¦  «        ‚|dk    r| j        n| } |�t          || | j	        ¬¦  «        }t          | ||||¬¦  «        S )a7	  Compute incremental mean and variance along an axis on a CSR or CSC matrix.

    last_mean, last_var are the statistics computed at the last step by this
    function. Both must be initialized to 0-arrays of the proper size, i.e.
    the number of features in X. last_n is the number of samples encountered
    until now.

    Parameters
    ----------
    X : CSR or CSC sparse matrix of shape (n_samples, n_features)
        Input data.

    axis : {0, 1}
        Axis along which the axis should be computed.

    last_mean : ndarray of shape (n_features,) or (n_samples,), dtype=floating
        Array of means to update with the new data X.
        Should be of shape (n_features,) if axis=0 or (n_samples,) if axis=1.

    last_var : ndarray of shape (n_features,) or (n_samples,), dtype=floating
        Array of variances to update with the new data X.
        Should be of shape (n_features,) if axis=0 or (n_samples,) if axis=1.

    last_n : float or ndarray of shape (n_features,) or (n_samples,),             dtype=floating
        Sum of the weights seen so far, excluding the current weights
        If not float, it should be of shape (n_features,) if
        axis=0 or (n_samples,) if axis=1. If float it corresponds to
        having same weights for all samples (or features).

    weights : ndarray of shape (n_samples,) or (n_features,), default=None
        If axis is set to 0 shape is (n_samples,) or
        if axis is set to 1 shape is (n_features,).
        If it is set to None, then samples are equally weighted.

        .. versionadded:: 0.24

    Returns
    -------
    means : ndarray of shape (n_features,) or (n_samples,), dtype=floating
        Updated feature-wise means if axis = 0 or
        sample-wise means if axis = 1.

    variances : ndarray of shape (n_features,) or (n_samples,), dtype=floating
        Updated feature-wise variances if axis = 0 or
        sample-wise variances if axis = 1.

    n : ndarray of shape (n_features,) or (n_samples,), dtype=integral
        Updated number of seen samples per feature if axis=0
        or number of seen features per sample if axis=1.

        If weights is not None, n is a sum of the weights of the seen
        samples or features instead of the actual number of seen
        samples or features.

    Notes
    -----
    NaNs are ignored in the algorithm.
    )r.   r+   r   )Údtypez8last_mean, last_var, last_n do not have the same shapes.r   zHIf axis=1, then last_mean, last_n, last_var should be of size n_samples z (Got z).zIIf axis=0, then last_mean, last_n, last_var should be of size n_features N)Ú	last_meanÚlast_varÚlast_nr,   )r   r
   r   r   r   r%   ÚsizeÚfullr   r4   r   r1   r   Ú_incr_mean_var_axis0)r   r   r5   r6   r7   r,   s         r   Úincr_mean_variance_axisr;   „   så  € õx ˜DÑ!Ô!Ð!åŒK˜‰NŒNð ˜qœx¨>Ð9Ð9Ý˜ÑÔÐå	„wˆv�„˜!ÒÐÝ”˜œ¨&¸	¼ÐHÑHÔHˆåŒG�IÑÔ¥"¤'¨(Ñ"3Ô"3ÐFÐFÒFÐFµr´w¸v±´ÒFÐFÐFÐFÝÐSÑTÔTÐTàˆq‚y€yÝŒ7�9ÑÔ ¤¨¤Ò+Ð+ÝðKØ"#¤'¨!¤*ðKð KÝ46´G¸IÑ4FÔ4FðKð Kð Kñô ð ð ,õ Œ7�9ÑÔ ¤¨¤Ò+Ð+ÝðLØ#$¤7¨1¤:ðLð LÝ57´W¸YÑ5GÔ5GðLð Lð Lñô ð ð
 �qŠyˆyˆŒˆ˜a€AàÐÝ& w°¸¼ÐAÑAÔAˆåØ	�Y¨¸&È'ðñ ô ð r   c                 óò   — t          j        | ¦  «        r"| j        dk    rt          | j        |¦  «         dS t          j        | ¦  «        r| j        dk    rt          | |¦  «         dS t          | ¦  «         dS )a  Inplace column scaling of a CSC/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 CSC or CSR format.

    scale : ndarray of shape (n_features,), dtype={np.float32, np.float64}
        Array of precomputed feature-wise values to use for scaling.
    r.   r+   N)r
   r   r   r)   r1   r#   r   r!   s     r   Úinplace_column_scaler=   â   s~   € õ 
„{�1�~„~ð ˜!œ( eÒ+Ð+Ý˜aœc 5Ñ)Ô)Ð)Ð)Ð)Ý	Œ�Q‰Œð ˜AœH¨Ò-Ð-Ý   EÑ*Ô*Ð*Ð*Ð*å˜ÑÔÐÐÐr   c                 óò   — t          j        | ¦  «        r"| j        dk    rt          | j        |¦  «         dS t          j        | ¦  «        r| j        dk    rt          | |¦  «         dS t          | ¦  «         dS )aå  Inplace row scaling of a CSR or CSC matrix.

    Scale each row 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 be scaled. It should be of CSR or CSC format.

    scale : ndarray of shape (n_features,), dtype={np.float32, np.float64}
        Array of precomputed sample-wise values to use for scaling.
    r.   r+   N)r
   r   r   r#   r1   r)   r   r!   s     r   Úinplace_row_scaler?   ù   s~   € õ 
„{�1�~„~ð ˜!œ( eÒ+Ð+Ý  ¤ eÑ,Ô,Ð,Ð,Ð,Ý	Œ�Q‰Œð ˜AœH¨Ò-Ð-Ý˜a Ñ'Ô'Ð'Ð'Ð'å˜ÑÔÐÐÐr   c                 ó  — ||fD ]+}t          |t          j        ¦  «        rt          d¦  «        ‚Œ,|dk     r|| j        d         z  }|dk     r|| j        d         z  }| j        |k    }|| j        | j        |k    <   || j        |<   dS )aK  Swap two rows of a CSC matrix in-place.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Matrix whose two rows are to be swapped. It should be of
        CSC format.

    m : int
        Index of the row of X to be swapped.

    n : int
        Index of the row of X to be swapped.
    ú m and n should be valid integersr   N)Ú
isinstancer%   Úndarrayr   r   r    )r   ÚmÚnÚtÚm_masks        r   Úinplace_swap_row_cscrH     s¤   € ð �ˆVð @ð @ˆÝ�a�œÑ$Ô$ð 	@ÝÐ>Ñ?Ô?Ð?ð	@ð 	ˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆØˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆàŒY˜!Š^€FØ !€A„IˆaŒi˜1ŠnÑØ€A„IˆfÑÐÐr   c           	      ó<  — ||fD ]+}t          |t          j        ¦  «        rt          d¦  «        ‚Œ,|dk     r|| j        d         z  }|dk     r|| j        d         z  }||k    r||}}| j        }||         }||dz            }||         }||dz            }||z
  }	||z
  }
|	|
k    r:| j        |dz   |…xx         |
|	z
  z  cc<   ||
z   | j        |dz   <   ||	z
  | j        |<   t          j        | j        d|…         | j        ||…         | j        ||…         | j        ||…         | j        |d…         g¦  «        | _        t          j        | j        d|…         | j        ||…         | j        ||…         | j        ||…         | j        |d…         g¦  «        | _        dS )aK  Swap two rows of a CSR matrix in-place.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Matrix whose two rows are to be swapped. It should be of
        CSR format.

    m : int
        Index of the row of X to be swapped.

    n : int
        Index of the row of X to be swapped.
    rA   r   r   r   N)	rB   r%   rC   r   r   r(   Úconcatenater    r   )r   rD   rE   rF   r(   Úm_startÚm_stopÚn_startÚn_stopÚnz_mÚnz_ns              r   Úinplace_swap_row_csrrQ   ,  sæ  € ð �ˆVð @ð @ˆÝ�a�œÑ$Ô$ð 	@ÝÐ>Ñ?Ô?Ð?ð	@ð 	ˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆØˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆð 	ˆ1‚u€uØ�!ˆ1ˆàŒX€FØ�QŒi€GØ�A˜‘EŒ]€FØ�QŒi€GØ�A˜‘EŒ]€FØ�GÑ€DØ�GÑ€Dàˆt‚|€|à	Œ��Q‘˜�ÐÐÔ˜t d™{Ñ*ÐÐÑØ! D™.ˆŒ��Q‘‰Ø˜t‘mˆŒ�‰å”àŒI�h�w�hÔØŒI�g˜f�nÔ%ØŒI�f˜W�nÔ%ØŒI�g˜f�nÔ%ØŒI�f�g�gÔð	
ñô €A„Iõ Œ^àŒF�8�G�8ÔØŒF�7˜6�>Ô"ØŒF�6˜'�>Ô"ØŒF�7˜6�>Ô"ØŒF�6�7�7ŒOð	
ñô €A„F€F€Fr   c                 óì   — t          j        | ¦  «        r| j        dk    rt          | ||¦  «         dS t          j        | ¦  «        r| j        dk    rt	          | ||¦  «         dS t          | ¦  «         dS )a[  
    Swap two rows of a CSC/CSR matrix in-place.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Matrix whose two rows are to be swapped. It should be of CSR or
        CSC format.

    m : int
        Index of the row of X to be swapped.

    n : int
        Index of the row of X to be swapped.
    r.   r+   N)r
   r   r   rH   rQ   r   ©r   rD   rE   s      r   Úinplace_swap_rowrT   k  s€   € õ  
„{�1�~„~ð ˜!œ( eÒ+Ð+Ý˜Q  1Ñ%Ô%Ð%Ð%Ð%Ý	Œ�Q‰Œð ˜AœH¨Ò-Ð-Ý˜Q  1Ñ%Ô%Ð%Ð%Ð%å˜ÑÔÐÐÐr   c                 óD  — |dk     r|| j         d         z  }|dk     r|| j         d         z  }t          j        | ¦  «        r| j        dk    rt	          | ||¦  «         dS t          j        | ¦  «        r| j        dk    rt          | ||¦  «         dS t          | ¦  «         dS )ag  
    Swap two columns of a CSC/CSR matrix in-place.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Matrix whose two columns are to be swapped. It should be of
        CSR or CSC format.

    m : int
        Index of the column of X to be swapped.

    n : int
        Index of the column of X to be swapped.
    r   r   r.   r+   N)r   r
   r   r   rQ   rH   r   rS   s      r   Úinplace_swap_columnrV   ƒ  s°   € ð  	ˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆØˆ1‚u€uØ	ˆQŒW�QŒZ‰ˆÝ	„{�1�~„~ð ˜!œ( eÒ+Ð+Ý˜Q  1Ñ%Ô%Ð%Ð%Ð%Ý	Œ�Q‰Œð ˜AœH¨Ò-Ð-Ý˜Q  1Ñ%Ô%Ð%Ð%Ð%å˜ÑÔÐÐÐr   c                 ó  — t          j        t          j        | j        ¦  «        ¦  «        } t	          | ¦  «        | j        | j        | j        f| j        ¬¦  «        } |                     | j        | j        |         ¦  «        }||fS )N)r   )	r%   Úflatnonzeror'   r(   r   r   r    r   Úreduceat)r   ÚufuncÚmajor_indexÚvalues       r   Ú_minor_reducer]   Ÿ  so   € Ý”.¥¤¨¬Ñ!2Ô!2Ñ3Ô3€Kð
 	�ˆQ‰Œ�”˜œ A¤HÐ-°Q´WÐ=Ñ=Ô=€AØ�NŠN˜1œ6 1¤8¨KÔ#8Ñ9Ô9€EØ˜ÐÐr   c           	      ó$  — | j         |         }|dk    rt          d¦  «        ‚| j         d|z
           }|dk    r|                      ¦   «         n|                      ¦   «         }|                     ¦   «          t          ||¦  «        \  }}t          j        |j        ¦  «        |         |k     } |||         d¦  «        ||<   |dk    }	t          j	        |	|¦  «        }t          j	        |	|¦  «        }|dk    rBt          j        |t          j        t          |¦  «        ¦  «        |ff| j        d|f¬¦  «        }
nAt          j        ||t          j        t          |¦  «        ¦  «        ff| j        |df¬¦  «        }
|
j                             ¦   «         S )Nr   ú&zero-size array to reduction operationr   )r4   r   )r   r   ÚtocscÚtocsrÚsum_duplicatesr]   r%   r'   r(   Úcompressr
   Ú
coo_matrixÚzerosÚlenr4   ÚAÚravel)r   r   Ú
min_or_maxÚNÚMÚmatr[   r\   Únot_fullÚmaskÚress              r   Ú_min_or_max_axisrp   ª  sx  € Ø	Œ�Œ€AØˆA‚v€vÝÐAÑBÔBÐBØ	Œ��D‘Ô€AØ˜q’y�yˆ!�'Š'‰)Œ)ˆ) a§g¢g¡i¤i€CØ×ÒÑÔÐÝ& s¨JÑ7Ô7Ñ€K�ÝŒw�s”zÑ"Ô" ;Ô/°!Ò3€HØ �j  x¤°!Ñ4Ô4€Eˆ(�OØ�AŠ:€DÝ”+˜d KÑ0Ô0€KÝŒK˜˜eÑ$Ô$€Eàˆq‚y€yÝŒmØ•R”X�c %™jœjÑ)Ô)¨;Ð7Ð8ÀÄÐPQÐSTÈvð
ñ 
ô 
ˆˆõ ŒmØ�[¥"¤(­3¨u©:¬:Ñ"6Ô"6Ð7Ð8ÀÄÐPQÐSTÈvð
ñ 
ô 
ˆð Œ5�;Š;‰=Œ=Ðr   c                 óª  — |€›d| j         v rt          d¦  «        ‚| j                             d¦  «        }| j        dk    r|S |                     | j                             ¦   «         ¦  «        }| j        t          j	        | j         ¦  «        k    r |||¦  «        }|S |dk     r|dz  }|dk    s|dk    rt          | ||¦  «        S t          d¦  «        ‚)Nr   r_   r   r   z.invalid axis, use 0 for rows, or 1 for columns)r   r   r4   r   ÚnnzÚreducer   rh   r%   Úprodrp   )r   r   ri   ÚzerorD   s        r   Ú_sparse_min_or_maxrv   Ã  sÒ   € Ø€|Ø�”ˆ<ˆ<ÝÐEÑFÔFÐFØŒw�|Š|˜A‰ŒˆØŒ5�AŠ:ˆ:ØˆKØ×Ò˜aœfŸlšl™nœnÑ-Ô-ˆØŒ5•B”G˜AœGÑ$Ô$Ò$Ð$Ø�
˜4 Ñ#Ô#ˆAØˆØˆa‚x€xØ�‰	ˆØ�Š	ˆ	�t˜q’y�yÝ  4¨Ñ4Ô4Ð4åÐIÑJÔJÐJr   c                 ón   — t          | |t          j        ¦  «        t          | |t          j        ¦  «        fS ©N)rv   r%   ÚminimumÚmaximum©r   r   s     r   Ú_sparse_min_maxr|   Ö  s.   € å˜1˜d¥B¤JÑ/Ô/Ý˜1˜d¥B¤JÑ/Ô/ðð r   c                 ón   — t          | |t          j        ¦  «        t          | |t          j        ¦  «        fS rx   )rv   r%   ÚfminÚfmaxr{   s     r   Ú_sparse_nan_min_maxr€   Ý  s*   € Ý˜q $­¬Ñ0Ô0Õ2DÀQÈÍbÌgÑ2VÔ2VÐWÐWr   c                 ó¦   — t          j        | ¦  «        r-| j        dv r$|rt          | |¬¦  «        S t	          | |¬¦  «        S t          | ¦  «         dS )a�  Compute minimum and maximum along an axis on a CSR or CSC matrix.

     Optionally ignore NaN values.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Input data. It should be of CSR or CSC format.

    axis : {0, 1}
        Axis along which the axis should be computed.

    ignore_nan : bool, default=False
        Ignore or passing through NaN values.

        .. versionadded:: 0.20

    Returns
    -------

    mins : ndarray of shape (n_features,), dtype={np.float32, np.float64}
        Feature-wise minima.

    maxs : ndarray of shape (n_features,), dtype={np.float32, np.float64}
        Feature-wise maxima.
    )r+   r.   r   N)r
   r   r   r€   r|   r   )r   r   Ú
ignore_nans      r   Úmin_max_axisrƒ   á  sb   € õ6 
„{�1�~„~ð ˜!œ( nÐ4Ð4Øð 	1Ý& q¨tÐ4Ñ4Ô4Ð4å" 1¨4Ð0Ñ0Ô0Ð0å˜ÑÔÐÐÐr   c                 ó´  — |dk    rd}n;|dk    rd}n2| j         dk    r't          d                      | j         ¦  «        ¦  «        ‚|€5|€| j        S t          j        t          j        | j        ¦  «        |¦  «        S |dk    r5t          j        | j        ¦  «        }|€|                     d¦  «        S ||z  S |dk    r{|€&t          j        | j	        | j
        d         ¬	¦  «        S t          j        |t          j        | j        ¦  «        ¦  «        }t          j        | j	        | j
        d         |¬
¦  «        S t          d                      |¦  «        ¦  «        ‚)a¾  A variant of X.getnnz() with extension to weighting on axis 0.

    Useful in efficiently calculating multilabel metrics.

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_labels)
        Input data. It should be of CSR format.

    axis : {0, 1}, default=None
        The axis on which the data is aggregated.

    sample_weight : array-like of shape (n_samples,), default=None
        Weight for each row of X.

    Returns
    -------
    nnz : int, float, ndarray of shape (n_samples,) or ndarray of shape (n_features,)
        Number of non-zero values in the array along a given axis. Otherwise,
        the total number of non-zero values in the array is returned.
    éÿÿÿÿr   éþÿÿÿr   r+   z#Expected CSR sparse format, got {0}NÚintp)Ú	minlength)rˆ   r,   zUnsupported axis: {0})r   r   rr   r%   Údotr'   r(   ÚastypeÚbincountr    r   r&   r   )r   r   Úsample_weightÚoutr,   s        r   Úcount_nonzerorŽ     sD  € ð, ˆr‚z€zØˆˆØ	�ŠˆØˆˆØ	
Œ�UÒ	Ð	ÝÐ=×DÒDÀQÄXÑNÔNÑOÔOÐOð €|ØÐ Ø”5ˆLå”6�"œ' !¤(Ñ+Ô+¨]Ñ;Ô;Ð;Ø	�ŠˆÝŒg�a”hÑÔˆØÐ à—:’:˜fÑ%Ô%Ð%Ø�]Ñ"Ð"Ø	�ŠˆØÐ Ý”;˜qœy°A´G¸A´JÐ?Ñ?Ô?Ð?å”i ­r¬w°q´xÑ/@Ô/@ÑAÔAˆGÝ”;˜qœy°A´G¸A´JÈÐPÑPÔPÐPåÐ0×7Ò7¸Ñ=Ô=Ñ>Ô>Ð>r   c                 ó>  — t          | ¦  «        |z   }|st          j        S t          j        | dk     ¦  «        }t	          |d¦  «        \  }}|                      ¦   «          |rt          || ||¦  «        S t          |dz
  | ||¦  «        t          || ||¦  «        z   dz  S )z”Compute the median of data with n_zeros additional zeros.

    This function is used to support sparse matrices; it modifies data
    in-place.
    r   r   r   g       @)rf   r%   ÚnanrŽ   ÚdivmodÚsortÚ_get_elem_at_rank)r   Ún_zerosÚn_elemsÚ
n_negativeÚmiddleÚis_odds         r   Ú_get_medianr™   ;  s®   € õ �$‰iŒi˜'Ñ!€GØð ÝŒvˆÝÔ! $¨¢(Ñ+Ô+€JÝ˜G QÑ'Ô'�N€FˆFØ‡I‚I�K„K€Kàð DÝ  ¨¨z¸7ÑCÔCÐCõ 	˜& 1™* d¨J¸Ñ@Ô@Ý
˜F D¨*°gÑ
>Ô
>ñ	?àñð r   c                 óJ   — | |k     r||          S | |z
  |k     rdS || |z
           S )z@Find the value in data augmented with n_zeros for the given rankr   © )Úrankr   r–   r”   s       r   r“   r“   Q  s;   € àˆjÒÐØ�DŒzÐØˆjÑ˜7Ò"Ð"ØˆqØ��w‘ÔÐr   c                 ó¤  — t          j        | ¦  «        r| j        dk    st          d| j        z  ¦  «        ‚| j        }| j        \  }}t          j        |¦  «        }t          t          |dd…         |dd…         ¦  «        ¦  «        D ]F\  }\  }}t          j
        | j        ||…         ¦  «        }||j        z
  }	t          ||	¦  «        ||<   ŒG|S )aC  Find the median across axis 0 of a CSC matrix.

    It is equivalent to doing np.median(X, axis=0).

    Parameters
    ----------
    X : sparse matrix of shape (n_samples, n_features)
        Input data. It should be of CSC format.

    Returns
    -------
    median : ndarray of shape (n_features,)
        Median.
    r.   z%Expected matrix of CSC format, got %sNr…   r   )r
   r   r   r   r(   r   r%   re   Ú	enumerateÚzipÚcopyr   r8   r™   )
r   r(   Ú	n_samplesÚ
n_featuresÚmedianÚf_indÚstartÚendr   Únzs
             r   Úcsc_median_axis_0r¨   Z  sÓ   € õ ŒK˜‰NŒNð L˜qœx¨5Ò0Ð0ÝÐ?À!Ä(ÑJÑKÔKÐKàŒX€FØœGÑ€IˆzÝŒX�jÑ!Ô!€Få(­¨V°C°R°C¬[¸&ÀÀÀ¼*Ñ)EÔ)EÑFÔFð .ð .Ñˆ‰|��såŒw�q”v˜e C˜iÔ(Ñ)Ô)ˆØ˜œÑ"ˆÝ# D¨"Ñ-Ô-ˆˆu‰ˆà€Mr   )NF)F)NN)$Únumpyr%   Úscipy.sparseÚsparser
   Úutils.validationr   Úsparsefuncs_fastr   r0   r   r/   r   r:   r   r   r#   r)   r2   r;   r=   r?   rH   rQ   rT   rV   r]   rp   rv   r|   r€   rƒ   rŽ   r™   r“   r¨   r›   r   r   ú<module>r®      s  ðð Ð Ð Ð Ø Ð Ð Ð Ð Ð à 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ð
ð ð ð
ð 
ð 
ð1ð 1ð 1ð&2ð 2ð 2ð$9ð 9ð 9ð 9ðx NRð [ð [ð [ð [ð [ð|ð ð ð.ð ð ð,ð ð ð:<ð <ð <ð~ð ð ð0ð ð ð8ð ð ðð ð ð2Kð Kð Kð&ð ð ðXð Xð Xð!ð !ð !ð !ðH3?ð 3?ð 3?ð 3?ðlð ð ð, ð  ð  ðð ð ð ð r   