Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose assign methods #58

Merged
merged 10 commits into from
Dec 17, 2023
1 change: 1 addition & 0 deletions coefs/CoefStruct.H
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ namespace CoefClasses
//! Assign array
void assign(const Eigen::VectorXcd& arr)
{
cols = arr.size();
store = arr;
coefs = std::make_shared<coefType>(store.data(), store.size());
}
Expand Down
3 changes: 2 additions & 1 deletion coefs/Coefficients.H
michael-petersen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _COEFFICIENTS_H

#include <tuple>
#include <stdexcept>

// Needed by member functions for writing parameters and stanzas
#include <highfive/H5File.hpp>
Expand Down Expand Up @@ -604,7 +605,7 @@ namespace CoefClasses
if (d=='x') return NmaxX;
if (d=='y') return NmaxY;
if (d=='z') return NmaxZ;
std::runtime_error("CubeCoefs: error in nmax accessor");
throw std::runtime_error("CubeCoefs: error in nmax accessor");
}
};

Expand Down
2 changes: 1 addition & 1 deletion coefs/Coefficients.cc
michael-petersen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ namespace CoefClasses
for (int t=0; t<ntim; t++) {
auto cof = coefs[times[t]];
for (int c=0; c<cols; c++) {
ret(c, t) = (*cof->coefs)(0, c).real();
ret(c, t) = (*cof->coefs)(c).real();
}
}

Expand Down
217 changes: 160 additions & 57 deletions pyEXP/CoefWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ void CoefficientClasses(py::module &m) {
"----------\n"
"The CoefStruct class is low-level structure that stores the data\n"
"and metadata specific to each geometry. These are spherical\n"
"(SphStruct), cylindrical (CylStruct), and table data (TblStruct).\n"
"EXP also knows about rectangular grids and slabs. These may be\n"
"(SphStruct), cylindrical (CylStruct), cube (CubeStruct) and table\n"
"data (TblStruct). EXP also knows about slabs. These may be\n"
"added in a future release if there is a need. Instances of these\n"
"structures represent individual times points and are created,\n"
"maintained, and interfaced by the Coefs class. Access to the\n"
"underlying data is provided to Python in case you need to change\n"
"or rewrite the data for some reason. We have also provided a\n"
"create() member so that you can instaniate and load a coefficient\n"
"assign() member so that you can instaniate and load a coefficient\n"
"structure using Python. To do this, use the constructor to make\n"
"a blank instance, assign the dimensions and use create() to create\n"
"a data matrix of initially zero values. The dimensions are \n"
"(lmax, nmax) for SphStruct, (mmax,nmax) for a CylStruct, and\n"
"(cols) for a TblStruct.\n\n"
"a blank instance, assign the dimensions and use assign() to create\n"
"a data matrix with the supplied matrix or array. The dimensions are\n"
"(lmax, nmax) for SphStruct, (mmax, nmax) for a CylStruct, (nmaxx,\n"
"nmaxy, nmaxz) for a CubeStruct and (cols) for a TblStruct.\n\n"
"Coefs\n"
"-----\n"
"The base class, 'Coefs', provides a factory reader that will\n"
"create one of the derived coefficient classes, SphCoef, CylCoef,\n"
"or TblCoef, deducing the type from the input file. The input\n"
"files may be EXP native or HDF5 cofficient files. The Basis\n"
"create one of the derived coefficient classes, SphCoefs, CylCoefs,\n"
"CubeCoefs, or TblCoefs, deducing the type from the input file. The\n"
"input files may be EXP native or HDF5 cofficient files. The Basis\n"
"factory, Basis::createCoefficients, will create set of coef-\n"
"ficients from phase-space snapshots. See help(pyEXP.basis).\n"
"Files which are not recognized as EXP coefficient files are\n"
Expand Down Expand Up @@ -134,14 +134,6 @@ void CoefficientClasses(py::module &m) {
PYBIND11_OVERRIDE_PURE(void, Coefs, setData, time, array);
}

// This has left the interface
/*
using ValueError = std::tuple<Eigen::VectorXcd&, bool>;
ValueError interpolate(double time) override {
PYBIND11_OVERRIDE(ValueError, Coefs, interpolate, time);
}
*/

std::shared_ptr<CoefStruct> getCoefStruct(double time) override {
PYBIND11_OVERRIDE_PURE(std::shared_ptr<CoefStruct>, Coefs, getCoefStruct, time);
}
Expand Down Expand Up @@ -223,14 +215,6 @@ void CoefficientClasses(py::module &m) {
time);
}

// No longer in the abstract interface
/*
void dump(int mmin, int mmax, int nmin, int nmax) override {
PYBIND11_OVERRIDE(void, SphCoefs,dump,
mmin, mmax, nmin, nmax);
}
*/

std::vector<double> Times() override {
PYBIND11_OVERRIDE(std::vector<double>, SphCoefs, Times,);
}
Expand Down Expand Up @@ -310,14 +294,6 @@ void CoefficientClasses(py::module &m) {
time);
}

// Left the interface
/*
void dump(int mmin, int mmax, int nmin, int nmax) override {
PYBIND11_OVERRIDE(void, CylCoefs, dump,
mmin, mmax, nmin, nmax);
}
*/

std::vector<double> Times() override {
PYBIND11_OVERRIDE(std::vector<double>, CylCoefs, Times,);
}
Expand Down Expand Up @@ -396,14 +372,6 @@ void CoefficientClasses(py::module &m) {
time);
}

// Left the interface
/*
void dump(int mmin, int mmax, int nmin, int nmax) override {
PYBIND11_OVERRIDE(void, CubeCoefs,dump,
mmin, mmax, nmin, nmax);
}
*/

std::vector<double> Times() override {
PYBIND11_OVERRIDE(std::vector<double>, CubeCoefs, Times,);
}
Expand Down Expand Up @@ -483,14 +451,6 @@ void CoefficientClasses(py::module &m) {
time);
}

// No longer in the interface
/*
void dump(int mmin, int mmax, int nmin, int nmax) override {
PYBIND11_OVERRIDE(void, TableData, dump,
mmin, mmax, nmin, nmax);
}
*/

std::vector<double> Times() override {
PYBIND11_OVERRIDE(std::vector<double>, TableData, Times,);
}
Expand Down Expand Up @@ -608,13 +568,80 @@ void CoefficientClasses(py::module &m) {


py::class_<CoefClasses::SphStruct, std::shared_ptr<CoefClasses::SphStruct>, CoefStruct>(m, "SphStruct")
.def(py::init<>(), "Spherical coefficient data structure object");
.def(py::init<>(), "Spherical coefficient data structure object")
.def("assign", &SphStruct::assign,
R"(
Assign a coefficient matrix to CoefStruct.

Parameters
----------
mat : numpy.ndarray
Matrix of coefficients
lmax : int
angular order
nmax : int
radial order

Returns
-------
None
)");

py::class_<CoefClasses::CylStruct, std::shared_ptr<CoefClasses::CylStruct>, CoefStruct>(m, "CylStruct")
.def(py::init<>(), "Cylindrical coefficient data structure object");
.def(py::init<>(), "Cylindrical coefficient data structure object")
.def("assign", &CylStruct::assign,
R"(
Assign a coefficient matrix to CoefStruct.

Parameters
----------
mat : numpy.ndarray
Matrix of coefficients
mmax : int
angular order
nmax : int
radial order

Returns
-------
None
)");

py::class_<CoefClasses::CubeStruct, std::shared_ptr<CoefClasses::CubeStruct>, CoefStruct>(m, "CubeStruct")
.def(py::init<>(), "Cube coefficient data structure object")
.def("assign", &CubeStruct::assign,
R"(
Assign a coefficient matrix to CoefStruct.

Parameters
----------
mat : numpy.ndarray, complex
complex-valued NumPy tensor of coefficient values

Returns
-------
None

Notes
-----
The dimensions are inferred from the 3-dimensional NumPy array (tensor)
)");

py::class_<CoefClasses::TblStruct, std::shared_ptr<CoefClasses::TblStruct>, CoefStruct>(m, "TblStruct")
.def(py::init<>(), "Multicolumn table data structure object");
.def(py::init<>(), "Multicolumn table data structure object")
.def("assign", &TblStruct::assign,
R"(
Assign a coefficient matrix to CoefStruct.

Parameters
----------
mat : numpy.ndarray, complex
complex-valued NumPy array of table values

Returns
-------
None
)");

py::class_<CoefClasses::Coefs, std::shared_ptr<CoefClasses::Coefs>, PyCoefs>(m, "Coefs")
.def(py::init<std::string, bool>(),
Expand Down Expand Up @@ -919,7 +946,19 @@ void CoefficientClasses(py::module &m) {
py::arg("coef"), py::arg("name")="");

py::class_<CoefClasses::SphCoefs, std::shared_ptr<CoefClasses::SphCoefs>, PySphCoefs, CoefClasses::Coefs>(m, "SphCoefs", "Container for spherical coefficients")
.def(py::init<bool>())
.def(py::init<bool>(),
R"(
Construct a null SphCoefs object

Parameters
----------
verbose : bool
display verbose information.

Returns
-------
SphCoefs instance
)")
.def("__call__",
&CoefClasses::SphCoefs::getMatrix,
R"(
Expand Down Expand Up @@ -980,7 +1019,19 @@ void CoefficientClasses(py::module &m) {
)");

py::class_<CoefClasses::CylCoefs, std::shared_ptr<CoefClasses::CylCoefs>, PyCylCoefs, CoefClasses::Coefs>(m, "CylCoefs", "Container for cylindrical coefficients")
.def(py::init<bool>())
.def(py::init<bool>(),
R"(
Construct a null CylCoefs object

Parameters
----------
verbose : bool
display verbose information.

Returns
-------
CylCoefs instance
)")
.def("__call__",
&CoefClasses::CylCoefs::getMatrix,
R"(
Expand Down Expand Up @@ -1067,7 +1118,19 @@ void CoefficientClasses(py::module &m) {


py::class_<CoefClasses::CubeCoefs, std::shared_ptr<CoefClasses::CubeCoefs>, PyCubeCoefs, CoefClasses::Coefs>(m, "CubeCoefs", "Container for cube coefficients")
.def(py::init<bool>())
.def(py::init<bool>(),
R"(
Construct a null CubeCoefs object

Parameters
----------
verbose : bool
display verbose information.

Returns
-------
CubeCoefs instance
)")
.def("__call__",
&CoefClasses::CubeCoefs::getTensor,
R"(
Expand Down Expand Up @@ -1124,7 +1187,47 @@ void CoefficientClasses(py::module &m) {


py::class_<CoefClasses::TableData, std::shared_ptr<CoefClasses::TableData>, PyTableData, CoefClasses::Coefs>(m, "TableData", "Container for simple data tables with multiple columns")
.def(py::init<bool>())
.def(py::init<bool>(),
R"(
Construct a null TableData object

Parameters
----------
verbose : bool
display verbose information.

Returns
-------
TableData instance
)")
.def(py::init<std::string&>(),
R"(
Construct a TableData object from a data file

Parameters
----------
type : str
ascii table data file

Returns
-------
TableData instance
)")
.def(py::init<std::string&, bool>(),
R"(
Construct a TableData object from a data file

Parameters
----------
type : str
ascii table data file
verbose : bool
display verbose information.

Returns
-------
TableData instance
)")
.def("getAllCoefs", &CoefClasses::TableData::getAllCoefs,
R"(
Return a 2-dimensional ndarray indexed by column and time
Expand Down
Loading