bugGNU Octave - Bugs: bug #49979, format compact/loose different...

 
 

bug #49979: format compact/loose different from Matlab

Submitter:  Rik <rik5>
Submitted:  Tue 03 Jan 2017 04:49:22 PM UTC
   
 
Category:  Interpreter Severity:  1 - Wish
Priority:  1 - Later Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 05 Jan 2017 06:39:36 PM UTC, comment #5: 

I think jwe's suggestion is reasonable.  If anyone wants 100% visual compatibility with Matlab they can write their own display routines to do so.

For comment #3, bug #49794 was fixed by jwe.  I just closed bug #33383 because it was in turn resolved by the cset for #49794.

To anyone who comes later, I have changed the Severity to Wish and the Priority to Later.  We can review any changesets that people have, but the core developers aren't going to work on it.

Rik <rik5>
Group administrator
Thu 05 Jan 2017 06:18:37 PM UTC, comment #4: 

If the output format changed, it wasn't intentional.

I agree that each element of a struct or cell should be formatted independently of context.  I really don't want to have the function that displays the contents of a matrix checking to see whether it is called in the context of displaying a cell or struct or some other object and doing special things because of that.

Meta comment:  I find it a little crazy that people seem to care about this issue and expect that Octave displays all output exactly as Matlab does.  But whatever, we could certainly have an option.  Or, now it should be possible for you to write your own @cell/display.m and @cell/disp.m functions to do whatever you want.

John W. Eaton <jwe>
Group administrator
Thu 05 Jan 2017 05:57:27 PM UTC, comment #3: 

I prefer Octave's cell array output by default, showing the contents. This is similar to the intentional difference in struct arrays (configurable with struct_levels_to_print).

If people want truly compatible output, maybe there could be a similar configuration option, cell_contents_display, that could be set with the --traditional command line option.

The major drawback with Octave's approach is bug #33383. Octave's core should be in charge of how the cell array is formatted (whether it shows indices in brackets or not, whether it shows a value in brackets or not, or whether it just shows a dimension), and each element should be in charge of only how its value is displayed. That may have changed with bug #49794, I haven't been following developments in the past month or so.

Mike Miller <mtmiller>
Group Member
Thu 05 Jan 2017 05:34:16 PM UTC, comment #2: 

Thanks for checking in Matlab.  Should we make it a goal of Octave to move to the Matlab method of displaying cell arrays?  Or is what we have good enough?

Rik <rik5>
Group administrator
Thu 05 Jan 2017 10:26:43 AM UTC, comment #1: 

For Matlab R2016b I get:

Scalars


>> format compact
>> theta = pi/2
theta =
    1.5708
>> format loose
>> theta = pi/2

theta =

    1.5708

>>


Matrices


>> format compact
>> x = magic (3)
x =
     8     1     6
     3     5     7
     4     9     2
>> format loose
>> x = magic (3)

x =

     8     1     6
     3     5     7
     4     9     2

>>


Cell arrays


>> format compact
>> y = {magic(2); magic(3)}
y =
  2×1 cell array
    [2×2 double]
    [3×3 double]
>> format loose
>> y = {magic(2); magic(3)}

y =

  2×1 cell array

    [2×2 double]
    [3×3 double]

>>


I think Octave and Matlab produce reasonable output. For your last example, Matlab chooses a more pragmatic approach to avoid too verbose output. Maybe we can also adapt this for matrices? For scalars one gets in Matlab the values (as `1x1 double` is less informative than printing out the value itself):


>> format compact
>> y = {3; magic(2)}
y =
  2×1 cell array
    [         3]
    [2×2 double]
>> format loose
>> y = {3; magic(2)}

y =

  2×1 cell array

    [         3]
    [2×2 double]

>>


Kai Torben Ohlhus <siko1056>
Group Member
Tue 03 Jan 2017 04:49:22 PM UTC, original submission:  

There are a number of differences in the display of variables between Matlab and Octave related to the compact/loose option to format.

The first, which I don't think we should change, is the the universal presence of a newline after the name of the variable in Matlab.  Under Octave, the interpreter makes a decision about how large the display of the variable will be and if it is short, it puts it all on one line.  I like that.

For instructional purposes, here are the documented Matlab display of the same variable under compact/loose


Compact:
theta = pi/2
theta =
  1.5708


and


Loose:
theta = pi/2

theta =

  1.5708


Under Octave with either format


theta = pi/2
theta =  1.5708


The question is how to display something more complicated, like a matrix, under the two different formats.  This is the result under 4.2.0


>> x = magic (3);
>> format compact
>> x
x =
   8   1   6
   3   5   7
   4   9   2
>> format loose
>> x
x =

   8   1   6
   3   5   7
   4   9   2

>>


The difference is a newline before and after the matrix.  However, there is no newline before the name of the variable "x =" as there is in Matlab under format loose to help separate the interpreter command from the display.  Maybe that is worth changing?

A second possible change is that the newline is always inserted after the matrix object, when for cells it should be after the cell braces which mark the start and end of the object.

An example is


>> format compact
>> y = {magic(2); magic(3)}
y =
{
  [1,1] =
     4   3
     1   2
  [2,1] =
     8   1   6
     3   5   7
     4   9   2
}
>> format loose
>> y
y =
{
  [1,1] =

     4   3
     1   2

  [2,1] =

     8   1   6
     3   5   7
     4   9   2

}
>>


Again, just a question, but maybe it would make more sense to remove the newline before the final '}' and place it after the '}' so there was some space before the start of the next interpreter command prompt.  Someone could also check under Matlab and see how it treats these examples.

Rik <rik5>
Group administrator

 

(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 jwe (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by rik5 (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-05 rik5 Severity2 - Minor 1 - Wish
        Priority5 - Normal 1 - Later

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code