@@ -24,25 +24,42 @@ class Tensor : public TensorBase {
2424 public:
2525 Tensor () = default ;
2626 Tensor (const PaddleTensor& tensor) : TensorBase(tensor){}; // NOLINT
27+ Tensor (const Tensor& tensor) = default ;
28+ Tensor (Tensor&& tensor) = default ;
2729
2830 // Implicitly move-constructible from TensorBase, but must be explicit to
2931 // increase refcount
3032 explicit Tensor (const TensorBase& base) : TensorBase(base) {} // NOLINT
3133 /* implicit*/ Tensor(TensorBase&& base) // NOLINT
3234 : TensorBase(std::move(base)) {}
3335
34- // TODO(dev): Implement assignment operators
35- // Tensor& operator=(const Tensor& x) & noexcept {
36- // return operator=(static_cast<const TensorBase&>(x));
37- // }
38- // Tensor& operator=(Tensor&& x) & noexcept {
39- // return operator=(static_cast<TensorBase&&>(x));
40- // }
36+ Tensor& operator =(const PaddleTensor& x) & noexcept {
37+ tensor_ = x;
38+ return *this ;
39+ }
40+ Tensor& operator =(const TensorBase& x) & noexcept {
41+ const PaddleTensor& inner = x._PD_GetInner ();
42+ tensor_ = inner;
43+ return *this ;
44+ }
45+ Tensor& operator =(PaddleTensor&& x) & noexcept {
46+ tensor_ = std::move (x);
47+ return *this ;
48+ }
49+ Tensor& operator =(TensorBase&& x) & noexcept {
50+ tensor_ = std::move (x)._PD_GetInner ();
51+ return *this ;
52+ }
4153
54+ Tensor& operator =(const Tensor& x) & noexcept {
55+ return operator =(static_cast <const TensorBase&>(x));
56+ }
57+ Tensor& operator =(Tensor&& x) & noexcept {
58+ return operator =(static_cast <TensorBase&&>(x));
59+ }
4260 Tensor& operator =(const Scalar& v) && { return fill_ (v); }
43- // TODO(dev): Implement assignment operators
44- // Tensor& operator=(const Tensor& rhs) && { return copy_(rhs); }
45- // Tensor& operator=(Tensor&& rhs) && { return copy_(rhs); }
61+ Tensor& operator =(const Tensor& rhs) && { return copy_ (rhs); }
62+ Tensor& operator =(Tensor&& rhs) && { return copy_ (rhs); }
4663
4764 void * data_ptr () const { return const_cast <void *>(tensor_.data ()); }
4865 template <typename T>
0 commit comments