Opened 13 years ago

Closed 13 years ago

#122 closed defect (fixed)

Checking for even array size is incorrect

Reported by: simon.guest@… Owned by: MatthewWhiting
Priority: normal Milestone:
Component: Code base Version: 1.1.12
Severity: normal Keywords:
Cc:

Description

In the file getStats.cc a the following methods attempt to detect and do something to deal with even length arrays.

template <class T> T findMADFM(T *array, int size, bool changeArray)
template <class T> T findMADFM(T *array, int size, T median, bool changeArray)
template <class T> T findMedian(T *array, int size, bool changeArray)

Each contain a section of code similar to that below. Note the first line of the snippet is failing to correct check for even size, merely whether size is 0 or 1.

I am not sure of the implication of this, however I thought it worth reporting.

  bool isEven = ((size/2)==0);
  std::nth_element(newarray,newarray+size/2,newarray+size);
  median = newarray[size/2];
  if(isEven){
    std::nth_element(newarray,newarray+size/2-1,newarray+size);
    median += newarray[size/2-1];
    median /= T(2);
  }

Change History (1)

comment:1 Changed 13 years ago by MatthewWhiting

Resolution: fixed
Status: newclosed

Thanks Simon,

I have fixed this, and it is available in the latest release that I made available this week.

It does have an effect, albeit a small one in most cases. The difference will be for even-length arrays, the median was estimate by array[size/2], instead of 0.5(array[size/2]+array[size/2-1]. If those two are different you'll get a different result, and that will depend on the nature of the data.

Unfortunately, this can mean differences in detection thresholds in some cases, which may mean different source lists that come out.

So, an important bug and thanks for pointing it out!

Note: See TracTickets for help on using tickets.