Skip to content
Snippets Groups Projects
Commit 49e72157 authored by René Fritze's avatar René Fritze Committed by René Milk
Browse files

[py] replace deprecated placement new for custom ctors

parent 6a4db8be
No related branches found
No related tags found
No related merge requests found
......@@ -42,10 +42,9 @@ struct addbind_Matrix
namespace py = pybind11;
using namespace pybind11::literals;
c.def("__init__",
[](T& self, const ssize_t rows, const ssize_t cols, const S& value) {
new (&self) T(Common::numeric_cast<size_t>(rows), Common::numeric_cast<size_t>(cols), value);
},
c.def(py::init([](const ssize_t rows, const ssize_t cols, const S& value) {
return new T(Common::numeric_cast<size_t>(rows), Common::numeric_cast<size_t>(cols), value);
}),
"rows"_a = 0,
"cols"_a = 0,
"value"_a = 0.0);
......@@ -100,10 +99,9 @@ typename std::enable_if<is_matrix<C>::value, pybind11::class_<C>>::type bind_Mat
addbind_ProvidesBackend(c);
internal::addbind_Matrix<C, sparse>::template ctor<S>(c);
c.def("__init__",
[](C& self, const ssize_t rows, const ssize_t cols, const SparsityPatternDefault& pattern) {
new (&self) C(Common::numeric_cast<size_t>(rows), Common::numeric_cast<size_t>(cols), pattern);
},
c.def(py::init([](const ssize_t rows, const ssize_t cols, const SparsityPatternDefault& pattern) {
return new C(Common::numeric_cast<size_t>(rows), Common::numeric_cast<size_t>(cols), pattern);
}),
"rows"_a,
"cols"_a,
"pattern"_a);
......
......@@ -35,10 +35,9 @@ pybind11::class_<SparsityPatternDefault> bind_SparsityPatternDefault(pybind11::m
py::class_<SparsityPatternDefault> c(m, "SparsityPatternDefault", "SparsityPatternDefault");
c.def("__init__",
[](C& self, const ssize_t size) {
c.def(py::init([](const ssize_t size) {
try {
new (&self) C(boost::numeric_cast<size_t>(size));
return new C(boost::numeric_cast<size_t>(size));
} catch (boost::bad_numeric_cast& ee) {
DUNE_THROW(Common::Exceptions::wrong_input_given,
"Given size has to be positive!\n\n The error in boost while converting '"
......@@ -48,7 +47,7 @@ pybind11::class_<SparsityPatternDefault> bind_SparsityPatternDefault(pybind11::m
<< "' was: "
<< ee.what());
}
},
}),
"size"_a = 0);
c.def("insert", &C::insert, "outer_index"_a, "inner_index"_a);
......
......@@ -46,22 +46,15 @@ typename std::enable_if<is_vector<C>::value, pybind11::class_<C>>::type bind_Vec
py::class_<C> c = bind_ProvidesDataAccess<C>(m, ClassName, ClassName);
addbind_ProvidesBackend(c);
c.def("__init__",
[](C& vec, const ssize_t size, const S& value) { new (&vec) C(Common::numeric_cast<size_t>(size), value); },
c.def(py::init([](const ssize_t size, const S& value) { return new C(Common::numeric_cast<size_t>(size), value); }),
"size"_a = 0,
"value"_a = 0.0);
c.def("__init__",
[](C& vec, py::iterable it) {
c.def(py::init([](py::iterable it) {
std::vector<S> tmp;
try {
for (py::handle h : it)
tmp.push_back(h.cast<S>());
new (&vec) C(tmp);
} catch (...) {
vec.~C();
throw;
}
},
for (py::handle h : it)
tmp.push_back(h.cast<S>());
return new C(tmp);
}),
"Assigns the elements of the iterable to the vector.");
c.def("__repr__",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment