bugGNU Octave - Bugs: bug #64113, optimget should accept [] as first...

 
 

bug #64113: optimget should accept [] as first argument

Submitter:  Muhali <muhali>
Submitted:  Wed 26 Apr 2023 09:05:10 AM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 7.3.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 31 May 2023 12:32:45 AM UTC, comment #10: 

I would propose to close this report with "Won't Fix".  I don't see a compelling use case for supporting this undocumented behavior.

Rik <rik5>
Group administrator
Thu 27 Apr 2023 08:17:09 PM UTC, comment #9: 

i just meant consistent in behavior when a size = [0,0] 'something' is passed to it.  struct() returns something of size = [1,1].  a lot of matlab functions seem to have nonstandard handling of (only ) [], while empties of any other size do other things. so, consistently inconsistent?

Nicholas Jankowski <nrjank>
Group Member
Thu 27 Apr 2023 06:45:46 PM UTC, comment #8: 

Definitely inconsistent.  The input is supposed to be a scalar struct, not a struct array.  It's nonsensical to have an optimget settings array with more than one element because then how would the interpreter decide which to apply?

Rik <rik5>
Group administrator
Wed 26 Apr 2023 06:53:57 PM UTC, comment #7: 

note there is a difference between:


>> a = struct

a =

  struct with no fields.

>> a = struct.empty

a =

  0×0 empty struct array with no fields.


>> optimget (struct,"Display")
Unrecognized field name "Display".

Error in optimget (line 94)
o = options.(Names(j));

>> optimget (struct.empty,"Display")

ans =

     []


so, it's somewhat consistent.  when passed an empty array as an input OPTION structure, the returned value is always [].  (unless you use the three input form in which case the return is always the default value set)

Nicholas Jankowski <nrjank>
Group Member
Wed 26 Apr 2023 06:08:15 PM UTC, comment #6: 

I think we should choose the path that makes sense here, rather than slavish Matlab compatibility.  Testing with R2023a


optimget ([], 'Display')
ans = []
optimget ([], 'Display', 'abc')
ans = 'abc'
optimget (struct, 'Display', 'abc')
=> Unrecognized field name "Display"


Seems inconsistent to accept empty matrix inputs and return the default value, but not accept empty struct inputs and return the default value.

Also, what is the use case for this?  More code---to handle weird exceptions---means more maintenance burden.

Octave seems better to me because it checks the first argument for being the expected type (struct) and for the third example, it returns "abc" because Octave correctly finds that there is no field "Display" in the empty struct.

If anything, I think the input validation could be made more precise.  The code in optimget.m is


  if (nargin < 2 || ! isstruct (options) || ! ischar (optname))
    print_usage ();
  endif


I would use print_usage () only for the case where the number of arguments is wrong.  I would then break out the argument 1 and argument 2 checking to produce specific error messages about what is wrong with each input.

Rik <rik5>
Group administrator
Wed 26 Apr 2023 03:31:57 PM UTC, comment #5: 

R2023a i get the same `help optimget` output including [] comment.

Nicholas Jankowski <nrjank>
Group Member
Wed 26 Apr 2023 03:12:18 PM UTC, comment #4: 

Funny. I looked directly at my ML R2019b help, which one would think is the same as

https://www.mathworks.com/help/releases/R2019b/matlab/ref/optimget.html?s_tid=doc_ta

But it is not. Here is what I get:

>> help optimget

 optimget Get OPTIM OPTIONS parameters.
    VAL = optimget(OPTIONS,'NAME') extracts the value of the named parameter
    from optimization options structure OPTIONS, returning an empty matrix if
    the parameter value is not specified in OPTIONS.  It is sufficient to
    type only the leading characters that uniquely identify the
    parameter.  Case is ignored for parameter names.  [] is a valid OPTIONS
    argument.
 
    VAL = optimget(OPTIONS,'NAME',DEFAULT) extracts the named parameter as
    above, but returns DEFAULT if the named parameter is not specified (is [])
    in OPTIONS.  For example
 
      val = optimget(opts,'TolX',1e-4);
 
    returns val = 1e-4 if the TolX parameter is not specified in opts.
 
    See also optimset.

>> ver

-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.7.0.1737446 (R2019b) Update 9

Muhali <muhali>
Wed 26 Apr 2023 02:55:22 PM UTC, comment #3: 

I do not see that text in the current online Matlab documentation here:

https://www.mathworks.com/help/matlab/ref/optimget.html

Are you looking at the documentation for some older version?

John W. Eaton <jwe>
Group administrator
Wed 26 Apr 2023 02:36:17 PM UTC, comment #2: 

The doc has

----------
...  [] is a valid OPTIONS argument.

VAL = optimget(OPTIONS,'NAME',DEFAULT) extracts the named parameter as
    above, but returns DEFAULT if the named parameter is not specified (is [])
    in OPTIONS.  For example
 
      val = optimget(opts,'TolX',1e-4);
 
    returns val = 1e-4 if the TolX parameter is not specified in opts.
----------

which sounds pretty clear to me. That is, optimget([],'TolX',1e-4) should return 1e-4.

Muhali <muhali>
Wed 26 Apr 2023 12:31:51 PM UTC, comment #1: 

ML doc specifies that the first argument should be a struct, and that the return argument should also be a struct. So this looks like a doubly undefined behavior (or undocumented "feature" if you prefer).

Pantxo Diribarne <pantxo>
Group Member
Wed 26 Apr 2023 09:05:10 AM UTC, original submission:  

In Matlab,

optimget ([], "Display", "notify")

returns 'notify' whereas ocatve returns an error.

Muhali <muhali>

 

(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 nrjank (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by muhali (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
    2023-04-26 rik5 Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
    2023-04-26 pantxo StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code