bugGNU Octave - Bugs: bug #49389, inputParser changes order of...


bug #49389: inputParser changes order of Results structure depending on order by which parameters are assigned

Submitted by:  Carlo de Falco <cdf>
Submitted on:  Wed 19 Oct 2016 10:37:50 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Sun 30 Oct 2016 03:36:53 PM UTC, comment #11:


Carlo de Falco <cdf>
Project Member
Sun 30 Oct 2016 03:18:58 PM UTC, comment #10:

With matlab 2015a

Tue 25 Oct 2016 12:13:19 AM UTC, comment #9:

For completeness, can this test be run under Matlab?

This checks that the Parameters field is being used to order the output in Results, and also whether the Parameters list is held in alphabetical order.

Rik <rik5>
Project Administrator
Fri 21 Oct 2016 03:47:01 PM UTC, comment #8:

What I am trying to achieve is something similar to the way graphics properties are handled. Every object has a core set of graphics properties that are listed first, followed by the list of properties that are specific to the object in question.

From a user perspective, I think it will be easiest to understand if the core set of ODE solver options is presented first and in alphabetical order, followed by any customized properties supplied by the user.

One way to achieve that is to have full Matlab compatibility for the inputParser function. The other would be to post-process the Results structure with orderfields(), but it sounds like Carlo has an approach that will work.

Rik <rik5>
Project Administrator
Fri 21 Oct 2016 02:30:53 PM UTC, comment #7:


While trying to prepare a patch to avoid changing the order of parameters with "parse ()" I noticed that "Switches" are not available in Matlab, why do we have that in Octave? Is there
some backward compatibility we need to keep?

Carlo de Falco <cdf>
Project Member
Fri 21 Oct 2016 02:12:45 PM UTC, comment #6:


For completeness here's the result of the test you asked:

Carlo de Falco <cdf>
Project Member
Fri 21 Oct 2016 02:07:12 PM UTC, comment #5:


Matlab does not keep struct keys sorted alphabetically
they are ordered according to the order in which they
were added to the struct.

Indeed the properties returned by odeset are not in
alphabetical order in Matlab either:

on the other hand they do not change with each assignment.


In inputParser.parse () the values passed are assigned first,
then the the remaining Parameters are assigned the default value.

If we would assign the default value to all parameters first,
then overwrite those passed to parse we would get the same behaviour
as Matlab, and it would propbably also run a bit faster.

But you are right that this does not seem to be a documented Matlab
feature so we don't necessarily need to copy it.

Carlo de Falco <cdf>
Project Member
Fri 21 Oct 2016 11:24:22 AM UTC, comment #4:

> It may be that Matlab always maintains struct keys in sorted order.

Matlab struct keys are ordered by insertion. But Results does not have values inserted until parse is called. This is the same in Matlab addParameter/addParamValue

The actual order of insertion is kept, in Parameters:

If Matlab Results has the same order of values as the order of add*, then that's an implementation detail. And an undocumented one. Since Results is a struct, the type of thing where order of keys does not usually matter, what is the use case for this?

Also, is this a Matlab compatibility issue? There are more functions in Octave that return structs where the order of keys differ from Matlab.

Carnë Draug <carandraug>
Project Member
Fri 21 Oct 2016 04:02:26 AM UTC, comment #3:

To see whether Matlab internally orders struct fields try

It may be that Matlab always maintains struct keys in sorted order.

Rik <rik5>
Project Administrator
Thu 20 Oct 2016 07:48:05 PM UTC, comment #2:

inputParser does not change the order of Results because Results is empty before parse.

Is this bug really about the order of values in Results (a scalar struct) or about the display method?

Carnë Draug <carandraug>
Project Member
Thu 20 Oct 2016 03:22:56 PM UTC, comment #1:

@Carlo: Could you run one more test in Matlab to see if it always sorts the return values by Parameter name, or whether it uses the order in which parameters were added to the inputParser.

Rik <rik5>
Project Administrator
Wed 19 Oct 2016 10:37:50 PM UTC, original submission:

The following example demonstrates the issue

In Matlab 2016a:

In Octave 4.2-rc2:

Carlo de Falco <cdf>
Project Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

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 cdf (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.3