Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoonson committed Oct 19, 2023
1 parent fc8fabe commit ade255f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
7 changes: 4 additions & 3 deletions cpp/include/cudf/detail/interop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ std::unique_ptr<cudf::scalar> from_arrow(arrow::Scalar const& input,

/**
* @brief Return a maximum precision for a given type.
*
*
* @tparam T the type to get the maximum precision for
*/
template<typename T>
constexpr std::size_t max_precision() {
template <typename T>
constexpr std::size_t max_precision()
{
auto constexpr num_bits = sizeof(T) * 8;
return std::floor(num_bits * std::log(2) / std::log(10));
}
Expand Down
18 changes: 10 additions & 8 deletions cpp/include/cudf/interop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ struct column_metadata {
* @param stream CUDA stream used for device memory operations and kernel launches
* @param ar_mr arrow memory pool to allocate memory for arrow Table
* @return arrow Table generated from `input`
*
*
* @note For decimals, since the precision is not stored for them in libcudf,
* it will be converted to an Arrow decimal128 that has the widest-precision the cudf decimal type supports.
* For example, numeric::decimal32 will be converted to Arrow decimal128 of the precision 9 which is the maximum
* precision for 32-bit types. Similarly, numeric::decimal128 will be converted to Arrow decimal128 of the precision 38.
* it will be converted to an Arrow decimal128 that has the widest-precision the cudf decimal type
* supports. For example, numeric::decimal32 will be converted to Arrow decimal128 of the precision
* 9 which is the maximum precision for 32-bit types. Similarly, numeric::decimal128 will be
* converted to Arrow decimal128 of the precision 38.
*/
std::shared_ptr<arrow::Table> to_arrow(table_view input,
std::vector<column_metadata> const& metadata = {},
Expand All @@ -150,11 +151,12 @@ std::shared_ptr<arrow::Table> to_arrow(table_view input,
* @param stream CUDA stream used for device memory operations and kernel launches
* @param ar_mr arrow memory pool to allocate memory for arrow Scalar
* @return arrow Scalar generated from `input`
*
*
* @note For decimals, since the precision is not stored for them in libcudf,
* it will be converted to an Arrow decimal128 that has the widest-precision the cudf decimal type supports.
* For example, numeric::decimal32 will be converted to Arrow decimal128 of the precision 9 which is the maximum
* precision for 32-bit types. Similarly, numeric::decimal128 will be converted to Arrow decimal128 of the precision 38.
* it will be converted to an Arrow decimal128 that has the widest-precision the cudf decimal type
* supports. For example, numeric::decimal32 will be converted to Arrow decimal128 of the precision
* 9 which is the maximum precision for 32-bit types. Similarly, numeric::decimal128 will be
* converted to Arrow decimal128 of the precision 38.
*/
std::shared_ptr<arrow::Scalar> to_arrow(cudf::scalar const& input,
column_metadata const& metadata = {},
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/interop/to_arrow.cu
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ std::shared_ptr<arrow::Array> dispatch_to_arrow::operator()<numeric::decimal32>(
rmm::cuda_stream_view stream)
{
using DeviceType = int32_t;
return unsupported_decimals_to_arrow<DeviceType>(input, cudf::detail::max_precision<DeviceType>(), ar_mr, stream);
return unsupported_decimals_to_arrow<DeviceType>(
input, cudf::detail::max_precision<DeviceType>(), ar_mr, stream);
}

template <>
Expand All @@ -210,7 +211,8 @@ std::shared_ptr<arrow::Array> dispatch_to_arrow::operator()<numeric::decimal64>(
rmm::cuda_stream_view stream)
{
using DeviceType = int64_t;
return unsupported_decimals_to_arrow<DeviceType>(input, cudf::detail::max_precision<DeviceType>(), ar_mr, stream);
return unsupported_decimals_to_arrow<DeviceType>(
input, cudf::detail::max_precision<DeviceType>(), ar_mr, stream);
}

template <>
Expand All @@ -221,7 +223,7 @@ std::shared_ptr<arrow::Array> dispatch_to_arrow::operator()<numeric::decimal128>
arrow::MemoryPool* ar_mr,
rmm::cuda_stream_view stream)
{
using DeviceType = __int128_t;
using DeviceType = __int128_t;
auto const max_precision = cudf::detail::max_precision<DeviceType>();

rmm::device_uvector<DeviceType> buf(input.size(), stream);
Expand Down
4 changes: 3 additions & 1 deletion cpp/tests/interop/to_arrow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ struct ToArrowDecimalScalarTest : public cudf::test::BaseFixture {};
TEST_F(ToArrowDecimalScalarTest, Basic)
{
auto const value{42};
auto const precision = cudf::detail::max_precision<__int128_t>(); // cudf will convert to the widest-precision Arrow scalar of the type
auto const precision =
cudf::detail::max_precision<__int128_t>(); // cudf will convert to the widest-precision Arrow
// scalar of the type
int32_t const scale{4};

auto const cudf_scalar =
Expand Down

0 comments on commit ade255f

Please sign in to comment.