Avoid to call memory allocation if tensor size is 0 (#972)

This commit is contained in:
Yufeng Li 2019-05-05 21:46:00 -07:00 committed by GitHub
parent af4a41fd13
commit 8b3c8561ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,9 @@ Tensor::Tensor(MLDataType p_type, const TensorShape& shape, std::shared_ptr<IAll
int64_t shape_size = shape.Size();
if (shape_size < 0 || static_cast<uint64_t>(shape_size) >= std::numeric_limits<size_t>::max())
ORT_THROW("shape.Size() must >=0");
void* p_data = allocator->AllocArray(static_cast<size_t>(shape_size), p_type->Size());
void* p_data = nullptr;
if(shape_size > 0)
p_data = allocator->AllocArray(static_cast<size_t>(shape_size), p_type->Size());
Init(p_type, shape, p_data, allocator, offset);
}