bugGNU Octave - Bugs: bug #54736, load() should issue an error if...

 
 

bug #54736: load() should issue an error if specified variable does not exist in file

Submitter:  Guillaume <gyom>
Submitted:  Wed 26 Sep 2018 04:41:25 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Missed Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 12 Oct 2018 04:37:59 AM UTC, comment #4: 

There is more oddness to this bug report.  If the saved file format is Octave binary then no error is ever printed regardless of whether one or more of the requested variables does not exist.

Rik <rik5>
Group administrator
Thu 27 Sep 2018 04:23:26 PM UTC, comment #3: 

Yes.  I assumed that was the case where Octave iterated over the list of variables ('A', 'B', ...) and tried each one individually.  I tried your test case and it doesn't so that should be fixed.

Re-titling and re-opening bug report.


Rik <rik5>
Group administrator
Thu 27 Sep 2018 03:52:50 PM UTC, comment #2: 

In that case, should we also throw an error for


x = load ('A.mat', 'A', 'B')


if A.mat doesn't contain a variable named B?

John W. Eaton <jwe>
Group administrator
Thu 27 Sep 2018 03:46:11 PM UTC, comment #1: 

I understand that Octave is different in this regard, but I want to keep the stricter checking.

Philosophically, I prefer that Octave signal to the programmer at the earliest possible opportunity when something has gone wrong.  This makes debugging easier because the problem and the resulting error are located close together.

Matlab's approach is often to return a silent null ([]) when things go wrong.  But this allows the script to continue and it may be quite a while before the error is detected, or maybe never.  Many scripts are run in batch mode and so warning messages printed are never seen, whereas a hard error will be detected.

Rik <rik5>
Group administrator
Wed 26 Sep 2018 04:41:25 PM UTC, original submission:  

When trying to load a named variable of a mat-file, if it is not present, Octave returns an error while  Matlab displays a warning and returns an empty structure.

Octave:


octave> A = pi;
octave> save('A.mat','A');
octave> x = load('A.mat','A')
x =
  scalar structure containing the fields:
    A =  3.1416
octave> x = load('A.mat','B')
error: load: empty name keyword or no data found in file 'A.mat'
octave> x = load('A.mat','A','B')
x =
  scalar structure containing the fields:
    A =  3.1416


Matlab:


>> A = pi;
>> save('A.mat','A');
>> x = load('A.mat','A')
x =
  struct with fields:
    A: 3.141592653589793
>> x = load('A.mat','B')
Warning: Variable 'B' not found.
x =
  struct with no fields.
>> x = load('A.mat','A','B')
Warning: Variable 'B' not found.
x =
  struct with fields:
    A: 3.141592653589793


Guillaume <gyom>

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-02 rik5 Priority5 - Normal 3 - Low
    2018-09-27 rik5 Item GroupMatlab Compatibility Missed Error or Warning
        StatusWont Fix Confirmed
        Open/ClosedClosed Open
        SummaryBehavior of load() when a specified name keyword is missing load() should issue an error if specified variable does not exist in file
    2018-09-27 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code