Chore: move TensorObj::clone to .cc

This commit is contained in:
Liyan Zheng 2023-04-22 16:03:16 +08:00
parent 84f9d6731a
commit 0865f8d823
2 changed files with 30 additions and 19 deletions

View File

@ -78,25 +78,8 @@ class TensorObj : public TensorBaseObj {
void setData(
std::function<void(void *, size_t, DataType)> const &generator) const;
void setData(const Blob &_blob) { data = _blob; }
Tensor clone() const {
auto obj = make_ref<TensorObj>(*this);
obj->freeData();
obj->targets.clear();
obj->source.reset();
return obj;
}
Tensor clone(Runtime runtime) const {
auto obj = make_ref<TensorObj>(*this);
obj->runtime = runtime;
obj->freeData();
obj->targets.clear();
obj->source.reset();
if (hasData()) {
obj->dataMalloc();
obj->copyData(this);
}
return obj;
}
Tensor clone() const;
Tensor clone(Runtime runtime) const;
void printData() const;
bool equalData(const Tensor &rhs, double relativeError = 1e-6) const;
@ -127,6 +110,12 @@ class TensorObj : public TensorBaseObj {
if (i % dimSzVec[j] == 0)
builder << "[";
if (iEnd > 1000 && i > 20 && i < iEnd - 20) {
printf("... , ");
i = iEnd - 20;
continue;
}
builder << ptr[i];
for (size_t j = 0; j < numDims; ++j)
if ((int)i % dimSzVec[j] == dimSzVec[j] - 1)

View File

@ -182,4 +182,26 @@ size_t TensorObj::getOffsetByBroadcastOffset(size_t bcOffset,
return getOffsetByPos(pos, shape);
}
Tensor TensorObj::clone() const {
auto obj = make_ref<TensorObj>(*this);
obj->freeData();
obj->targets.clear();
obj->source.reset();
return obj;
}
Tensor TensorObj::clone(Runtime runtime) const {
auto obj = make_ref<TensorObj>(*this);
obj->runtime = runtime;
obj->freeData();
obj->targets.clear();
obj->source.reset();
if (hasData()) {
obj->dataMalloc();
obj->copyData(this);
}
return obj;
}
}; // namespace infini