Skip to content

Fix grp2idx empty output shape - #501

Merged
pr0m1th3as merged 2 commits into
gnu-octave:mainfrom
sahilphad07-sudo:fix-grp2idx-empty-output
Sep 24, 2026
Merged

pr0m1th3as merged 2 commits into
gnu-octave:mainfrom
sahilphad07-sudo:fix-grp2idx-empty-output

Conversation

@sahilphad07-sudo

Copy link
Copy Markdown
Contributor

grp2idx returned an incorrectly shaped output for empty numeric vectors. MATLAB returns an empty column vector with size 0x1, while Octave returned an empty 0x0 matrix. This happened because unique (s(:)) returns g with size 0x0 when the input is empty. Fixed by ensuring an empty g has size 0x1.

BEFORE:

octave:> [g, gn, gl] = grp2idx(zeros(0, 1));
octave:> size(g)
ans =

   0   0

AFTER:

octave:> [g, gn, gl] = grp2idx(zeros(0, 1));
octave:> size(g)
ans =

   0   1

MATLAB:
>> [g, gn, gl] = grp2idx(zeros(0, 1));
>> size(g)

ans =

     0     1

@pr0m1th3as
pr0m1th3as merged commit 11d8bca into gnu-octave:main Sep 24, 2026
8 checks passed
pr0m1th3as added a commit that referenced this pull request Sep 24, 2026
…low-up to #501.

  * inst/Data_Manipulation/grp2idx.m: take an empty cell array or string
  array, which failed on an undefined variable; return a 0-by-1 GL for an
  empty categorical, keeping GN 0-by-1 where MATLAB has it 0-by-0; say
  so in the help text; add tests.
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.

2 participants