U
    Ñtœdç  ã                   @   s(   d dl mZmZ d
dd„Zddd„Zd	S )é    )Ú_graph_from_sparse_matrixÚ"_graph_from_weighted_sparse_matrixÚdirectedc                 O   s  ddl m} zddl}W n tk
r0   d}Y nX zddlm} W n tk
rZ   d}Y nX zddl}W n tk
r€   d}Y nX |dk	r¤t||jƒr¤t	| ||d�S |dk	rÊt||j
ƒrÊ|j ¡ }	|j}nd}	|dk	rêt||jƒrê| ¡ }t|| ƒj||d�}
|	dk	�r|	|
jd< |
S )a€  Generates a graph from its adjacency matrix.

    @param matrix: the adjacency matrix. Possible types are:
      - a list of lists
      - a numpy 2D array or matrix (will be converted to list of lists)
      - a scipy.sparse matrix (will be converted to a COO matrix, but not
        to a dense matrix)
      - a pandas.DataFrame (column/row names must match, and will be used
        as vertex names).
    @param mode: the mode to be used. Possible values are:
      - C{"directed"} - the graph will be directed and a matrix
        element gives the number of edges between two vertex.
      - C{"undirected"} - alias to C{"max"} for convenience.
      - C{"max"} - undirected graph will be created and the number of
        edges between vertex M{i} and M{j} is M{max(A(i,j), A(j,i))}
      - C{"min"} - like C{"max"}, but with M{min(A(i,j), A(j,i))}
      - C{"plus"}  - like C{"max"}, but with M{A(i,j) + A(j,i)}
      - C{"upper"} - undirected graph with the upper right triangle of
        the matrix (including the diagonal)
      - C{"lower"} - undirected graph with the lower left triangle of
        the matrix (including the diagonal)
    r   ©ÚGraphN©Úsparse)ÚmodeÚname)Úigraphr   ÚnumpyÚImportErrorÚscipyr   ÚpandasÚ
isinstanceÚspmatrixr   Ú	DataFrameÚindexÚtolistÚvaluesÚndarrayÚsuperZ	AdjacencyÚvs)ÚclsÚmatrixr	   ÚargsÚkwargsr   Únpr   ÚpdÚvertex_namesÚgraph© r!   úL/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/io/adjacency.pyÚ_construct_graph_from_adjacency   s2    





r#   ÚweightTc                 C   s*  ddl m} zddl}W n tk
r0   d}Y nX zddlm} W n tk
rZ   d}Y nX zddl}W n tk
r€   d}Y nX |dk	r¨t||jƒr¨t	| ||||d�S |dk	rÎt||j
ƒrÎ|j ¡ }	|j}nd}	|dk	rît||jƒrî| ¡ }t|| ƒj|||d�\}
}||
j|< |	dk	�r&|	|
jd< |
S )aF  Generates a graph from its weighted adjacency matrix.

    @param matrix: the adjacency matrix. Possible types are:
      - a list of lists
      - a numpy 2D array or matrix (will be converted to list of lists)
      - a scipy.sparse matrix (will be converted to a COO matrix, but not
        to a dense matrix)
    @param mode: the mode to be used. Possible values are:
      - C{"directed"} - the graph will be directed and a matrix
        element gives the number of edges between two vertex.
      - C{"undirected"} - alias to C{"max"} for convenience.
      - C{"max"}   - undirected graph will be created and the number of
        edges between vertex M{i} and M{j} is M{max(A(i,j), A(j,i))}
      - C{"min"}   - like C{"max"}, but with M{min(A(i,j), A(j,i))}
      - C{"plus"}  - like C{"max"}, but with M{A(i,j) + A(j,i)}
      - C{"upper"} - undirected graph with the upper right triangle of
        the matrix (including the diagonal)
      - C{"lower"} - undirected graph with the lower left triangle of
        the matrix (including the diagonal)

      These values can also be given as strings without the C{ADJ} prefix.
    @param attr: the name of the edge attribute that stores the edge
      weights.
    @param loops: whether to include loop edges. When C{False}, the diagonal
      of the adjacency matrix will be ignored.

    r   r   Nr   )r	   ÚattrÚloops)r	   r&   r
   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z_Weighted_AdjacencyÚesr   )r   r   r	   r%   r&   r   r   r   r   r   r    Úweightsr!   r!   r"   Ú(_construct_graph_from_weighted_adjacencyE   sH    


û

ý



r)   N)r   )r   r$   T)Zigraph.sparse_matrixr   r   r#   r)   r!   r!   r!   r"   Ú<module>   s
   
?     ÿ