From 38c972fcc05b5f21b0003ba7bc4134b3aa548c56 Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Fri, 23 Feb 2024 14:39:47 +1100 Subject: [PATCH] NLWPY: remove NLW2_ prefix #30 --- nl-writer2/nlwpy/src/nlw_bindings.cc | 44 ++++++++++++++-------------- nl-writer2/nlwpy/tests/test.py | 22 +++++++------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/nl-writer2/nlwpy/src/nlw_bindings.cc b/nl-writer2/nlwpy/src/nlw_bindings.cc index 9ccd99479..4730d5c63 100644 --- a/nl-writer2/nlwpy/src/nlw_bindings.cc +++ b/nl-writer2/nlwpy/src/nlw_bindings.cc @@ -267,48 +267,48 @@ PYBIND11_MODULE(nlwpy, m) .. autosummary:: :toctree: _generate - NLW2_ObjSense -NLW2_VarType -NLW2_MatrixFormat -NLW2_HessianFormat - -NLW2_NLOptionsBasic - NLW2_MakeNLOptionsBasic_Default -NLW2_NLSuffix -NLW2_NLModel -NLW2_NLSolution -NLW2_NLSolver + ObjSense +VarType +MatrixFormat +HessianFormat + +NLOptionsBasic + MakeNLOptionsBasic_Default +NLSuffix +NLModel +NLSolution +NLSolver )pbdoc"; - py::enum_(m, "NLW2_ObjSense", py::arithmetic()) + py::enum_(m, "ObjSense", py::arithmetic()) .value("Minimize", NLW2_ObjSenseMinimize) .value("Maximize", NLW2_ObjSenseMaximize); // .export_values(); -- Leave them scoped - py::enum_(m, "NLW2_VarType", py::arithmetic()) + py::enum_(m, "VarType", py::arithmetic()) .value("Continuous", NLW2_VarTypeContinuous) .value("Integer", NLW2_VarTypeInteger); - py::enum_(m, "NLW2_MatrixFormat", py::arithmetic()) + py::enum_(m, "MatrixFormat", py::arithmetic()) .value("Rowwise", NLW2_MatrixFormatRowwise); - py::enum_(m, "NLW2_HessianFormat", py::arithmetic()) + py::enum_(m, "HessianFormat", py::arithmetic()) .value("Triangular", NLW2_HessianFormatTriangular) .value("Square", NLW2_HessianFormatSquare); /// NLOptionsBasic - py::class_(m, "NLW2_NLOptionsBasic") + py::class_(m, "NLOptionsBasic") .def(py::init<>()) .def_readwrite("n_text_mode_", &NLW2_NLOptionsBasic_C::n_text_mode_) .def_readwrite("want_nl_comments_", &NLW2_NLOptionsBasic_C::want_nl_comments_) .def_readwrite("flags_", &NLW2_NLOptionsBasic_C::flags_); - m.def("NLW2_MakeNLOptionsBasic_Default", &NLW2_MakeNLOptionsBasic_C_Default, R"pbdoc( + m.def("MakeNLOptionsBasic_Default", &NLW2_MakeNLOptionsBasic_C_Default, R"pbdoc( Use this to create default options for NLModel. )pbdoc"); /// NLSuffix - py::class_(m, "NLW2_NLSuffix") + py::class_(m, "NLSuffix") .def(py::init>()) .def(py::init>()) .def_readwrite("name_", &mp::NLSuffix::name_) @@ -317,7 +317,7 @@ NLW2_NLSolver .def_readwrite("values_", &mp::NLSuffix::values_); /// NLSuffixSet - py::class_(m, "NLW2_NLSuffixSet") + py::class_(m, "NLSuffixSet") .def("Find", // Find(): return None if not found [=](mp::NLSuffixSet const& ss, std::string const& name, int kind) -> py::object { @@ -335,7 +335,7 @@ NLW2_NLSolver ; /// NLModel - py::class_(m, "NLW2_NLModel") + py::class_(m, "NLModel") .def(py::init()) .def("SetCols", &NLWPY_NLModel::SetCols) .def("SetColNames", &NLWPY_NLModel::SetColNames) @@ -350,7 +350,7 @@ NLW2_NLSolver ; /// NLSolution - py::class_(m, "NLW2_NLSolution") + py::class_(m, "NLSolution") .def_readwrite("solve_result_", &mp::NLSolution::solve_result_) .def_readwrite("nbs_", &mp::NLSolution::nbs_) .def_readwrite("solve_message_", &mp::NLSolution::solve_message_) @@ -360,7 +360,7 @@ NLW2_NLSolver .def_readwrite("suffixes_", &mp::NLSolution::suffixes_); /// NLSolver - py::class_(m, "NLW2_NLSolver") + py::class_(m, "NLSolver") .def(py::init<>()) .def("SetFileStub", &mp::NLSolver::SetFileStub) .def("SetNLOptions", &mp::NLSolver::SetNLOptions) diff --git a/nl-writer2/nlwpy/tests/test.py b/nl-writer2/nlwpy/tests/test.py index babce431f..d5d4ce214 100644 --- a/nl-writer2/nlwpy/tests/test.py +++ b/nl-writer2/nlwpy/tests/test.py @@ -24,11 +24,11 @@ import numpy as np from scipy.sparse import csr_matrix -import nlwpy as m +import nlwpy -assert m.__version__ == "0.0.1" +assert nlwpy.__version__ == "0.0.1" -nlwo = m.NLW2_MakeNLOptionsBasic_Default() +nlwo = nlwpy.MakeNLOptionsBasic_Default() assert 0 == nlwo.n_text_mode_ assert 0 == nlwo.want_nl_comments_ assert 1 == nlwo.flags_ @@ -36,7 +36,7 @@ ## --------------------------------------------------------------- class ModelBuilder: def GetModel(self): - nlme = m.NLW2_NLModel(self.prob_name_) + nlme = nlwpy.NLModel(self.prob_name_) nlme.SetCols(self.var_lb_, self.var_ub_, self.var_type_) nlme.SetColNames(self.var_names_) @@ -62,10 +62,10 @@ def GetModel(self): if len(self.ini_y_i_)>0: nlme.SetDualWarmstart(self.ini_y_i_, self.ini_y_v_) if len(self.bas_x_)>0: - suf = m.NLW2_NLSuffix("status", 0, self.bas_x_) + suf = nlwpy.NLSuffix("status", 0, self.bas_x_) nlme.AddSuffix(suf) if len(self.bas_y_)>0: - suf = m.NLW2_NLSuffix("status", 1, self.bas_y_) + suf = nlwpy.NLSuffix("status", 1, self.bas_y_) nlme.AddSuffix(suf) return nlme @@ -116,17 +116,17 @@ def __init__(self): self.var_type_ = [0, 1, 1, 1, 0, 0] self.var_names_ = \ ["x1_4", "x2_6", "x3_5", "x4_3", "x5_1", "x6_2"] - self.A_format_ = m.NLW2_MatrixFormat.Rowwise + self.A_format_ = nlwpy.MatrixFormat.Rowwise self.A_ = np.array([ [0,1,1,1,0,1], [0,1,-1,-1,0,1]]) self.row_lb_ = [15, 10] self.row_ub_ = [15, np.inf] self.row_names_ = ["C1", "C2"] - self.obj_sense_ = m.NLW2_ObjSense.Minimize + self.obj_sense_ = nlwpy.ObjSense.Minimize self.obj_c0_ = 3.24 self.obj_c_ = [0,1,0,0,0,0] - self.Q_format_ = m.NLW2_HessianFormat.Square + self.Q_format_ = nlwpy.HessianFormat.Square self.Q_ = np.zeros([6, 6]) self.Q_[3, 3] = 10 self.Q_[3, 5] = 12 @@ -148,8 +148,8 @@ def __init__(self): def SolveAndCheck(solver, sopts, binary, stub): mb = ModelBuilder() nlme = mb.GetModel() - nlse = m.NLW2_NLSolver() - nlopts = m.NLW2_MakeNLOptionsBasic_Default() + nlse = nlwpy.NLSolver() + nlopts = nlwpy.MakeNLOptionsBasic_Default() nlopts.n_text_mode_ = not binary nlopts.want_nl_comments_ = 1 nlse.SetNLOptions(nlopts)