bugGNU Octave - Bugs: bug #65008, ind2sub with indices lower than 0

 
 

bug #65008: ind2sub with indices lower than 0

Submitter:  None
Submitted:  Mon 11 Dec 2023 10:23:29 AM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  1 - Later Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 13 Dec 2023 11:28:16 PM UTC, comment #6: 

The behavior in bug #62184 had a use case in indexing, and Octave was changed to match Matlab behavior.  I'm still left wondering why this behavior would be useful.  It can't be in indexing because negative dimensions aren't allowed.

Rik <rik5>
Group administrator
Wed 13 Dec 2023 10:39:33 PM UTC, comment #5: 
Anonymous
Mon 11 Dec 2023 08:01:53 PM UTC, comment #4: 

Confirmed.  Although, I wonder as Philip does whether there is any interesting use case here.  Octave hasn't supported this for 20 years and we haven't had complaints; it can't be a feature that is used that often.

Rik <rik5>
Group administrator
Mon 11 Dec 2023 07:52:09 PM UTC, comment #3: 

I had never notived that behavior before and it is not explictly documented but, somehow, why not:


>> [x,y] = ind2sub([2,2],-4:8)

x =

     0     1     0     1     0     1     2     1     2     1     2     1     2


y =

    -1    -1     0     0     1     1     1     2     2     3     3     4     4


Anonymous
Mon 11 Dec 2023 07:26:39 PM UTC, comment #2: 

I would imagine maybe it is supported because you could try to do general location arithmetic using sums of those indices, but I haven't done it.  What i do notice looking at their public help is that while they do specify the array size be restricted only to positive integers, they make no such restriction on the index input:


Input Arguments

sz — Size of array
vector of positive integers
Size of array, specified as a vector of positive integers...

ind — Linear indices
scalar | vector | matrix | multidimensional array
Linear indices, specified as a scalar, vector, matrix, or multidimensional array.

https://www.mathworks.com/help/matlab/ref/ind2sub.html

Nicholas Jankowski <nrjank>
Group Member
Mon 11 Dec 2023 07:02:42 PM UTC, comment #1: 

Just curious:
Can Matlab do something useful with those negative subscripts?

Philip Nienhuis <philipnienhuis>
Group Member
Mon 11 Dec 2023 10:23:29 AM UTC, original submission:  

In Matlab, indices in ind2sub are not restricted to be strictly greater than 0:


[x,y] = ind2sub([32 32], 0)
x =
     0
y =
     1


Octave complains:


[x,y] = ind2sub([32 32], 0)
error: ind2sub: invalid index index 0: subscripts must be either integers 1 to (2^63)-1 or logicals


This is what Matlab returns more generally:


[x,y] = ind2sub([32 32], -3:3)
x =
    -3    -2    -1     0     1     2     3
y =
     1     1     1     1     1     1     1


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 rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-12-11 rik5 Severity3 - Normal 1 - Wish
        Priority5 - Normal 1 - Later
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-04b1.
    Corresponding source code