Skip to content

Commit

Permalink
Fix interface compatibility check for null types when subsets are all…
Browse files Browse the repository at this point in the history
…owed.
  • Loading branch information
lebedov committed Feb 10, 2015
1 parent 9fb23ba commit e621fc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 6 additions & 4 deletions neurokernel/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,12 @@ def is_compatible(self, a, i, b, allow_subsets=False):
if not len(data_merged):
return False

# Compatible identifiers must have the same 'type' attribute
# and their 'io' attributes must be the inverse of each other;:
# Compatible identifiers must have the same non-null 'type'
# attribute and their 'io' attributes must be the inverse of each
# other:
if not data_merged.apply(lambda row: \
(row['type_x'] == row['type_y']) and \
((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')),
axis=1).any():
Expand All @@ -640,7 +642,7 @@ def is_compatible(self, a, i, b, allow_subsets=False):
return False

# If the 'type' attributes of the same identifiers in each
# interfaces are not equivalent, they are incompatible:
# 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'])),
Expand Down
20 changes: 19 additions & 1 deletion tests/test_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ def test_is_compatible_with_nulls_types(self):
def test_is_compatible_subsets(self):
"""
Interfaces that both share a subset of compatible ports can be deemed
compatible by setting the `allow_subsets` option of the compatibility test.
compatible by setting the `allow_subsets` option of the compatibility
test.
"""

i = Interface('/foo[0:6]')
Expand All @@ -482,6 +483,23 @@ def test_is_compatible_subsets(self):
assert i.is_compatible(0, j, 1, True)
assert i.is_compatible(0, k, 1, True) == False

def test_is_compatible_subsets_with_null_types(self):
"""
Interfaces that both share a subset of compatible ports can be deemed
compatible by setting the `allow_subsets` option of the compatibility
test even when the types are null.
"""

i = Interface('/foo[0:6]')
i['/foo[0:3]'] = [0, 'out']
i['/foo[3:6]'] = [0, 'out']
j = Interface('/foo[0:6]')
j['/foo[0:2]'] = [1, 'in']
j['/foo[3:5]'] = [1, 'in']
k = Interface('/foo[0:6]')
assert i.is_compatible(0, j, 1, True)
assert i.is_compatible(0, k, 1, True) == False

def test_which_int_unset(self):
i = Interface('/foo[0:4]')
assert i.which_int('/foo[0:2]') == set()
Expand Down

0 comments on commit e621fc3

Please sign in to comment.