-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start * style: pre-commit fixes * results of chatting * style: pre-commit fixes * Add toplevel func * fix * fix in indexedoptionarray * Add tests and fixes * style: pre-commit fixes * use direct np module (for now) * style: pre-commit fixes * Don't accidentally iterate cupy with CPU * style: pre-commit fixes * Update src/awkward/_errors.py * add docstring * Add string * style: pre-commit fixes * Simpler for numerics This works also for time types, without going via cupy --------- Co-authored-by: Martin Durant <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1420121
commit 1c368f1
Showing
15 changed files
with
210 additions
and
1 deletion.
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
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
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,21 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE | ||
from __future__ import annotations | ||
|
||
import awkward as ak | ||
from awkward._dispatch import high_level_function | ||
|
||
__all__ = ("to_cudf",) | ||
|
||
|
||
@high_level_function() | ||
def to_cudf( | ||
array: ak.Array, | ||
): | ||
"""Create a cuDF.Series out of the given ak array | ||
Buffers that are not already in GPU memory will be transferred, and some | ||
structural reformatting may happen to account for differences in architecture. | ||
""" | ||
import cudf | ||
|
||
return cudf.Series(array.layout._to_cudf(cudf, None, len(array))) |
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,57 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import awkward as ak | ||
|
||
cudf = pytest.importorskip("cudf") | ||
cupy = pytest.importorskip("cupy") | ||
|
||
|
||
def test_jagged(): | ||
arr = ak.Array([[[1, 2, 3], [], [3, 4]], []]) | ||
out = ak.to_cudf(arr) | ||
assert isinstance(out, cudf.Series) | ||
assert out.to_arrow().tolist() == [[[1, 2, 3], [], [3, 4]], []] | ||
|
||
|
||
def test_nested(): | ||
arr = ak.Array( | ||
[{"a": 0, "b": 1.0, "c": {"d": 0}}, {"a": 1, "b": 0.0, "c": {"d": 1}}] | ||
) | ||
out = ak.to_cudf(arr) | ||
assert isinstance(out, cudf.Series) | ||
assert out.to_arrow().tolist() == [ | ||
{"a": 0, "b": 1.0, "c": {"d": 0}}, | ||
{"a": 1, "b": 0.0, "c": {"d": 1}}, | ||
] | ||
|
||
|
||
def test_null(): | ||
arr = ak.Array([12, None, 21, 12]) | ||
# calls ByteMaskedArray._to_cudf not NumpyArray | ||
out = ak.to_cudf(arr) | ||
assert isinstance(out, cudf.Series) | ||
assert out.to_arrow().tolist() == [12, None, 21, 12] | ||
|
||
# True is valid, LSB order | ||
arr2 = ak.Array(arr.layout.to_BitMaskedArray(True, True)) | ||
out = ak.to_cudf(arr2) | ||
assert isinstance(out, cudf.Series) | ||
assert out.to_arrow().tolist() == [12, None, 21, 12] | ||
|
||
# reversed LSB (should be rare, involves extra work!) | ||
arr3 = ak.Array(arr.layout.to_BitMaskedArray(True, False)) | ||
out = ak.to_cudf(arr3) | ||
assert isinstance(out, cudf.Series) | ||
assert out.to_arrow().tolist() == [12, None, 21, 12] | ||
|
||
|
||
def test_strings(): | ||
arr = ak.Array(["hey", "hi", "hum"]) | ||
out = ak.to_cudf(arr) | ||
assert out.to_arrow().tolist() == ["hey", "hi", "hum"] | ||
|
||
arr = ak.Array(["hey", "hi", None, "hum"]) | ||
out = ak.to_cudf(arr) | ||
assert out.to_arrow().tolist() == ["hey", "hi", None, "hum"] |