Skip to content

Commit

Permalink
fix the error of float cast to double
Browse files Browse the repository at this point in the history
Signed-off-by: lentitude2tk <[email protected]>
  • Loading branch information
lentitude2tk committed May 8, 2024
1 parent 64e42bf commit 1dfca08
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/io/milvus/orm/iterator/SearchIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SearchIterator {
private int cacheId;
private boolean initSuccess;
private int returnedCount;
private double width;
private float width;
private float tailBand;

private List<Object> filteredIds;
Expand Down Expand Up @@ -140,8 +140,8 @@ private void checkForSpecialIndexParam() {

private void checkRmRangeSearchParameters() {
if (params.containsKey(RADIUS) && params.containsKey(RANGE_FILTER)) {
float radius = (float) params.get(RADIUS);
float rangeFilter = (float) params.get(RANGE_FILTER);
float radius = getFloatValue(RADIUS);
float rangeFilter = getFloatValue(RANGE_FILTER);
if (metricsPositiveRelated(metricType) && radius <= rangeFilter) {
String msg = String.format("for metrics:%s, radius must be larger than range_filter, please adjust your parameter", metricType);
ExceptionUtils.throwUnExpectedException(msg);
Expand Down Expand Up @@ -298,7 +298,7 @@ private void updateWidth(List<QueryResultsWrapper.RowRecord> page) {

if (width == 0.0) {
// enable a minimum value for width to avoid radius and range_filter equal error
width = 0.05;
width = 0.05f;
}
}

Expand Down Expand Up @@ -386,16 +386,16 @@ private Map<String, Object> nextParams(int coefficient) {
});

if (metricsPositiveRelated(metricType)) {
double nextRadius = tailBand + width * coefficient;
if (params.containsKey(RADIUS) && nextRadius > (double) params.get(RADIUS)) {
nextParams.put(RADIUS, params.get(RADIUS));
float nextRadius = tailBand + width * coefficient;
if (params.containsKey(RADIUS) && nextRadius > getFloatValue(RADIUS)) {
nextParams.put(RADIUS, getFloatValue(RADIUS));
} else {
nextParams.put(RADIUS, nextRadius);
}
} else {
double nextRadius = tailBand - width * coefficient;
if (params.containsKey(RADIUS) && nextRadius < (double) params.get(RADIUS)) {
nextParams.put(RADIUS, params.get(RADIUS));
if (params.containsKey(RADIUS) && nextRadius < getFloatValue(RADIUS)) {
nextParams.put(RADIUS, getFloatValue(RADIUS));
} else {
nextParams.put(RADIUS, nextRadius);
}
Expand Down Expand Up @@ -457,4 +457,8 @@ private String convertToStr(Object value) {
DecimalFormat df = new DecimalFormat("0.0");
return df.format(value);
}

private float getFloatValue(String key) {
return ((Double) params.get(key)).floatValue();
}
}

0 comments on commit 1dfca08

Please sign in to comment.