octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ML incompatibility when concatenating objects of different classes


From: Ben Abbott
Subject: ML incompatibility when concatenating objects of different classes
Date: Sun, 07 Aug 2011 17:54:12 -0400

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

I've opened a bug report, but thought I'd mention here in case it might be 
important enough to fix prior to the next release.

        https://savannah.gnu.org/bugs/index.php?33966

Ben





reply via email to

[Prev in Thread] Current Thread [Next in Thread]