-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial investigation into NumPy proxying in
cudf.pandas
(#16286)
Apart of #15397. Closes #14537. Creates `ProxyNDarray` which inherits from `np.ndarray`. Authors: - Matthew Murray (https://github.com/Matt711) - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) - Matthew Roeschke (https://github.com/mroeschke) URL: #16286
- Loading branch information
Showing
4 changed files
with
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. | ||
# All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import cupy as cp | ||
import numpy as np | ||
|
||
|
||
class ProxyNDarrayBase(np.ndarray): | ||
def __new__(cls, arr): | ||
if isinstance(arr, cp.ndarray): | ||
obj = np.asarray(arr.get()).view(cls) | ||
return obj | ||
elif isinstance(arr, np.ndarray): | ||
obj = np.asarray(arr).view(cls) | ||
return obj | ||
else: | ||
raise TypeError( | ||
"Unsupported array type. Must be numpy.ndarray or cupy.ndarray" | ||
) | ||
|
||
def __array_finalize__(self, obj): | ||
self._fsproxy_wrapped = getattr(obj, "_fsproxy_wrapped", None) |
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