bugGNU Octave - Bugs: bug #57383, cell2mat could issue...

 
 

bug #57383: cell2mat could issue "Octave:language-extension" warning on mixed class numeric input

Submitted by:  A.R. Burgers <arb>
Submitted on:  Sun 08 Dec 2019 06:31:37 PM UTC  
 
Category:  Octave Function Severity:  1 - Wish
Priority:  1 - Later Item Group:  Missed Error or Warning
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  5.1.0 Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 23 Aug 2021 11:25:41 AM UTC, comment #4: 

In this example:

c = {pi, single(2)}
cm = cell2mat(c)
class(cm)

the octave m script cell2mat generates a call to cat that boils down to:

c = {pi, single(2)}
cm = reshape(cat(1, c{:}), size(c))

While matlab throws an error on executing the cell2mat call, it does execute the cat function, and return a single result, as octave does.

A.R. Burgers <arb>
Mon 09 Dec 2019 04:12:35 PM UTC, comment #3: 

The Octave philosophy is to be a superset of Matlab.  Any Matlab code you have should run in Octave.  But we specifically don't guarantee the reverse, that Octave code you write will run in Matlab.  For that case, the programmer needs to be aware of any Matlab restrictions and program with those in mind.

There is a particular warning ID for Octave-specific features: "Octave:language-extension".  This could be applied in this case.  I have re-title the bug report to reflect that.  But, I've lowered the priority as I think there are more important code challenges to tackle.

Rik <rik5>
Project Administrator
Mon 09 Dec 2019 08:21:11 AM UTC, comment #2: 

In your final example matlab gives:

>> cell2mat({pi, int8(1)})
Error using cell2mat (line 45)
All contents of the input cell array must be of the same data type.

matlab and octave agree on the rules of concatenation, and addition of mixed numeric classes, no problem there, 1+single(2) and 1+int8(2) give the same result in matlab as octave.

However cell2mat in matlab has more stringent rules, and does not allow mixed classes.

My point is that code with cell2mat involving mixed class numeric input runs under octave, for good reasons, but throws an error in matlab, and a warning in octave could alert the user to that possible error.

A.R. Burgers <arb>
Sun 08 Dec 2019 07:21:51 PM UTC, comment #1: 

I don't think a warning is necessary here.  The rules for mathematical operations involving mixed types (integers, singles, doubles) are well-defined.  Concatenation is just another mathematical operation and follows the same rules.

As an example, should there be a warning for this code?

octave:2> x = 1 + single (2)
x = 3
octave:3> class (x)
ans = single

This works the same with integers

octave:7> x = 1 + int8 (2)
x = 3
octave:8> class (x)
ans = int8

And it works the same way with cell2mat

octave:4> a = { pi, int8(1) }
a =
{
  [1,1] = 3.1416
  [1,2] = 1
}

octave:5> x = cell2mat (a)
x =

  3  1

octave:6> class (x)
ans = int8

Rik <rik5>
Project Administrator
Sun 08 Dec 2019 06:31:37 PM UTC, original submission:  

with this script

ver = version
mixed = {pi, single(2.0)};
class_cat = class([pi, single(2.0)])
a = cell2mat(mixed);
class_cell2mat = class(a)

Octave outputs:

ver = 5.1.1
class_cat = single
class_cell2mat = single

matlab outputs:

ver = '9.5.0.1049112 (R2018b) Update 3'
class_cat = 'single'

Error using cell2mat (line 45)
All contents of the input cell array must be of the same data type.

Error in tst (line 4)
a = cell2mat(mixed);

Both matlab and octave concatenate single/double matrices, with a single result.

Octave's cell2mat is written in terms of cat, returns a single result, matlab errors.

I guess octave doesn't need to produce an error in this case, but a warning on mixed class input would be nice.

A.R. Burgers <arb>

 

(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 arb (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-12-09 rik5 Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 1 - Later
        Summarycell2mat does not warn on mixed class numeric input => cell2mat could issue "Octave:language-extension" warning on mixed class numeric input

    Back to the top


    Powered by Savane 3.7