bugGNU Octave - Bugs: bug #47298, zeros() with empty dimensions but...

 
 

bug #47298: zeros() with empty dimensions but non zero rows or columns does not fail

Submitter:  Carnë Draug <carandraug>
Submitted:  Sun 28 Feb 2016 06:07:03 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  carandraug
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 05 Mar 2016 02:40:19 AM UTC, comment #4: 

Thank you Markus for the heads up on what Matlab does in this cases.

I pushed http://hg.savannah.gnu.org/hgweb/octave/rev/120bb822c6f4 which fixes this, keeping Matlab compatibility but also in accordance with Octave's acceptance of any vector.

Carnë Draug <carandraug>
Group Member
Sat 05 Mar 2016 01:43:10 AM UTC, comment #3: 

Hmm... I see the logic behind supporting a 1x0 vector by Matlab. Because they require it to be a row vector.  But Octave will accept both a row and column vector so by the same logic it should accept both a 1x0 and a 0x1 vector.

I will rework on this patch.

Carnë Draug <carandraug>
Group Member
Thu 03 Mar 2016 02:50:28 PM UTC, comment #2: 

For what it's worth:
Matlab R2012a does not fail on

zeros(zeros(1,0))


but it produces an empty matrix of size 0x0.
This seems to be the only case where you can pass empty matrices to zeros(), ones(), Inf() or NaN() without provoking an error.

I am not sure whether this is an error in Matlab or whether its behaviour is correct. After all, the documentation [1] states that the input argument sz is the "Size of each dimension, specified as a row vector of integer values." You could argue that a 1x0 vector was a row vector. Thus, a matrix with "no dimensions" should be returned...

[1] https://de.mathworks.com/help/matlab/ref/zeros.html

The function nan() behaves the same as described in #comment 0 and is not touched with your patch. Maybe you could fix it, too?

Markus Mützel <mmuetzel>
Group administrator
Sun 28 Feb 2016 07:10:20 PM UTC, comment #1: 

I have attached a cset that fixes this.

(file #36500)

Carnë Draug <carandraug>
Group Member
Sun 28 Feb 2016 06:07:03 PM UTC, original submission:  

Check for the dimensions for zeros() seems a bit odd.


>> zeros ([])
error: zeros (A): use zeros (size (A)) instead
>> zeros (zeros (0, 1))
ans = 0
>> zeros (zeros (1, 0))
ans = 0
>> zeros (zeros (0, 0, 1))
error: zeros (A): use zeros (size (A)) instead


It should have errored in all of the examples above.

Carnë Draug <carandraug>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #36500:  fill_matrix_empty_array.cset added by carandraug (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by carandraug (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
    2016-03-05 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2016-02-28 carandraug Attached File- Added fill_matrix_empty_array.cset, #36500

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code