Skip to content

Commit ede03b2

Browse files
committed
Use require and not_implemented_for decorators.
1 parent a775a66 commit ede03b2

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

networkx/linalg/laplacianmatrix.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# All rights reserved.
99
# BSD license.
1010
import networkx as nx
11+
from networkx.utils import require, not_implemented_for
12+
1113
__author__ = "\n".join(['Aric Hagberg (hagberg@lanl.gov)',
1214
'Pieter Swart (swart@lanl.gov)',
1315
'Dan Schult(dschult@colgate.edu)'])
@@ -173,6 +175,9 @@ def normalized_laplacian_matrix(G, nodelist=None, weight='weight'):
173175
# Code based on
174176
# https://bitbucket.org/bedwards/networkx-community/src/370bd69fc02f/networkx/algorithms/community/
175177

178+
@require('numpy')
179+
@not_implemented_for('undirected')
180+
@not_implemented_for('multigraph')
176181
def directed_laplacian(G, nodelist=None, weight='weight', walk_type=None, alpha=0.95):
177182
r"""Return the directed Laplacian matrix of G.
178183
@@ -215,6 +220,13 @@ def directed_laplacian(G, nodelist=None, weight='weight', walk_type=None, alpha=
215220
L : NumPy array
216221
Normalized Laplacian of G.
217222
223+
Raises
224+
------
225+
NetworkXError
226+
If NumPy cannot be imported
227+
NetworkXNotImplemnted
228+
If G is not a DiGraph
229+
218230
Notes
219231
-----
220232
Only implemented for DiGraphs
@@ -228,14 +240,7 @@ def directed_laplacian(G, nodelist=None, weight='weight', walk_type=None, alpha=
228240
.. [1] Fan Chung (2005). Laplacians and the Cheeger inequality for directed
229241
graphs. Annals of Combinatorics, 9(1), 2005
230242
"""
231-
try:
232-
import numpy as np
233-
except ImportError:
234-
raise ImportError(
235-
"normalized_laplacian() requires numpy: http://scipy.org/ ")
236-
237-
if not nx.is_directed(G):
238-
raise nx.NetworkXError('G must be a DiGraph')
243+
import numpy as np
239244

240245
if walk_type is None:
241246
if nx.is_strongly_connected(G):

0 commit comments

Comments
 (0)