diff --git a/coefs/CoefStruct.H b/coefs/CoefStruct.H index 8cf3a54e2..3ac3bec89 100644 --- a/coefs/CoefStruct.H +++ b/coefs/CoefStruct.H @@ -295,6 +295,7 @@ namespace CoefClasses //! Assign array void assign(const Eigen::VectorXcd& arr) { + cols = arr.size(); store = arr; coefs = std::make_shared(store.data(), store.size()); } diff --git a/coefs/Coefficients.H b/coefs/Coefficients.H index a2345075d..8f369f069 100644 --- a/coefs/Coefficients.H +++ b/coefs/Coefficients.H @@ -2,6 +2,7 @@ #define _COEFFICIENTS_H #include +#include // Needed by member functions for writing parameters and stanzas #include @@ -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"); } }; diff --git a/coefs/Coefficients.cc b/coefs/Coefficients.cc index 4a15e2510..3be56da2b 100644 --- a/coefs/Coefficients.cc +++ b/coefs/Coefficients.cc @@ -1495,7 +1495,7 @@ namespace CoefClasses for (int t=0; tcoefs)(0, c).real(); + ret(c, t) = (*cof->coefs)(c).real(); } } diff --git a/pyEXP/CoefWrappers.cc b/pyEXP/CoefWrappers.cc index 835a4c2de..efe8f9232 100644 --- a/pyEXP/CoefWrappers.cc +++ b/pyEXP/CoefWrappers.cc @@ -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" @@ -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; - ValueError interpolate(double time) override { - PYBIND11_OVERRIDE(ValueError, Coefs, interpolate, time); - } - */ - std::shared_ptr getCoefStruct(double time) override { PYBIND11_OVERRIDE_PURE(std::shared_ptr, Coefs, getCoefStruct, time); } @@ -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 Times() override { PYBIND11_OVERRIDE(std::vector, SphCoefs, Times,); } @@ -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 Times() override { PYBIND11_OVERRIDE(std::vector, CylCoefs, Times,); } @@ -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 Times() override { PYBIND11_OVERRIDE(std::vector, CubeCoefs, Times,); } @@ -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 Times() override { PYBIND11_OVERRIDE(std::vector, TableData, Times,); } @@ -608,13 +568,80 @@ void CoefficientClasses(py::module &m) { py::class_, 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_, 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_, 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_, 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_, PyCoefs>(m, "Coefs") .def(py::init(), @@ -919,7 +946,19 @@ void CoefficientClasses(py::module &m) { py::arg("coef"), py::arg("name")=""); py::class_, PySphCoefs, CoefClasses::Coefs>(m, "SphCoefs", "Container for spherical coefficients") - .def(py::init()) + .def(py::init(), + R"( + Construct a null SphCoefs object + + Parameters + ---------- + verbose : bool + display verbose information. + + Returns + ------- + SphCoefs instance + )") .def("__call__", &CoefClasses::SphCoefs::getMatrix, R"( @@ -980,7 +1019,19 @@ void CoefficientClasses(py::module &m) { )"); py::class_, PyCylCoefs, CoefClasses::Coefs>(m, "CylCoefs", "Container for cylindrical coefficients") - .def(py::init()) + .def(py::init(), + R"( + Construct a null CylCoefs object + + Parameters + ---------- + verbose : bool + display verbose information. + + Returns + ------- + CylCoefs instance + )") .def("__call__", &CoefClasses::CylCoefs::getMatrix, R"( @@ -1067,7 +1118,19 @@ void CoefficientClasses(py::module &m) { py::class_, PyCubeCoefs, CoefClasses::Coefs>(m, "CubeCoefs", "Container for cube coefficients") - .def(py::init()) + .def(py::init(), + R"( + Construct a null CubeCoefs object + + Parameters + ---------- + verbose : bool + display verbose information. + + Returns + ------- + CubeCoefs instance + )") .def("__call__", &CoefClasses::CubeCoefs::getTensor, R"( @@ -1124,7 +1187,47 @@ void CoefficientClasses(py::module &m) { py::class_, PyTableData, CoefClasses::Coefs>(m, "TableData", "Container for simple data tables with multiple columns") - .def(py::init()) + .def(py::init(), + R"( + Construct a null TableData object + + Parameters + ---------- + verbose : bool + display verbose information. + + Returns + ------- + TableData instance + )") + .def(py::init(), + R"( + Construct a TableData object from a data file + + Parameters + ---------- + type : str + ascii table data file + + Returns + ------- + TableData instance + )") + .def(py::init(), + 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