Skip to content

Commit e505c68

Browse files
committed
fix: Fix the bugs when importing gedlibpy.py.
1 parent 8cbfea2 commit e505c68

File tree

7 files changed

+1608
-17
lines changed

7 files changed

+1608
-17
lines changed

gklearn/ged/median/test_median_graph_estimator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def test_median_graph_estimator():
1010
from gklearn.utils import load_dataset
1111
from gklearn.ged.median import MedianGraphEstimator, constant_node_costs
12-
from gklearn.gedlib import librariesImport, gedlibpy
12+
from gklearn.gedlib import libraries_import, gedlibpy
1313
from gklearn.preimage.utils import get_same_item_indices
1414
import multiprocessing
1515

@@ -83,7 +83,7 @@ def test_median_graph_estimator():
8383
def test_median_graph_estimator_symb():
8484
from gklearn.utils import load_dataset
8585
from gklearn.ged.median import MedianGraphEstimator, constant_node_costs
86-
from gklearn.gedlib import librariesImport, gedlibpy
86+
from gklearn.gedlib import libraries_import, gedlibpy
8787
from gklearn.preimage.utils import get_same_item_indices
8888
import multiprocessing
8989

gklearn/ged/util/util.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def compute_ged(g1, g2, options):
2828
- # of edit operations are not computed in this method.
2929
3030
"""
31-
from gklearn.gedlib import librariesImport, gedlibpy
31+
from gklearn.gedlib import libraries_import, gedlibpy
3232

3333
ged_env = gedlibpy.GEDEnv()
3434
ged_env.set_edit_cost(
@@ -375,7 +375,7 @@ def _compute_geds_without_permutation(
375375
-----
376376
- # of edit operations are computed in this method.
377377
"""
378-
from gklearn.gedlib import librariesImport, gedlibpy
378+
from gklearn.gedlib import libraries_import, gedlibpy
379379

380380
# initialize ged env.
381381
ged_env = gedlibpy.GEDEnv()
@@ -626,19 +626,25 @@ def get_nb_edit_operations(
626626
g1, g2, forward_map, backward_map,
627627
node_attrs=node_attrs, edge_attrs=edge_attrs
628628
)
629-
elif edit_cost == 'CONSTANT':
629+
elif edit_cost in ['CONSTANT', 'CHEM_1', 'CHEM_2']:
630630
node_labels = kwargs.get('node_labels', [])
631631
edge_labels = kwargs.get('edge_labels', [])
632632
return get_nb_edit_operations_symbolic(
633633
g1, g2, forward_map, backward_map,
634634
node_labels=node_labels, edge_labels=edge_labels
635635
)
636636
else:
637-
return get_nb_edit_operations_symbolic(
638-
g1, g2, forward_map,
639-
backward_map
637+
# The following edit costs include non-symbolic computations:
638+
# 'CMU', 'GREC_1', 'GREC_2', 'FINGERPRINT', 'PROTEIN', 'GEOMETRIC'.
639+
raise NotImplementedError(
640+
f'`get_nb_edit_operations()` is not implemented for edit cost "{edit_cost}". '
640641
)
641642

643+
# return get_nb_edit_operations_symbolic(
644+
# g1, g2, forward_map,
645+
# backward_map
646+
# )
647+
642648

643649
def get_nb_edit_operations_symbolic(
644650
g1, g2, forward_map, backward_map, node_labels=[], edge_labels=[]

gklearn/gedlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
# info
88
__version__ = "0.1"
9-
__author__ = "Linlin Jia"
10-
__date__ = "March 2020"
9+
__author__ = "Linlin Jia"
10+
__date__ = "March 2020"

gklearn/gedlib/gedlibpy_attr.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,15 +706,19 @@ cdef class GEDEnvAttr:
706706
config_bool[key.encode('utf-8')] = value
707707
else:
708708
raise EditCostError(
709-
"Edit cost configuration values must be either string or boolean."
709+
'Edit cost configuration values must be either string or boolean.'
710710
)
711711

712712
# # debug test only:
713713
# print(f'[gedlibpy_attr.pyx] Edit cost config passed to C++ wrapper is {edit_cost_config}.')
714-
715-
self.c_env.setEditCost(
716-
edit_cost_b, edit_cost_constant, config_str, config_bool
717-
)
714+
try:
715+
self.c_env.setEditCost(
716+
edit_cost_b, edit_cost_constant, config_str, config_bool
717+
)
718+
except Exception as e:
719+
raise EditCostError(
720+
f"Caught C++ Exception': {str(e)}."
721+
)
718722
else:
719723
raise EditCostError(
720724
"This edit cost function doesn't exist, please see list_of_edit_cost_options for selecting a edit cost function"

0 commit comments

Comments
 (0)