Serious bug in find()?

Dean S. Messing deanm at sharplabs.com
Wed Nov 17 20:24:21 CET 2010


Before I submit this to Bugzilla I'd like your expert opinions: does the
following tickle a longstanding bug in find()?

I have is an array of 19,200,000 reals.  There are seven sub-vectors
w/in the array that each contain 2000 Nan's (due to hardware failure in
a device).

When I use find() together with isnan() to find the beginning of each
sub-vector, some indices that find() returns are off by 1.  Following is
a short script to demonstrate.  This bug is in both scilab-branch-5.3
and scilab-4.1.1.  I've verified that the vector isnan() returns is
correct.

How to demonstrate the bug:

Fire up Scilab and run the following script:

// Generate a vector, v, containing 7 subvectors == %nan*ones(2000,1)
// Each subvector begins at a multiple of 2000 (plus 1).
stacksize(100000000)
clear v
v=rand(19200000,1);
i=[10336001,..
   13716001,..
   15400001,..
   15402001,..
   18278001,..
   18762001,..
   19198001];
for j=i
  v(j:j+1999) = %nan*ones(2000,1);
end


// w  conforms to v and contains %t everywhere v == %nan.
w=isnan(v);

// w1 are the indices in v at whose location v == %nan
w1=find(w); 

// zero out all the Nan's in v.
v(w1) = 0;  

// This shd. be a real.  But it's Nan!
// So v still contains at least one Nan.
sum(v)

// Step though w1 to and print the seven starting indices of each
// subvector of Nan's in v.
w1(1 : 2000 : 7*2000)
                      



The output of the last two insructions is:

-->sum(v)
 ans  =
 
    Nan 
 
-->
 
-->// Step though w1 to and print the seven starting indices of each
 
-->// subvector of Nan's in v.
 
-->w1(1 : 2000 : 7*2000)
 ans  =
 
    10336001.    13716001.    15400001.    15402001.    18278000.    18762000.    19198000.  

The last three indices are off by 1!

Indeed, for example, w(18278000) == %f  and  w(18278001) == %t.
So find() has returned the wrong indices!

Dean



More information about the dev mailing list