# Source code for sknetwork.utils.format

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Apr 8, 2019
@author: Nathan de Lara <ndelara@enst.fr>
"""
from typing import Union

import numpy as np
from scipy import sparse

from sknetwork.linalg.sparse_lowrank import SparseLR

"""Check if input is csr or SparseLR and raise an error otherwise."""
if type(adjacency) not in [sparse.csr_matrix, SparseLR]:
raise TypeError('Input must be a scipy CSR matrix or a SparseLR object.')
else:
return

weighted: bool = True) -> Union[sparse.csr_matrix, SparseLR]:
"""Adjacency matrix of the undirected graph associated with some directed graph.

The new adjacency matrix becomes either:

:math:A+A^T (default)

or

:math:\\max(A,A^T)

If the initial adjacency matrix :math:A is binary, bidirectional edges have weight 2
(first method, default) or 1 (second method).

Parameters
----------
weighted :
If True, return the sum of the weights in both directions of each edge.

Returns
-------
New adjacency matrix (same format as input).
"""
if weighted:
else:
else:
if weighted:
new_tuples = [(y, x) for (x, y) in adjacency.low_rank_tuples]
else:
raise ValueError('This function only works with weighted=True for SparseLR objects.')

[docs]def bipartite2directed(biadjacency: Union[sparse.csr_matrix, SparseLR]) -> Union[sparse.csr_matrix, SparseLR]:
"""Adjacency matrix of the directed graph associated with a bipartite graph
(with edges from one part to the other).

:math:A  = \\begin{bmatrix} 0 & B \\\\ 0 & 0 \\end{bmatrix}

where :math:B is the biadjacency matrix.

Parameters
----------

Returns
-------
Adjacency matrix (same format as input).
"""
else:
new_tuples = [(np.hstack((x, np.zeros(n_col))), np.hstack((np.zeros(n_row), y)))

[docs]def bipartite2undirected(biadjacency: Union[sparse.csr_matrix, SparseLR]) -> Union[sparse.csr_matrix, SparseLR]:

:math:A  = \\begin{bmatrix} 0 & B \\\\ B^T & 0 \\end{bmatrix}

where :math:B is the biadjacency matrix of the bipartite graph.

Parameters
----------

Returns
-------
Adjacency matrix (same format as input).
"""