|
13 | 13 | #include <cudf/copying.hpp> |
14 | 14 | #include <cudf/detail/iterator.cuh> |
15 | 15 | #include <cudf/dictionary/dictionary_column_view.hpp> |
| 16 | +#include <cudf/dictionary/encode.hpp> |
16 | 17 | #include <cudf/dictionary/update_keys.hpp> |
17 | 18 | #include <cudf/fixed_point/fixed_point.hpp> |
18 | 19 | #include <cudf/reduction.hpp> |
@@ -2179,6 +2180,61 @@ TYPED_TEST(FixedPointTestAllReps, FixedPointReductionMaxLarge) |
2179 | 2180 | } |
2180 | 2181 | } |
2181 | 2182 |
|
| 2183 | +TYPED_TEST(FixedPointTestAllReps, FixedPointMinMax) |
| 2184 | +{ |
| 2185 | + using namespace numeric; |
| 2186 | + using decimalXX = TypeParam; |
| 2187 | + using RepType = cudf::device_storage_type_t<decimalXX>; |
| 2188 | + using fp_wrapper = cudf::test::fixed_point_column_wrapper<RepType>; |
| 2189 | + |
| 2190 | + for (auto const i : {0, -1, -2, -3}) { |
| 2191 | + auto const scale = scale_type{i}; |
| 2192 | + auto const column = fp_wrapper{{2, 3, 1, 4}, scale}; |
| 2193 | + |
| 2194 | + auto const expected_min = decimalXX{scaled_integer<RepType>{1, scale}}; |
| 2195 | + auto const expected_max = decimalXX{scaled_integer<RepType>{4, scale}}; |
| 2196 | + |
| 2197 | + auto const result = cudf::minmax(column); |
| 2198 | + auto const min_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.first.get()); |
| 2199 | + auto const max_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.second.get()); |
| 2200 | + |
| 2201 | + // Scale must be preserved in the output scalars. |
| 2202 | + EXPECT_EQ(min_scalar->type().scale(), i); |
| 2203 | + EXPECT_EQ(max_scalar->type().scale(), i); |
| 2204 | + |
| 2205 | + EXPECT_EQ(min_scalar->fixed_point_value(), expected_min); |
| 2206 | + EXPECT_EQ(max_scalar->fixed_point_value(), expected_max); |
| 2207 | + } |
| 2208 | +} |
| 2209 | + |
| 2210 | +TYPED_TEST(FixedPointTestAllReps, FixedPointMinMaxWithNulls) |
| 2211 | +{ |
| 2212 | + using namespace numeric; |
| 2213 | + using decimalXX = TypeParam; |
| 2214 | + using RepType = cudf::device_storage_type_t<decimalXX>; |
| 2215 | + using fp_wrapper = cudf::test::fixed_point_column_wrapper<RepType>; |
| 2216 | + |
| 2217 | + for (auto const i : {0, -1, -2, -3}) { |
| 2218 | + auto const scale = scale_type{i}; |
| 2219 | + // valid: {2, null, 1, null, 4} — min=1, max=4 |
| 2220 | + auto const column = fp_wrapper{{2, 3, 1, 5, 4}, {true, false, true, false, true}, scale}; |
| 2221 | + |
| 2222 | + auto const expected_min = decimalXX{scaled_integer<RepType>{1, scale}}; |
| 2223 | + auto const expected_max = decimalXX{scaled_integer<RepType>{4, scale}}; |
| 2224 | + |
| 2225 | + auto const result = cudf::minmax(column); |
| 2226 | + auto const min_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.first.get()); |
| 2227 | + auto const max_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.second.get()); |
| 2228 | + |
| 2229 | + // Scale must be preserved in the output scalars. |
| 2230 | + EXPECT_EQ(min_scalar->type().scale(), i); |
| 2231 | + EXPECT_EQ(max_scalar->type().scale(), i); |
| 2232 | + |
| 2233 | + EXPECT_EQ(min_scalar->fixed_point_value(), expected_min); |
| 2234 | + EXPECT_EQ(max_scalar->fixed_point_value(), expected_max); |
| 2235 | + } |
| 2236 | +} |
| 2237 | + |
2182 | 2238 | TYPED_TEST(FixedPointTestAllReps, FixedPointReductionNUnique) |
2183 | 2239 | { |
2184 | 2240 | using namespace numeric; |
@@ -3098,6 +3154,65 @@ TYPED_TEST(DictionaryReductionTest, Quantile) |
3098 | 3154 | 45.0); |
3099 | 3155 | } |
3100 | 3156 |
|
| 3157 | +template <typename T> |
| 3158 | +struct FixedPointDictionaryReductionTest : public cudf::test::BaseFixture {}; |
| 3159 | + |
| 3160 | +TYPED_TEST_SUITE(FixedPointDictionaryReductionTest, cudf::test::FixedPointTypes); |
| 3161 | + |
| 3162 | +TYPED_TEST(FixedPointDictionaryReductionTest, FixedPointDictionaryMinMax) |
| 3163 | +{ |
| 3164 | + using namespace numeric; |
| 3165 | + using decimalXX = TypeParam; |
| 3166 | + using RepType = cudf::device_storage_type_t<decimalXX>; |
| 3167 | + using fp_wrapper = cudf::test::fixed_point_column_wrapper<RepType>; |
| 3168 | + |
| 3169 | + for (auto const i : {0, -1, -2, -3}) { |
| 3170 | + auto const scale = scale_type{i}; |
| 3171 | + auto const col = fp_wrapper{{1, 2, 3, 4}, scale}; |
| 3172 | + auto const dict = cudf::dictionary::encode(col); |
| 3173 | + auto const expected_min = decimalXX{scaled_integer<RepType>{1, scale}}; |
| 3174 | + auto const expected_max = decimalXX{scaled_integer<RepType>{4, scale}}; |
| 3175 | + |
| 3176 | + auto const result = cudf::minmax(dict->view()); |
| 3177 | + auto const min_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.first.get()); |
| 3178 | + auto const max_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.second.get()); |
| 3179 | + |
| 3180 | + EXPECT_EQ(min_scalar->type().scale(), i); |
| 3181 | + EXPECT_EQ(max_scalar->type().scale(), i); |
| 3182 | + EXPECT_EQ(min_scalar->fixed_point_value(), expected_min); |
| 3183 | + EXPECT_EQ(max_scalar->fixed_point_value(), expected_max); |
| 3184 | + EXPECT_TRUE(min_scalar->is_valid()); |
| 3185 | + EXPECT_TRUE(max_scalar->is_valid()); |
| 3186 | + } |
| 3187 | +} |
| 3188 | + |
| 3189 | +TYPED_TEST(FixedPointDictionaryReductionTest, FixedPointDictionaryMinMaxWithNulls) |
| 3190 | +{ |
| 3191 | + using namespace numeric; |
| 3192 | + using decimalXX = TypeParam; |
| 3193 | + using RepType = cudf::device_storage_type_t<decimalXX>; |
| 3194 | + using fp_wrapper = cudf::test::fixed_point_column_wrapper<RepType>; |
| 3195 | + |
| 3196 | + for (auto const i : {0, -1, -2, -3}) { |
| 3197 | + auto const scale = scale_type{i}; |
| 3198 | + auto const col = fp_wrapper{{1, 2, 3, 4, 5}, {true, false, true, false, true}, scale}; |
| 3199 | + auto const dict = cudf::dictionary::encode(col); |
| 3200 | + auto const expected_min = decimalXX{scaled_integer<RepType>{1, scale}}; |
| 3201 | + auto const expected_max = decimalXX{scaled_integer<RepType>{5, scale}}; |
| 3202 | + |
| 3203 | + auto const result = cudf::minmax(dict->view()); |
| 3204 | + auto const min_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.first.get()); |
| 3205 | + auto const max_scalar = static_cast<cudf::scalar_type_t<decimalXX>*>(result.second.get()); |
| 3206 | + |
| 3207 | + EXPECT_EQ(min_scalar->type().scale(), i); |
| 3208 | + EXPECT_EQ(max_scalar->type().scale(), i); |
| 3209 | + EXPECT_EQ(min_scalar->fixed_point_value(), expected_min); |
| 3210 | + EXPECT_EQ(max_scalar->fixed_point_value(), expected_max); |
| 3211 | + EXPECT_TRUE(min_scalar->is_valid()); |
| 3212 | + EXPECT_TRUE(max_scalar->is_valid()); |
| 3213 | + } |
| 3214 | +} |
| 3215 | + |
3101 | 3216 | struct ListReductionTest : public cudf::test::BaseFixture { |
3102 | 3217 | void reduction_test(cudf::column_view const& input_data, |
3103 | 3218 | cudf::column_view const& expected_value, |
|
0 commit comments