Skip to content

Commit

Permalink
i.smap: fix possible pole error with log in extract function
Browse files Browse the repository at this point in the history
Using logarithm function call with zero argument will lead to
a pole error, which occurs if the mathematical function has
an exact infinite result.

Check if the argument value is zero before passing that to
the log function to avoid such errors. I also added check
for negative numbers just to make sure the argument is in
the right domain for the log function as well.

Signed-off-by: Mohan Yelugoti <ymdatta.work@gmail.com>
  • Loading branch information
ymdatta committed Oct 11, 2024
1 parent cbc3ff4 commit b1597d6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion imagery/i.smap/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */
for (k = 0; k < C->nsubclasses; k++)
subsum += exp(subll[k] - maxlike) * C->SubSig[k].pi;

ll[i][j][m] = log(subsum) + maxlike;
if (subsum > 0)
ll[i][j][m] = log(subsum) + maxlike;
}
}
}
Expand Down

0 comments on commit b1597d6

Please sign in to comment.