Skip to content

Fix harmmean Inf vecdim validation - #510

Open
sahilphad07-sudo wants to merge 1 commit into
gnu-octave:mainfrom
sahilphad07-sudo:fix-harmmean-inf-vecdim
Open

sahilphad07-sudo wants to merge 1 commit into
gnu-octave:mainfrom
sahilphad07-sudo:fix-harmmean-inf-vecdim

Conversation

@sahilphad07-sudo

@sahilphad07-sudo sahilphad07-sudo commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

harmmean accepted Inf values in the vecdim argument and silently ignored them. MATLAB rejects non-finite dimension values with an error.

This change updates vecdim validation to reject non-finite values, matching MATLAB behavior.

Before

octave:1> harmmean ([1 2 4], [1 Inf])
ans =

   1   2   4

After

octave:1> harmmean ([1 2 4], [1 Inf])
error: harmmean: DIM must be a positive integer scalar or vector.

The same validation now applies to all occurrences of Inf in vecdim.

MATLAB Behavior

>> harmmean([1 2 4], [1 Inf])
Error using sum
Dimension argument must be a positive integer scalar, a vector of unique positive integers, or 'all'.

Regression Tests Added

  • Scalar Inf dimension
  • Inf after a valid dimension: [1 Inf]
  • Inf before a valid dimension: [Inf 1]
  • Multiple Inf dimensions: [Inf Inf]

Test Results

All existing and new harmmean BISTs pass:

PASSES 27 out of 27 tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant