bugGNU Octave - Bugs: bug #33218, transpose (') operator not working...

 
 

bug #33218: transpose (') operator not working on scalar structs

Submitter:  None
Submitted:  Tue 03 May 2011 02:07:47 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Jochen Weber Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.4.0
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 05 May 2011 01:53:30 AM UTC, comment #2: 

I checked in the following change to the stable branch:

http://hg.savannah.gnu.org/hgweb/octave/rev/eaba9d671fb7

John W. Eaton <jwe>
Group administrator
Wed 04 May 2011 01:35:19 AM UTC, comment #1: 

This bug is confirmed on both 3.4.0 and the development branch.  Very simple test code to reproduce is


s.a = 1;
s'
error: unary operator `'' not implemented for `scalar struct' operands


For the original reporter, there are several workarounds.  One would be to use a dummy index variable in the loop like so:


for i = 1:numel (STRUCT_LIST)
  ITEM = STRUCT_LIST(i);
  ...
end


A second approach would to use reshape() to get the row vector you are looking for rather than the combination of (:) to produce a column vector and transpose ' to change the column vector to a row vector.  For example:


for ITEM = reshape (STRUCT_LIST, 1, numel (STRUCT_LIST))
  ...
end

Rik <rik5>
Group administrator
Tue 03 May 2011 02:07:47 PM UTC, original submission:  

Again, I'm using a construction which I think should be permissible frequently in my Matlab code:


for ITEM = LIST(:)',
    CODEBLOCK;
end


The colon operator followed by the transpose operation makes sure that the for-loop indeed selects individual items from LIST. Now, if LIST is of type struct, this works for any size combination (with 2 dims, obviously), 0x0, 0xN, Nx0, 1xN, Nx1, MxN, except 1x1 (scalar struct), which IMO should just return the same object. While there is a workaround possible by adding a construction like


if numel(LIST) ~= 1,
    % FORLOOP;
else,
    % SINGLEBLOCK;
end


around the code, this is really cumbersome and should not be necessary, should it?

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

    Date Changed by Updated Field Previous Value => Replaced by
    2011-05-05 jwe StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2011-05-04 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code