Skip to content

Commit 5da8a8c

Browse files
ezyangfacebook-github-bot
authored andcommitted
Handle undefined tensor in blob correctly. (pytorch#12125)
Summary: You can't GetDeviceType an undefined tensor, so test for this case first. This allows you to safely move tensors out of blobs. Signed-off-by: Edward Z. Yang <[email protected]> Pull Request resolved: pytorch#12125 Reviewed By: smessmer Differential Revision: D10080075 Pulled By: ezyang fbshipit-source-id: bb99b089b6daa9d4db99015208f939d7ce4d4a79
1 parent 3251012 commit 5da8a8c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

caffe2/core/blob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ inline bool BlobIsTensorType(const Blob& blob, DeviceType device_type) {
2121
return false;
2222
}
2323
const Tensor* tensor = &blob.Get<Tensor>();
24-
return tensor && tensor->GetDeviceType() == device_type;
24+
return tensor && *tensor && tensor->GetDeviceType() == device_type;
2525
}
2626

2727
inline Tensor* BlobGetMutableTensor(Blob* blob, DeviceType device_type) {
2828
if (blob->IsType<Tensor>()) {
2929
Tensor* tensor = blob->GetMutable<Tensor>();
30-
if (tensor->GetDeviceType() == device_type) {
30+
if (*tensor && tensor->GetDeviceType() == device_type) {
3131
return tensor;
3232
}
3333
}

0 commit comments

Comments
 (0)