From a9994591ce5987365793eb6a1ddccdaf4193e03d Mon Sep 17 00:00:00 2001 From: Nickolai Belakovski Date: Mon, 18 Mar 2024 16:55:58 +0800 Subject: [PATCH] PR feedback --- python/_prima.cpp | 10 +++++----- python/prima/__init__.py | 2 +- python/prima/_bounds.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/_prima.cpp b/python/_prima.cpp index 4adbf29421..7d32423e65 100644 --- a/python/_prima.cpp +++ b/python/_prima.cpp @@ -161,7 +161,7 @@ PYBIND11_MODULE(_prima, m) { // Process options. prima_options_t options; prima_init_options(&options); - if (options_dict.is_none() == false) { + if ( ! options_dict.is_none()) { if(options_dict.contains("ftarget")) { options.ftarget = options_dict["ftarget"].cast(); } if(options_dict.contains("iprint")) { options.iprint = options_dict["iprint"].cast(); } if(options_dict.contains("maxfev")) { options.maxfun = options_dict["maxfev"].cast(); } @@ -246,7 +246,7 @@ PYBIND11_MODULE(_prima, m) { } prima_callback_t cpp_callback_function_wrapper = nullptr; - if (python_callback_function_holder.is_none() == false) { + if ( ! python_callback_function_holder.is_none()) { cpp_callback_function_wrapper = [](const int n, const double x[], const double f, int nf, int tr, const double cstrv, int m_nlcon, const double nlconstr[], bool *terminate) { // In order for xlist to not copy the data from x, we need to provide a dummy base object @@ -264,7 +264,7 @@ PYBIND11_MODULE(_prima, m) { //===================== // Handle Bounds //===================== - if (lb.is_none() == false && ub.is_none() == false) { + if (( ! lb.is_none()) && ( ! ub.is_none())) { // Use the buffer protocol to avoid copying py::buffer_info lb_buffer_info = lb.cast().request(); if (lb_buffer_info.format != "d") @@ -283,7 +283,7 @@ PYBIND11_MODULE(_prima, m) { //============================== // Handle Linear Constraints //============================== - if(A_eq.is_none() == false) { + if( ! A_eq.is_none()) { py::buffer_info A_eq_buffer_info = A_eq.cast().request(); if (A_eq_buffer_info.format != "d") { @@ -298,7 +298,7 @@ PYBIND11_MODULE(_prima, m) { } problem.beq = (double*) b_eq_buffer_info.ptr; } - if(A_ineq.is_none() == false) { + if( ! A_ineq.is_none()) { py::buffer_info A_ineq_buffer_info = A_ineq.cast().request(); if (A_ineq_buffer_info.format != "d") { diff --git a/python/prima/__init__.py b/python/prima/__init__.py index afee7b08e9..10ff27369b 100644 --- a/python/prima/__init__.py +++ b/python/prima/__init__.py @@ -133,7 +133,7 @@ def minimize(fun, x0, args=(), method=None, bounds=None, constraints=(), callbac m_nlcon = len(nlconstr0) f0 = fun(x0) else: - m_nlcon = None + m_nlcon = 0 f0 = None return _minimize( diff --git a/python/prima/_bounds.py b/python/prima/_bounds.py index 7255498fe4..89afe9529f 100644 --- a/python/prima/_bounds.py +++ b/python/prima/_bounds.py @@ -3,7 +3,7 @@ def process_bounds(bounds, lenx0): ''' - bounds can either be an object with the properties lb and ub, or a list of tuples + `bounds` can either be an object with the properties lb and ub, or a list of tuples indicating a lower bound and an upper bound for each variable. If the list contains fewer entries than the length of x0, the remaining entries will generated as -/+ infinity. Some examples of valid lists of tuple, assuming len(x0) == 3: