o
    wTh                     @   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   sV  t | r	| jdv st| } | jdkrdS d|  k r!dk s&td tdd| d }t| j}| j\}}|d dkrL|d dkrL|dt| d	  }nd
}|d dkrd|d dkrd|dt| d  }nd
}||kr||kr|dt| d  }||kr}dS dS |d dkr|d dkr|dt| d  }	nd
}	|	|krdS ||krdS ||krd	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   )r   formatr   nnz
ValueErrorfloatshaper   )
A
efficiencyhigh_efficiencyr   MNe22e33e66e44 r    V/home/air/segue/gemini/back/venv/lib/python3.10/site-packages/scipy/sparse/_spfuncs.pyr      s@   


c                 C   sz   |\}}|dk s|dk rt dt| r6| jdkr)| j\}}t||||| j| jS | jdkr6t| 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   indptrindicesr   Tr   )r   	blocksizercr   r   r    r    r!   r   >   s   


N)r   )
__doc____all___baser   _csrr   _sparsetoolsr   r   r   r    r    r    r!   <module>   s    
3