U
    td                     @   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	rt||jrt	| ||dS |dk	rt||j
r|j }	|j}nd}	|dk	rt||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	rt||jrt	| ||||dS |dk	rt||j
r|j }	|j}nd}	|dk	rt||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
   
?     