未验证 提交 9303b095 编写于 作者: 石晓伟 提交者: GitHub

add the shallow clone member func of the dense tensor, test=develop (#37146)

上级 4d536678
......@@ -172,6 +172,12 @@ class DenseTensor : public TensorBase,
/// \return The const data pointer value of raw type.
const void* data() const;
/// \brief Get the shallow clone of current tensor.
/// \return The shallow clone of current tensor.
DenseTensor shallow_clone() const {
return DenseTensor(copy_intrusive(storage_), meta_);
}
private:
friend class CompatibleDenseTensorUtils;
......
......@@ -82,4 +82,11 @@ inline bool DenseTensorMeta::valid() const noexcept {
return valid;
}
inline bool operator==(const DenseTensorMeta& lhs, const DenseTensorMeta& rhs) {
bool ret = true;
return ret && (lhs.is_scalar == rhs.is_scalar) && (lhs.dims == rhs.dims) &&
(lhs.type == rhs.type) && (lhs.layout == rhs.layout) &&
(lhs.lod == rhs.lod);
}
} // namespace pten
......@@ -125,5 +125,20 @@ TEST(dense_tensor, resize) {
CHECK_EQ(storage->size(), 6u);
}
TEST(dense_tensor, shallow_clone) {
const DDim dims({1, 2});
const DataType dtype{DataType::INT8};
const DataLayout layout{DataLayout::NHWC};
const std::vector<std::vector<size_t>> lod{};
DenseTensorMeta meta(dtype, dims, layout, lod);
auto alloc = std::make_shared<FancyAllocator>();
DenseTensor tensor_0(alloc, meta);
auto tensor_1 = tensor_0.shallow_clone();
CHECK(tensor_0.meta() == tensor_1.meta());
CHECK(tensor_0.release() == tensor_1.release());
}
} // namespace tests
} // namespace pten
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册