From b329aecf836bfcffeae30dbf493a8a838bf14bab Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 17 Dec 2023 21:55:27 -0800 Subject: [PATCH] Add comment for dependent variable warning (#242) --- src/autodiff/Variable.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/autodiff/Variable.cpp b/src/autodiff/Variable.cpp index 30008382..f88f591b 100644 --- a/src/autodiff/Variable.cpp +++ b/src/autodiff/Variable.cpp @@ -34,6 +34,8 @@ Variable& Variable::SetValue(double value) { if (detail::IsZero(expr)) { expr = detail::MakeExpressionPtr(value); } else { + // We only need to check the first argument since unary and binary operators + // both use it if (!detail::IsZero(expr->args[0])) { fmt::print(stderr, "WARNING: {}:{}: Modified the value of a dependent variable\n", @@ -48,6 +50,8 @@ Variable& Variable::SetValue(int value) { if (detail::IsZero(expr)) { expr = detail::MakeExpressionPtr(value); } else { + // We only need to check the first argument since unary and binary operators + // both use it if (!detail::IsZero(expr->args[0])) { fmt::print(stderr, "WARNING: {}:{}: Modified the value of a dependent variable\n",