Skip to content

Commit

Permalink
ENH: Use Numpy bridge with array of dimension 1
Browse files Browse the repository at this point in the history
Allow the use of the function GetImageFromArray with arrays of dimension
1.

The previous assert prevented the use of the Numpy bridge for the
dimension 1 even if this dimension was wrapped.
  • Loading branch information
arobert01 authored and thewtex committed Jul 2, 2020
1 parent 4fa1867 commit caae216
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Modules/Bridge/NumPy/wrapping/PyBuffer.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
if not HAVE_NUMPY:
raise ImportError('Numpy not available.')

assert ndarr.ndim in ( 2, 3, 4 ), \
"Only arrays of 2, 3 or 4 dimensions are supported."
assert ndarr.ndim in ( 1, 2, 3, 4 ), \
"Only arrays of 1, 2, 3 or 4 dimensions are supported."
if not ndarr.flags['C_CONTIGUOUS'] and not ndarr.flags['F_CONTIGUOUS']:
ndarr = np.ascontiguousarray(ndarr)

Expand All @@ -91,7 +91,7 @@
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray( ndarr, ndarr.shape[-2::-1], ndarr.shape[-1] )
else:
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray( ndarr, ndarr.shape[-1:0:-1], ndarr.shape[0] )
elif ndarr.ndim in ( 2, 3 ):
elif ndarr.ndim in ( 1, 2, 3 ):
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray( ndarr, ndarr.shape[::-1], 1)

# Keep a reference
Expand Down

0 comments on commit caae216

Please sign in to comment.