[Fix] Non-const reference
authorJihoon Lee <jhoon.it.lee@samsung.com>
Thu, 13 Jan 2022 02:24:32 +0000 (11:24 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 19 Jan 2022 00:52:32 +0000 (09:52 +0900)
This patch fixes returning reference of local variable.

**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/layers/layer_context.cpp

index a197bd8..92011f5 100644 (file)
@@ -275,17 +275,10 @@ const Tensor &RunLayerContext::getInput(unsigned int idx) const {
  */
 Tensor &RunLayerContext::getInputGrad(unsigned int idx) {
   if (!inputs[idx]->hasGradient()) {
-    //
-    // TODO: This is temporal fixes. We need to find way to handle
-    //       the getInputGrad for multiple inputs ( input 1: Input Layer,
-    //       input 2: Normal Input ). In this situation, if we enable
-    //       inPlaceOptimization, it will fail.
-    //
-    // throw std::invalid_argument(
-    //   "Requesting gradient for a non-trainable tensor.");
-    //
-    return Tensor(inputs[idx]->getDim());
+    throw std::invalid_argument(
+      "Requesting gradient for a non-trainable tensor.");
   }
+
   return inputs[idx]->getGradientRef();
 }