From 42209914ed308cccda9579105e410a4e738582ed Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 14 Dec 2023 16:17:51 -0800 Subject: [PATCH] Add comment for dependent variable warning --- 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",