help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a function for computing bursts of errors


From: Francesco Potorti`
Subject: Re: a function for computing bursts of errors
Date: Wed, 02 Mar 2005 15:37:21 +0100

>"If it ain't broke don't fix it"

:-)

>Unless you have specific problems (maybe you have HUGE vectors and
>want to minimise memory usage)

Yes, that's it.  I currently work with arrays in the high tens of
millions of packets, for which my memory is barely enough, and I want to
try more.  And squeezing a factor of eight would be nice, also possibly
increasing speed because of less real memory (not cached) access.

More precisely, I have two questions:

- would I obtain any advantage in adding a line like 
      x = logical(x)
  just at the beginning of the function?

- would I obtain any advantage in passing a boolean vector to the
  function, rather than a numeric one?

>> ===File /home/pot/math/octavelib/tsa/bursts.m===============
>> function b = bursts(x)
>> 
>>   ## usage: B = bursts (X)
>>   ##
>>   ## Given a matrix X, return the number of bursts of different lengths.
>>   ##
>>   ## A burst of length n is a sequence of n values different from 0,
>>   ## delimited either by zero values or the start or end of the vector.
>>   ##
>>   ## Francesco Potortì <address@hidden>, 2004
>>   ## License: GNU GPL <http://www.gnu.org/licenses/gpl.html>
>> 
>>   if (nargin != 1)
>>     usage ("B = bursts (X)");
>>   endif
>> 
>>   if (!isvector(x))
>>     error ("bursts: x must be a vector");
>>   endif
>> 
>>   ## Make x a column vector of ones where different from 0.
>>   if (columns(x) != 1)
>>     x = x';
>>   endif
>>   x = !x;
>> 
>>   ## Find the places where there is a 1, then compute the burst lenghts.
>>   b = diff([0;find(x);rows(x)+1])-1;
>> 
>>   ## Remove the zero-length bursts
>>   b = b(b>0);
>> endfunction
>> ============================================================

P.S. about the license: John Eaton rightfully suggested that referring to
an URL for the license is not enough.  I know, but I use three grades of
correctness, depending on the size of the program and its importance:
the first grade is just an URL, like below.  The second is the usual
blurb that says you should write to the FSF.  The second is the usual
blurb plus the license text, bundled in a tar file.  The program below
is so small and trivial as to being barely worth a license at all :-)

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 313 8091
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]