-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable round in cudf for DataFrame and Series (#7022)
This enables round for DataFrames and Series using the libcudf round implementation and removes the old numba round implementation. Closes #1270 Authors: - @ChrisJar Approvers: - Ashwin Srinath (@shwina) - Michael Wang (@isVoid) - Ram (Ramakrishna Prabhu) (@rgsl888prabhu) - GALI PREM SAGAR (@galipremsagar) URL: #7022
- Loading branch information
Showing
9 changed files
with
303 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. | ||
|
||
from libc.stdint cimport int32_t | ||
from libcpp.memory cimport unique_ptr | ||
|
||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.column.column_view cimport column_view | ||
|
||
cdef extern from "cudf/round.hpp" namespace "cudf" nogil: | ||
|
||
ctypedef enum rounding_method "cudf::rounding_method": | ||
HALF_UP "cudf::rounding_method::HALF_UP" | ||
HALF_EVEN "cudf::rounding_method::HALF_EVEN" | ||
|
||
cdef unique_ptr[column] round ( | ||
const column_view& input, | ||
int32_t decimal_places, | ||
rounding_method method, | ||
) except + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
|
||
from cudf._lib.column cimport Column | ||
|
||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.column.column_view cimport column_view | ||
from cudf._lib.cpp.round cimport ( | ||
rounding_method as cpp_rounding_method, | ||
round as cpp_round | ||
) | ||
|
||
|
||
def round(Column input_col, int decimal_places=0): | ||
""" | ||
Round column values to the given number of decimal places | ||
Parameters | ||
---------- | ||
input_col : Column whose values will be rounded | ||
decimal_places : The number or decimal places to round to | ||
Returns | ||
------- | ||
A Column with values rounded to the given number of decimal places | ||
""" | ||
|
||
cdef column_view input_col_view = input_col.view() | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move( | ||
cpp_round( | ||
input_col_view, | ||
decimal_places, | ||
cpp_rounding_method.HALF_EVEN, | ||
) | ||
) | ||
|
||
return Column.from_unique_ptr(move(c_result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.