Skip to content

BUG: Handle empty VectorContainer NumPy conversions - #6986

Merged
dzenanz merged 1 commit into
InsightSoftwareConsortium:mainfrom
jdotc1:bug/3150-empty-vector-container-numpy
Oct 27, 2026
Merged

dzenanz merged 1 commit into
InsightSoftwareConsortium:mainfrom
jdotc1:bug/3150-empty-vector-container-numpy

Conversation

@jdotc1

@jdotc1 jdotc1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Return a correctly shaped and typed NumPy array for empty VectorContainer conversions. Cover scalar and point containers through both view and copy helpers. Closes #3150.

Validation

Native arm64 macOS build with AppleClang 21, Python 3.13.9, and SWIG 4.4.1 passed on the published commit. The registered itkPyVectorContainerTest passed both methods, covering six empty-container subcases and the existing nonempty view/copy checks. Imports were confirmed to use the newly built native extensions.

The original wheel harness also passed; its six pre-fix empty-buffer errors remain the negative control. Windows/MSVC 19.44 native wrapper build and the registered NumPy CTest also pass. The upstream Linux and macOS Azure Python jobs also pass at e890f827.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Bridge Issues affecting the Bridge module labels Oct 22, 2026
@dzenanz

dzenanz commented Oct 22, 2026

Copy link
Copy Markdown
Member

There was another PR recently which mentioned empty arrays. Should some change be done there?

@jdotc1

jdotc1 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

The recent related change I found is #6929. I checked it against this PR: it handles empty transform parameters before calling GetArrayFromVnlVector, whereas #6986 fixes the separate VectorContainer-to-NumPy bridge.

The VNL bridge is unchanged here, so #6929's explicit empty float64 arrays should remain. Its empty TranslationTransform fixed-parameter test also remains applicable. I do not see a corresponding change needed in #6929 for this fix.

@jdotc1
jdotc1 marked this pull request as ready for review October 22, 2026 21:46
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Returns correctly shaped and typed NumPy arrays when VectorContainer is empty.

  • Empty VectorContainers convert to correctly shaped NumPy arrays.

Reviews (1) · Last reviewed commit: "BUG: Handle empty VectorContainer NumPy ..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson force-pushed the bug/3150-empty-vector-container-numpy branch from e890f82 to 246eb72 Compare October 25, 2026 19:56
An empty VectorContainer can expose a null data pointer, which
PyMemoryView_FromBuffer rejects, so array_view_from_vector_container
and array_from_vector_container raised ValueError instead of returning
an empty array. Return an empty array of the container's shape and
dtype before creating the memory view.

Closes InsightSoftwareConsortium#3150.
@hjmjohnson
hjmjohnson force-pushed the bug/3150-empty-vector-container-numpy branch from 246eb72 to 7736c3b Compare October 25, 2026 20:01
@dzenanz
dzenanz merged commit 443d201 into InsightSoftwareConsortium:main Oct 27, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Python wrapping Python bindings for a class type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

itk. array_from_vector_container fails for empty numpy array

2 participants