bugGNU Octave - Bugs: bug #47631, ind2sub with empty dimension vector

 
 

bug #47631: ind2sub with empty dimension vector

Submitter:  None
Submitted:  Wed 06 Apr 2016 12:45:04 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  WTF, Matlab?!?
Status:  Wont Fix Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 29 Apr 2016 02:46:18 AM UTC, comment #7: 

Lachlan, yes I'm suggesting closing this Won't Fix, we haven't yet seen a viable example showing where this would be useful to emulate. The argument to ind2sub is supposed to be the size of an array, so how would that be an empty array?

Mike Miller <mtmiller>
Group Member
Fri 15 Apr 2016 06:12:18 PM UTC, comment #6: 

The user may not call ind2sub with a [] matrix (willingly), but it may happen in case a lot of operations are being performed (failure of user to pass the parameters correctly while scripting/ inability of user to foresee this kind of problem with data while writing the script). I think we could simply give the user a warning (upon execution) that this operation can cause a problem in computations because it is not a logically correct operation (and not because Octave cannot do it ).

MATLAB trial using 2^30 gives:

>> [ii, jj, kk] = ind2sub ([1, 1, 2^30], [3 4; 5 6])


ii =
     1     1
     1     1

jj =
     1     1
     1     1

kk =
     3     4
     5     6

-Deleted Account- <carpediem>
Wed 13 Apr 2016 12:49:35 AM UTC, comment #5: 

Aditya, if x = [], which is size [0,0], there is no reason to expect that ind2sub ([], ...) will generate indices that can index it.

Note also that your example used "sizem" where Mike suggested "sizemax" (which seems not to be supported in Matlab -- try 2^30 instead).

The important question is: can you think of a reason a user may want to call  ind2sub  with an empty size matrix?

Lachlan Andrew <lachlan>
Mon 11 Apr 2016 10:50:35 AM UTC, comment #4: 

I would like to work on this.
Upon testing the MATLAB outputs:

>> x=[];
>> [i,j] = ind2sub ([], 3)


i =
     1

j =
     3

I think this output might be wrong.

>> x(3)

Index exceeds matrix dimensions.
 

>> x(i,j)

Index exceeds matrix dimensions.

Should Octave give the same error "Index exceeds matrix dimensions." for the ind2sub command?
 
More MATLAB testing gives:

>> [ii, jj, kk] = ind2sub ([1, 1, sizem], [3 4; 5 6])

Error using sizem (line 21)
Not enough input arguments.

>> [i,j] = ind2sub ([0, 0], 3)


i =
   NaN


j =
   NaN


-Deleted Account- <carpediem>
Mon 11 Apr 2016 08:03:26 AM UTC, comment #3: 

Mike, are you suggesting closing this with "won't fix"?

Rik, I don't quite follow your example.  Your comments after the example seem to apply to


x = [];
[i,j] = ind2sub ([0, 0], 3)      % <-- [0, 0] = size (x)
% Now what do the following do in Matlab?
x(3)
x(i,j)


rather than the example you gave.  As Mike pointed out, [] is not the size of any valid matrix.

To me, the question is whether or not handling [] in this way may allow a user to avoid a "special case" check in some context.  If so, there is value in handling it the way Matlab does.

Unfortunately the original poster didn't leave an email, so we'll never know where this came up.

Lachlan Andrew <lachlan>
Wed 06 Apr 2016 05:58:46 PM UTC, comment #2: 

Judging by the example given for Matlab's behavior, it looks like it is basically interpreting the empty dimension vector something like this (which does work in Octave):


[ii, jj, kk] = ind2sub ([1, 1, sizemax], [3 4; 5 6])


But since everything in Octave has at least 2 dimensions, I don't see what the point of all this is.

Mike Miller <mtmiller>
Group Member
Wed 06 Apr 2016 03:25:38 PM UTC, comment #1: 

I'm not sure we want to follow Matlab in this regard.

Take a simpler example


x = [];
[i,j] = ind2sub ([], 3)
% Now what do the following do in Matlab?
x(3)
x(i,j)


If they both produce errors then it seems like we should be warning the user as soon as the error condition has been created (the call to ind2sub) rather than when the indexing x(i,j) is later done.  Particularly as the calculation of the indices might be done in a subroutine which could be very far removed from their eventual usage in the main code for indexing.



Rik <rik5>
Group administrator
Wed 06 Apr 2016 12:45:04 PM UTC, original submission:  

The Octave function ind2sub with an empty dimension vector gives an error. In Matlab it returns the value of the second argument.

>> ind2sub([], [3 4; 5 6])


ans =
     3     4
     5     6

>> [ii,jj,kk] = ind2sub([], [3 4; 5 6])


ii =
     1     1
     1     1

jj =
     1     1
     1     1

kk =
     3     4
     5     6

Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by carpediem (Posted a comment)
  • -email is unavailable- added by lachlan (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-05-04 rik5 Open/ClosedOpen Closed
    2016-04-29 mtmiller Item GroupMatlab Compatibility WTF, Matlab?!?
        StatusNeed Info Wont Fix
    2016-04-11 lachlan Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        Release4.0.0 dev
    2016-04-06 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code