def test_to_undirected(self): spA = SparseGraph(self.A) spA.to_undirected() resA = sp.csr_matrix( np.array([[1., 0., 0.5, 0., 0.], [0., 1., 1., 0., 1.], [0.5, 1., 1., 1., 0.], [0., 0., 1., 0., 2.], [0., 1., 0., 2., 0.]])) assert np.allclose(spA.adj_matrix.A, resA.A)
def test_to_undirected_edgeattrs(self): edge_attrs = np.array([0, 1, 2, 3, 1, 5, 6, 7, 8]) spA = SparseGraph(self.A, edge_attr_matrix=edge_attrs) spA.to_undirected() resA = sp.csr_matrix( np.array([[1., 0., 0.5, 0., 0.], [0., 1., 1., 0., 1.], [0.5, 1., 1., 1., 0.], [0., 0., 1., 0., 2.], [0., 1., 0., 2., 0.]])) res_edge_attrs = np.array([0, 1, 2, 3, 8, 1, 3, 5, 6, 6, 7, 8, 7]) assert np.allclose(spA.adj_matrix.A, resA.A) assert np.allclose(spA.edge_attr_matrix, res_edge_attrs)
def test_to_undirected_edgeattrs_contradiction(self): edge_attrs = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8]) spA = SparseGraph(self.A, edge_attr_matrix=edge_attrs) with pytest.raises(ValueError): spA.to_undirected()
def test_to_undirected_contradiction(self): self.A[0, 2] = 0.2 spA = SparseGraph(self.A) with pytest.raises(ValueError): spA.to_undirected()