Skip to content

Commit

Permalink
Remove redundant int overloads from Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jul 3, 2024
1 parent d5993da commit 5b14ed3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 62 deletions.
40 changes: 0 additions & 40 deletions include/sleipnir/autodiff/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand Down
20 changes: 1 addition & 19 deletions jormungandr/cpp/Docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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``:
Expand All @@ -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";

Expand Down
6 changes: 3 additions & 3 deletions jormungandr/cpp/autodiff/BindVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ void BindVariable(py::module_& autodiff, py::class_<Variable>& cls) {

cls.def(py::init<>(), DOC(sleipnir, Variable, Variable));
cls.def(py::init<double>(), "value"_a, DOC(sleipnir, Variable, Variable, 2));
cls.def(py::init<int>(), "value"_a, DOC(sleipnir, Variable, Variable, 3));
cls.def(py::init<int>(), "value"_a, DOC(sleipnir, Variable, Variable, 2));
cls.def("set_value", py::overload_cast<double>(&Variable::SetValue),
"value"_a, DOC(sleipnir, Variable, SetValue));
cls.def("set_value", py::overload_cast<double>(&Variable::SetValue),
"value"_a, DOC(sleipnir, Variable, SetValue));
cls.def("set_value", py::overload_cast<int>(&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);
Expand Down

0 comments on commit 5b14ed3

Please sign in to comment.