mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-06 00:03:22 +00:00
Avoid to call memory allocation if tensor size is 0 (#972)
This commit is contained in:
parent
af4a41fd13
commit
8b3c8561ce
1 changed files with 3 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue