ó
\c           @   sh   d  Z  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 e e d	  Z d S(
   s   Helpers for preprocessingi˙˙˙˙N(   t   sparsei   (   t   check_array(   t   FLOAT_DTYPES(   t   sixt   allc         C   sä  t  |  d d d | d t }  t j |   rB | rB t d   n  t | t j  rj | d k rj | |   St |  d k r |  S|  j	 d } t
 j |  } t
 j | d t } t | t
 j |  <t
 j |  }	 t
 j |  }
 |
 d k rň |  S|
 | k r| |   S| |  d	 d	  | | f  } |  d	 d	  | |	 f j |  } | r| j	 d | j	 d | k r~t d
   n  | |  d	 d	  | | f <|  St j |  sşt j |  rÍt j | | f  St
 j | | f  Sd	 S(   s÷  Apply a transform function to portion of selected features.

    Returns an array Xt, where the non-selected features appear on the right
    side (largest column indices) of Xt.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape [n_samples, n_features]
        Dense array or sparse matrix.

    transform : callable
        A callable transform(X) -> X_transformed

    dtype : number type
        Desired dtype of output.

    copy : boolean, default=True
        Copy X even if it could be avoided.

    selected : "all" or array of indices or mask
        Specify which features to apply the transform to.

    retain_order : boolean, default=False
        If True, the non-selected features will not be displaced to the right
        side of the transformed array. The number of features in Xt must
        match the number of features in X. Furthermore, X and Xt cannot be
        sparse.

    Returns
    -------
    Xt : array or sparse matrix, shape=(n_samples, n_features_new)
    t   accept_sparset   csct   copyt   dtypesC   The retain_order option can only be set to True for dense matrices.R   i    i   Ns   The retain_order option can only be set to True if the dimensions of the input array match the dimensions of the transformed array.(   R   R   R    t   issparset
   ValueErrort
   isinstanceR   t   string_typest   lent   shapet   npt   aranget   zerost   boolt   Truet   asarrayt   logical_nott   sumt   astypet   hstack(   t   Xt	   transformR   t   selectedR   t   retain_ordert
   n_featurest   indt   selt   not_selt
   n_selectedt   X_selt	   X_not_sel(    (    s9   lib/python2.7/site-packages/sklearn/preprocessing/base.pyt   _transform_selected   s6    "

 #(   t   __doc__t   numpyR   t   scipyR    t   utilsR   t   utils.validationR   t	   externalsR   R   t   FalseR$   (    (    (    s9   lib/python2.7/site-packages/sklearn/preprocessing/base.pyt   <module>   s   