bugGNU Octave - Bugs: bug #63538, nchoosek random errors for some...

 
 

bug #63538: nchoosek random errors for some inputs

Submitter:  None
Submitted:  Fri 16 Dec 2022 09:40:34 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 7.3.0
Operating System:  * Any Fixed Release:  8.1.0
Planned Release:  8.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 19 Dec 2022 06:23:26 PM UTC, comment #7: 

I made a slight tweak to Arun's patch and checked it in under his name on the stable branch of Octave (http://hg.savannah.gnu.org/hgweb/octave/rev/9be3a2706d62).

This will be a part of the 8.1 Octave release.

Rik <rik5>
Group administrator
Sat 17 Dec 2022 11:19:13 PM UTC, comment #6: 

matlab 2022b accepts row or column inputs:


>> nchoosek (1:3, 2)

ans =

     1     2
     1     3
     2     3

>>  nchoosek ((1:3)', 2)

ans =

     1     2
     1     3
     2     3


Nicholas Jankowski <nrjank>
Group Member
Sat 17 Dec 2022 08:44:25 PM UTC, comment #5: 

The attached patch against stable fixes it for me. I converted the input to a row vector, removed some minor code duplication, and added a BIST.



(file #54123)

Arun Giridhar <arungiridhar>
Group Member
Sat 17 Dec 2022 07:26:04 PM UTC, comment #4: 

Looks like a regression from Octave 6.4:

octave:2> nchoosek ((1:3)', 2)
ans =

   1   2
   1   3
   2   3

octave:3> nchoosek (1:3, 2)
ans =

   1   2
   1   3
   2   3


Could someone pls check in current Matlab to see if it accepts column vector input?

Arun Giridhar <arungiridhar>
Group Member
Sat 17 Dec 2022 06:25:46 PM UTC, comment #3: 

normally x(:) gives a column vector.
A more independent solution would be


x = repelem (v(1:n-1), [n-1:-1:1]);
if size(x,1) < size(x,2)
  x = x.';
end


Steve <alzi123>
Sat 17 Dec 2022 03:48:57 PM UTC, comment #2: 

Could reshape vector input to row vector.

Anonymous
Sat 17 Dec 2022 10:41:50 AM UTC, comment #1: 

in version 7.3.0 / nchoosek.m
an additional command after line 166 is a possible solution:


162  elseif (k > n)
163    C = v(zeros (0, k));  # return 0xk object for Matlab compatibility
164  elseif (k == 2)
165    ## Can do it without transpose.
166    x = repelem (v(1:n-1), [n-1:-1:1]).';

ADD    x = x(:);

167    y = cat (1, cellslices (v(:), 2:n, n*ones (1, n-1)){:});
168    C = [x, y];
169  elseif (k < n)
170    v = v(:).';
171    C = v(k:n);
172    l = 1:n-k+1;


Steve <alzi123>
Fri 16 Dec 2022 09:40:34 PM UTC, original submission:  

OK:

nchoosek((1:3),1)
nchoosek((1:3),2)
nchoosek((1:3),3)


First and third OK, second error:

nchoosek((1:3)',1)
nchoosek((1:3)',2)
nchoosek((1:3)',3)

error: horizontal dimensions mismatch


But error only for second case, not all cases.

nchoosek should take column vector input or give better error message.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #54123:  nck.patch added by arungiridhar (1KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by alzi123 (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-19 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 8.1.0
    2022-12-17 arungiridhar Attached File- Added nck.patch, #54123
    2022-12-17 arungiridhar Planned ReleaseNone 8.1.0

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code