Skip to content

Commit

Permalink
STYLE: Rename _GetImageViewFromArray to GetImageViewFromContiguousArray
Browse files Browse the repository at this point in the history
Aims to clarify the difference between the C++ `itk::PyBuffer` member function
(which only supports contiguous arrays as input) and the Python method
`itkPyBuffer.GetImageViewFromArray` (which supports *both* contiguous and
non-contiguous arrays).

This commit also removes the leading underscore, as identifiers beginning with
an underscore, followed by an uppercase letter are reserved by the C++ standard.

Follow-up to pull request InsightSoftwareConsortium#4888
commit b769b81
"BUG: PyBuffer _GetImageViewFromArray should reject non-contiguous buffer"
  • Loading branch information
N-Dekker committed Oct 29, 2024
1 parent 4b7886a commit 6e2c412
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Modules/Bridge/NumPy/include/itkPyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ class PyBuffer
_GetArrayViewFromImage(ImageType * image);

/**
* Get an ITK image from a Python array
* Get an ITK image from a contiguous Python array. Internal helper function for the implementation of
* `itkPyBuffer.GetImageViewFromArray`.
*/
static OutputImagePointer
_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObject * numOfComponent);
GetImageViewFromContiguousArray(PyObject * arr, PyObject * shape, PyObject * numOfComponent);
};

} // namespace itk
Expand Down
2 changes: 1 addition & 1 deletion Modules/Bridge/NumPy/include/itkPyBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PyBuffer<TImage>::_GetArrayViewFromImage(ImageType * image)

template <class TImage>
auto
PyBuffer<TImage>::_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObject * numOfComponent)
PyBuffer<TImage>::GetImageViewFromContiguousArray(PyObject * arr, PyObject * shape, PyObject * numOfComponent)
-> OutputImagePointer
{
Py_buffer pyBuffer{};
Expand Down
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 @@ -99,11 +99,11 @@

if is_vector:
if ndarr.flags['C_CONTIGUOUS']:
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray(ndarr, ndarr.shape[-2::-1], ndarr.shape[-1])
imgview = itkPyBuffer@PyBufferTypes@.GetImageViewFromContiguousArray(ndarr, ndarr.shape[-2::-1], ndarr.shape[-1])
else:
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray(ndarr, ndarr.shape[-1:0:-1], ndarr.shape[0])
imgview = itkPyBuffer@PyBufferTypes@.GetImageViewFromContiguousArray(ndarr, ndarr.shape[-1:0:-1], ndarr.shape[0])
else:
imgview = itkPyBuffer@PyBufferTypes@._GetImageViewFromArray(ndarr, ndarr.shape[::-1], 1)
imgview = itkPyBuffer@PyBufferTypes@.GetImageViewFromContiguousArray(ndarr, ndarr.shape[::-1], 1)

# Keep a reference
imgview._SetBase(ndarr)
Expand Down

0 comments on commit 6e2c412

Please sign in to comment.