Skip to content

Commit 67c3b91

Browse files
authored
Merge pull request #730 from apache/fix_getRSE
Fixes the getRSE() function and updates the SketchesCheckstyle.xml.
2 parents 649ca9c + 3abbe20 commit 67c3b91

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/main/java/org/apache/datasketches/req/BaseReqSketch.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract class BaseReqSketch implements QuantilesFloatsAPI {
7171
* @return an a priori estimate of relative standard error (RSE, expressed as a number in [0,1]).
7272
*/
7373
public static double getRSE(final int k, final double rank, final boolean hra, final long totalN) {
74-
return getRankUB(k, 2, rank, 1, hra, totalN); //more conservative to assume > 1 level
74+
return getRankUB(k, 2, rank, 1, hra, totalN) - rank; //more conservative to assume > 1 level
7575
}
7676

7777
@Override
@@ -188,9 +188,8 @@ public boolean isReadOnly() {
188188
*/
189189
public abstract String viewCompactorDetail(String fmt, boolean allData);
190190

191-
static boolean exactRank(final int k, final int levels, final double rank,
192-
final boolean hra, final long totalN) {
193-
final int baseCap = k * INIT_NUMBER_OF_SECTIONS;
191+
static boolean exactRank(final int k, final int levels, final double rank, final boolean hra, final long totalN) {
192+
final long baseCap = (long)k * INIT_NUMBER_OF_SECTIONS;
194193
if ((levels == 1) || (totalN <= baseCap)) { return true; }
195194
final double exactRankThresh = (double)baseCap / totalN;
196195
return (hra ? (rank >= (1.0 - exactRankThresh)) : (rank <= exactRankThresh));

src/test/java/org/apache/datasketches/req/ReqSketchOtherTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
import org.apache.datasketches.common.SketchesArgumentException;
3434
import org.apache.datasketches.quantilescommon.FloatsSortedView;
3535
import org.apache.datasketches.quantilescommon.InequalitySearch;
36-
import org.apache.datasketches.req.BaseReqSketch;
37-
import org.apache.datasketches.req.ReqSketch;
38-
import org.apache.datasketches.req.ReqSketchBuilder;
3936
import org.testng.annotations.Test;
4037

4138
/**
@@ -114,7 +111,7 @@ public void checkEstimationMode() {
114111
assertEquals(v, 120.0f);
115112
final FloatsSortedView aux = sk.getSortedView();
116113
assertNotNull(aux);
117-
assertTrue(BaseReqSketch.getRSE(sk.getK(), .5, false, 120) > 0);
114+
assertTrue(BaseReqSketch.getRSE(sk.getK(), .5, false, 120) >= 0);
118115
assertTrue(sk.getSerializedSizeBytes() > 0);
119116
}
120117

@@ -185,7 +182,7 @@ public void checkEmpty() {
185182
try { sk.getQuantiles(new double[] {0.5}); fail(); } catch (IllegalArgumentException e) {}
186183
try { sk.getPMF(new float[] {1f}); fail(); } catch (IllegalArgumentException e) {}
187184
try { sk.getCDF(new float[] {1f}); fail(); } catch (IllegalArgumentException e) {}
188-
assertTrue(BaseReqSketch.getRSE(50, 0.5, true, 0) > 0);
185+
assertTrue(BaseReqSketch.getRSE(50, 0.5, true, 0) >= 0);
189186
assertTrue(sk.getRankUpperBound(0.5, 1) > 0);
190187
}
191188

tools/SketchesCheckstyle.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
25

36
<!--
47
Licensed to the Apache Software Foundation (ASF) under one

0 commit comments

Comments
 (0)