a
    Re                     @   sF   d Z ddgZddl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   )issparse)	csr_array)csr_count_blocksffffff?c           
      C   s`  t | r| jdv st| } | jdkr(dS d|  k r<dk sFn 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rJdS ||krXd	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
    )csccsr    )r   r   g      ?z.efficiency must satisfy 0.0 < efficiency < 1.0g       @      )r   r   g           	   )r   r   $   )   r      )r   r   N)r   formatr   nnz
ValueErrorfloatshaper   )
AZ
efficiencyZhigh_efficiencyr   MNZe22Ze33Ze66Ze44 r   I/var/www/sunrise/env/lib/python3.9/site-packages/scipy/sparse/_spfuncs.pyr      s<    





c                 C   sz   |\}}|dk s|dk r t dt| rl| jdkrR| j\}}t||||| j| jS | jdkrlt| j||fS tt	| |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 positiver	   r   )
r   r   r   r   r   Zindptrindicesr   Tr   )r   	blocksizercr   r   r   r   r   r   >   s    


N)r   )
__doc____all___baser   Z_csrr   Z_sparsetoolsr   r   r   r   r   r   r   <module>   s   
3