Skip to content

Commit

Permalink
Make Interface.is_compatible() more compact.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Mar 18, 2015
1 parent fa0416b commit 73d6c2d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions neurokernel/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,14 @@ def is_compatible(self, a, i, b, allow_subsets=False):
return False

# Compatible identifiers must have the same non-null 'type'
# attribute and their 'io' attributes must be the inverse of each
# other:
# attribute and their non-null 'io' attributes must be the inverse
# of each other:
if not data_merged.apply(lambda row: \
((row['type_x'] == row['type_y']) or \
(pd.isnull(row['type_x']) and pd.isnull(row['type_y']))) and \
((row['io_x'] == 'out' and row['io_y'] == 'in') or \
(row['io_x'] == 'in' and row['io_y'] == 'out')),
(row['io_x'] == 'in' and row['io_y'] == 'out') or \
(pd.isnull(row['io_x']) and pd.isnull(row['io_y']))),
axis=1).any():
return False

Expand All @@ -688,20 +689,15 @@ def is_compatible(self, a, i, b, allow_subsets=False):
len(i.data[i.data['interface'] == b])):
return False

# If the 'type' attributes of the same identifiers in each
# interfaces are not equivalent or both null, they are incompatible:
if not data_merged.apply(lambda row: \
(row['type_x'] == row['type_y']) or \
(pd.isnull(row['type_x']) and pd.isnull(row['type_y'])),
axis=1).all():
return False

# If the 'io' attributes of the same identifiers in each interfaces
# are not the inverse of each other, they are incompatible:
# Compatible identifiers must have the same non-null 'type'
# attribute and their non-null 'io' attributes must be the inverse
# of each other:
if not data_merged.apply(lambda row: \
(row['io_x'] == 'out' and row['io_y'] == 'in') or \
(row['io_x'] == 'in' and row['io_y'] == 'out') or \
(pd.isnull(row['io_x']) and pd.isnull(row['io_y'])),
((row['type_x'] == row['type_y']) or \
(pd.isnull(row['type_x']) and pd.isnull(row['type_y']))) and \
((row['io_x'] == 'out' and row['io_y'] == 'in') or \
(row['io_x'] == 'in' and row['io_y'] == 'out') or \
(pd.isnull(row['io_x']) and pd.isnull(row['io_y']))),
axis=1).all():
return False

Expand Down

0 comments on commit 73d6c2d

Please sign in to comment.