bugGNU Octave - Bugs: bug #39378, randperm cannot handle large...


bug #39378: randperm cannot handle large arguments

Submitted by:  Marco Caliari <caliari>
Submitted on:  Mon Jul 1 07:28:51 2013  
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 3.6.2Operating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Tue Oct 15 18:53:27 2013, comment #8:

I have finally pushed my fix:


This should be part of the upcoming release.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Wed Jul 17 17:20:32 2013, comment #7:

At the time I wrote my original comments, I was going off memory without reading the actual source code. Now that I look at it again, I realise that a slightly more sophisticated fix is required, first see if m will fit into an octave_idx_type, and if it doesn't then force a short shuffle.

It's a bit more than a one-liner right now, and at the moment I can't dedicate any time to this possibly easy problem.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Wed Jul 17 15:43:41 2013, comment #6:

Jordi, can you apply this one-liner fix of yours or is there more testing to be done?

Rik <rik5>
Project Administrator
Wed Jul 3 14:01:50 2013, comment #5:



Marco Caliari <caliari>
Project Member
Wed Jul 3 13:26:11 2013, comment #4:

No, I meant double(n) > ..., rather. The problem is that if the full size of the vector is too big, then there's no hope that the "long" shuffle can work, because then line 1149 fails:


In this case, we must do a short shuffle.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Wed Jul 3 08:25:28 2013, comment #3:

Probably you mean


Marco Caliari <caliari>
Project Member
Tue Jul 2 19:40:12 2013, comment #2:

I had some reason for capping the size of M. My reasoning was that if M was big enough, you might as well just allocate the full vector for speed. Perhaps a more sophisticated approach would be to do


Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Tue Jul 2 14:02:49 2013, comment #1:

The workaround is to change the "quick and dirty" test in rand.cc into


Marco Caliari <caliari>
Project Member
Mon Jul 1 07:28:51 2013, original submission:

Dear all,

the following

gives me the "memory exhausted or requested size too large for range of Octave's index type" error. I think it should work since:

1) N < intmax
2) M < N/5 and so O(M) memory should be used (according to help)
3) Matlab works with such an example

Best regards,


Marco Caliari <caliari>
Project Member


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

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by jordigh (Updated the item)
  • -unavailable- added by caliari (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue Oct 15 18:53:27 2013jordighStatusConfirmed=>Fixed
    Wed Jul 17 17:20:32 2013jordighStatusNone=>Confirmed
    Tue Jul 2 13:28:34 2013jordighSummaryPossible bug in randperm=>randperm cannot handle large arguments

    Back to the top

    Powered by Savane 3.1-cleanup1