From 32dce75975abe6241199b70062c988a2ebe029b2 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Thu, 13 Jan 2022 11:24:32 +0900 Subject: [PATCH] [Fix] Non-const reference 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 --- nntrainer/layers/layer_context.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/nntrainer/layers/layer_context.cpp b/nntrainer/layers/layer_context.cpp index a197bd8..92011f5 100644 --- a/nntrainer/layers/layer_context.cpp +++ b/nntrainer/layers/layer_context.cpp @@ -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(); } -- 2.7.4