Skip to content

Commit

Permalink
Add log10
Browse files Browse the repository at this point in the history
  • Loading branch information
metab0t committed Nov 22, 2024
1 parent ff7b613 commit 4f65128
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/pyoptinterface/nlexpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum class UnaryOperator
Sqrt,
Exp,
Log,
Log10
};

enum class BinaryOperator
Expand Down
3 changes: 3 additions & 0 deletions lib/cppad_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ CppAD::AD<double> cppad_build_unary_expression(UnaryOperator op, const CppAD::AD
case UnaryOperator::Log: {
return CppAD::log(operand);
}
case UnaryOperator::Log10: {
return CppAD::log10(operand);
}
default: {
throw std::runtime_error("Invalid unary operator");
}
Expand Down
3 changes: 2 additions & 1 deletion lib/nlexpr_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ NB_MODULE(nlexpr_ext, m)
.value("Abs", UnaryOperator::Abs)
.value("Sqrt", UnaryOperator::Sqrt)
.value("Exp", UnaryOperator::Exp)
.value("Log", UnaryOperator::Log);
.value("Log", UnaryOperator::Log)
.value("Log10", UnaryOperator::Log10);

nb::enum_<BinaryOperator>(m, "BinaryOperator")
.value("Sub", BinaryOperator::Sub)
Expand Down
1 change: 1 addition & 0 deletions src/pyoptinterface/_src/function_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def f(expr):
sqrt = unary_mathematical_function(math.sqrt, UnaryOperator.Sqrt)
exp = unary_mathematical_function(math.exp, UnaryOperator.Exp)
log = unary_mathematical_function(math.log, UnaryOperator.Log)
log10 = unary_mathematical_function(math.log10, UnaryOperator.Log10)


# Implement binary mathematical functions
Expand Down
1 change: 1 addition & 0 deletions src/pyoptinterface/nlfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
sqrt,
exp,
log,
log10,
pow,
ifelse,
)
1 change: 1 addition & 0 deletions tests/test_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def con(vars):
nlfunc.cos,
nlfunc.exp,
nlfunc.log,
nlfunc.log10,
nlfunc.pow,
nlfunc.sin,
nlfunc.sqrt,
Expand Down

0 comments on commit 4f65128

Please sign in to comment.