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.

Refactor the conditional to only execute the code when number
of subclasses are more than 1, which would preemptively stop
us from getting into situation where log would have a zero
argument. In cases where number of subclasses are <= 0, set
the default value to 0. This is necessary as `ll` points to
malloc'd memory and can contain renadom value.

Signed-off-by: Mohan Yelugoti <ymdatta.work@gmail.com>
  • Loading branch information
ymdatta committed Oct 23, 2024
1 parent cbc3ff4 commit cf4a759
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion imagery/i.smap/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */
ll[i][j][m] = subll[0];
}
/* compute mixture likelihood */
else {
else if (C->nsubclasses > 1) {
/* find the most likely subclass */
for (k = 0; k < C->nsubclasses; k++) {
if (k == 0)
Expand All @@ -157,6 +157,9 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */

ll[i][j][m] = log(subsum) + maxlike;
}
else {
ll[i][j][m] = 0.0;
}
}
}
}
Expand Down

0 comments on commit cf4a759

Please sign in to comment.