U
    Gvf                     @   sJ   d Z ddgZddlmZmZ ddlmZ ddlmZ dddZ	d	d Z
d
S )z+ Functions that operate on sparse matrices
count_blocksestimate_blocksize   )isspmatrix_csr
csr_matrix)isspmatrix_csc)csr_count_blocksffffff?c           
      C   s^  t | st| st| } | jdkr&dS d|  k r:dk sDn t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r||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rHdS ||krVd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       @      )r
   r
   g           	   )r   r   $   )   r      )r   r   N)r   r   r   nnz
ValueErrorfloatshaper   )
AZ
efficiencyZhigh_efficiencyr   MNZe22Ze33Ze66Ze44 r   9/tmp/pip-unpacked-wheel-96ln3f52/scipy/sparse/_spfuncs.pyr      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   >   s    
N)r   )__doc____all__Z_csrr   r   Z_cscr   Z_sparsetoolsr   r   r   r   r   r   r   <module>   s   
3