bugGNU Octave - Bugs: bug #33966, object precedence with...

 
 

bug #33966: object precedence with concatenating

Submitter:  Ben Abbott <bpabbott>
Submitted:  Sun 07 Aug 2011 09:52:51 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Ben Abbott Open/Closed:  * Closed
Release:  * dev Operating System:  * Mac OS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 15 Sep 2011 09:35:06 PM UTC, comment #2: 

I checked in the following changeset which seems to make concatenation much more compatible with Matlab.  Using your tests as a starting point, I created a more complete set of tests for all combinations of built-in classes.

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

Since all the tests are passing now, I'm closing this report.  Reopen this report or start a new one if you see some new problem.

John W. Eaton <jwe>
Group administrator
Mon 08 Aug 2011 12:25:09 AM UTC, comment #1: 

I've prepared a changeset to test Octave and placed in the patch tracker.

https://savannah.gnu.org/patch/index.php?7592

Ben Abbott <bpabbott>
Group Member
Sun 07 Aug 2011 09:52:51 PM UTC, original submission:  

On the help list a question came up on object precedence with concatenating objects. Found very little information in either Octave's or Mathworks' documentation, so I did some experimenting at the command line and found that ML and Octave give different results.

I've identified seven groups of objects in ML. Objects within groups have equal precedence.  Group (1/logical) has the lowest pecedence and group (7/function_handle) has the highest precedence.

(1) logical
(2) double
(3) single
(4) uint8, uint16, uint32, uint64, int8, int16, int32, int64
(5) char
(6) struct, cell
(7) function_handle

Arrays of function handles are not allowed. Thus, they may be ignored  with regards to precedence when concatenating objects.

If a cell is concatenated with other objects, of lower precedence, they are each converted to cells. For example, the command below is valid ML syntax and produces a cell array.

a = [{}, logical(1), double(1), single(1), uint32(1), 'a', struct('foo','bar')]

ML gives the indicated results for the concatentations below

class ([true, double(1)]) = "double"
class ([double(1), single(1)]) = "single"
class ([single(1), uint32(1)]) = "uint32"
class ([uint32(1), 'a']) = "char"
class (['a', cell(1)]) = "cell"
class ([cell(1), struct('foo','bar')]) = "cell"

When concatenating objects of equal precedence, Octave and ML return an object whos class  consistent with that of the fist object.

Octave is also consistent with ML when concatenating numeric and character classes.

Concatenating matrices with cell arrays gives an error in Octave. For example, using a trival character scalar ...

a = 'a';
[a, cell(1)]
error: invalid concatenation of cell array with matrix

[cell(1), a]
error: concatenation operator not implemented for `cell' by `scalar' operations

Structures and cells have equal precedence, and the example below should produce a cell object.

[cell(1), struct('foo','bar')]
error: concatenation operator not implemented for `cell' by `scalar struct' operations

But the one below should (and does) give an error.

>> [struct('foo','bar'), cell(1)]

error: concatenation operator not implemented for `struct' by `cell' operations

Ben Abbott <bpabbott>
Group Member

 

(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 bpabbott (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
    2011-09-15 jwe StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code