Skip to content
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

Fix for legate data interface #429

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cunumeric/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ def __legate_data_interface__(self):
# so we just need to convert our type and stick it in
# a Legate Array
arrow_type = pyarrow.from_numpy_dtype(self.dtype)
# If the thunk is an eager array, we need to convert it to a
# deferred array so we can extract a legate store
deferred_thunk = runtime.to_deferred_array(self._thunk)
# We don't have nullable data for the moment
# until we support masked arrays
array = Array(arrow_type, [None, self._thunk])
array = Array(arrow_type, [None, deferred_thunk.base])
self._legate_data = dict()
self._legate_data["version"] = 1
data = dict()
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/test_data_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2022 NVIDIA Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import pytest

import cunumeric as num


# A simple wrapper with a legate data interface implementation for testing
class Wrapper:
def __init__(self, wrapped):
self.wrapped = wrapped

@property
def __legate_data_interface__(self):
return self.wrapped


def test_roundtrip():
arr1 = num.array([1, 2, 3, 4], dtype=num.float64)
data = Wrapper(arr1.__legate_data_interface__)
arr2 = num.asarray(data)
assert num.array_equal(arr1, arr2)


if __name__ == "__main__":
import sys

sys.exit(pytest.main(sys.argv))