[Weight] Add ctors
authorJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 19 Oct 2020 11:02:07 +0000 (20:02 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Fri, 23 Oct 2020 07:01:57 +0000 (16:01 +0900)
Weight did not have copy/move ctor which they should have.
This patch adds them.

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/include/weight.h
nntrainer/src/weight.cpp

index d62d364..b6a8be6 100644 (file)
@@ -102,12 +102,26 @@ public:
   }
 
   /**
+   * @brief Copy constructor for weight
+   *
+   * @param rhs weight to construct from
+   */
+  Weight(const Weight &rhs);
+
+  /**
+   * @brief Move constructor for weight
+   *
+   * @param rhs weight to construct from
+   */
+  Weight(Weight &&rhs) = default;
+
+  /**
    * @brief copy assigment
    *
    * @param rhs copy from
    * @return Weight& Updated weight
    */
-  Weight &operator=(const Weight &rhs) = default;
+  Weight &operator=(const Weight &rhs);
 
   /**
    * @brief move assignment
index afb8164..5c15020 100644 (file)
 
 namespace nntrainer {
 
+Weight::Weight(const Weight &rhs) :
+  initializer(rhs.initializer),
+  trainable(rhs.trainable),
+  name(rhs.name) {
+  var = rhs.var.clone();
+  grad = rhs.grad.clone();
+}
+
+Weight &Weight::operator=(const Weight &rhs) {
+  Weight temp(rhs);
+  swap(temp, *this);
+  return *this;
+}
+
 Weight::Weight(const TensorDim &dim, const WeightInitializer init, bool train,
                std::string name) :
   initializer(init),