From 47ba5ae4ce6df3efbf4a039974c214dd12ec5a60 Mon Sep 17 00:00:00 2001 From: JackieWu Date: Sat, 22 Dec 2018 02:03:54 +0800 Subject: [PATCH] Fix NDArray ToDLPack Bug (#13698) --- src/ndarray/ndarray.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ndarray/ndarray.cc b/src/ndarray/ndarray.cc index 081d4e759323..5a4cb29bc218 100644 --- a/src/ndarray/ndarray.cc +++ b/src/ndarray/ndarray.cc @@ -330,11 +330,10 @@ struct NDArrayDLManager { }; DLManagedTensor* NDArray::ToDLPack() const { + CHECK(!is_none()) << "NDArray is not initialized"; NDArrayDLManager* dlmanager(new NDArrayDLManager); dlmanager->handle = *this; - if (!is_none()) { - dlmanager->tensor.dl_tensor = data().dltensor(); - } + dlmanager->tensor.dl_tensor = dlmanager->handle.data().dltensor(); dlmanager->tensor.manager_ctx = dlmanager; dlmanager->tensor.deleter = [](DLManagedTensor* dlmanager){ delete static_cast(dlmanager->manager_ctx);