bugGNU Octave - Bugs: bug #62870, reshape gives unexpected OOM/dim...

 
 

bug #62870: reshape gives unexpected OOM/dim too large error for improper size vector

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Sat 06 Aug 2022 04:07:22 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 21 Oct 2022 06:41:50 AM UTC, comment #5: 

No complaints in a couple of weeks.

Closing as fixed.

Markus Mützel <mmuetzel>
Group administrator
Sun 09 Oct 2022 02:55:26 PM UTC, comment #4: 

Imho, throwing an exception in dim_vector::safe_numel is fine. We'll just need to make sure to catch that exception if we need/prefer to (like in this case).

I added a commit message to the diff in comment #1 and pushed it with jwe as the author here:
https://hg.savannah.gnu.org/hgweb/octave/rev/4707df477065

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Tue 30 Aug 2022 12:12:10 PM UTC, comment #3: 

That change looks like a step in a good direction to me. The error message is more specific and is probably more helpful for users.

Keeping the complete list of dimensions might be a lot if there are many of them. But this is an error. So, we don't need to be "pretty" in that case imho. And we could still change that later on.

Markus Mützel <mmuetzel>
Group administrator
Sat 06 Aug 2022 05:42:11 PM UTC, comment #2: 

i mean, it's a bit ridiculous but it would point (at least to me) out right away where my error was.

not sure about the first question, but it would make sense to limit it, but since the initial 100x1 can vary as well as the 10x2x6x... what would be the not-to-onerous way to do that.   if(numchar > 80) [trim to 80 and end with ...] ?

checking how matlab's reshape yells about such things, first it doesn't allow  anything other than a row vector.  i was surprised ours took an array at all. then it gives:


Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.


making me think it is just failing on a numel(a)==prod(b) check and reporting that.

Nicholas Jankowski <nrjank>
Group Member
Sat 06 Aug 2022 05:05:20 PM UTC, comment #1: 

Something like the attached change should help.  With it, I see:


octave:1> a = rand (100,1);
octave:2> b = randi ([0,10],10);
octave:3> reshape (a, b)
error: reshape: can't reshape 100x1 array to 10x2x6x1x4x8x9x1x7x0x0x0x10x6x7x0x9x3x4x9x10x9x0x10x2x2x7x4x6x1x7x9x2x8x6x9x2x8x9x4x10x1x4x7x10x7x8x0x8x5x10x10x1x0x9x5x7x2x10x10x0x1x8x6x9x10x8x7x6x9x8x6x0x0x2x1x4x2x2x8x4x6x5x10x3x6x0x5x9x10x6x3x0x7x7x5x2x1x5x6 array
octave:4>


Should we handle errors in dim_vector::safe_numel in some other way than throwing std::bad_alloc?

Should we issue a different message if the number of dimensions is larger than some limit (say, 50?) since generating and displaying the exact list of dimensions is probably meaningless at that point.


(file #53536)

John W. Eaton <jwe>
Group administrator
Sat 06 Aug 2022 04:07:22 PM UTC, original submission:  

looking at failing code in another report (see bug #50286), it appears that a reshape was called supplying an array A as the reshape dimensions instead of size(A).  this produced an error as it should, but it seems that the error slipped past input checking and instead triggered an unexpected "out of memory or dimension too large for Octave's index type", when I would think it should get caught by input checking on acceptable reshape vector size, hence making it a bit less obvious to diagnose than it should be

steps to reproduce:


a = rand(100,1);
b = randi([0 10], 10);
c = reshape (a, b)
error: out of memory or dimension too large for Octave's index type


would have expected something like:

c = reshape (a, [10 10 10])
error: reshape: can't reshape 100x1 array to 10x10x10 array


Nicholas Jankowski <nrjank>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #53536:  reshape-diffs.txt added by jwe (973B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by nrjank (Submitted the item)
  •  

    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-10-21 mmuetzel StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2022-10-09 mmuetzel StatusNone Ready For Test
        Release7.2.0 dev
    2022-08-06 jwe Attached File- Added reshape-diffs.txt, #53536

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code