Unverified Commit 93476196 authored by pyynb's avatar pyynb Committed by GitHub
Browse files

[GraphBolt] Disable support for F_contiguous arrays in DiskBasedFeature (#7316)


Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-2-128.us-west-2.compute.internal>
Co-authored-by: default avatarRhett Ying <85214957+Rhett-Ying@users.noreply.github.com>
parent 41a38486
......@@ -260,9 +260,11 @@ class DiskBasedFeature(Feature):
def __init__(self, path: str, metadata: Dict = None):
super().__init__()
mmap_mode = "r+"
self._tensor = torch.from_numpy(
np.load(path, mmap_mode=mmap_mode)
).contiguous()
ondisk_data = np.load(path, mmap_mode=mmap_mode)
assert ondisk_data.flags[
"C_CONTIGUOUS"
], "DiskBasedFeature only supports C_CONTIGUOUS array."
self._tensor = torch.from_numpy(ondisk_data)
self._metadata = metadata
self._ondisk_npy_array = torch.ops.graphbolt.ondisk_npy_array(
......
......@@ -64,31 +64,21 @@ def test_disk_based_feature():
with pytest.raises(IndexError):
feature_a.read(torch.tensor([0, 1, 2, 3]))
# Test loading a Fortran contiguous ndarray.
a_T = np.asfortranarray(a)
path_a_T = test_dir + "a_T.npy"
np.save(path_a_T, a_T)
with pytest.raises(
AssertionError,
match="DiskBasedFeature only supports C_CONTIGUOUS array.",
):
gb.DiskBasedFeature(path=path_a_T, metadata=metadata)
# For windows, the file is locked by the numpy.load. We need to delete
# it before closing the temporary directory.
a = b = None
feature_a = feature_b = None
# Test loaded tensors' contiguity from C/Fortran contiguous ndarray.
contiguous_numpy = np.array([[1, 2, 3], [4, 5, 6]], order="C")
non_contiguous_numpy = np.array([[1, 2, 3], [4, 5, 6]], order="F")
assert contiguous_numpy.flags["C_CONTIGUOUS"]
assert non_contiguous_numpy.flags["F_CONTIGUOUS"]
path_contiguous = os.path.join(test_dir, "contiguous_numpy.npy")
path_non_contiguous = os.path.join(test_dir, "non_contiguous_numpy.npy")
np.save(path_contiguous, contiguous_numpy)
np.save(path_non_contiguous, non_contiguous_numpy)
feature_c = gb.DiskBasedFeature(path=path_contiguous, metadata=metadata)
feature_n = gb.DiskBasedFeature(path=path_non_contiguous)
assert feature_c._tensor.is_contiguous()
assert feature_n._tensor.is_contiguous()
contiguous_numpy = non_contiguous_numpy = None
feature_c = feature_n = None
@unittest.skipIf(
sys.platform.startswith("win"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment