bugGNU Octave - Bugs: bug #45837, inputParser: checks property...

 
 

bug #45837: inputParser: checks property default value but should not

Submitter:  Avinoam Kalma <avinoam>
Submitted:  Thu 27 Aug 2015 03:41:17 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Avinoam Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 08 Oct 2015 07:16:08 PM UTC, comment #6: 
Carnë Draug <carandraug>
Group Member
Mon 31 Aug 2015 02:55:27 PM UTC, comment #5: 

It is bad programming what ML does, but I do not care. I think is better to follow their behavior, so that ML code works in Octave.

Would you do it or shall I do it?

Juan Pablo Carbajal <juanpi>
Group Member
Mon 31 Aug 2015 02:50:28 PM UTC, comment #4: 

So apparently the issue is that Matlab does not checks if the default value passed to inputParser is valid or not.  This is done by the validate_default method

  http://hg.savannah.gnu.org/hgweb/octave/file/784ed55fdde8/scripts/general/inputParser.m#l438

and fixing it would be as simple as removing it.  There is some performance to be gained by not running this test everytime if we want to go that way.

Carnë Draug <carandraug>
Group Member
Mon 31 Aug 2015 09:16:33 AM UTC, comment #3: 

Therefore, if when the function ip_bug is called without arguments, the validator

p.addParamValue ('Dir', def_dir, @ischar);

gets and empty array (your default value) and it fails. This is consistent and correct, since as you just saw [] is double not char.

Now, it might be that Matlab's inputParser is not calling the validator when the default argument is given. I would deem that as a ML bug. Because it allows for default initializations that cannot be passed as input arguments.

The solution is to use consistent defautl values. in your case def_dir should pass the validation step, therefore it should be

+varbatim+
def_dir =""
-verbatim-

or if you think that is ambiguous


def_dir = char([])




Juan Pablo Carbajal <juanpi>
Group Member
Mon 31 Aug 2015 03:52:09 AM UTC, comment #2: 


Using Matlab 2010b


>> x = [];
>> whos x
  Name      Size            Bytes  Class     Attributes

  x         0x0                 0  double

>> ischar(x)

ans =

     0


same results as Octave.

Avinoam Kalma <avinoam>
Group Member
Thu 27 Aug 2015 03:54:43 PM UTC, comment #1: 

I octave the empty array is not of char type. Could you test the following in Matlab


x = [];
whos x
ischar(x)


In your function you could use def_dir = "" to make it work and be more conssistent.

Juan Pablo Carbajal <juanpi>
Group Member
Thu 27 Aug 2015 03:41:17 PM UTC, original submission:  


Using the following function


function ip_bug (varargin)

def_dir = [];
p = inputParser;

p.addParamValue ('Dir', def_dir, @ischar);
p.parse (varargin{:});
input_dir = p.Results.Dir;

if (isempty (input_dir))
  disp ('no path');
 else
  disp (input_dir);
end
end


in matlab R2010b


>> ip_bug ()
no dir


in Octave:


>> ip_bug ()
error: inputParser.addParamValue: failed validation for 'Dir' default value
error: called from
    validate_default at line 440 column 9
    addParamValue at line 315 column 7
    ip_bug at line 6 column 1


Avinoam Kalma <avinoam>
Group Member

 

(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 juanpi (Posted a comment)
  • -email is unavailable- added by avinoam (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
    2015-10-08 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2015-08-31 carandraug SummaryinputParser.addParamValue: failed validation for empty string inputParser: checks property default value but should not

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code