-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate reshape.pxd to pylibcudf #15827
Merged
rapids-bot
merged 8 commits into
rapidsai:branch-24.08
from
lithomas1:pylibcudf-reshape
May 24, 2024
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc2cfac
Migrate reshape.pxd to pylibcudf
lithomas1 6c41e55
finish docs
lithomas1 7838ce5
add tests
lithomas1 a13a1e4
use fixture
lithomas1 4ff5da3
Merge branch 'branch-24.08' into pylibcudf-reshape
lithomas1 491d57f
Update reshape.rst
lithomas1 ddbbb1d
Update python/cudf/cudf/_lib/pylibcudf/reshape.pyx
lithomas1 bd63930
update following feedback
lithomas1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 @@ | ||
======= | ||
reshape | ||
======= | ||
|
||
.. automodule:: cudf._lib.pylibcudf.reshape | ||
: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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ set(cython_sources | |
merge.pyx | ||
reduce.pyx | ||
replace.pyx | ||
reshape.pyx | ||
rolling.pyx | ||
scalar.pyx | ||
search.pyx | ||
|
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ from . cimport ( | |
merge, | ||
reduce, | ||
replace, | ||
reshape, | ||
rolling, | ||
search, | ||
sorting, | ||
|
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
merge, | ||
reduce, | ||
replace, | ||
reshape, | ||
rolling, | ||
search, | ||
sorting, | ||
|
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,11 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from cudf._lib.pylibcudf.libcudf.types cimport size_type | ||
|
||
from .column cimport Column | ||
from .scalar cimport Scalar | ||
from .table cimport Table | ||
|
||
|
||
cpdef Column interleave_columns(Table source_table) | ||
cpdef Table tile(Table source_table, size_type count) |
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,65 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
|
||
from cudf._lib.pylibcudf.libcudf.column.column cimport column | ||
from cudf._lib.pylibcudf.libcudf.reshape cimport ( | ||
interleave_columns as cpp_interleave_columns, | ||
tile as cpp_tile, | ||
) | ||
from cudf._lib.pylibcudf.libcudf.table.table cimport table | ||
from cudf._lib.pylibcudf.libcudf.types cimport size_type | ||
|
||
from .column cimport Column | ||
from .table cimport Table | ||
|
||
|
||
cpdef Column interleave_columns(Table source_table): | ||
"""Interleave columns of a table into a single column. | ||
|
||
Converts the column major table `input` into a row major column. | ||
|
||
Example: | ||
in = [[A1, A2, A3], [B1, B2, B3]] | ||
return = [A1, B1, A2, B2, A3, B3] | ||
|
||
Parameters | ||
---------- | ||
source_table: Table | ||
The input table to interleave | ||
|
||
Returns | ||
------- | ||
Column | ||
A new column which is the result of interleaving the input columns | ||
""" | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_interleave_columns(source_table.view())) | ||
|
||
return Column.from_libcudf(move(c_result)) | ||
|
||
|
||
cpdef Table tile(Table source_table, size_type count): | ||
"""Repeats the rows from input table count times to form a new table. | ||
|
||
Parameters | ||
---------- | ||
source_table: Table | ||
The input table containing rows to be repeated | ||
count: size_type | ||
The number of times to tile "rows". Must be non-negative | ||
|
||
Returns | ||
------- | ||
Table | ||
The table containing the tiled "rows" | ||
""" | ||
cdef unique_ptr[table] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_tile(source_table.view(), count)) | ||
|
||
return Table.from_libcudf(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
import pyarrow as pa | ||
import pytest | ||
from utils import assert_column_eq, assert_table_eq | ||
|
||
from cudf._lib import pylibcudf as plc | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def reshape_data(): | ||
data = [[1, 2, 3], [4, 5, 6]] | ||
return data | ||
|
||
|
||
def test_interleave_columns(reshape_data): | ||
arrow_tbl = pa.Table.from_arrays(reshape_data, names=["a", "b"]) | ||
plc_tbl = plc.interop.from_arrow(arrow_tbl) | ||
|
||
res = plc.reshape.interleave_columns(plc_tbl) | ||
|
||
interleaved_data = [pa.array(pair) for pair in zip(*reshape_data)] | ||
|
||
expect = pa.concat_arrays(interleaved_data) | ||
|
||
assert_column_eq(res, expect) | ||
|
||
|
||
@pytest.mark.parametrize("cnt", [0, 1, 3]) | ||
def test_tile(reshape_data, cnt): | ||
arrow_tbl = pa.Table.from_arrays(reshape_data, names=["a", "b"]) | ||
plc_tbl = plc.interop.from_arrow(arrow_tbl) | ||
|
||
res = plc.reshape.tile(plc_tbl, cnt) | ||
|
||
tiled_data = [pa.array(col * cnt) for col in reshape_data] | ||
|
||
expect = pa.Table.from_arrays(tiled_data, schema=arrow_tbl.schema) | ||
|
||
assert_table_eq(res, expect) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well pull this out into a fixture too so that it's only done once (especially since you parametrize the tile test below so it'll do this four times).