bugGNU Octave - Bugs: bug #49759, Inconsistent concatenation with...

 
 

bug #49759: Inconsistent concatenation with cat, horzcat, vertcat, and []

Submitted by:  Amro <amro_octave>
Submitted on:  Sat 03 Dec 2016 12:53:35 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

Fri 16 Dec 2016 01:17:01 AM UTC, comment #7:

I changed do_cat to strip out empty matrices when doing cell concatenation (http://hg.savannah.gnu.org/hgweb/octave/rev/0ab9eecbb165). I also added the test case in this bug report as a BIST test. Fixed, closing report.

Rik <rik5>
Project Administrator
Tue 13 Dec 2016 05:50:26 AM UTC, comment #6:

There are two code paths, never a good idea, for concatenation. One is through the parser and the other is through cat() in data.cc. The actual function is do_cat which gets called by cat, vertcat, and horzcat.

Rik <rik5>
Project Administrator
Wed 07 Dec 2016 03:36:23 PM UTC, comment #5:

@mtmiller
The type of the empty numeric matrix doesn't seem to matter.
Using "A = int32([])" or "A = single([])" in the previous MATLAB example gives the same results as before.

Amro <amro_octave>
Tue 06 Dec 2016 05:48:43 PM UTC, comment #4:

I agree, I don't see any open reports about the *cat functions specifically.

The problem looks like it occurs when empty numeric arrays are converted into cell arrays for concatenation. Any homogeneous set collapses correctly:

But as soon as a mixed set is introduced, it adds empty elements to a non-empty cell array.

Amro - in Matlab, does the empty array have to be a double or can it be any empty numeric? What does your original example do with "A = int32([])" or "A = rand(0, 'single')"?

Mike Miller <mtmiller>
Project Administrator
Tue 06 Dec 2016 02:03:05 PM UTC, comment #3:

Thank you for finding those previous reports.

It's actually interesting because none of the examples in those threads apply anymore in the latest Octave 4.2.0, as the behavior of concatenating using square-brackets is now consistent with that of MATLAB.

I don't know if this was fixed on purpose or simply a happy accident! Either way the issue that remains here is that cat/horzcat/vertcat in Octave are giving different results than the equivalent []-concatenation.

Regardless of whether this concat behavior is considered an undocumented MATLAB feature/bug or not, Octave should at least be consistent with itself no matter how concatenation is performed. So I think that the functions cat/horzcat/vertcat should be fixed to be conformant with [].

Amro <amro_octave>
Mon 05 Dec 2016 05:17:57 PM UTC, comment #2:

Something similar was reported in bug #37086 and bug #35481.

Guillaume <gyom>
Mon 05 Dec 2016 04:46:45 PM UTC, comment #1:

Isn't there already a bug report for this? Could you check to see whether this is a duplicate?

Rik <rik5>
Project Administrator
Sat 03 Dec 2016 12:53:35 PM UTC, original submission:

Concatenating an empty matrix 0x0 with a cell array produce the wrong result, and is inconsistent depending on how we do it.

For example, in Octave 4.2.0 I get this:

On the other hand, in MATLAB R2016b I get this:

So it seems that in Octave using square-brackets to concatenate gives different results than using the equivalent cat/horzcat/vertcat.

Note that if you replace the empty array with an empty cell array (i.e A={} instead of A=[]) then Octave behaves correctly and give the same results as MATLAB in all cases.

Amro <amro_octave>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by gyom (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by amro_octave (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 16 Dec 2016 01:17:01 AM UTCrik5Item GroupIncorrect Result=>Matlab Compatibility
      StatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
      Release4.2.0=>dev
    Mon 05 Dec 2016 04:46:45 PM UTCrik5StatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup1