Repository navigation
harmmean: accept negative and complex values - #518
Closed
dheerchheda77 wants to merge 1 commit into
Closed
dheerchheda77 wants to merge 1 commit into
dheerchheda77 wants to merge 1 commit into
Conversation
* inst/Descriptive_Statistics/harmmean.m: Only require X to be numeric, as MATLAB does, instead of real and nonnegative. Update the documentation and the error message. Add tests for negative and complex input with DIM, VECDIM, "all" and "omitnan". * inst/Descriptive_Statistics/doc-cache: Update the harmmean entry. * NEWS: Mention the change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
|
Tested locally with Octave 11.3.0 (Windows): |
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.
Fixes the MATLAB incompatibility reported for harmmean with negative and
complex input.
In MATLAB:
In Octave both calls raised "harmmean: X must contain real nonnegative
values."
Cause
The input check at the top of harmmean.m rejected anything that was not
real and nonnegative. The computation below it, n ./ sum (1 ./ x), is
valid for negative and complex values on every code path (default DIM,
"all", DIM, VECDIM, "omitnan"), so only the check had to change.
Changes
numeric."). Update the docstring, including the notes saying that a 0
gives 0, which only holds without negative or complex values.
negative and complex input with default DIM, "all", DIM, VECDIM and
"omitnan", and for [1 -1] returning Inf.
Not changed
geomean has the same check, but its zero handling assumes real
nonnegative data and I have not confirmed MATLAB's behaviour for negative
input, so it is left out of this PR.
Testing
The expected values in the new tests were checked by hand and with an
independent calculation. Not yet run in Octave locally; relying on CI
for
test harmmean. Still to compare against MATLAB: harmmean ([0 1i]).