bugGNU Octave - Bugs: bug #40296, Consistent matrix return sizes

 
 

bug #40296: Consistent matrix return sizes

Submitter:  David Spies <dspyz>
Submitted:  Fri 18 Oct 2013 04:07:08 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Wont Fix Assigned to:  None
Originator Name:  dspies Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 04 Jun 2019 03:56:08 PM UTC, comment #2: 

Introducing a huge discontinuity with Matlab is not something we want to do.  But there are workarounds that are not onerous.  For the example code in comment #0 fails depending on the orientation of m.


[i,j] = find(m);
inds = [i,j]';

for b = inds
  r = inds(1)
  c = inds(2)
  # Do something with r and c
endfor


This can be rewritten, modestly, to


[i,j] = find(m);
inds = [i(:),j(:)];

for b = inds
  r = inds(1)
  c = inds(2)
  # Do something with r and c
endfor


which will always work in both Octave and Matlab.

Rik <rik5>
Group administrator
Tue 08 Dec 2015 10:21:07 AM UTC, comment #1: 

I agree this would be convenient, however I don't think it would be sufficiently useful to justify the code bloat.

If someone posted a patch on Savannah but it was not applied to the main code base, could this request be closed?

Lachlan Andrew <lachlan>
Fri 18 Oct 2013 04:07:08 AM UTC, original submission:  

Can there be a flag which removes all special cases in matrix return sizes?

In other words, if I say v = A(b), where b is a logical vector, the return type will always be a column vector, regardless of the dimensions of A (instead of being a row vector when A has vertical dimension 1).

Additionally, if v = A(i) where i is a double matrix/vector, v will always have the same dimensions as i, regardless of the dimension of A (instead of being a row vector when i has horiz. dimension 1 and v has vert. dimension 1)

And the find method, [i,j,v] = find(m) will always return column vectors for i, j, and v, even if m is a row vector.

When I'm trying to write Octave functions, I keep on having to deal with these special cases and they don't seem like they should be necessary.

For instance, if I write
[i,j] = find(m);
inds = [i,j]';

for b = inds
 r = inds(1)
 c = inds(2)
 # Do something with r and c
endfor

This fails when m is a row vector, because i and j are made into row vectors and then inds ends up being a 2nx1 column vector instead of 2xn matrix as expected

It would be nice if I could turn off all these special case behaviors (even if it's not matlab compatible)

David Spies <dspyz>

 

(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 lachlan (Posted a comment)
  • -email is unavailable- added by dspyz (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-04 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code