From: Bborie Park Date: Sat, 20 Aug 2011 17:51:04 +0000 (+0000) Subject: More fixups for the quantile coverage function. Fixes segfault that seems to only... X-Git-Tag: 2.0.0alpha1~1079 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c3dac62a89bd7c67349e972186da0eca343ec60;p=postgis More fixups for the quantile coverage function. Fixes segfault that seems to only occur on OSX. git-svn-id: http://svn.osgeo.org/postgis/trunk@7771 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index d2ac7320e..c4cb470cd 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -2362,6 +2362,7 @@ rt_band_get_quantiles_stream(rt_band band, assert(NULL != band); assert(cov_count > 1); + RASTER_DEBUGF(3, "cov_count = %d", cov_count); if (band->offline) { rterror("rt_band_get_summary_stats not implemented yet for OFFDB bands"); @@ -2433,6 +2434,7 @@ rt_band_get_quantiles_stream(rt_band band, if (!(i % 2)) { qll->algeq = 1; qll->tau = (uint64_t) ROUND(cov_count - (cov_count * qll->quantile), 0); + if (qll->tau < 1) qll->tau = 1; } /* AL-GT */ else { diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 08c3af9af..25738cec5 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -4952,6 +4952,14 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS) quantile_llist_destroy(&qlls, qlls_count); if (quantiles_count) pfree(quantiles); + covquant2 = palloc(sizeof(struct rt_quantile_t) * count); + for (i = 0; i < count; i++) { + covquant2[i].quantile = covquant[i].quantile; + covquant2[i].value = covquant[i].value; + } + pfree(covquant); + covquant = covquant2; + POSTGIS_RT_DEBUGF(3, "%d quantiles returned", count); /* Store needed information */ diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 00968c572..8b98f023f 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -1131,10 +1131,58 @@ static void testBandStats() { CHECK(quantile); CHECK(count); CHECK((qlls_count > 0)); - quantile_llist_destroy(&qlls, qlls_count); CHECK(FLT_EQ(quantile[0].value, 78)); + rtdealloc(quantile); + quantile_llist_destroy(&qlls, qlls_count); + qlls = NULL; + qlls_count = 0; + + quantile = (rt_quantile) rt_band_get_quantiles_stream( + band, 1, 1, 60, + &qlls, &qlls_count, + NULL, 0, + &count); + CHECK(quantile); + CHECK(count); + CHECK((qlls_count > 0)); + + quantile = (rt_quantile) rt_band_get_quantiles_stream( + band, 1, 1, 60, + &qlls, &qlls_count, + NULL, 0, + &count); + CHECK(quantile); + CHECK(count); + CHECK((qlls_count > 0)); + + quantile = (rt_quantile) rt_band_get_quantiles_stream( + band, 1, 1, 60, + &qlls, &qlls_count, + NULL, 0, + &count); + CHECK(quantile); + CHECK(count); + CHECK((qlls_count > 0)); + + quantile = (rt_quantile) rt_band_get_quantiles_stream( + band, 1, 1, 60, + &qlls, &qlls_count, + NULL, 0, + &count); + CHECK(quantile); + CHECK(count); + CHECK((qlls_count > 0)); + + quantile_llist_destroy(&qlls, qlls_count); + + /* + for (x = 0; x < count; x++) { + printf("%f = %f\n", quantile[x].quantile, quantile[x].value); + } + */ rtdealloc(quantile); + deepRelease(raster); } diff --git a/raster/test/regress/rt_quantile.sql b/raster/test/regress/rt_quantile.sql index 0d6c56cd9..a7c4a25e7 100644 --- a/raster/test/regress/rt_quantile.sql +++ b/raster/test/regress/rt_quantile.sql @@ -204,7 +204,7 @@ CREATE TEMP TABLE test ) AS rast ) AS rast FULL JOIN ( - SELECT generate_series(1, 1000) AS id + SELECT generate_series(1, 2) AS id ) AS id ON 1 = 1; SELECT diff --git a/raster/test/regress/rt_quantile_expected b/raster/test/regress/rt_quantile_expected index 81d4a3309..023a34a55 100644 --- a/raster/test/regress/rt_quantile_expected +++ b/raster/test/regress/rt_quantile_expected @@ -46,7 +46,7 @@ BEGIN 0.100|-10.000 0.200|-10.000 0.300|-10.000 -0.400|-10.000 +0.400|3.142 0.500|3.142 0.600|3.142 0.700|3.142