[Other]Fix the fd tensor copy assignment (#506)

Fix the fd tensor copy assignment
This commit is contained in:
Jack Zhou
2022-11-06 20:17:35 +08:00
committed by GitHub
parent 6408af263a
commit 08a384f7c2
2 changed files with 100 additions and 11 deletions

View File

@@ -89,8 +89,9 @@ void FDTensor::Squeeze(int64_t axis) {
size_t ndim = shape.size();
FDASSERT(axis >= 0 && axis < ndim,
"The allowed 'axis' must be in range of (0, %lu)!", ndim);
FDASSERT(shape[axis]==1,
"The No.%ld dimension of shape should be 1, but it is %ld!", (long)axis, (long)shape[axis]);
FDASSERT(shape[axis] == 1,
"The No.%ld dimension of shape should be 1, but it is %ld!",
(long)axis, (long)shape[axis]);
shape.erase(shape.begin() + axis);
}
@@ -220,9 +221,9 @@ bool FDTensor::ReallocFn(size_t nbytes) {
return buffer_ != nullptr;
#else
FDASSERT(false,
"The FastDeploy FDTensor allocator didn't compile under "
"-DWITH_GPU=ON,"
"so this is an unexpected problem happend.");
"The FastDeploy FDTensor allocator didn't compile under "
"-DWITH_GPU=ON,"
"so this is an unexpected problem happend.");
#endif
}
buffer_ = realloc(buffer_, nbytes);
@@ -316,16 +317,15 @@ FDTensor& FDTensor::operator=(const FDTensor& other) {
if (other.buffer_ == nullptr) {
FreeFn();
buffer_ = nullptr;
shape = other.shape;
name = other.name;
dtype = other.dtype;
device = other.device;
} else {
Resize(other.shape);
Resize(other.shape, other.dtype, other.name, other.device);
size_t nbytes = Nbytes();
CopyBuffer(buffer_, other.buffer_, nbytes);
}
shape = other.shape;
name = other.name;
dtype = other.dtype;
device = other.device;
external_data_ptr = other.external_data_ptr;
}
return *this;