Re-use CopyAsType<>() to implement copy ctor

This commit is contained in:
Po-Yen, Chen
2022-08-19 01:02:36 -04:00
parent e03cece9c4
commit dd849a8736

View File

@@ -254,7 +254,7 @@ struct Tensor
Tensor(const HostTensorDescriptor& desc) : mDesc(desc), mData(mDesc.GetElementSpaceSize()) {}
template <typename OutT>
Tensor<OutT> CopyAsType()
Tensor<OutT> CopyAsType() const
{
Tensor<OutT> ret(mDesc);
for(size_t i = 0; i < mData.size(); i++)
@@ -266,11 +266,10 @@ struct Tensor
Tensor(const Tensor& other) : mDesc(other.mDesc), mData(other.mData) {}
template <typename OtherT,
typename =
std::enable_if_t<sizeof(T) == sizeof(OtherT) && std::is_convertible_v<T, OtherT>>>
Tensor(const Tensor<OtherT>& other)
: mDesc(other.mDesc), mData(std::begin(other.mData), std::end(other.mData))
Tensor(Tensor&& other) = default;
template <typename OtherT>
Tensor(const Tensor<OtherT>& other) : Tensor(other.template CopyAsType<T>())
{
}