#254 closed defect (fixed)
Ordinary polynomial evaluation is incorrect
| Reported by: | Paul Price | Owned by: | Paul Price |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | types | Version: | 0.3.0 |
| Severity: | major | Keywords: | |
| Cc: | gusciora@… |
Description
The implementation of the evaluation of ordinary polynomials is incorrect. The
accumulation is placed inside the "if (mask)" test, such that accumulation does
not take place if a coefficient is masked.
This is the case both in rel_3 and the mainline (I have revision 1.71 of
psFunctions.c, dated 3 Dec, but the lines in question don't appear to have been
updated since then).
I will attach example code demonstrating the bug (I suggest that it be worked in
to unit tests to demonstrate the masking functionality). It calculates a 1D
polynomial in two ways. The first is to mask out one of the coefficients; the
other is to set that coefficient to zero and not mask it. These two methods
should produce the same result. Here's what I get:
price@mithrandir:/home/mithrandir/price/testing>./polynomialBug
Value using mask: 1.000000
Value using coefficient zeroing: 0.500000
The fix is to move lines such as "xSum *= x;" outside the "if (mask)" block.
Note that this bug applies to evaluation of single- and double-precision
versions of ordinary polynomials of all dimensions.
Attachments (1)
Change History (8)
by , 22 years ago
| Attachment: | polynomialBug.c added |
|---|
comment:1 by , 22 years ago
| Owner: | changed from to |
|---|
comment:2 by , 22 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
I fixed this in our current development version of psLib.
Actually, according to version 10 of the SDRS, your code isn't quite right
either. The SDRS states "those coefficients that have the corresponding mask
element non-zero shall not be masked". So, according to the SDRS, setting the
mask element to zero, not one, masks that coefficient.
Personally, I prefer your code, not the SDR: masks set to one should mean the
coefficients will be ignored (that's how we use masks in the images).
What do you think?
comment:3 by , 22 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
comment:4 by , 22 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → new |
comment:5 by , 22 years ago
| Status: | new → assigned |
|---|
I used 1 to mask because that's what the code does.
This is a matter for personal preference, but we should be consistent
throughout. I shall propose to Gene that throughout psLib we adopt for masks
that non-zero stands for "ignore this", while zero means "use this".
comment:6 by , 22 years ago
| Cc: | added |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |
Adopted: if a mask is non-zero, the corresponding value is not included. This
affects polynomials and minimization.

Code to reproduce polynomial bug.