3

6^                 @   sf   d Z ddlmZmZmZ ddgZddlmZmZ ddl	m
Z
 ddlmZ d	d
 ZdddZdd ZdS )z+ Functions that operate on sparse matrices
    )divisionprint_functionabsolute_importcount_blocksestimate_blocksize   )isspmatrix_csr
csr_matrix)isspmatrix_csc)csr_count_blocksc             C   s   t dd S )Nzuse .diagonal() instead)NotImplementedError)A r   5/tmp/pip-build-vw4w4j08/scipy/scipy/sparse/spfuncs.pyextract_diagonal   s    r   ffffff?c       
      C   sd  t | pt| st| } | jdkr&dS d|  k o8dk n  sFtdd| d }t| j}| j\}}|d dkr|d dkr|dt| d  }nd}|d	 dkr|d	 dkr|d
t| d  }nd}||ko||k r|dt| d  }||k rdS dS nb|d dkr.|d dkr.|dt| d  }	nd}	|	|kr@dS ||krNdS ||kr\dS dS dS )zAttempt to determine the blocksize of a sparse matrix

    Returns a blocksize=(r,c) such that
        - A.nnz / A.tobsr( (r,c) ).nnz > efficiency
    r   r   g      ?z.efficiency must satisfy 0.0 < efficiency < 1.0g       @      g           	   $         N)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	   nnz
ValueErrorfloatshaper   )
r   Z
efficiencyZhigh_efficiencyr   MNZe22Ze33Ze66Ze44r   r   r   r   #   s<    






c             C   sr   |\}}|dk s|dk r t dt| rH| j\}}t||||| j| jS t| r`t| j||fS tt	| |S dS )z]For a given blocksize=(r,c) count the number of occupied
    blocks in a sparse matrix A
    r   zr and c must be positiveN)
r   r   r   r   Zindptrindicesr
   r   Tr	   )r   	blocksizercr   r   r   r   r   r   V   s    
N)r   )__doc__
__future__r   r   r   __all__Zcsrr   r	   Zcscr
   Z_sparsetoolsr   r   r   r   r   r   r   r   <module>   s   
3