Repository navigation
Fix im3DNORM returning None for supported norm orders and improve input validation (fixes #797) - #805
Merged
Conversation
…ut validation (fixes CERN#797)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #797.
This PR fixes
im3DNORMsilently returningNonefor supported norm orders (np.inf,-np.inf, floats, and NumPy integer types) and improves input validation across the function.Root Cause
if normind is [np.inf, -np.inf, "fro", "nuc"]:, testing identity against a new list literal, which always evaluated toFalse.if type(normind) is int:excluded NumPy integers (np.int64,np.int32) and floating-point orders (float,np.floating).im3DNORMwithout a return statement, returningNone.froandnuc:im3DNORMflattens the input array into a 1D vector (img.ravel()). In NumPy, Frobenius and nuclear norms are defined only for 2D matrices, so vectors raiseValueError. Passingfroornucnow explicitly raisesValueErrorconsistent with NumPy norm semantics.Changes Made
normindand rejectNone, booleans, NaNs, and non-scalar structures withValueError.l2norm(img)optimized float32 accumulator for all order-2 representations (2,np.int64(2),2.0,np.float64(2.0)).forward,backward,central), supporting 3D volumes with zero-padding matching MATLAB's implementation.np.inf,-np.inf), integer orders, floating-point orders, and NumPy numeric types.ValueErrorfor unsupported norm orders (fro,nuc,unknown,L2, etc.).Testing
Added comprehensive unit and regression tests in
Python/tests/test_im3dnorm.pycovering:np.infand-np.inf(andfloat("inf"),float("-inf"))1,3,4,-1,-2,1.5,0.5,2.5,0)np.int64andnp.int32norm ordersValueErrorNone,True,False,unknown,L2, lists, dicts) raisingValueErrorforward,backward, andcentralgradient options