From ca5a950b78dca6e6b5ba804238f2409ef46eae03 Mon Sep 17 00:00:00 2001 From: wkcn Date: Thu, 20 Dec 2018 12:16:27 +0800 Subject: [PATCH 1/2] fix the reference of tblob --- src/ndarray/ndarray.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ndarray/ndarray.cc b/src/ndarray/ndarray.cc index 081d4e759323..d0de73cb3cbe 100644 --- a/src/ndarray/ndarray.cc +++ b/src/ndarray/ndarray.cc @@ -333,7 +333,7 @@ DLManagedTensor* NDArray::ToDLPack() const { 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){ From 56ff9ca665f0e9ec33f1a22f9726211832e1378d Mon Sep 17 00:00:00 2001 From: wkcn Date: Thu, 20 Dec 2018 12:29:21 +0800 Subject: [PATCH 2/2] check is_none in NDArray::ToDLPack --- 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 d0de73cb3cbe..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 = dlmanager->handle.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);