ó
Ê½÷Xc           @` sØ   d  Z  d d l m Z m Z m Z d Z d d g 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 d l m Z m Z m Z m Z d d l m Z d e e f d „  ƒ  YZ d „  Z d S(   s&   Compressed Sparse Column matrix formati    (   t   divisiont   print_functiont   absolute_imports   restructuredtext ent
   csc_matrixt   isspmatrix_cscN(   t   xrangei   (   t   spmatrix(   t	   csc_tocsr(   t   _sparsetools(   t   upcastt	   isintliket
   IndexMixint   get_index_dtype(   t
   _cs_matrixc           B` s­   e  Z d  Z d Z d e d „ Z e j j e _ d „  Z e d „ Z	 e j	 j e	 _ e d „ Z
 e j
 j e
 _ d „  Z d „  Z e j j e _ d „  Z d	 „  Z d
 „  Z RS(   sÈ
  
    Compressed Sparse Column matrix

    This can be instantiated in several ways:

        csc_matrix(D)
            with a dense matrix or rank-2 ndarray D

        csc_matrix(S)
            with another sparse matrix S (equivalent to S.tocsc())

        csc_matrix((M, N), [dtype])
            to construct an empty matrix with shape (M, N)
            dtype is optional, defaulting to dtype='d'.

        csc_matrix((data, (row_ind, col_ind)), [shape=(M, N)])
            where ``data``, ``row_ind`` and ``col_ind`` satisfy the
            relationship ``a[row_ind[k], col_ind[k]] = data[k]``.

        csc_matrix((data, indices, indptr), [shape=(M, N)])
            is the standard CSC representation where the row indices for
            column i are stored in ``indices[indptr[i]:indptr[i+1]]``
            and their corresponding values are stored in
            ``data[indptr[i]:indptr[i+1]]``.  If the shape parameter is
            not supplied, the matrix dimensions are inferred from
            the index arrays.

    Attributes
    ----------
    dtype : dtype
        Data type of the matrix
    shape : 2-tuple
        Shape of the matrix
    ndim : int
        Number of dimensions (this is always 2)
    nnz
        Number of nonzero elements
    data
        Data array of the matrix
    indices
        CSC format index array
    indptr
        CSC format index pointer array
    has_sorted_indices
        Whether indices are sorted

    Notes
    -----

    Sparse matrices can be used in arithmetic operations: they support
    addition, subtraction, multiplication, division, and matrix power.

    Advantages of the CSC format
        - efficient arithmetic operations CSC + CSC, CSC * CSC, etc.
        - efficient column slicing
        - fast matrix vector products (CSR, BSR may be faster)

    Disadvantages of the CSC format
      - slow row slicing operations (consider CSR)
      - changes to the sparsity structure are expensive (consider LIL or DOK)


    Examples
    --------

    >>> import numpy as np
    >>> from scipy.sparse import csc_matrix
    >>> csc_matrix((3, 4), dtype=np.int8).toarray()
    array([[0, 0, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 0]], dtype=int8)

    >>> row = np.array([0, 2, 2, 0, 1, 2])
    >>> col = np.array([0, 0, 1, 2, 2, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_matrix((data, (row, col)), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    >>> indptr = np.array([0, 2, 3, 6])
    >>> indices = np.array([0, 2, 2, 0, 1, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_matrix((data, indices, indptr), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    t   cscc         C` se   | d  k	 r t d ƒ ‚ n  |  j \ } } d d l m } | |  j |  j |  j f | | f d | ƒS(   Nso   Sparse matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.i   (   t
   csr_matrixt   copy(   t   Nonet
   ValueErrort   shapet   csrR   t   datat   indicest   indptr(   t   selft   axesR   t   Mt   NR   (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt	   transposep   s    c         c` sC   |  j  ƒ  } x0 t |  j d ƒ D] } | | d  d  … f Vq  Wd  S(   Ni    (   t   tocsrR   R   (   R   R   t   r(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   __iter__~   s    c         C` s   | r |  j  ƒ  S|  Sd  S(   N(   R   (   R   R   (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   tocscƒ   s    
c   
   	   C` s   |  j  \ } } t |  j |  j f d t |  j | ƒ ƒ} t j | d d | ƒ} t j |  j d | ƒ} t j |  j d t |  j	 ƒ ƒ} t
 | | |  j j | ƒ |  j j | ƒ |  j | | | ƒ d d l m } | | | | f d |  j  ƒ}	 t |	 _ |	 S(   Nt   maxvali   t   dtype(   R   R   (   R   R   R   R   t   maxt   nnzt   npt   emptyR	   R"   R   t   astypeR   R   R   t   Truet   has_sorted_indices(
   R   R   R   R   t	   idx_dtypeR   R   R   R   t   A(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyR   ‹   s"    !		c         C` st   |  j  | ƒ \ } } t | t ƒ sK t | t ƒ sK t | ƒ sK t | ƒ r_ |  j | | f j S|  j | | f Sd  S(   N(   t   _unpack_indext
   isinstancet   sliceR
   t   T(   R   t   keyt   rowt   col(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   __getitem__¢   s
    c   	      C` sÉ   |  j  |  j ƒ \ } } |  j } t j t | ƒ d |  j j ƒ} t j | |  j	 | ƒ |  j  | | f ƒ \ } } |  j
 d k } | | } | | } t j | d d ƒ} | | } | | } | | f S(   NR"   i    t   kindt	   mergesort(   t   _swapR   R   R%   R&   t   lenR"   R   t	   expandptrR   R   t   argsort(	   R   t	   major_dimt	   minor_dimt   minor_indicest   major_indicesR1   R2   t   nz_maskt   ind(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   nonzero®   s    	!



c         C` s   |  j  | t d ƒ ƒ j ƒ  S(   s]   Returns a copy of row i of the matrix, as a (1 x n)
        CSR matrix (row vector).
        N(   t   _get_submatrixR.   R   R   (   R   t   i(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   getrowÇ   s    c         C` s   |  j  t d ƒ | ƒ S(   sc   Returns a copy of column i of the matrix, as a (m x 1)
        CSC matrix (column vector).
        N(   RA   R.   R   (   R   RB   (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   getcolÏ   s    c         C` s   | d | d f S(   sB   swap the members of x if this is a column-oriented matrix
        i   i    (    (   R   t   x(    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyR6   ×   s    N(   t   __name__t
   __module__t   __doc__t   formatR   t   FalseR   R   R   R    R   R3   R@   R   RC   RD   R6   (    (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyR      s   Y					c         C` s   t  |  t ƒ S(   N(   R-   R   (   RE   (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyR   Ü   s    (   RH   t
   __future__R    R   R   t   __docformat__t   __all__t   numpyR%   t   scipy._lib.sixR   t   baseR   R   R   t    t   sputilsR	   R
   R   R   t
   compressedR   R   R   (    (    (    s/   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/csc.pyt   <module>   s   "È