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

 
 

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

Submitted by:  Volkmar Glauche <glauche>
Submitted on:  Wed 20 Jul 2011 10:27:27 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment (Rich MarkupRich 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)

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>
Project 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>
Project 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>
Project 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 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 rik5 (Posted a comment)
  • -unavailable- added by glauche (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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 20 Jul 2011 05:48:06 PM UTCrik5StatusNone=>Fixed
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup