-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Migrate unary operations to pylibcudf (#14850)
This PR migrates the unary operations in cuDF Python to pylibcudf. Authors: - Vyas Ramasubramani (https://github.com/vyasr) - Bradley Dice (https://github.com/bdice) Approvers: - Ashwin Srinath (https://github.com/shwina) URL: #14850
- Loading branch information
Showing
14 changed files
with
257 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ This page provides API documentation for pylibcudf. | |
scalar | ||
table | ||
types | ||
unary |
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,6 @@ | ||
===== | ||
unary | ||
===== | ||
|
||
.. automodule:: cudf._lib.pylibcudf.unary | ||
:members: |
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
Empty file.
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
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) 2024, NVIDIA CORPORATION. | ||
|
||
from cudf._lib.cpp.unary cimport unary_operator | ||
|
||
from .column cimport Column | ||
from .types cimport DataType | ||
|
||
|
||
cpdef Column unary_operation(Column input, unary_operator op) | ||
|
||
cpdef Column is_null(Column input) | ||
|
||
cpdef Column is_valid(Column input) | ||
|
||
cpdef Column cast(Column input, DataType data_type) | ||
|
||
cpdef Column is_nan(Column input) | ||
|
||
cpdef Column is_not_nan(Column input) |
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,156 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
|
||
from cudf._lib.cpp cimport unary as cpp_unary | ||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.unary cimport unary_operator | ||
|
||
from cudf._lib.cpp.unary import \ | ||
unary_operator as UnaryOperator # no-cython-lint | ||
|
||
from .column cimport Column | ||
from .types cimport DataType | ||
|
||
|
||
cpdef Column unary_operation(Column input, unary_operator op): | ||
"""Perform a unary operation on a column. | ||
For details, see :cpp:func:`unary_operation`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to operate on. | ||
op : UnaryOperator | ||
The operation to perform. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
The result of the unary operation | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.unary_operation(input.view(), op)) | ||
|
||
return Column.from_libcudf(move(result)) | ||
|
||
|
||
cpdef Column is_null(Column input): | ||
"""Check whether elements of a column are null. | ||
For details, see :cpp:func:`is_null`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to check. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
A boolean column with ``True`` representing null values. | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.is_null(input.view())) | ||
|
||
return Column.from_libcudf(move(result)) | ||
|
||
|
||
cpdef Column is_valid(Column input): | ||
"""Check whether elements of a column are valid. | ||
For details, see :cpp:func:`is_valid`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to check. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
A boolean column with ``True`` representing valid values. | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.is_valid(input.view())) | ||
|
||
return Column.from_libcudf(move(result)) | ||
|
||
|
||
cpdef Column cast(Column input, DataType data_type): | ||
"""Cast a column to a different data type. | ||
For details, see :cpp:func:`cast`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to check. | ||
data_type : DataType | ||
The data type to cast to. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
A boolean column with ``True`` representing null values. | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.cast(input.view(), data_type.c_obj)) | ||
|
||
return Column.from_libcudf(move(result)) | ||
|
||
|
||
cpdef Column is_nan(Column input): | ||
"""Check whether elements of a column are nan. | ||
For details, see :cpp:func:`is_nan`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to check. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
A boolean column with ``True`` representing nan values. | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.is_nan(input.view())) | ||
|
||
return Column.from_libcudf(move(result)) | ||
|
||
|
||
cpdef Column is_not_nan(Column input): | ||
"""Check whether elements of a column are not nan. | ||
For details, see :cpp:func:`is_not_nan`. | ||
Parameters | ||
---------- | ||
input : Column | ||
The column to check. | ||
Returns | ||
------- | ||
pylibcudf.Column | ||
A boolean column with ``True`` representing non-nan values. | ||
""" | ||
cdef unique_ptr[column] result | ||
|
||
with nogil: | ||
result = move(cpp_unary.is_not_nan(input.view())) | ||
|
||
return Column.from_libcudf(move(result)) |
Oops, something went wrong.