ó
    ¦ñ:iZX  ã                   óè   • S r SSKrSSKJr  SSKJr  SSKJ	r	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  S rS rS rS rSS jrSS.S jrS rS rS rS rS rS rSS jr S S jr!S r"S r#S r$S r%g)!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                 ó†   • [         R                  " U 5      (       a  U R                  O
[        U 5      nSU-  n[	        U5      e)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      Ú\/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/utils/sparsefuncs.pyÚ_raise_typeerrorr      s1   € äŸ[š[¨Ÿ^™^�—’´°a³€JØ
8¸:Ñ
E€CÜ
�C‹.Ðó    c                 ó,   • U S;  a  [        SU -  5      eg )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                 ó¢   • UR                   S   U R                   S   :X  d   eU =R                  UR                  U R                  SS9-  sl        g)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&   '   sB   € ðJ �;‰;�q‰>˜QŸW™W Q™ZÓ'Ð'Ð'Ø‡F‚Fˆe�j‰j˜Ÿ™¨ˆjÐ0Ñ0†Fr   c                 óØ   • UR                   S   U R                   S   :X  d   eU =R                  [        R                  " U[        R                  " U R
                  5      5      -  sl        g)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,   P   sH   € ð �;‰;�q‰>˜QŸW™W Q™ZÓ'Ð'Ð'Ø‡F‚FŒb�iŠi˜œrŸwšw q§x¡xÓ0Ó1Ñ1†Fr   c                 ól  • [        U5        [        R                  " U 5      (       a4  U R                  S:X  a$  US:X  a
  [	        XUS9$ [        U R                  X#S9$ [        R                  " U 5      (       a4  U R                  S:X  a$  US:X  a
  [        XUS9$ [	        U R                  X#S9$ [        U 5        g)a×  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`.

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.mean_variance_axis(csr, axis=0)
(array([2.  , 0.25, 1.75]), array([12.    ,  0.1875,  4.1875]))
Úcsrr   )ÚweightsÚreturn_sum_weightsÚcscN)r   r   r   r   Ú_csr_mean_var_axis0Ú_csc_mean_var_axis0ÚTr   )r   r   r/   r0   s       r   Úmean_variance_axisr5   b   s­   € ôl ˜DÔ!ä	‡{‚{�1‡~�~˜!Ÿ(™( eÓ+Ø�1‹9Ü&ØÐ7Iñð ô 'Ø—‘˜Wñð ô 
�Š�Q�‰˜AŸH™H¨Ó-Ø�1‹9Ü&ØÐ7Iñð ô 'Ø—‘˜Wñð ô 	˜Õr   )r/   c                ó˜  • [        U5        [        R                  " U 5      (       a  U R                  S;   d  [	        U 5        [
        R                  " U5      S:X  a)  [
        R                  " UR                  XBR                  S9n[
        R                  " U5      [
        R                  " U5      s=:X  a  [
        R                  " U5      :X  d  O  [        S5      eUS:X  a[  [
        R                  " U5      U R                  S   :w  a3  [        SU R                  S    S[
        R                  " U5       S35      eOZ[
        R                  " U5      U R                  S   :w  a3  [        S	U R                  S    S[
        R                  " U5       S35      eUS:X  a  U R                  OU n Ub  [        XPU R                  S9n[        XX4US
9$ )aì
  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.

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.incr_mean_variance_axis(
...     csr, axis=0, last_mean=np.zeros(3), last_var=np.zeros(3), last_n=2
... )
(array([1.3..., 0.1..., 1.1...]), array([8.8..., 0.1..., 3.4...]),
array([6., 6., 6.]))
)r1   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 )Ú	last_meanÚlast_varÚlast_nr/   )r   r   r   r   r   r(   ÚsizeÚfullr    r7   r   r4   r   Ú_incr_mean_var_axis0)r   r   r8   r9   r:   r/   s         r   Úincr_mean_variance_axisr>   °   ss  € ôb ˜DÔ!ä�KŠK˜�N‰N˜qŸx™x¨>Ó9Ü˜Ôä	‡w‚wˆvƒ˜!ÓÜ—’˜Ÿ™¨&¿¹ÑHˆä�GŠG�IÓ¤"§'¢'¨(Ó"3ÕF´r·w²w¸v³ÕFÜÐSÓTÐTàˆqƒyÜ�7Š7�9Ó §¡¨¡Ó+Üð"Ø"#§'¡'¨!¡* ¨V´B·G²G¸IÓ4FÐ3GÀrðKóð ð ,ô �7Š7�9Ó §¡¨¡Ó+Üð#Ø#$§7¡7¨1¡: ,¨f´R·W²W¸YÓ5GÐ4HÈðLóð ð
 �q‹yˆ�Š˜a€AàÑÜ& w¸¿¹ÑAˆäØ	¨È'ñð r   c                 ó  • [         R                  " U 5      (       a'  U R                  S:X  a  [        U R                  U5        g[         R                  " U 5      (       a  U R                  S:X  a  [        X5        g[        U 5        g)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.

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_column_scale(csr, scale)
>>> csr.todense()
matrix([[16,  3,  4],
        [ 0,  0, 10],
        [ 0,  0,  0],
        [ 0,  0,  0]])
r1   r.   N)r   r   r   r,   r4   r&   r   r$   s     r   Úinplace_column_scaler@   #  sS   € ôJ 
‡{‚{�1‡~�~˜!Ÿ(™( eÓ+Ü˜aŸc™c 5Õ)Ü	�Š�Q�‰˜AŸH™H¨Ó-Ü  Õ*ä˜Õr   c                 ó  • [         R                  " U 5      (       a'  U R                  S:X  a  [        U R                  U5        g[         R                  " U 5      (       a  U R                  S:X  a  [        X5        g[        U 5        g)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.

Examples
--------
>>> from sklearn.utils import sparsefuncs
>>> from scipy import sparse
>>> import numpy as np
>>> indptr = np.array([0, 2, 3, 4, 5])
>>> indices = np.array([0, 1, 2, 3, 3])
>>> data = np.array([8, 1, 2, 5, 6])
>>> scale = np.array([2, 3, 4, 5])
>>> csr = sparse.csr_matrix((data, indices, indptr))
>>> csr.todense()
matrix([[8, 1, 0, 0],
        [0, 0, 2, 0],
        [0, 0, 0, 5],
        [0, 0, 0, 6]])
>>> sparsefuncs.inplace_row_scale(csr, scale)
>>> csr.todense()
 matrix([[16,  2,  0,  0],
         [ 0,  0,  6,  0],
         [ 0,  0,  0, 20],
         [ 0,  0,  0, 30]])
r1   r.   N)r   r   r   r&   r4   r,   r   r$   s     r   Úinplace_row_scalerB   P  sS   € ôH 
‡{‚{�1‡~�~˜!Ÿ(™( eÓ+Ü  §¡ eÕ,Ü	�Š�Q�‰˜AŸH™H¨Ó-Ü˜aÕ'ä˜Õr   c                 ó8  • X4 H-  n[        U[        R                  5      (       d  M$  [        S5      e   US:  a  XR                  S   -  nUS:  a  X R                  S   -  nU R
                  U:H  nXR
                  U R
                  U:H  '   X R
                  U'   g)a#  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_cscrK   |  sˆ   € ð ‹VˆÜ�aœŸ™×$Ó$ÜÐ>Ó?Ð?ñ ð 	ˆ1ƒuØ	�W‰W�Q‰Z‰ˆØˆ1ƒuØ	�W‰W�Q‰Z‰ˆà�Y‰Y˜!‰^€FØ !‡I�Iˆa�i‰i˜1‰nÑØ‡I�IˆfÒr   c           	      ó0  • X4 H-  n[        U[        R                  5      (       d  M$  [        S5      e   US:  a  XR                  S   -  nUS:  a  X R                  S   -  nX:”  a  X!p!U R
                  nXA   nXAS-      nXB   nXBS-      nXe-
  n	X‡-
  n
Xš:w  aB  U R
                  US-   U=== X©-
  -  sss& XZ-   U R
                  US-   '   X‰-
  U R
                  U'   [        R                  " U R                  SU U R                  Xx U R                  Xg U R                  XV U R                  US /5      U l        [        R                  " U R                  SU U R                  Xx U R                  Xg U R                  XV U R                  US /5      U l        g)a#  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.
rD   r   r   r   N)	rE   r(   rF   r   r    r+   Úconcatenater#   r!   )r   rG   rH   rI   r+   Úm_startÚm_stopÚn_startÚn_stopÚnz_mÚnz_ns              r   Úinplace_swap_row_csrrT   ™  s’  € ð ‹VˆÜ�aœŸ™×$Ó$ÜÐ>Ó?Ð?ñ ð 	ˆ1ƒuØ	�W‰W�Q‰Z‰ˆØˆ1ƒuØ	�W‰W�Q‰Z‰ˆð 	ƒuØˆ1à�X‰X€FØ‰i€GØ˜‘E‰]€FØ‰i€GØ˜‘E‰]€FØÑ€DØÑ€Dàƒ|à	�‰��Q‘˜Ó˜t™{Ñ*ÓØ!™.ˆ�‰��Q‘‰Ø‘mˆ�‰�‰ä—’à�I‰I�h�wÐØ�I‰I�gÐ%Ø�I‰I�fÐ%Ø�I‰I�gÐ%Ø�I‰I�f�gÐð	
ó€A„Iô �^Š^à�F‰F�8�GÐØ�F‰F�7Ð"Ø�F‰F�6Ð"Ø�F‰F�7Ð"Ø�F‰F�6�7ˆOð	
ó€A…Fr   c                 óú   • [         R                  " U 5      (       a  U R                  S:X  a  [        XU5        g[         R                  " U 5      (       a  U R                  S:X  a  [	        XU5        g[        U 5        g)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.

Examples
--------
>>> from sklearn.utils import sparsefuncs
>>> from scipy import sparse
>>> import numpy as np
>>> indptr = np.array([0, 2, 3, 3, 3])
>>> indices = np.array([0, 2, 2])
>>> data = np.array([8, 2, 5])
>>> csr = sparse.csr_matrix((data, indices, indptr))
>>> csr.todense()
matrix([[8, 0, 2],
        [0, 0, 5],
        [0, 0, 0],
        [0, 0, 0]])
>>> sparsefuncs.inplace_swap_row(csr, 0, 1)
>>> csr.todense()
matrix([[0, 0, 5],
        [8, 0, 2],
        [0, 0, 0],
        [0, 0, 0]])
r1   r.   N)r   r   r   rK   rT   r   ©r   rG   rH   s      r   Úinplace_swap_rowrW   Ø  sQ   € ôJ 
‡{‚{�1‡~�~˜!Ÿ(™( eÓ+Ü˜Q 1Õ%Ü	�Š�Q�‰˜AŸH™H¨Ó-Ü˜Q 1Õ%ä˜Õr   c                 óV  • US:  a  XR                   S   -  nUS:  a  X R                   S   -  n[        R                  " U 5      (       a  U R                  S:X  a  [	        XU5        g[        R                  " U 5      (       a  U R                  S:X  a  [        XU5        g[        U 5        g)a6  
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.

Examples
--------
>>> from sklearn.utils import sparsefuncs
>>> from scipy import sparse
>>> import numpy as np
>>> indptr = np.array([0, 2, 3, 3, 3])
>>> indices = np.array([0, 2, 2])
>>> data = np.array([8, 2, 5])
>>> csr = sparse.csr_matrix((data, indices, indptr))
>>> csr.todense()
matrix([[8, 0, 2],
        [0, 0, 5],
        [0, 0, 0],
        [0, 0, 0]])
>>> sparsefuncs.inplace_swap_column(csr, 0, 1)
>>> csr.todense()
matrix([[0, 8, 2],
        [0, 0, 5],
        [0, 0, 0],
        [0, 0, 0]])
r   r   r1   r.   N)r    r   r   r   rT   rK   r   rV   s      r   Úinplace_swap_columnrY     s}   € ðJ 	ˆ1ƒuØ	�W‰W�Q‰Z‰ˆØˆ1ƒuØ	�W‰W�Q‰Z‰ˆÜ	‡{‚{�1‡~�~˜!Ÿ(™( eÓ+Ü˜Q 1Õ%Ü	�Š�Q�‰˜AŸH™H¨Ó-Ü˜Q 1Õ%ä˜Õr   c                 ó¢   • [         R                  " U 5      (       a)  U R                  S;   a  U(       a	  [        XS9$ [	        XS9$ [        U 5        g)aY  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.   r1   r   N)r   r   r   r   r   r   )r   r   Ú
ignore_nans      r   Úmin_max_axisr\   6  s=   € ô6 
‡{‚{�1‡~�~˜!Ÿ(™( nÓ4ÞÜ& qÑ4Ð4ä" 1Ñ0Ð0ä˜Õr   c                 óú  • US:X  a  SnO=US:X  a  SnO4U R                   S:w  a$  [        SR                  U R                   5      5      eUcD  Uc  U R                  $ [        R                  " [        R
                  " U R                  5      U5      $ US:X  a8  [        R
                  " U R                  5      nUc  UR                  S5      $ X2-  $ US:X  a‘  Uc,  [        R                  " U R                  U R                  S   S9$ [        R                  " U[        R
                  " U R                  5      5      n[        R                  " U R                  U R                  S   US	9$ [        S
R                  U5      5      e)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}Úintp)Ú	minlength)ra   r/   zUnsupported axis: {0})r   r   Únnzr(   Údotr*   r+   ÚastypeÚbincountr#   r    r)   r   )r   r   Úsample_weightÚoutr/   s        r   Úcount_nonzerorh   Z  s+  € ð, ˆrƒzØ‰Ø	�‹Ø‰Ø	
�‰�UÓ	ÜÐ=×DÑDÀQÇXÁXÓNÓOÐOð �|ØÑ Ø—5‘5ˆLä—6’6œ"Ÿ'š' !§(¡(Ó+¨]Ó;Ð;Ø	�‹Ü�gŠg�a—h‘hÓˆØÑ à—:‘:˜fÓ%Ð%ØÑ"Ð"Ø	�‹ØÑ Ü—;’;˜qŸy™y°A·G±G¸A±JÑ?Ð?ä—i’i ¬r¯wªw°q·x±xÓ/@ÓAˆGÜ—;’;˜qŸy™y°A·G±G¸A±JÈÑPÐPäÐ0×7Ñ7¸Ó=Ó>Ð>r   c                 ó   • [        U 5      U-   nU(       d  [        R                  $ [        R                  " U S:  5      n[	        US5      u  pEU R                  5         U(       a  [        X@X15      $ [        US-
  XU5      [        X@X15      -   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       @)Úlenr(   Únanrh   ÚdivmodÚsortÚ_get_elem_at_rank)r!   Ún_zerosÚn_elemsÚ
n_negativeÚmiddleÚis_odds         r   Ú_get_medianrt   �  s‡   € ô �$‹i˜'Ñ!€GÞÜ�v‰vˆÜ×!Ò! $¨¡(Ó+€JÜ˜G QÓ'�N€FØ‡I�I„KæÜ  ¨zÓCÐCô 	˜& 1™* d¸Ó@Ü
˜F¨*Ó
>ñ	?àñð r   c                 ó4   • X:  a  X   $ X-
  U:  a  gXU-
     $ )z@Find the value in data augmented with n_zeros for the given rankr   © )Úrankr!   rq   ro   s       r   rn   rn   ¦  s+   € àÓØ‰zÐØÑ˜7Ó"ØØ�w‘ÑÐr   c                 ó´  • [         R                  " U 5      (       a  U R                  S:X  d  [        SU R                  -  5      eU R                  nU R
                  u  p#[        R                  " U5      n[        [        USS USS 5      5       HE  u  nu  pg[        R                  " U R                  Xg 5      nX(R                  -
  n	[        X‰5      XE'   MG     U$ )a  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.
r1   z%Expected matrix of CSC format, got %sNr^   r   )r   r   r   r   r+   r    r(   ÚzerosÚ	enumerateÚzipÚcopyr!   r;   rt   )
r   r+   Ú	n_samplesÚ
n_featuresÚmedianÚf_indÚstartÚendr!   Únzs
             r   Úcsc_median_axis_0r„   ¯  s´   € ô �KŠK˜�N‰N˜qŸx™x¨5Ó0ÜÐ?À!Ç(Á(ÑJÓKÐKà�X‰X€FØŸG™GÑ€IÜ�XŠX�jÓ!€Fä(¬¨V°C°R¨[¸&ÀÀ¸*Ó)EÖFÑˆ‰|�ä�wŠw�q—v‘v˜eÐ(Ó)ˆØŸ™Ñ"ˆÜ# DÓ-ˆ‹ñ	  Gð €Mr   c           	      óž   ^ ^^• TSSS24   mT R                   m[        U U4S jU U4S jUU4S jUU4S jT R                  T R                  S9$ )a  Create an implicitly offset linear operator.

This is used by PCA on sparse data to avoid densifying the whole data
matrix.

Params
------
    X : sparse matrix of shape (n_samples, n_features)
    offset : ndarray of shape (n_features,)

Returns
-------
centered : LinearOperator
Nc                 ó   >• TU -  TU -  -
  $ ©Nrv   ©Úxr   Úoffsets    €€r   Ú<lambda>Ú)_implicit_column_offset.<locals>.<lambda>à  ó   ø€ ˜˜Q™ ¨!¡Ò+r   c                 ó   >• TU -  TU -  -
  $ r‡   rv   rˆ   s    €€r   r‹   rŒ   á  r�   r   c                 ó6   >• TU -  TU R                  5       -  -
  $ r‡   )Úsum©r‰   ÚXTrŠ   s    €€r   r‹   rŒ   â  s   ø€ ˜"˜q™& F¨Q¯U©U«WÑ$4Ò5r   c                 óV   >• TU -  TR                   U R                  SS9S S S 24   -  -
  $ )Nr   r   )r4   r�   r‘   s    €€r   r‹   rŒ   ã  s*   ø€ ˜"˜q™& 6§8¡8¨a¯e©e¸¨e¨m¸DÂ!¸GÑ.DÑ#DÒDr   )ÚmatvecÚmatmatÚrmatvecÚrmatmatr7   r    )r4   r   r7   r    )r   rŠ   r’   s   ``@r   Ú_implicit_column_offsetr˜   Î  sB   ú€ ð �Dš!�G‰_€FØ	
�‰€BÜÝ+Ý+Ý5ÝDØ�g‰gØ�g‰gñð r   )NF)F)NN)&Ú__doc__Únumpyr(   Úscipy.sparseÚsparser   Úscipy.sparse.linalgr   Úutils.fixesr   r   Úutils.validationr   Úsparsefuncs_fastr	   r3   r
   r2   r   r=   r   r   r&   r,   r5   r>   r@   rB   rK   rT   rW   rY   r\   rh   rt   rn   r„   r˜   rv   r   r   Ú<module>r¡      s•   ðÙ Hó Ý Ý .ç >Ý 3õõõò
ò
ò&1òR2ô$Kð\ NRõ pòf*òZ)òXò:<ò~*òZ.ôb!ôH3?òlò, òó>r   