bugGNU Octave - Bugs: bug #40575, Saving cells containing matrices...

 
 

bug #40575: Saving cells containing matrices with NA fails to load

Submitter:  None
Submitted:  Thu 14 Nov 2013 04:07:03 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Matt Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.4
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 16 Nov 2013 02:39:15 PM UTC, comment #8: 

The problem with loading/saving NA values in text format has been solved, so I think it would be useful to find any code that transmutes NaNs to NAs, but probably not essential.  I did a few simple tests on the command line and the NA behavior appears to be correct.


octave:1> NA + 1
ans = NA
octave:2> NA + NaN
ans = NaN
octave:3> sin (NA)
ans = NA
octave:4> NA/NA
ans = NA


Rik <rik5>
Group administrator
Fri 15 Nov 2013 08:02:55 AM UTC, comment #7: 

In reply to comment 4,  if you think this would help octave I can try to dig further to find out where NaNs transform to NAs.

  However once you get save working for NA,  if for most operational use,  NAs work the same way as NaNs,  then maybe it's not that big a deal.

I don't know enough about how NA works to evaluate such a thing.  I do know that isnan() evaluates to true on NAs and that they do propagate.  NaNs appear to dominate NAs in most calculations so it is odd.


Matt <seventhunders>
Thu 14 Nov 2013 06:03:50 PM UTC, comment #6: 

I fixed the problem in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/079da800451b).  The fix will be a part of Octave-3.8.0 which is due out in just a few weeks.

Rik <rik5>
Group administrator
Thu 14 Nov 2013 03:40:27 PM UTC, comment #5: 

The problem is likely to be in the code for handling complex numbers in text files.  I can save and restore NA values in ordinary real values.


x.a = NA;
x.b = 2;
x.c = NaN;
save -text tst.txt x
clear x
load tst.txt  # works


Rik <rik5>
Group administrator
Thu 14 Nov 2013 07:32:31 AM UTC, comment #4: 

If you provide some code that reproduces the problem with generating unexpecte NA values, then maybe someone can fix it.

For the other problem, I'll try to take a look at it and see why NAs fail to load in text files.

John W. Eaton <jwe>
Group administrator
Thu 14 Nov 2013 07:23:27 AM UTC, comment #3: 

The code is very complex unfortunately and I'm not the author of it.  I am merely hacking it until it conforms to octave.  The original array is actually initialized to all zeros.

However both NaNs and Infs are deliberately introduced to mark certain elements as unused.  Of course Matlab does not have NA, so that was not used.

I have to conclude that there are octave functions, built in or not that actually produce NAs, perhaps from NaNs.  In the code I notice things like fliplr() and sort() and isinf() and isnan() being used.  What happens to sort if there are NaNs in the array for example?

It would take a bit of work to skin out, but I can verify this much.  The array is filled with 0s prior to a section of code that loads the array with mathematical quantities derived from another array that contains some NaNs.  After this process, NAs are produced.


Matt <seventhunders>
Thu 14 Nov 2013 06:39:01 AM UTC, comment #2: 

It looks to me like there are only a few ways you could generate NA.  You can read NA from a file.  You can generate NA by reading it from a string with str2double.  Or you can generate it by extrapolating with an interpolation function like interp1.  It might also be possible for the glpk linear programming solver to return NA in some cases.  Which are you using?  For compatibility, maybe one or more of these functions should return NaN instead of NA.

John W. Eaton <jwe>
Group administrator
Thu 14 Nov 2013 06:12:05 AM UTC, comment #1: 

Confirmed.  This is still present on the development branch.  However, the problem seems to be limited only to the text format.  If you can save the data in another format--matlab binary (since you're starting with a Matlab project), octave binary, hdf5--then the data will load correctly.

Alternatively, you could just open the text file in an editor and do a search and replace with NA -> NaN.  Then the file will also load.

Rik <rik5>
Group administrator
Thu 14 Nov 2013 04:07:03 AM UTC, original submission:  

If your cell array contains matrices with NA (not NaN), and you save it as ascii (is this the default?),  you can not load it in again.

Here is a simple example

H = cell(2,1)
H{1} = ones(2,3) - j * ones(2,3) ;
zz = ones(2,3) ;
zz(2,:) = j *[NA, NA, NA] ;
H{2} = zz ;
save bad H
load bad


This fails with the error:
error: load: failed to load matrix constant
error: load: trouble reading ascii file ''
error: load: reading file
error: load: cell array element had unexpected name
error: load: failed to load cell element
error: load: trouble reading ascii file 'bad'
error: load: reading file bad
error: called from:


I have run across several bugs in trying to convert a large complex matlab project into octave.  For some reason some of the converted Matlab code is filling some columns of my matrices with NA's instead of NaNs.  I am now faced with the prospect of flushing out the NAs and replacing them with NaNs to get this to work.


Anonymous

 

(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 seventhunders (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (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
    2013-11-14 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2013-11-14 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code