bugGNU Octave - Bugs: bug #52420, inputParser optional argument is...

 
 

bug #52420: inputParser optional argument is "not a valid parameter"

Submitter:  None
Submitted:  Thu 16 Nov 2017 01:31:08 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Ryan Govostes Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 17 Nov 2017 02:04:37 AM UTC, comment #4: 

Octave generally doesn't try to match undocumented Matlab behavior because it can change unpredictably between versions.  I'm not sure why addOptional is working in Matlab, but since usin addParameter seems to be the correct thing to do, and it works, I'm going to close this report.

Rik <rik5>
Group administrator
Fri 17 Nov 2017 01:35:17 AM UTC, comment #3: 

I confirmed that the snippet works Matlab R2017a, but the documentation for Matlab's addOptional indicates that maybe Octave is correct here:

> Use addOptional to add an individual argument into the input parser scheme. If you want to parse an optional name-value pair, use the addParameter function.


I changed the code to use addParameter and it seems to be happier now.

Anonymous
Fri 17 Nov 2017 01:09:03 AM UTC, comment #2: 

Can the original reporter test this code, as written, in Matlab?  I'm not certain that it is valid.  According to the documentation for addOptional (http://www.mathworks.com/help/matlab/ref/inputparser.addoptional.html), addOptional creates a positional input variable, not a key/value pair.


Arguments added to the input parser scheme with the addOptional function are positional. Therefore, add them to the input parser scheme in the same order they are passed into the function.

Use addOptional to add an individual argument into the input parser scheme. If you want to parse an optional name-value pair, use the addParameter function.


If you want to call with syntax of "name", value then you need to use addParameter.  Making that change to foo allows the function to run correctly.


function foo(a, varargin)
    p = inputParser();
    addParameter(p, 'sigma', 0, @isnumeric);
    parse(p, varargin{:});
    p.Results.sigma
end



Rik <rik5>
Group administrator
Fri 17 Nov 2017 12:52:16 AM UTC, comment #1: 

Confirmed.  Version 4.0.3 of Octave which you reported as using is deprecated and no longer supported.  However, I can reproduce this bug on the latest development code as well.



Thanks for taking the time to report this bug.

Without a stack trace from the crash it's very hard to determine
what caused it. Can you get us a stack trace? Please see
http://wiki.octave.org/Debugging_Octave for more information on
how to do so. Thanks in advance!

Rik <rik5>
Group administrator
Thu 16 Nov 2017 01:31:08 PM UTC, original submission:  

I'm running some code originally written for MATLAB which uses an inputParser to parse arguments. Here's a reduced example:


function foo(a, varargin)
    p = inputParser();
    addOptional(p, 'sigma', 0, @isnumeric);
    parse(p, varargin{:});
    p.Results.sigma
end


When I invoke this, I get an unexpected error:


>> foo(3, 'sigma', 3)
error: argument 'SIGMA' is not a valid parameter
error: called from
    error at line 480 column 7
    parse at line 397 column 13
    foo at line 4 column 5


I'm not very familiar with MATLAB but the documentation for function input parsing seems to suggest that this code is correct and that Octave's behavior deviates from MATLAB's.

Anonymous

 

(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 None (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-11-17 rik5 Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        StatusNeed Info Wont Fix
        Open/ClosedOpen Closed
    2017-11-17 rik5 StatusConfirmed Need Info
    2017-11-17 rik5 StatusNone Confirmed
        Release4.0.3 dev
        Operating SystemMac OS Any

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code