Mercurial > hg > audiodb
changeset 231:a5d2fa43accf refactoring
Code defensively in sequence_sum()
Previously, we could end up subtracting -inf from itself, giving nan.
This then propagated into power comparisons, leading to humour.
Instead, take a slow path if isfinite(<double>) is false.
author | mas01cr |
---|---|
date | Mon, 10 Dec 2007 18:25:55 +0000 |
parents | 0eab3ca2267d |
children | c76cdcf096fd |
files | query.cpp |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/query.cpp Mon Dec 10 18:21:35 2007 +0000 +++ b/query.cpp Mon Dec 10 18:25:55 2007 +0000 @@ -275,7 +275,13 @@ w = length - seqlen; // +1 - 1 while(w--) { tmp2 = *ps; - *ps = *(ps - 1) - tmp1 + *(ps + seqlen - 1); + if(isfinite(tmp1)) { + *ps = *(ps - 1) - tmp1 + *(ps + seqlen - 1); + } else { + for(int i = 1; i < seqlen; i++) { + *ps += *(ps + i); + } + } tmp1 = tmp2; ps++; } @@ -456,7 +462,7 @@ if(queryPoint > *nvp || queryPoint > *nvp - sequenceLength + 1) { error("queryPoint > numVectors-wL+1 in query"); } else { - VERB_LOG(1, "query point: %ud\n", queryPoint); + VERB_LOG(1, "query point: %u\n", queryPoint); *vqp = *qp + queryPoint * dbH->dim; *vqnp = *qnp + queryPoint; if (usingPower) {