bugGNU Octave - Bugs: bug #33808, nargchk should return empty matrix...

 
 

bug #33808: nargchk should return empty matrix if inputs are within range

Submitter:  Volkmar Glauche <glauche>
Submitted:  Wed 20 Jul 2011 10:27:27 AM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
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
   

Jump to the original submission

Sun 16 Oct 2011 08:35:34 PM UTC, comment #6: 

Fixed in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/a0875c6cab7e).  The error function now ignores empty struct inputs.

Rik <rik5>
Group administrator
Sat 15 Oct 2011 01:19:21 AM UTC, comment #5: 

the problem is the error function:

matlab> foo

foo =

0x1 struct array with fields:
    message
    identifier
matlab> error(foo)


octave> foo
foo =

  0x1 struct array containing the fields:

    message
    identifier

octave> error(foo)
error: invalid conversion of multi-dimensional struct to scalar struct

Muhali <muhali>
Fri 14 Oct 2011 10:28:38 PM UTC, comment #4: 

but now I get

octave:1> error(nargchk(1,5,4,'struct'))
error: invalid conversion of multi-dimensional struct to scalar struct

Muhali <muhali>
Mon 25 Jul 2011 05:39:06 PM UTC, comment #3: 

Sorry about that.  I have now put in a special case into nargchk and nargoutchk to return a 0x1 struct array exactly as Matlab does.  The changeset is here (http://hg.savannah.gnu.org/hgweb/octave/rev/49553ea11764).

Rik <rik5>
Group administrator
Mon 25 Jul 2011 09:36:16 AM UTC, comment #2: 

I still seem to get a non-empty struct:

octave:1> s=nargchk(1,5,4,'struct')
s =

  scalar structure containing the fields:

    message =
    identifier =

octave:2> whos s
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        s           1x1                          0  struct

Total is 1 element using 0 bytes

octave:3> isempty(s)
ans = 0
octave:4> ver
----------------------------------------------------------------------
GNU Octave Version 3.5.0+
GNU Octave License: GNU General Public License
Operating System: Linux 2.6.38-11-generic #47-Ubuntu SMP Fri Jul 15 19:27:09 UTC 2011 x86_64
----------------------------------------------------------------------
no packages installed.


s should not be 1x1, but 1x0, 0x0 whatever... At least, isempty(s) should return "true".

Volkmar Glauche <glauche>
Wed 20 Jul 2011 05:48:06 PM UTC, comment #1: 

Fixed in this changeset <http://hg.savannah.gnu.org/hgweb/octave/rev/a4d1581f9e72>

You will need to build from the Mercurial development sources in order to see the fix.

Rik <rik5>
Group administrator
Wed 20 Jul 2011 10:27:27 AM UTC, original submission:  

nargchk behaviour differs between MATLAB and octave in cases like the following:

s = nargchk(1,5,4,'struct')

MATLAB returns

s =

0x1 struct array with fields:
    message
    identifier

Octave returns

s =

  scalar structure containing the fields:


octave:5> whos s
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        s           1x1                          0  struct

I.e. MATLAB returns an empty struct with two fields, while Octave returns a 1-element struct with no fields. MATLAB has documented its nargchk behaviour as follows:

--- cited from MATLAB help
MSGSTRUCT = NARGCHK(LOW,HIGH,N,'struct') returns an appropriate message structure if N is not between LOW and HIGH. If N is in the specified range, the message structure is empty. The message structure has at a minimum two fields, 'message' and 'identifier'.
---

MATLAB code that relies on this behaviour will fail on Octave if N is in the specified range. This may be related to bug #33428.

Volkmar Glauche <glauche>

 

(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 glauche (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-07-20 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code