Return zero gradient for zero norm function. #393
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.
Fix issues #370
Now the gradient at zero (origin) point of np.linalg.norm() is the same as np.abs, which is zero, one of its subgradient.
For second order gradients, mathematically they should be +infinity, but
here when ord>=2 it returns 0 (same as np.abs()), when 1<ord<2, it is
NaN with plenty of warnings, which should be enough to prevent user from
doing that.
Also note that when x is complex number, the gradient of the norm seems wrong according to your document, there should be a conj(x) in the expression, see also the comments in the committed code.