
&]\c           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z m Z m Z d d	 d
 d d g Z d e f d     YZ d e f d     YZ d e f d     YZ i d d g d 6d d g d 6d d g d 6d d g d 6d d g d 6d d g d  6d! d" g d# 6d$ d% g d& 6d' d( g d) 6d* d+ g d, 6d- d. g d/ 6d0 d1 g d2 6d3 d4 g d5 6d6 d7 g d8 6d9 d: g d; 6d< d= g d> 6d? d@ g dA 6dB dC g dD 6dE dF g dG 6dH dI g dJ 6Z e e j e j e j e j e j e j  e j! e j" e j# e j$ e j% e j& e j' e j( e j) e j* e j+ e j, g  Z- dK Z. d e/ f dL     YZ0 dM   Z1 e1 Z2 d S(N   s   Base class for sparse matricesi    (   t   divisiont   print_functiont   absolute_importN(   t   xrange(   t   broadcast_toi   (   t   isdenset   isscalarliket	   isintliket   get_sum_dtypet   validateaxist   check_reshape_kwargst   check_shapet   spmatrixt
   isspmatrixt   issparset   SparseWarningt   SparseEfficiencyWarningc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR      s   t   SparseFormatWarningc           B` s   e  Z RS(    (   R   R   (    (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR      s   c           B` s   e  Z RS(    (   R   R   (    (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR      s   s   Compressed Sparse Columnt   cscs   Compressed Sparse Rowt   csri   s   Dictionary Of Keyst   doki   s   LInked Listt   lili   s   Dictionary of Dictionariest   dodi   s   Symmetric Sparse Skylinet   sssi   t
   COOrdinatet   cooi   s   Linpack BAndedt   lbai   s#   Ellpack-itpack Generalized Diagonalt   egdi	   t   DIAgonalt   diai
   s   Block Sparse Rowt   bsri   s   Modified compressed Sparse Rowt   msri   s   Block Sparse Columnt   bsci   s!   Modified compressed Sparse Columnt   msci   s   Symmetric SKylinet   sski   s   Nonsymmetric SKylinet   nski   s   JAgged Diagonalt   jadi   s   Unsymmetric Sparse Skylinet   ussi   s   Variable Block Rowt   vbri   t	   Undefinedt   undi2   c           B` s  e  Z d  Z d Z d Z e d  Z d   Z d   Z e	 d e d e  Z
 d   Z d	   Z d
 e d  Z d   Z d   Z d   Z d   Z d\ d  Z e	 d    Z d   Z d   Z d   Z d   Z e Z d   Z e d  Z d   Z d   Z d   Z  d   Z! 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(   Z. d)   Z/ d*   Z0 d+   Z1 d,   Z2 d-   Z3 d.   Z4 d/   Z5 d0   Z6 d1   Z7 d2   Z8 d3   Z9 d4   Z: e e d5  Z; d6   Z< d7   Z= d8   Z> d9   Z? d:   Z@ d;   ZA d<   ZB d=   ZC d>   ZD d?   ZE d@   ZF dA   ZG d\ e dB  ZH e dC  ZI e dD  ZJ eI j eJ _ dE   ZK dF   ZL dG   ZM dH   ZN dI   ZO dJ   ZP d\ d\ dK  ZQ d\ d\ dL  ZR e dM  ZS e dN  ZT e dO  ZU e dP  ZV e dQ  ZW d\ e dR  ZX e dS  ZY dT   ZZ d\ d\ d\ dU  Z[ d\ d\ d\ dV  Z\ dW dX  Z] dW dY  Z^ dZ   Z_ d[   Z` RS(]   s    This class provides a base class for all sparse matrices.  It
    cannot be instantiated.  Most of the work is provided by subclasses.
    g333333$@i   c         C` s7   d  |  _ |  j j d k r* t d   n  | |  _ d  S(   NR   s7   This class is not intended to be instantiated directly.(   t   Nonet   _shapet	   __class__R   t
   ValueErrort   maxprint(   t   selfR/   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __init__H   s    	c         C` s1   |  j  | d t j |  j  } | j |  _ d S(   s   See `reshape`.t   copyN(   t   reshapet   Falset   asformatt   formatt   __dict__(   R0   t   shapet
   new_matrix(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt	   set_shapeO   s    !c         C` s   |  j  S(   s   Get shape of a matrix.(   R,   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt	   get_shapeV   s    t   fgett   fsetc         O` so   t  | |  j  } t |  \ } } | |  j k rJ | rC |  j   S|  Sn  |  j d |  j | d | d t S(   s  reshape(self, shape, order='C', copy=False)

        Gives a new shape to a sparse matrix without changing its data.

        Parameters
        ----------
        shape : length-2 tuple of ints
            The new shape should be compatible with the original shape.
        order : {'C', 'F'}, optional
            Read the elements using this index order. 'C' means to read and
            write the elements using C-like index order; e.g. read entire first
            row, then second row, etc. 'F' means to read and write the elements
            using Fortran-like index order; e.g. read entire first column, then
            second column, etc.
        copy : bool, optional
            Indicates whether or not attributes of self should be copied
            whenever possible. The degree to which attributes are copied varies
            depending on the type of sparse matrix being used.

        Returns
        -------
        reshaped_matrix : sparse matrix
            A sparse matrix with the given `shape`, not necessarily of the same
            format as the current object.

        See Also
        --------
        np.matrix.reshape : NumPy's implementation of 'reshape' for matrices
        R2   t   order(   R   R8   R
   R2   t   tocooR3   R4   (   R0   t   argst   kwargsR8   R>   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR3   \   s     
c         C` s"   t  d j t |   j    d S(   s  Resize the matrix in-place to dimensions given by ``shape``

        Any elements that lie within the new shape will remain at the same
        indices, while non-zero elements lying outside the new shape are
        removed.

        Parameters
        ----------
        shape : (int, int)
            number of rows and columns in the new matrix

        Notes
        -----
        The semantics are not identical to `numpy.ndarray.resize` or
        `numpy.resize`.  Here, the same data will be maintained at each index
        before and after reshape, if that index is within the new bounds.  In
        numpy, resizing maintains contiguity of the array, moving elements
        around in the logical matrix but not within a flattened representation.

        We give no guarantees about whether the underlying data attributes
        (arrays, etc.) will be modified in place or replaced with new objects.
        s   {}.resize is not implementedN(   t   NotImplementedErrorR6   t   typeR   (   R0   R8   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   resize   s    t   unsafec         C` sa   t  j |  } |  j | k rI |  j   j | d | d | j |  j  S| rY |  j   S|  Sd S(   s  Cast the matrix elements to a specified type.

        Parameters
        ----------
        dtype : string or numpy dtype
            Typecode or data-type to which to cast the data.
        casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
            Controls what kind of data casting may occur.
            Defaults to 'unsafe' for backwards compatibility.
            'no' means the data types should not be cast at all.
            'equiv' means only byte-order changes are allowed.
            'safe' means only casts which can preserve values are allowed.
            'same_kind' means only safe casts or casts within a kind,
            like float64 to float32, are allowed.
            'unsafe' means any data conversions may be done.
        copy : bool, optional
            If `copy` is `False`, the result might share some memory with this
            matrix. If `copy` is `True`, it is guaranteed that the result and
            this matrix do not share any memory.
        t   castingR2   N(   t   npt   dtypet   tocsrt   astypeR5   R6   R2   (   R0   RH   RF   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRJ      s    
c         C` sx   d d d d g } |  j  j | k r( |  Sx3 | D]+ } |  j  t j  |  k r/ |  j |  Sq/ Wt d |  j  j   d S(   s7   Upcast matrix to a floating point format (if necessary)t   ft   dt   Ft   Ds-   cannot upcast [%s] to a floating point formatN(   RH   t   charRG   RJ   t	   TypeErrort   name(   R0   t   fp_typest   fp_type(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   asfptype   s    c         c` s7   x0 t  |  j d  D] } |  | d  d   f Vq Wd  S(   Ni    (   R   R8   (   R0   t   r(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __iter__   s    c         C` s   |  j  S(   s3   Maximum number of elements to display when printed.(   R/   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   getmaxprint   s    c         C` s   t  d |  j j   d S(   s(  Number of non-zero entries, equivalent to

        np.count_nonzero(a.toarray())

        Unlike getnnz() and the nnz property, which return the number of stored
        entries (the length of the data attribute), this method counts the
        actual number of non-zero entries in data.
        s%   count_nonzero not implemented for %s.N(   RB   R-   R   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   count_nonzero   s    	c         C` s   t  d |  j j   d S(   sJ  Number of stored values, including explicit zeros.

        Parameters
        ----------
        axis : None, 0, or 1
            Select between the number of values across the whole matrix, in
            each column, or in each row.

        See also
        --------
        count_nonzero : Number of non-zero entries
        s   getnnz not implemented for %s.N(   RB   R-   R   (   R0   t   axis(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   getnnz   s    c         C` s
   |  j    S(   s   Number of stored values, including explicit zeros.

        See also
        --------
        count_nonzero : Number of non-zero entries
        (   RZ   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   nnz   s    c         C` s   t  |  d d  S(   s.   Format of a matrix representation as a string.R6   R*   (   t   getattr(   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt	   getformat   s    c         C` s7   t  |  j   \ } } d |  j |  j j |  j | f S(   NsH   <%dx%d sparse matrix of type '%s'
	with %d stored elements in %s format>(   t   _formatsR]   R8   RH   RC   R[   (   R0   t   _t   format_name(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __repr__  s    c         C` s   |  j    } |  j   } d   } |  j | k r | d } | | j |  | j |  | j |   } | d 7} | | d } | | | j | | j | | j |  7} n | | j | j | j  } | S(   Nc         S` sB   t  t t  |  |   |  } d j g  | D] } d | ^ q+  S(   Ns   
s     %s	%s(   t   zipt   listt   join(   t   rowt   colt   datat   triplest   t(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   tostr  s    i   s   
  :	:
(   RW   R?   R[   Re   Rf   Rg   (   R0   R/   t   ARj   t   halft   out(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __str__  s    	
'
1c         C` s,   |  j  d k r |  j d k St d   d  S(   Ni   i    s\   The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().(   i   i   (   R8   R[   R.   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __bool__  s    c         C` s   t  d   d  S(   Ns;   sparse matrix length is ambiguous; use getnnz() or shape[0](   RP   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __len__'  s    c         C` s   | d k s | |  j k r2 | r+ |  j   S|  Sni y t |  d |  } Wn& t k
 rq t d j |    n Xy | d |  SWn t k
 r |   SXd S(   s  Return this matrix in the passed format.

        Parameters
        ----------
        format : {str, None}
            The desired matrix format ("csr", "csc", "lil", "dok", "array", ...)
            or None for no conversion.
        copy : bool, optional
            If True, the result is guaranteed to not share data with self.

        Returns
        -------
        A : This matrix in the passed format.
        t   tos   Format {} is unknown.R2   N(   R+   R6   R2   R\   t   AttributeErrorR.   RP   (   R0   R6   R2   t   convert_method(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR5   +  s    
c         C` s   |  j    j |  S(   s4   Point-wise multiplication by another matrix
        (   RI   t   multiply(   R0   t   other(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRt   R  s    c         C` s   |  j    j |  S(   s5   Element-wise maximum between this and another matrix.(   RI   t   maximum(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRv   W  s    c         C` s   |  j    j |  S(   s5   Element-wise minimum between this and another matrix.(   RI   t   minimum(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRw   [  s    c         C` s   |  | S(   s1  Ordinary dot product

        Examples
        --------
        >>> import numpy as np
        >>> from scipy.sparse import csr_matrix
        >>> A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
        >>> v = np.array([1, 0, -1])
        >>> A.dot(v)
        array([ 1, -3, -1], dtype=int64)

        (    (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   dot_  s    c         C` s   |  j    j | d | S(   s   Element-wise power.RH   (   RI   t   power(   R0   t   nRH   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRy   n  s    c         C` s   |  j    j |  S(   N(   RI   t   __eq__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR{   r  s    c         C` s   |  j    j |  S(   N(   RI   t   __ne__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR|   u  s    c         C` s   |  j    j |  S(   N(   RI   t   __lt__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR}   x  s    c         C` s   |  j    j |  S(   N(   RI   t   __gt__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR~   {  s    c         C` s   |  j    j |  S(   N(   RI   t   __le__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   ~  s    c         C` s   |  j    j |  S(   N(   RI   t   __ge__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   t  |  j    S(   N(   t   absRI   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __abs__  s    c         C` s   |  j    j |  S(   N(   RI   t   _add_sparse(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j |  S(   N(   R?   t
   _add_dense(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j |  S(   N(   RI   t   _sub_sparse(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    | S(   N(   t   todense(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt
   _sub_dense  s    c         C` s   | |  j    S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   _rsub_dense  s    c         C` s   t  |  r1 | d k r" |  j   St d   ni t |  rk | j |  j k r^ t d   n  |  j |  St |  r t | |  j  } |  j	 |  St
 Sd  S(   Ni    s;   adding a nonzero scalar to a sparse matrix is not supporteds   inconsistent shapes(   R   R2   RB   R   R8   R.   R   R   R   R   t   NotImplemented(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __add__  s    
c         C` s   |  j  |  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __radd__  s    c         C` s   t  |  r1 | d k r" |  j   St d   ni t |  rk | j |  j k r^ t d   n  |  j |  St |  r t | |  j  } |  j	 |  St
 Sd  S(   Ni    sB   subtracting a nonzero scalar from a sparse matrix is not supporteds   inconsistent shapes(   R   R2   RB   R   R8   R.   R   R   R   R   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __sub__  s    
c         C` se   t  |  r2 | d k r# |  j   St d   n/ t |  r] t | |  j  } |  j |  St Sd  S(   Ni    sB   subtracting a sparse matrix from a nonzero scalar is not supported(   R   R2   RB   R   R   R8   R   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __rsub__  s    c         C` s  |  j  \ } } | j t j k r | j  | f k r@ |  j |  S| j  | d f k rt |  j | j    j | d  S| j d k r | j  d | k r |  j |  Sn  t	 |  r |  j
 |  St |  r|  j  d | j  d k r t d   n  |  j |  St j |  } | j d k r5| j t j k r5t Sy | j  Wn t k
 rY| } n X| j d k s| j d k r8| j  d d k r8| j  | f k r| j  | d f k rt d   n  |  j t j |   } t | t j  rt j |  } n  | j d k r4| j  d d k r4| j d d  } n  | S| j d k r| j  d |  j  d k rpt d   n  |  j t j |   } t | t j  rt j |  } n  | St d   d S(   s   interpret other and call one of the following

        self._mul_scalar()
        self._mul_vector()
        self._mul_multivector()
        self._mul_sparse_matrix()
        i   i   i    s   dimension mismatchis   could not interpret dimensionsN(   R8   R-   RG   t   ndarrayt   _mul_vectort   ravelR3   t   ndimt   _mul_multivectorR   t   _mul_scalarR   R.   t   _mul_sparse_matrixt
   asanyarrayRH   t   object_R   Rr   t
   isinstancet   matrixt   asmatrixt   asarray(   R0   Ru   t   Mt   Nt   other_at   result(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __mul__  sL    	"!
1'"c         C` s   |  j    j |  S(   N(   RI   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j |  S(   N(   RI   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j |  S(   N(   RI   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j |  S(   N(   RI   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` sj   t  |  r |  j |  Sy | j   } Wn& t k
 rQ t j |  j   } n X|  j   | j   Sd  S(   N(   R   R   t	   transposeRr   RG   R   (   R0   Ru   t   tr(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __rmul__  s    c         C` s(   t  |  r t d   n  |  j |  S(   Ns0   Scalar operands are not allowed, use '*' instead(   R   R.   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt
   __matmul__.  s    c         C` s(   t  |  r t d   n  |  j |  S(   Ns0   Scalar operands are not allowed, use '*' instead(   R   R.   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __rmatmul__4  s    c         C` s  t  |  r | rG | r. t j | |  j    St j | |  j    Sn  | r t j |  j t j  r |  j t j  j	 d |  S|  j	 d |  } t j
 |  j } t j |  j t j  r t j | t j  r | j |  j  S| Sn t |  rg| s2| rt j |  j   |  St j |  j   |  Sq| rNt j | |  j    St j | |  j    Sn t |  r| r| j |  | d t S|  j   } | rt j |  j t j  r| j t j  j |  S| j |  Sn t Sd  S(   Ng      ?t   rdivide(   R   RG   t   true_divideR   t   dividet   can_castRH   t   float_RJ   R   R   t
   issubdtypet   integerR   R   t   _divideR4   RI   t   _divide_sparseR   (   R0   Ru   R   R   RU   t   scalar_dtypet   self_csr(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   >  s:    c         C` s   |  j  | d t S(   NR   (   R   t   True(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __truediv__i  s    c         C` s   |  j  | d t S(   NR   (   R   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __div__l  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __rtruediv__p  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __rdiv__t  s    c         C` s   |  j    S(   N(   RI   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __neg__x  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __iadd__{  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __isub__~  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __imul__  s    c         C` s   |  j  |  S(   N(   t   __itruediv__(   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __idiv__  s    c         C` s   t  S(   N(   R   (   R0   Ru   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j  d |  j  d k r) t d   n  t |  r t |  } | d k  r\ t d   n  | d k r d d l m } | |  j  d d |  j S| d k r |  j   S|  j	 | d  } | d r |  | | S| | Sn t
 |  r t d   n t Sd  S(	   Ni    i   s   matrix is not squares   exponent must be >= 0(   t   eyeRH   i   s   exponent must be an integer(   R8   RP   R   t   intR.   t	   constructR   RH   R2   t   __pow__R   R   (   R0   Ru   R   t   tmp(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s$    

c         C` s   | d k r |  j    S| d k r, |  j   S| d k rB |  j   S| d k rX |  j   S| d k rn |  j   S| d k r |  j   St | d   d  S(   NRk   t   Tt   Ht   realt   imagt   sizes
    not found(   t   toarrayR   t   getHt   _realt   _imagRZ   Rr   (   R0   t   attr(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   __getattr__  s    





c         C` s"   |  j  d |  j d | d t  S(   s  
        Reverses the dimensions of the sparse matrix.

        Parameters
        ----------
        axes : None, optional
            This argument is in the signature *solely* for NumPy
            compatibility reasons. Do not pass in anything except
            for the default value.
        copy : bool, optional
            Indicates whether or not attributes of `self` should be
            copied whenever possible. The degree to which attributes
            are copied varies depending on the type of sparse matrix
            being used.

        Returns
        -------
        p : `self` with the dimensions reversed.

        See Also
        --------
        np.matrix.transpose : NumPy's implementation of 'transpose'
                              for matrices
        R2   t   axes(   RI   R   R4   (   R0   R   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` sL   t  j |  j t  j  r4 |  j d |  j d t  S| rD |  j   S|  Sd S(   s  Element-wise complex conjugation.

        If the matrix is of non-complex data type and `copy` is False,
        this method does nothing and the data is not copied.

        Parameters
        ----------
        copy : bool, optional
            If True, the result is guaranteed to not share data with self.

        Returns
        -------
        A : The element-wise complex conjugate.

        R2   N(   RG   R   RH   t   complexfloatingRI   t   conjR4   R2   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s
    
c         C` s   |  j  d |  S(   NR2   (   R   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt	   conjugate  s    c         C` s   |  j    j   S(   s   Return the Hermitian transpose of this matrix.

        See Also
        --------
        np.matrix.getH : NumPy's implementation of `getH` for matrices
        (   R   R   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j   S(   N(   RI   R   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j    j   S(   N(   RI   R   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s3   |  j    } | j d k } | j | | j | f S(   sg  nonzero indices

        Returns a tuple of arrays (row,col) containing the indices
        of the non-zero elements of the matrix.

        Examples
        --------
        >>> from scipy.sparse import csr_matrix
        >>> A = csr_matrix([[1,2,0],[0,0,3],[4,0,5]])
        >>> A.nonzero()
        (array([0, 0, 1, 2, 2]), array([0, 1, 2, 0, 2]))

        i    (   R?   Rg   Re   Rf   (   R0   Rk   t   nz_mask(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   nonzero  s    c         C` s   d d l  m } |  j d } | d k  r6 | | 7} n  | d k  sN | | k r] t d   n  | d g | g d g g f d | d f d |  j } |  | S(   sg   Returns a copy of column j of the matrix, as an (m x 1) sparse
        matrix (column vector).
        i   (   t
   csc_matrixi    s   index out of boundsR8   RH   (   R   R   R8   t
   IndexErrorRH   (   R0   t   jR   Rz   t   col_selector(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   getcol  s    c         C` s   d d l  m } |  j d } | d k  r6 | | 7} n  | d k  sN | | k r] t d   n  | d g d g | g g f d d | f d |  j } | |  S(   s`   Returns a copy of row i of the matrix, as a (1 x n) sparse
        matrix (row vector).
        i   (   t
   csr_matrixi    s   index out of boundsR8   RH   (   R   R   R8   R   RH   (   R0   t   iR   t   mt   row_selector(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   getrow  s    c         C` s   t  j |  j d | d |   S(   s  
        Return a dense matrix representation of this matrix.

        Parameters
        ----------
        order : {'C', 'F'}, optional
            Whether to store multi-dimensional data in C (row-major)
            or Fortran (column-major) order in memory. The default
            is 'None', indicating the NumPy default of C-ordered.
            Cannot be specified in conjunction with the `out`
            argument.

        out : ndarray, 2-dimensional, optional
            If specified, uses this array (or `numpy.matrix`) as the
            output buffer instead of allocating a new array to
            return. The provided array must have the same shape and
            dtype as the sparse matrix on which you are calling the
            method.

        Returns
        -------
        arr : numpy.matrix, 2-dimensional
            A NumPy matrix object with the same shape and containing
            the same data represented by the sparse matrix, with the
            requested memory order. If `out` was passed and was an
            array (rather than a `numpy.matrix`), it will be filled
            with the appropriate values and returned wrapped in a
            `numpy.matrix` object that shares the same memory.
        R>   Rm   (   RG   R   R   (   R0   R>   Rm   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   3  s    c         C` s"   |  j  d t  j d | d |  S(   s  
        Return a dense ndarray representation of this matrix.

        Parameters
        ----------
        order : {'C', 'F'}, optional
            Whether to store multi-dimensional data in C (row-major)
            or Fortran (column-major) order in memory. The default
            is 'None', indicating the NumPy default of C-ordered.
            Cannot be specified in conjunction with the `out`
            argument.

        out : ndarray, 2-dimensional, optional
            If specified, uses this array as the output buffer
            instead of allocating a new array to return. The provided
            array must have the same shape and dtype as the sparse
            matrix on which you are calling the method. For most
            sparse types, `out` is required to be memory contiguous
            (either C or Fortran ordered).

        Returns
        -------
        arr : ndarray, 2-dimensional
            An array with the same shape and containing the same
            data represented by the sparse matrix, with the requested
            memory order. If `out` was passed, the same object is
            returned after being modified in-place to contain the
            appropriate values.
        R2   R>   Rm   (   R?   R4   R   (   R0   R>   Rm   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   S  s    c         C` s   |  j  d |  j d t  S(   s   Convert this matrix to Compressed Sparse Row format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant csr_matrix.
        R2   (   R?   RI   R4   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyRI   v  s    c         C` s   |  j  d |  j d t  S(   s   Convert this matrix to Dictionary Of Keys format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant dok_matrix.
        R2   (   R?   t   todokR4   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   ~  s    c         C` s   |  j  d t  j d |  S(   s   Convert this matrix to COOrdinate format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant coo_matrix.
        R2   (   RI   R4   R?   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR?     s    c         C` s   |  j  d t  j d |  S(   s   Convert this matrix to LInked List format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant lil_matrix.
        R2   (   RI   R4   t   tolil(   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j  d |  j d t  S(   s   Convert this matrix to sparse DIAgonal format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant dia_matrix.
        R2   (   R?   t   todiaR4   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s"   |  j  d t  j d | d |  S(   s  Convert this matrix to Block Sparse Row format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant bsr_matrix.

        When blocksize=(R, C) is provided, it will be used for construction of
        the bsr_matrix.
        R2   t	   blocksize(   RI   R4   t   tobsr(   R0   R   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    	c         C` s   |  j  d |  j d t  S(   s   Convert this matrix to Compressed Sparse Column format.

        With copy=False, the data/indices may be shared between this matrix and
        the resultant csc_matrix.
        R2   (   RI   t   tocscR4   (   R0   R2   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    c         C` s   |  j  |  d t S(   s   Returns a copy of this matrix.

        No data/indices will be shared between the returned value and current
        matrix.
        R2   (   R-   R   (   R0   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR2     s    c         C` s-  t  |  |  j \ } } t |  j  } | d k rl |  t j t j | d f d |  j d | d |  S| d k  r | d 7} n  | d k r t j t j d | f d |  |  } n( |  t j t j | d f d |  } | d k	 r| j | j k rt	 d   n  | j d d	 d | d |  S(
   ss  
        Sum the matrix elements over a given axis.

        Parameters
        ----------
        axis : {-2, -1, 0, 1, None} optional
            Axis along which the sum is computed. The default is to
            compute the sum of all the matrix elements, returning a scalar
            (i.e. `axis` = `None`).
        dtype : dtype, optional
            The type of the returned matrix and of the accumulator in which
            the elements are summed.  The dtype of `a` is used by default
            unless `a` has an integer dtype of less precision than the default
            platform integer.  In that case, if `a` is signed then the platform
            integer is used while if `a` is unsigned then an unsigned integer
            of the same precision as the platform integer is used.

            .. versionadded:: 0.18.0

        out : np.matrix, optional
            Alternative output matrix in which to place the result. It must
            have the same shape as the expected output, but the type of the
            output values will be cast if necessary.

            .. versionadded:: 0.18.0

        Returns
        -------
        sum_along_axis : np.matrix
            A matrix with the same shape as `self`, with the specified
            axis removed.

        See Also
        --------
        np.matrix.sum : NumPy's implementation of 'sum' for matrices

        i   RH   Rm   i    i   s   dimensions do not matchRY   N(    (
   R	   R8   R   RH   R+   RG   R   t   onest   sumR.   (   R0   RY   RH   Rm   R   Rz   t	   res_dtypet   ret(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s"    &
	c   	      C` sE  d   } t  |  |  j j } | |  j  } | d	 k rO | ra t j } qa n t j |  j } | rp t j n | } |  j |  } | d	 k r | t j |  j d |  j d  j	 d | d |  S| d k  r | d 7} n  | d k r| d |  j d j	 d d d | d |  S| d |  j d j	 d d d | d |  Sd	 S(
   s  
        Compute the arithmetic mean along the specified axis.

        Returns the average of the matrix elements. The average is taken
        over all elements in the matrix by default, otherwise over the
        specified axis. `float64` intermediate and return values are used
        for integer inputs.

        Parameters
        ----------
        axis : {-2, -1, 0, 1, None} optional
            Axis along which the mean is computed. The default is to compute
            the mean of all elements in the matrix (i.e. `axis` = `None`).
        dtype : data-type, optional
            Type to use in computing the mean. For integer inputs, the default
            is `float64`; for floating point inputs, it is the same as the
            input dtype.

            .. versionadded:: 0.18.0

        out : np.matrix, optional
            Alternative output matrix in which to place the result. It must
            have the same shape as the expected output, but the type of the
            output values will be cast if necessary.

            .. versionadded:: 0.18.0

        Returns
        -------
        m : np.matrix

        See Also
        --------
        np.matrix.mean : NumPy's implementation of 'mean' for matrices

        c         S` s(   t  j |  t  j  p' t  j |  t  j  S(   N(   RG   R   R   t   bool_(   RH   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   _is_integral&  s    i    i   RH   Rm   i   g      ?RY   N(
   R	   RH   RC   R+   RG   t   float64RJ   t   arrayR8   R   (	   R0   RY   RH   Rm   R   R   t   integralt   inter_dtypet
   inter_self(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   mean  s*    %	
	i    c         C` s   |  j    j d |  S(   sU  Returns the k-th diagonal of the matrix.

        Parameters
        ----------
        k : int, optional
            Which diagonal to set, corresponding to elements a[i, i+k].
            Default: 0 (the main diagonal).

            .. versionadded:: 1.0

        See also
        --------
        numpy.diagonal : Equivalent numpy function.

        Examples
        --------
        >>> from scipy.sparse import csr_matrix
        >>> A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
        >>> A.diagonal()
        array([1, 0, 5])
        >>> A.diagonal(k=1)
        array([2, 3])
        t   k(   RI   t   diagonal(   R0   R   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   J  s    c         C` sl   |  j  \ } } | d k r' | | k s@ | d k  rO | | k rO t d   n  |  j t j |  |  d S(   s  
        Set diagonal or off-diagonal elements of the array.

        Parameters
        ----------
        values : array_like
            New values of the diagonal elements.

            Values may have any length.  If the diagonal is longer than values,
            then the remaining diagonal entries will not be set.  If values if
            longer than the diagonal, then the remaining values are ignored.

            If a scalar value is given, all of the diagonal is set to it.

        k : int, optional
            Which off-diagonal to set, corresponding to elements a[i,i+k].
            Default: 0 (the main diagonal).

        i    s   k exceeds matrix dimensionsN(   R8   R.   t   _setdiagRG   R   (   R0   t   valuesR   R   R   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   setdiagd  s    1c         C` s  |  j  \ } } | d k  r | j d k rk t | | |  } x t |  D] } | |  | | | f <qJ Wqt | | | t |   } | d k r d  Sx t | |   D]  \ } } | |  | | | f <q Wn | j d k rt | | |  } x t |  D] } | |  | | | f <q Wna t | | | t |   } | d k rKd  Sx2 t | |   D]  \ } } | |  | | | f <q\Wd  S(   Ni    (   R8   R   t   minR   t   lent	   enumerate(   R0   R   R   R   R   t	   max_indexR   t   v(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   }  s(    c         C` s   | d  k	 rh | d  k	 r' t d   n  | j |  j k sK | j |  j k rZ t d   n  d | d <| St j |  j d |  j d | Sd  S(   Ns,   order cannot be specified if out is not Nones7   out array must be same dtype and shape as sparse matrixg        .RH   R>   (   R+   R.   R8   RH   RG   t   zeros(   R0   R>   Rm   (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   _process_toarray_args  s    $
N(a   R   R   t   __doc__t   __array_priority__R   t   MAXPRINTR1   R:   R;   t   propertyR8   R3   RD   R   RJ   RT   RV   RW   RX   R+   RZ   R[   R]   Ra   Rn   Ro   t   __nonzero__Rp   R4   R5   Rt   Rv   Rw   Rx   Ry   R{   R|   R}   R~   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   RI   R   R?   R   R   R   R   R2   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR   @   s   			*					
					'																					L							
+																			 #	HI	c         C` s   t  |  t  S(   s  Is x of a sparse matrix type?

    Parameters
    ----------
    x
        object to check for being a sparse matrix

    Returns
    -------
    bool
        True if x is a sparse matrix, False otherwise

    Notes
    -----
    issparse and isspmatrix are aliases for the same function.

    Examples
    --------
    >>> from scipy.sparse import csr_matrix, isspmatrix
    >>> isspmatrix(csr_matrix([[5]]))
    True

    >>> from scipy.sparse import isspmatrix
    >>> isspmatrix(5)
    False
    (   R   R   (   t   x(    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyR     s    (3   R   t
   __future__R    R   R   t   syst   numpyRG   t   scipy._lib.sixR   t   scipy._lib._numpy_compatR   t   sputilsR   R   R   R   R	   R
   R   t   __all__t   WarningR   R   R   R^   t	   frozensett   sint   tant   arcsint   arctant   sinht   tanht   arcsinht   arctanht   rintt   signt   expm1t   log1pt   deg2radt   rad2degt   floort   ceilt   trunct   sqrtt    _ufuncs_with_fixed_point_at_zeroR   t   objectR   R   R   (    (    (    s0   lib/python2.7/site-packages/scipy/sparse/base.pyt   <module>   sV   4	*$'    j	