From 5b14ed37600f0fcfba1b4d6bd28bc605e2c153b5 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 3 Jul 2024 16:00:59 -0700 Subject: [PATCH] Remove redundant int overloads from Variable --- include/sleipnir/autodiff/Variable.hpp | 40 ----------------------- jormungandr/cpp/Docstrings.hpp | 20 +----------- jormungandr/cpp/autodiff/BindVariable.cpp | 6 ++-- 3 files changed, 4 insertions(+), 62 deletions(-) diff --git a/include/sleipnir/autodiff/Variable.hpp b/include/sleipnir/autodiff/Variable.hpp index 694817f9..80e9d993 100644 --- a/include/sleipnir/autodiff/Variable.hpp +++ b/include/sleipnir/autodiff/Variable.hpp @@ -32,13 +32,6 @@ class SLEIPNIR_DLLEXPORT Variable { */ Variable(double value) : expr{detail::MakeExpressionPtr(value)} {} // NOLINT - /** - * Constructs a Variable from an int. - * - * @param value The value of the Variable. - */ - Variable(int value) : expr{detail::MakeExpressionPtr(value)} {} // NOLINT - /** * Constructs a Variable pointing to the specified expression. * @@ -64,17 +57,6 @@ class SLEIPNIR_DLLEXPORT Variable { return *this; } - /** - * Assignment operator for int. - * - * @param value The value of the Variable. - */ - Variable& operator=(int value) { - expr = detail::MakeExpressionPtr(value); - - return *this; - } - /** * Sets Variable's internal value. * @@ -97,28 +79,6 @@ class SLEIPNIR_DLLEXPORT Variable { return *this; } - /** - * Sets Variable's internal value. - * - * @param value The value of the Variable. - */ - Variable& SetValue(int value) { - if (expr->IsConstant(0.0)) { - expr = detail::MakeExpressionPtr(value); - } else { - // We only need to check the first argument since unary and binary - // operators both use it - if (expr->args[0] != nullptr && !expr->args[0]->IsConstant(0.0)) { - sleipnir::println( - stderr, - "WARNING: {}:{}: Modified the value of a dependent variable", - __FILE__, __LINE__); - } - expr->value = value; - } - return *this; - } - /** * Variable-Variable multiplication operator. * diff --git a/jormungandr/cpp/Docstrings.hpp b/jormungandr/cpp/Docstrings.hpp index b2ccd456..9277086c 100644 --- a/jormungandr/cpp/Docstrings.hpp +++ b/jormungandr/cpp/Docstrings.hpp @@ -1537,12 +1537,6 @@ static const char *__doc_sleipnir_VariableMatrix_size = R"doc(Returns number of static const char *__doc_sleipnir_Variable_SetValue = R"doc(Sets Variable's internal value. -Parameter ``value``: - The value of the Variable.)doc"; - -static const char *__doc_sleipnir_Variable_SetValue_2 = -R"doc(Sets Variable's internal value. - Parameter ``value``: The value of the Variable.)doc"; @@ -1561,18 +1555,12 @@ Parameter ``value``: The value of the Variable.)doc"; static const char *__doc_sleipnir_Variable_Variable_3 = -R"doc(Constructs a Variable from an int. - -Parameter ``value``: - The value of the Variable.)doc"; - -static const char *__doc_sleipnir_Variable_Variable_4 = R"doc(Constructs a Variable pointing to the specified expression. Parameter ``expr``: The autodiff variable.)doc"; -static const char *__doc_sleipnir_Variable_Variable_5 = +static const char *__doc_sleipnir_Variable_Variable_4 = R"doc(Constructs a Variable pointing to the specified expression. Parameter ``expr``: @@ -1583,12 +1571,6 @@ static const char *__doc_sleipnir_Variable_expr = R"doc(The expression node.)doc static const char *__doc_sleipnir_Variable_operator_assign = R"doc(Assignment operator for double. -Parameter ``value``: - The value of the Variable.)doc"; - -static const char *__doc_sleipnir_Variable_operator_assign_2 = -R"doc(Assignment operator for int. - Parameter ``value``: The value of the Variable.)doc"; diff --git a/jormungandr/cpp/autodiff/BindVariable.cpp b/jormungandr/cpp/autodiff/BindVariable.cpp index 7460b2ee..23e8bab4 100644 --- a/jormungandr/cpp/autodiff/BindVariable.cpp +++ b/jormungandr/cpp/autodiff/BindVariable.cpp @@ -27,11 +27,11 @@ void BindVariable(py::module_& autodiff, py::class_& cls) { cls.def(py::init<>(), DOC(sleipnir, Variable, Variable)); cls.def(py::init(), "value"_a, DOC(sleipnir, Variable, Variable, 2)); - cls.def(py::init(), "value"_a, DOC(sleipnir, Variable, Variable, 3)); + cls.def(py::init(), "value"_a, DOC(sleipnir, Variable, Variable, 2)); + cls.def("set_value", py::overload_cast(&Variable::SetValue), + "value"_a, DOC(sleipnir, Variable, SetValue)); cls.def("set_value", py::overload_cast(&Variable::SetValue), "value"_a, DOC(sleipnir, Variable, SetValue)); - cls.def("set_value", py::overload_cast(&Variable::SetValue), "value"_a, - DOC(sleipnir, Variable, SetValue, 2)); cls.def(double() * py::self, "lhs"_a); cls.def(py::self * double(), "rhs"_a); cls.def(py::self * py::self, "rhs"_a);