Skip to content

Commit 03caf5e

Browse files
Merge pull request #112 from EXP-code/setCoefs
Minor update the pyEXP CoefStruct interface
2 parents fe0f93e + b97b3b4 commit 03caf5e

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

expui/BiorthBasis.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace BasisClasses
2424
"pcavar",
2525
"pcadiag",
2626
"pcavtk",
27+
"pcaeof",
2728
"subsamp",
2829
"snr",
2930
"samplesz",

expui/CoefStruct.H

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ namespace CoefClasses
5151
//! Read-write access to coefficient data (no copy)
5252
Eigen::Ref<Eigen::VectorXcd> setCoefs() { return store; }
5353

54+
//! Set new coefficient data (no copy)
55+
void setCoefs(Eigen::VectorXcd& STORE)
56+
{
57+
if (STORE.size() != store.size())
58+
throw std::invalid_argument("CoefStruct::setCoefs: coefficient vector size does not match");
59+
store = STORE;
60+
}
61+
5462
//! Read-only access to coefficient data (no copy)
5563
Eigen::Ref<const Eigen::VectorXcd> getCoefs() { return store; }
5664

pyEXP/CoefWrappers.cc

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,53 @@ void CoefficientClasses(py::module &m) {
724724
Returns
725725
-------
726726
numpy.ndarray
727-
complex-valued matrix as a NumPy array of complex values
727+
complex-valued matrix as a flattened NumPy array of complex values
728728
729729
See also
730730
--------
731731
setCoefs : read-write access to Coefs
732732
)")
733-
.def("setCoefs", &CoefStruct::setCoefs,
733+
.def("setCoefs", // Member function overload
734+
static_cast<void (CoefStruct::*)(Eigen::VectorXcd&)>(&CoefStruct::setCoefs),
735+
py::arg("mat"),
736+
R"(
737+
Set the coefficient matrix with the coefficient vector in the same form as returned
738+
by getCoefs
739+
740+
Parameters
741+
----------
742+
mat : numpy.ndarray
743+
Flattened array of coefficients
744+
745+
Returns
746+
-------
747+
None
748+
749+
Notes
750+
-----
751+
The rank data array must match the rank of the CoefStruct. Use getCoefs to create
752+
such an array with the correct rank.
753+
754+
See also
755+
--------
756+
getCoefs : read-only access to Coefs
757+
)")
758+
.def("setCoefs", // Member function overload
759+
static_cast<Eigen::Ref<Eigen::VectorXcd>(CoefStruct::*)()>(&CoefStruct::setCoefs),
734760
R"(
735761
Read-write access to the underlying data store
736762
737763
Returns
738764
-------
739765
numpy.ndarray
740-
complex-valued matrix represented as a NumPy array of complex values
766+
reference to a complex-valued matrix represented as a NumPy array of complex
767+
values
741768
742769
Notes
743770
-----
744-
Changes made to the data array will be automatically mapped
745-
back to the C++ CoefStruct instance.
771+
Changes made to the data array will be automatically mapped back to the C++
772+
CoefStruct instance. You may use the setCoefs(array) call to set the data array
773+
directly.
746774
747775
See also
748776
--------

0 commit comments

Comments
 (0)