Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions easygraph/functions/drawing/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ def vlen(vector):


def common_tangent_radian(r1, r2, d):
if r1 < 0 or r2 < 0:
raise ValueError("Circle radii must be non-negative.")
if d <= 0 or d < abs(r2 - r1):
raise ValueError("No common tangent exists for the given circles.")
value = abs(r2 - r1) / d
if value > 1.0: value = 1.0
elif value < -1.0: value = -1.0
if value > 1.0:
value = 1.0
elif value < -1.0:
value = -1.0
alpha = math.acos(value)
alpha = alpha if r1 > r2 else pi - alpha
return alpha
Expand Down
4 changes: 4 additions & 0 deletions easygraph/functions/structural_holes/NOBE.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def NOBE_SH(G, K, topk):
raise ValueError("Embedding dimension K must be a positive integer.")
if topk <= 0:
raise ValueError("Parameter topk must be a positive integer.")
if G.number_of_nodes() == 0:
raise ValueError("NOBE_SH is not defined for an empty graph.")
from sklearn.cluster import KMeans

Y = eg.graph_embedding.NOBE(G, K)
Expand Down Expand Up @@ -109,6 +111,8 @@ def NOBE_GA_SH(G, K, topk):
raise ValueError("Embedding dimension K must be a positive integer.")
if topk <= 0:
raise ValueError("Parameter topk must be a positive integer.")
if G.number_of_nodes() == 0:
raise ValueError("NOBE_GA_SH is not defined for an empty graph.")
from sklearn.cluster import KMeans

Y = eg.NOBE_GA(G, K)
Expand Down
3 changes: 2 additions & 1 deletion easygraph/readwrite/gexf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ def construct_types(self):
except ImportError:
pass
else:
np_float = getattr(np, "float_", np.float64)
# prepend so that python types are created upon read (last entry wins)
types = [
(np.float64, "float"),
(np.float32, "float"),
(np.float16, "float"),
(np.float_, "float"),
(np_float, "float"),
(np.int_, "int"),
(np.int8, "int"),
(np.int16, "int"),
Expand Down
5 changes: 3 additions & 2 deletions easygraph/readwrite/graphml.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,16 @@ def construct_types(self):
# These additions to types allow writing numpy types
try:
import numpy as np
except:
except ImportError:
pass
else:
np_float = getattr(np, "float_", np.float64)
# prepend so that python types are created upon read (last entry wins)
types = [
(np.float64, "float"),
(np.float32, "float"),
(np.float16, "float"),
(np.float_, "float"),
(np_float, "float"),
(np.int_, "int"),
(np.int8, "int"),
(np.int16, "int"),
Expand Down
3 changes: 2 additions & 1 deletion easygraph/readwrite/tests/test_graphml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,8 @@ def test_mixed_int_type_number_attributes(self):

def test_numpy_float(self):
np = pytest.importorskip("numpy")
wt = np.float_(3.4)
np_float = getattr(np, "float_", np.float64)
wt = np_float(3.4)
G = eg.Graph([(1, 2, {"weight": wt})])
fd, fname = tempfile.mkstemp()
self.writer(G, fname)
Expand Down
Loading