Skip to content

Commit dcf7eff

Browse files
Remove rounding from cudf java (#20110)
This has been moved to spark-rapids-jni, where we've implement rounding of floats since that is deprecated in cudf. [This](NVIDIA/spark-rapids-jni#3770) is the merged sr-jni PR implementing this rounding there, and [this](NVIDIA/spark-rapids#13497) is the merged spark-rapids PR switching the rounding calls to the new code. All of the spark-rapids integration tests pass with this old code deleted. Authors: - Paul Mattione (https://github.com/pmattione-nvidia) - Nghia Truong (https://github.com/ttnghia) Approvers: - Nghia Truong (https://github.com/ttnghia) URL: #20110
1 parent 2fd5141 commit dcf7eff

File tree

4 files changed

+1
-163
lines changed

4 files changed

+1
-163
lines changed

java/src/main/java/ai/rapids/cudf/ColumnView.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,51 +1105,6 @@ public final ColumnVector dateTimeRound(DateTimeRoundingFrequency freq) {
11051105
return new ColumnVector(dateTimeRound(getNativeView(), freq.getNativeId()));
11061106
}
11071107

1108-
/**
1109-
* Rounds all the values in a column to the specified number of decimal places.
1110-
*
1111-
* @param decimalPlaces Number of decimal places to round to. If negative, this
1112-
* specifies the number of positions to the left of the decimal point.
1113-
* @param mode Rounding method(either HALF_UP or HALF_EVEN)
1114-
* @return a new ColumnVector with rounded values.
1115-
*/
1116-
public ColumnVector round(int decimalPlaces, RoundMode mode) {
1117-
return new ColumnVector(round(this.getNativeView(), decimalPlaces, mode.nativeId));
1118-
}
1119-
1120-
/**
1121-
* Rounds all the values in a column with decimal places = 0. Default number of decimal places
1122-
* to round to is 0.
1123-
*
1124-
* @param round Rounding method(either HALF_UP or HALF_EVEN)
1125-
* @return a new ColumnVector with rounded values.
1126-
*/
1127-
public ColumnVector round(RoundMode round) {
1128-
return round(0, round);
1129-
}
1130-
1131-
/**
1132-
* Rounds all the values in a column to the specified number of decimal places with HALF_UP
1133-
* (default) as Rounding method.
1134-
*
1135-
* @param decimalPlaces Number of decimal places to round to. If negative, this
1136-
* specifies the number of positions to the left of the decimal point.
1137-
* @return a new ColumnVector with rounded values.
1138-
*/
1139-
public ColumnVector round(int decimalPlaces) {
1140-
return round(decimalPlaces, RoundMode.HALF_UP);
1141-
}
1142-
1143-
/**
1144-
* Rounds all the values in a column with these default values:
1145-
* decimalPlaces = 0
1146-
* Rounding method = RoundMode.HALF_UP
1147-
*
1148-
* @return a new ColumnVector with rounded values.
1149-
*/
1150-
public ColumnVector round() {
1151-
return round(0, RoundMode.HALF_UP);
1152-
}
11531108

11541109
/////////////////////////////////////////////////////////////////////////////
11551110
// ARITHMETIC
@@ -4709,7 +4664,6 @@ private static native long stringReplaceWithBackrefs(long columnView, String pat
47094664

47104665
private static native long findAndReplaceAll(long valuesHandle, long replaceHandle, long myself) throws CudfException;
47114666

4712-
private static native long round(long nativeHandle, int decimalPlaces, int roundingMethod) throws CudfException;
47134667

47144668
private static native long reverseStringsOrLists(long inputHandle);
47154669

java/src/main/java/ai/rapids/cudf/RoundMode.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

java/src/main/native/src/ColumnViewJni.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,20 +1162,6 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_unaryOperation(JNIEnv* en
11621162
JNI_CATCH(env, 0);
11631163
}
11641164

1165-
JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_round(
1166-
JNIEnv* env, jclass, jlong input_ptr, jint decimal_places, jint rounding_method)
1167-
{
1168-
JNI_NULL_CHECK(env, input_ptr, "input is null", 0);
1169-
JNI_TRY
1170-
{
1171-
cudf::jni::auto_set_device(env);
1172-
cudf::column_view* input = reinterpret_cast<cudf::column_view*>(input_ptr);
1173-
cudf::rounding_method method = static_cast<cudf::rounding_method>(rounding_method);
1174-
return release_as_jlong(cudf::round(*input, decimal_places, method));
1175-
}
1176-
JNI_CATCH(env, 0);
1177-
}
1178-
11791165
JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractDateTimeComponent(JNIEnv* env,
11801166
jclass,
11811167
jlong input_ptr,

java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
3+
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -817,77 +817,6 @@ void isNotNanTestAllNans() {
817817
}
818818
}
819819

820-
@Test
821-
void roundFloatsHalfUp() {
822-
try (ColumnVector v = ColumnVector.fromBoxedFloats(1.234f, 25.66f, null, 154.9f, 2346f);
823-
ColumnVector result1 = v.round();
824-
ColumnVector result2 = v.round(1, RoundMode.HALF_UP);
825-
ColumnVector result3 = v.round(-1, RoundMode.HALF_UP);
826-
ColumnVector expected1 = ColumnVector.fromBoxedFloats(1f, 26f, null, 155f, 2346f);
827-
ColumnVector expected2 = ColumnVector.fromBoxedFloats(1.2f, 25.7f, null, 154.9f, 2346f);
828-
ColumnVector expected3 = ColumnVector.fromBoxedFloats(0f, 30f, null, 150f, 2350f)) {
829-
assertColumnsAreEqual(expected1, result1);
830-
assertColumnsAreEqual(expected2, result2);
831-
assertColumnsAreEqual(expected3, result3);
832-
}
833-
}
834-
835-
@Test
836-
void roundFloatsHalfEven() {
837-
try (ColumnVector v = ColumnVector.fromBoxedFloats(1.5f, 2.5f, 1.35f, null, 1.25f, 15f, 25f);
838-
ColumnVector result1 = v.round(RoundMode.HALF_EVEN);
839-
ColumnVector result2 = v.round(1, RoundMode.HALF_EVEN);
840-
ColumnVector result3 = v.round(-1, RoundMode.HALF_EVEN);
841-
ColumnVector expected1 = ColumnVector.fromBoxedFloats(2f, 2f, 1f, null, 1f, 15f, 25f);
842-
ColumnVector expected2 = ColumnVector.fromBoxedFloats(1.5f, 2.5f, 1.4f, null, 1.2f, 15f, 25f);
843-
ColumnVector expected3 = ColumnVector.fromBoxedFloats(0f, 0f, 0f, null, 0f, 20f, 20f)) {
844-
assertColumnsAreEqual(expected1, result1);
845-
assertColumnsAreEqual(expected2, result2);
846-
assertColumnsAreEqual(expected3, result3);
847-
}
848-
}
849-
850-
@Test
851-
void roundIntsHalfUp() {
852-
try (ColumnVector v = ColumnVector.fromBoxedInts(12, 135, 160, -1454, null, -1500, -140, -150);
853-
ColumnVector result1 = v.round(2, RoundMode.HALF_UP);
854-
ColumnVector result2 = v.round(-2, RoundMode.HALF_UP);
855-
ColumnVector expected1 = ColumnVector.fromBoxedInts(12, 135, 160, -1454, null, -1500, -140, -150);
856-
ColumnVector expected2 = ColumnVector.fromBoxedInts(0, 100, 200, -1500, null, -1500, -100, -200)) {
857-
assertColumnsAreEqual(expected1, result1);
858-
assertColumnsAreEqual(expected2, result2);
859-
}
860-
}
861-
862-
@Test
863-
void roundIntsHalfEven() {
864-
try (ColumnVector v = ColumnVector.fromBoxedInts(12, 24, 135, 160, null, 1450, 1550, -1650);
865-
ColumnVector result1 = v.round(2, RoundMode.HALF_EVEN);
866-
ColumnVector result2 = v.round(-2, RoundMode.HALF_EVEN);
867-
ColumnVector expected1 = ColumnVector.fromBoxedInts(12, 24, 135, 160, null, 1450, 1550, -1650);
868-
ColumnVector expected2 = ColumnVector.fromBoxedInts(0, 0, 100, 200, null, 1400, 1600, -1600)) {
869-
assertColumnsAreEqual(expected1, result1);
870-
assertColumnsAreEqual(expected2, result2);
871-
}
872-
}
873-
874-
@Test
875-
void roundDecimal() {
876-
final int dec32Scale1 = -2;
877-
final int resultScale1 = -3;
878-
879-
final int[] DECIMAL32_1 = new int[]{14, 15, 16, 24, 25, 26} ;
880-
final int[] expectedHalfUp = new int[]{1, 2, 2, 2, 3, 3};
881-
final int[] expectedHalfEven = new int[]{1, 2, 2, 2, 2, 3};
882-
try (ColumnVector v = ColumnVector.decimalFromInts(-dec32Scale1, DECIMAL32_1);
883-
ColumnVector roundHalfUp = v.round(-3, RoundMode.HALF_UP);
884-
ColumnVector roundHalfEven = v.round(-3, RoundMode.HALF_EVEN);
885-
ColumnVector answerHalfUp = ColumnVector.decimalFromInts(-resultScale1, expectedHalfUp);
886-
ColumnVector answerHalfEven = ColumnVector.decimalFromInts(-resultScale1, expectedHalfEven)) {
887-
assertColumnsAreEqual(answerHalfUp, roundHalfUp);
888-
assertColumnsAreEqual(answerHalfEven, roundHalfEven);
889-
}
890-
}
891820

892821
@Test
893822
void decimal128Cv() {

0 commit comments

Comments
 (0)