Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #33562: better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Jun 6, 2022
1 parent 5fb2a6e commit aaabe1d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,19 @@ def weighted_adjacency_matrix(self, sparse=True, vertices=None, *, base_ring=Non
[0 0 0]
[1 0 0]
[1 0 0]

Check error message for non numerical edge weights (:trac:`33562`)::

sage: G = Graph([(0, 1)])
sage: G.weighted_adjacency_matrix()
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of (0, 1, None)
sage: G = Graph([(0, 1, 'a')])
sage: G.weighted_adjacency_matrix()
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of (0, 1, 'a')
"""
if self.has_multiple_edges():
raise NotImplementedError("don't know how to represent weights for a multigraph")
Expand All @@ -2395,6 +2408,15 @@ def weighted_adjacency_matrix(self, sparse=True, vertices=None, *, base_ring=Non
set(vertices) != set(self.vertex_iterator())):
raise ValueError("``vertices`` must be a permutation of the vertices")

# Check the edge weights
if base_ring is None:
def weight_function(e):
return e[2]
else:
def weight_function(e):
return base_ring(e[2])
self._check_weight_function(weight_function)

new_indices = {v: i for i,v in enumerate(vertices)}

D = {}
Expand Down

0 comments on commit aaabe1d

Please sign in to comment.