bugGNU Octave - Bugs: bug #29921, spline() should ignore NaNs

 
 

bug #29921: spline() should ignore NaNs

Submitted by:  Ben Abbott <bpabbott>
Submitted on:  Wed 19 May 2010 11:58:28 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: FixedAssigned to: Ben Abbott <bpabbott>
Originator Name: Ben AbbottOpen/Closed: Closed
Release: devOperating System: Mac OS

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Tue 25 May 2010 02:47:00 PM UTC, comment #4:

Sorry, I rushed through adding Rik's suggested change and neglected to delete the old code :-(

(file #20618)

Ben Abbott <bpabbott>
Project MemberIn charge of this item.
Tue 25 May 2010 01:45:05 PM UTC, comment #3:

In your patch, you have

+ for k = (1:columns (a))(any (isnan (a)))
+ ok = ! isnan (a(:,k));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+
+ if (any (isnan (a)))
+ for k = 1:size(a,2)
+ ok = (! isnan (a(:,k)));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+ endif

It looks like you are doing the same operation twice. Is that intended? If so, then it might be good to use a temporary variable to avoid computing this result more than once. Possibly also for the computation of the OK vectors.

Is the

if (any (isnan (a))

doing what you expect if A is a matrix? For example:

a = [1,2,3;4,NaN,6];

isnan (a) ==> [0,0,0;0,1,0]

any (isnan (a)) ==> [0,1,0]

and in an IF condition, this will be considered false.

John W. Eaton <jwe>
Project Administrator
Tue 25 May 2010 11:48:40 AM UTC, comment #2:

Rik, thanks for taking a look at this. I've uploaded a corrected version.

(file #20615)

Ben Abbott <bpabbott>
Project MemberIn charge of this item.
Tue 25 May 2010 04:52:57 AM UTC, comment #1:

From your Changeset:
+ if (any (isnan (a)))
+ for k = 1:size(a,2)
+ ok = (! isnan (a(:,k)));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+ endif

This will iterate over all of the columns (1:size(a,2)), including the ones which don't have NaNs in them. It would be more efficient to operate only on the columns with NaNs in them.
For example:
for k = (1:columns (a))(any (isnan (a)))
ok = ! isnan (a(:,k));
a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
endfor

It is a little opaque but the key is that it creates a range from 1 to the number of columns and then uses the isnan function to index into it so that only columns with NaNs will get processed.

Rik <rik5>
Project Administrator
Wed 19 May 2010 11:58:28 PM UTC, original submission:

An inconsistency with how Octave handles NaNs was reported on the help-list

http://www-old.cae.wisc.edu/pipermail/help-octave/2010-May/019689.html

Ben Abbott <bpabbott>
Project MemberIn charge of this item.

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #20618:  changeset.patch added by bpabbott (1KiB - application/octet-stream - version 3)
file #20615:  changeset.patch added by bpabbott (2KiB - application/octet-stream - version 2)
file #20567:  changeset.patch added by bpabbott (1KiB - application/octet-stream - proposed changeset)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by bpabbott (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 26 May 2010 04:08:46 PM UTCrik5Open/ClosedOpen=>Closed
    Tue 25 May 2010 10:18:11 PM UTCbpabbottStatusReady For Test=>Fixed
    Tue 25 May 2010 02:47:00 PM UTCbpabbottAttached File-=>Added changeset.patch, #20618
    Tue 25 May 2010 11:48:40 AM UTCbpabbottAttached File-=>Added changeset.patch, #20615
    Wed 19 May 2010 11:58:28 PM UTCbpabbottAttached File-=>Added changeset.patch, #20567

    Back to the top


    Powered by Savane 3.1-cleanup1