mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-18 14:40:44 +08:00
[Other]Fix the fd tensor copy assignment (#506)
Fix the fd tensor copy assignment
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user