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
8 changes: 7 additions & 1 deletion nibabel/cmdline/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""
Quick summary of the differences among a set of neuroimaging files

Notes:
- difference in data types for header fields will be detected, but
endianness difference will not be detected. It is done so to compare files
with native endianness used in data files.
"""
from __future__ import division, print_function, absolute_import

Expand Down Expand Up @@ -99,7 +104,8 @@ def are_values_different(*values):
if type(value0) != type(value): # if types are different, then we consider them different
return True
elif isinstance(value0, np.ndarray):
if value0.dtype != value.dtype or \
# use .dtype.type to provide endianness agnostic comparison
if value0.dtype.type != value.dtype.type or \
value0.shape != value.shape:
return True
# there might be nans and they need special treatment
Expand Down
6 changes: 6 additions & 0 deletions nibabel/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ def test_diff_values_array():
# and some inf should not be a problem
assert not are_values_different(array([0, inf]), array([0, inf]))
assert are_values_different(array([0, inf]), array([inf, 0]))

# we will allow for types to be of different endianness but the
# same in "instnatiation" type and value
assert not are_values_different(np.array(1, dtype='<i4'), np.array(1, dtype='>i4'))
# but do report difference if instantiation type is different:
assert are_values_different(np.array(1, dtype='<i4'), np.array(1, dtype='<i2'))