Skip to content

Commit

Permalink
Merge pull request #23 from sandialabs/dev-public
Browse files Browse the repository at this point in the history
Updating pybind11 interface
  • Loading branch information
whart222 authored Feb 7, 2023
2 parents e6b52c3 + 272e2f4 commit 23220b7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/coek/test/test_con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ TEST_CASE("elementary_constraint", "[smoke]")
#else
# define MODEL_TYPES coek::Model
#endif
#if __cpp_lib_variant
TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES)
{
TestType m;
Expand Down Expand Up @@ -1937,3 +1938,4 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES)
}
#endif
}
#endif
2 changes: 2 additions & 0 deletions lib/coek/test/test_subexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ TEST_CASE("mutable_subexpression", "[smoke]")
}
}

#if __cpp_lib_variant
TEST_CASE("indexed_subexpression", "[smoke]")
{
SECTION("simple array")
Expand Down Expand Up @@ -270,3 +271,4 @@ TEST_CASE("indexed_subexpression", "[smoke]")
}
#endif
}
#endif
4 changes: 2 additions & 2 deletions lib/poek/poek/tests/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def test_expr(self):
self.assertEqual(p.value, 2)
e = p + 3
self.assertEqual(e.value, 5)
with self.assertRaisesRegex(AttributeError, "can't set attribute"):
with self.assertRaisesRegex(AttributeError, "property of 'expression' object has no setter"):
e.value = 0

def test_constraint(self):
p = variable(value=2)
self.assertEqual(p.value, 2)
e = p < 3
self.assertEqual(e.value, 2)
with self.assertRaisesRegex(AttributeError, "can't set attribute"):
with self.assertRaisesRegex(AttributeError, "property of 'constraint' object has no setter"):
e.value = 0

def test_param1(self):
Expand Down
11 changes: 8 additions & 3 deletions lib/pycoek/pybind11/pycoek_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Expression construct_linear_expression(std::vector<double> coefs, std::vector<Va
return res;
}

double expression_eval(Expression& e, bool exception = false) { return e.value(); }
double expression_eval(Expression& e, bool /*exception*/ = false) { return e.value(); }

py::list to_nested_list(std::list<std::string>::iterator& it, std::list<std::string>::iterator& end)
{
Expand Down Expand Up @@ -577,7 +577,12 @@ VariableMap variable_fn(coek::ConcreteSet& index_set, py::kwargs kwargs)

VariableArray variable_fn(std::vector<int>& dimen, py::kwargs kwargs)
{
VariableArray tmp(dimen);
std::vector<size_t> _dimen(dimen.size());
for (size_t i=0; i<dimen.size(); ++i) {
assert (dimen[i] >= 0);
_dimen[i] = static_cast<size_t>(dimen[i]);
}
VariableArray tmp(_dimen);
set_kwargs(tmp, kwargs);
return tmp;
}
Expand Down Expand Up @@ -1269,7 +1274,7 @@ PYBIND11_MODULE(pycoek_pybind11, m)
"__iter__",
[](const coek::VariableArray& va) {
typedef coek::VecKeyIterator<std::vector<coek::Variable>::const_iterator> vec_key_t;
return py::make_iterator(vec_key_t(va.begin()), vec_key_t(va.end()));
return py::make_iterator(vec_key_t(va.cbegin()), vec_key_t(va.cend()));
/*
if (va.dim() == 0)
return py::make_iterator(vec_key_t(va.begin()), vec_key_t(va.end()));
Expand Down
1 change: 0 additions & 1 deletion tpl/cmake/BuildThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ macro(setup_builds)
SOURCE_DIR ${source_dir}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
CMAKE_ARGS
-DPYBIND11_MASTER_PROJECT=OFF
-DPYBIND11_INSTALL=ON
-DPYBIND11_TEST=OFF
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
Expand Down
6 changes: 3 additions & 3 deletions tpl/thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ add_revision(fmtlib
)

add_revision(pybind11
SRC "pybind11-2.6.2"
URL "https://github.com/pybind/pybind11/archive/refs/tags/v2.6.2.tar.gz"
URL_HASH SHA256=8ff2fff22df038f5cd02cea8af56622bc67f5b64534f1b83b9f133b8366acff2
SRC "pybind11-2.10.3"
URL "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.3.tar.gz"
URL_HASH SHA256=5d8c4c5dda428d3a944ba3d2a5212cb988c2fae4670d58075a5a49075a6ca315
)

add_revision(rapidjson
Expand Down

0 comments on commit 23220b7

Please sign in to comment.