Skip to content

Commit

Permalink
Overload CoefStruct::setCoefs() to have two call signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin D. Weinberg committed Feb 27, 2025
1 parent fe0f93e commit 888632a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
8 changes: 8 additions & 0 deletions expui/CoefStruct.H
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ namespace CoefClasses
//! Read-write access to coefficient data (no copy)
Eigen::Ref<Eigen::VectorXcd> setCoefs() { return store; }

//! Set new coefficient data (no copy)
void setCoefs(Eigen::VectorXcd& STORE)
{
if (STORE.size() != store.size())
throw std::invalid_argument("CoefStruct::setCoefs: coefficient vector size does not match");
store = STORE;
}

//! Read-only access to coefficient data (no copy)
Eigen::Ref<const Eigen::VectorXcd> getCoefs() { return store; }

Expand Down
38 changes: 33 additions & 5 deletions pyEXP/CoefWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,25 +724,53 @@ void CoefficientClasses(py::module &m) {
Returns
-------
numpy.ndarray
complex-valued matrix as a NumPy array of complex values
complex-valued matrix as a flattened NumPy array of complex values
See also
--------
setCoefs : read-write access to Coefs
)")
.def("setCoefs", &CoefStruct::setCoefs,
.def("setCoefs", // Member function overload
static_cast<void (CoefStruct::*)(Eigen::VectorXcd&)>(&CoefStruct::setCoefs),
py::arg("mat"),
R"(
Set the coefficient matrix with the coefficient vector in the same form as returned
by getCoefs
Parameters
----------
mat : numpy.ndarray
Flattened array of coefficients
Returns
-------
None
Notes
-----
The rank data array must match the rank of the CoefStruct. Use getCoefs to create
such an array with the correct rank.
See also
--------
getCoefs : read-only access to Coefs
)")
.def("setCoefs", // Member function overload
static_cast<Eigen::Ref<Eigen::VectorXcd>(CoefStruct::*)()>(&CoefStruct::setCoefs),
R"(
Read-write access to the underlying data store
Returns
-------
numpy.ndarray
complex-valued matrix represented as a NumPy array of complex values
reference to a complex-valued matrix represented as a NumPy array of complex
values
Notes
-----
Changes made to the data array will be automatically mapped
back to the C++ CoefStruct instance.
Changes made to the data array will be automatically mapped back to the C++
CoefStruct instance. You may use the setCoefs(array) call to set the data array
directly.
See also
--------
Expand Down

0 comments on commit 888632a

Please sign in to comment.