From 1d01017f5729b99995f4d9e359afa5f08fa094dd Mon Sep 17 00:00:00 2001 From: Parichay Kapoor Date: Fri, 26 Jun 2020 18:51:43 +0900 Subject: [PATCH] [optimizer] Bug fix Tensor copy constructor and copy assigment operator creates a copy of the vector This led to bug in optimizer which updated the copy of the weight than the weight itself Fixed by refernce of weight in optimizer Resolves #241 Signed-off-by: Parichay Kapoor --- nntrainer/src/optimizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nntrainer/src/optimizer.cpp b/nntrainer/src/optimizer.cpp index e9d686c..ff57a84 100644 --- a/nntrainer/src/optimizer.cpp +++ b/nntrainer/src/optimizer.cpp @@ -103,7 +103,7 @@ void Optimizer::apply_gradients( std::vector>::iterator w_iter, g_iter; for (w_iter = weights.begin(), g_iter = gradients.begin(); w_iter != weights.end(); ++w_iter, ++g_iter) { - Tensor x = *w_iter; + Tensor &x = *w_iter; Tensor x_grad = *g_iter; x_grad = x_grad.average(); -- 2.7.4