bugGNU Octave - Bugs: bug #45319, mxCreateNumericArray with zero size


bug #45319: mxCreateNumericArray with zero size

Submitted by:  Amro <amro_octave>
Submitted on:  Sun 14 Jun 2015 09:26:11 AM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  4.0.0 Operating System:  Microsoft Windows

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)

Fri 17 Jul 2015 10:54:58 AM UTC, comment #10:

Thanks, works fine again!

Guillaume <gyom>
Thu 16 Jul 2015 07:20:24 PM UTC, comment #9:

OK, thanks. I checked in the following changeset:


John W. Eaton <jwe>
Project Administrator
Thu 16 Jul 2015 06:55:20 PM UTC, comment #8:

From my understanding of the MEX API in MATLAB, the same goes for most other mx functions: they dont explicitly check for NULL pointers, it is up to the caller to not pass nulls.

Amro <amro_octave>
Thu 16 Jul 2015 06:50:56 PM UTC, comment #7:

yes, that will crash MATLAB (access violation).

Amro <amro_octave>
Thu 16 Jul 2015 06:47:56 PM UTC, comment #6:

Oh, so I misunderstood. It's not about dims == NULL, it's about ndims == 0?

I guess maybe there should also be a defensive check for dims == NULL in there somewhere anyway...

I'm curious though, does Matlab crash or issue an error or a warning for something like this:


John W. Eaton <jwe>
Project Administrator
Thu 16 Jul 2015 06:34:03 PM UTC, comment #5:

Here is a test:

In MATLAB, I get the following:

Amro <amro_octave>
Thu 16 Jul 2015 06:29:06 PM UTC, comment #4:

Does the attached change work?

(file #34454)

John W. Eaton <jwe>
Project Administrator
Thu 16 Jul 2015 06:13:56 PM UTC, comment #3:

So I suppose the logic should be

is that correct?

John W. Eaton <jwe>
Project Administrator
Thu 16 Jul 2015 06:00:29 PM UTC, comment #2:

This changeset creates a new incompatibility with MATLAB:

MATLAB returns a 10x1 array while Octave now returns a 10x0 one.

Guillaume <gyom>
Mon 15 Jun 2015 04:21:25 PM UTC, comment #1:

Technically, all Matlab mxArray objects have two dimensions. According to the documentation for mxCreateNumericArray (http://www.mathworks.com/help/matlab/apiref/mxcreatenumericarray.html) for the ndim argument:

So correct code for an empty matrix is to specify ndims = 2, with dims[0] = 0, dims[1] = 0. This will work in Octave or Matlab.

I have changed Octave to be Matlab-compatible if the ndims < 2. See this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/2691947f5409). This will be a part of the next bug fix release 4.0.1. Until then you can use the workaround above, or get the code from the stable branch of Octave's Mercurial repository and build Octave for yourself.

Rik <rik5>
Project Administrator
Sun 14 Jun 2015 09:26:11 AM UTC, original submission:

Take the following MEX-function:

and run it:

In Octave, this creates a scalar array initialized to 0,
i.e size(out) = [1 1], similar to double(0)

In MATLAB, this creates an empty array,
i.e size(out) = [0 0], similar to double([])

I'm using the official Octave installer, and the latest MATLAB R2015a.

Amro <amro_octave>


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

Attach Files:

Attached Files
file #34454:  diffs.txt added by jwe (999B - text/plain)


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 gyom (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by amro_octave (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
    2015-07-16 jwe Attached File- => Added diffs.txt, #34454
    2015-06-15 rik5 StatusNone => Fixed
        Open/ClosedOpen => Closed

    Back to the top

    Powered by Savane 3.4