Skip to content

Commit 97f8a14

Browse files
Merge branch 'devel' into AddUnits
2 parents e1eb438 + cdd9852 commit 97f8a14

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

expui/BiorthBasis.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ namespace BasisClasses
195195

196196
//! Evaluate acceleration in Cartesian coordinates in centered
197197
//! coordinate system for a collections of points
198-
virtual RowMatrixXd& getAccel(Eigen::VectorXd& x,
199-
Eigen::VectorXd& y,
200-
Eigen::VectorXd& z)
198+
virtual RowMatrixXd& getAccel(Eigen::Ref<const Eigen::VectorXd> x,
199+
Eigen::Ref<const Eigen::VectorXd> y,
200+
Eigen::Ref<const Eigen::VectorXd> z)
201201
{
202202
// Sanity check
203203
if (x.size() != y.size() || x.size() != z.size())
@@ -216,7 +216,7 @@ namespace BasisClasses
216216

217217
//! Evaluate acceleration in Cartesian coordinates in centered
218218
//! coordinate system for a collections of points
219-
virtual RowMatrixXd& getAccel(RowMatrixXd& pos)
219+
virtual RowMatrixXd& getAccel(Eigen::Ref<const RowMatrixXd> pos)
220220
{
221221
// Sanity check
222222
if (pos.cols() != 3)

pyEXP/BasisWrappers.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ void BasisFactoryClasses(py::module &m)
13701370
__call__ : same as getFields() but provides field labels in a tuple
13711371
)",
13721372
py::arg("x"), py::arg("y"), py::arg("z"))
1373-
.def("getAccel", py::overload_cast<Eigen::VectorXd&, Eigen::VectorXd&, Eigen::VectorXd&>(&BasisClasses::BiorthBasis::getAccel),
1373+
.def("getAccel", py::overload_cast<Eigen::Ref<const Eigen::VectorXd>, Eigen::Ref<const Eigen::VectorXd>, Eigen::Ref<const Eigen::VectorXd>>(&BasisClasses::BiorthBasis::getAccel),
13741374
R"(
13751375
Return the acceleration for a given cartesian position
13761376
@@ -1394,7 +1394,7 @@ void BasisFactoryClasses(py::module &m)
13941394
__call__ : same as getFields() but provides field labels in a tuple
13951395
)",
13961396
py::arg("x"), py::arg("y"), py::arg("z"))
1397-
.def("getAccel", py::overload_cast<RowMatrixXd&>(&BasisClasses::BiorthBasis::getAccel),
1397+
.def("getAccel", py::overload_cast<Eigen::Ref<const RowMatrixXd>>(&BasisClasses::BiorthBasis::getAccel),
13981398
R"(
13991399
Return the acceleration for an array of cartesian positions
14001400
@@ -1414,7 +1414,7 @@ void BasisFactoryClasses(py::module &m)
14141414
__call__ : same as getFields() but provides field labels in a tuple
14151415
)",
14161416
py::arg("pos"))
1417-
.def("getAccelArray", py::overload_cast<Eigen::VectorXd&, Eigen::VectorXd&, Eigen::VectorXd&>(&BasisClasses::BiorthBasis::getAccel),
1417+
.def("getAccelArray", py::overload_cast<Eigen::Ref<const Eigen::VectorXd>, Eigen::Ref<const Eigen::VectorXd>, Eigen::Ref<const Eigen::VectorXd>>(&BasisClasses::BiorthBasis::getAccel),
14181418
R"(
14191419
Return the acceleration for a given cartesian position
14201420
@@ -1561,7 +1561,29 @@ void BasisFactoryClasses(py::module &m)
15611561
Returns
15621562
-------
15631563
None
1564-
)", py::arg("coefs"));
1564+
)", py::arg("coefs"))
1565+
.def("get_shared_ptr_capsule", [](const std::shared_ptr<BasisClasses::BiorthBasis> &self) -> py::capsule {
1566+
return py::capsule(
1567+
new std::shared_ptr(self),
1568+
"BiorthBasis_shared_ptr",
1569+
[](void *v) { delete static_cast<std::shared_ptr<BasisClasses::BiorthBasis> *>(v); }
1570+
);
1571+
},
1572+
R"(
1573+
Get a capsule containing a shared pointer to the BiorthBasis instance.
1574+
1575+
Returns
1576+
-------
1577+
capsule: PyCapsule
1578+
A PyCapsule containing a shared pointer to the BiorthBasis instance with
1579+
the name "BiorthBasis_shared_ptr".
1580+
1581+
Notes
1582+
-----
1583+
This can be used to pass the BiorthBasis instance to non-Pybind11 C extensions
1584+
in a lifetime-safe manner.
1585+
)"
1586+
);
15651587

15661588
py::class_<BasisClasses::Cylindrical, std::shared_ptr<BasisClasses::Cylindrical>, PyCylindrical, BasisClasses::BiorthBasis>(m, "Cylindrical")
15671589
.def(py::init<const std::string&>(),

pyEXP/CoefWrappers.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,8 +1488,29 @@ void CoefficientClasses(py::module &m) {
14881488
--------
14891489
addcoef : add coefficient structures to an existing coefficieint container
14901490
)",
1491-
py::arg("coef"), py::arg("name")="");
1491+
py::arg("coef"), py::arg("name")="")
1492+
.def("get_shared_ptr_capsule", [](const std::shared_ptr<CoefClasses::Coefs> &self) -> py::capsule {
1493+
return py::capsule(
1494+
new std::shared_ptr(self),
1495+
"Coefs_shared_ptr",
1496+
[](void *v) { delete static_cast<std::shared_ptr<CoefClasses::Coefs> *>(v); }
1497+
);
1498+
},
1499+
R"(
1500+
Get a capsule containing a shared pointer to the Coefs instance.
1501+
1502+
Returns
1503+
-------
1504+
capsule: PyCapsule
1505+
A PyCapsule containing a shared pointer to the Coefs instance with
1506+
the name "Coefs_shared_ptr".
14921507
1508+
Notes
1509+
-----
1510+
This can be used to pass the Coefs instance to non-Pybind11 C extensions
1511+
in a lifetime-safe manner.
1512+
)"
1513+
);
14931514

14941515
py::class_<CoefClasses::SphCoefs, std::shared_ptr<CoefClasses::SphCoefs>, PySphCoefs, CoefClasses::Coefs>
14951516
(m, "SphCoefs", "Container for spherical coefficients")

0 commit comments

Comments
 (0)