o
    Ö­jÃ  ã                   @   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_blocksçffffffæ?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r�dS ||kr£dS ||kr©d	S dS )z—Attempt 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    úR/var/www/html/CropPilot/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