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

DM-37627: Use pybind wrappers, create only one shared lib #62

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 48 additions & 51 deletions python/astshim/SConscript
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
## -*- python -*-
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.pybind11([
"base",
"detail/testUtils",
"object",
"stream",
"channel",
"mapping",
"frame",
"frameSet",
"frameDict",
"keyMap/keyMap",
"table",
"fitsTable",

"mapBox",
"mapSplit",
"quadApprox",
"functional",

"fitsChan",
"xmlChan",

"chebyMap",
"cmpMap",
"lutMap",
"mathMap",
"matrixMap",
"normMap",
"parallelMap",
"seriesMap",
"pcdMap",
"permMap",
"polyMap",
"rateMap",
"shiftMap",
"slaMap",
"sphMap",
"timeMap",
"tranMap",
"unitMap",
"unitNormMap",
"wcsMap",
"winMap",
"zoomMap",

"cmpFrame",
"skyFrame",
"specFrame",
"timeFrame",
], addUnderscore=False)
scripts.BasicSConscript.python(['_astshimLib'], [
"_astshimLib.cc",
"base.cc",
"channel.cc",
"chebyMap.cc",
"cmpFrame.cc",
"cmpMap.cc",
"fitsChan.cc",
"fitsTable.cc",
"frame.cc",
"frameDict.cc",
"frameSet.cc",
"functional.cc",
"lutMap.cc",
"mapBox.cc",
"mapping.cc",
"mapSplit.cc",
"mathMap.cc",
"matrixMap.cc",
"normMap.cc",
"object.cc",
"parallelMap.cc",
"pcdMap.cc",
"permMap.cc",
"polyMap.cc",
"quadApprox.cc",
"rateMap.cc",
"seriesMap.cc",
"shiftMap.cc",
"skyFrame.cc",
"slaMap.cc",
"specFrame.cc",
"sphMap.cc",
"stream.cc",
"table.cc",
"timeFrame.cc",
"timeMap.cc",
"tranMap.cc",
"unitMap.cc",
"unitNormMap.cc",
"wcsMap.cc",
"winMap.cc",
"xmlChan.cc",
"zoomMap.cc",
"keyMap/keyMap.cc"
]
)
47 changes: 2 additions & 45 deletions python/astshim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,8 @@

"""lsst.astshim
"""
from .base import *
from .object import *
from .stream import *
from .channel import *
from .mapping import *
from .frame import *
from .frameSet import *
from .frameDict import *

from .keyMap import *
# Table
from .table import *
from ._astshimLib import *
from .fitsTableContinued import *
# misc
from .mapBox import *
from .mapSplit import *
from .quadApprox import *
from .functional import *
# channels
from .fitsChanContinued import *
from .xmlChan import *
# mappings
from .chebyMap import *
from .cmpMap import *
from .lutMap import *
from .mathMap import *
from .matrixMap import *
from .normMap import *
from .parallelMap import *
from .seriesMap import *
from .pcdMap import *
from .permMap import *
from .polyMap import *
from .rateMap import *
from .shiftMap import *
from .slaMap import *
from .sphMap import *
from .timeMap import *
from .tranMap import *
from .unitMap import *
from .unitNormMap import *
from .wcsMap import *
from .winMap import *
from .zoomMap import *
# frames
from .cmpFrame import *
from .skyFrame import *
from .specFrame import *
from .timeFrame import *
126 changes: 126 additions & 0 deletions python/astshim/_astshimLib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* This file is part of astshim.
*
* Developed for the LSST Data Management System.
* This product includes software developed by the LSST Project
* (https://www.lsst.org).
* See the COPYRIGHT file at the top-level directory of this distribution
* for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "pybind11/pybind11.h"
#include "lsst/cpputils/python.h"

namespace py = pybind11;
using namespace pybind11::literals;
using lsst::cpputils::python::WrapperCollection;

namespace ast {
void wrapBase(WrapperCollection&);
void wrapChannel(WrapperCollection&);
void wrapChebyMap(WrapperCollection&);
void wrapCmpFrame(WrapperCollection&);
void wrapCmpMap(WrapperCollection&);
void wrapFitsChan(WrapperCollection&);
void wrapFitsTable(WrapperCollection&);
void wrapFrame(WrapperCollection&);
void wrapFrameDict(WrapperCollection&);
void wrapFrameSet(WrapperCollection&);
void wrapFunctional(WrapperCollection&);
void wrapKeyMap(WrapperCollection&);
void wrapLutMap(WrapperCollection&);
void wrapMapBox(WrapperCollection&);
void wrapMapping(WrapperCollection&);
void wrapMapSplit(WrapperCollection&);
void wrapMathMap(WrapperCollection&);
void wrapMatrixMap(WrapperCollection&);
void wrapNormMap(WrapperCollection&);
void wrapObject(WrapperCollection&);
void wrapParallelMap(WrapperCollection&);
void wrapPcdMap(WrapperCollection&);
void wrapPermMap(WrapperCollection&);
void wrapPolyMap(WrapperCollection&);
void wrapQuadApprox(WrapperCollection&);
void wrapRateMap(WrapperCollection&);
void wrapSeriesMap(WrapperCollection&);
void wrapShiftMap(WrapperCollection&);
void wrapSkyFrame(WrapperCollection&);
void wrapSlaMap(WrapperCollection&);
void wrapSpecFrame(WrapperCollection&);
void wrapSphMap(WrapperCollection&);
void wrapStream(WrapperCollection&);
void wrapTable(WrapperCollection&);
void wrapTimeFrame(WrapperCollection&);
void wrapTimeMap(WrapperCollection&);
void wrapTranMap(WrapperCollection&);
void wrapUnitMap(WrapperCollection&);
void wrapUnitNormMap(WrapperCollection&);
void wrapWcsMap(WrapperCollection&);
void wrapWinMap(WrapperCollection&);
void wrapXmlChan(WrapperCollection&);
void wrapZoomMap(WrapperCollection&);

PYBIND11_MODULE(_astshimLib, mod) {
using lsst::cpputils::python::WrapperCollection;
lsst::utils::python::WrapperCollection wrappers(mod, "astshim");
wrapBase(wrappers);
wrapObject(wrappers);
wrapKeyMap(wrappers);
wrapMapping(wrappers);
wrapTable(wrappers);
wrapChannel(wrappers);
wrapCmpMap(wrappers);
wrapFrame(wrappers);
wrapFrameSet(wrappers);
wrapMapBox(wrappers);
wrapMapSplit(wrappers);

wrapChebyMap(wrappers);
wrapCmpFrame(wrappers);
wrapFitsChan(wrappers);
wrapFitsTable(wrappers);
wrapFrameDict(wrappers);
wrapFunctional(wrappers);
wrapLutMap(wrappers);
wrapMathMap(wrappers);
wrapMatrixMap(wrappers);
wrapNormMap(wrappers);
wrapParallelMap(wrappers);
wrapPcdMap(wrappers);
wrapPermMap(wrappers);
wrapPolyMap(wrappers);
wrapQuadApprox(wrappers);
wrapRateMap(wrappers);
wrapSeriesMap(wrappers);
wrapShiftMap(wrappers);
wrapSkyFrame(wrappers);
wrapSlaMap(wrappers);
wrapSpecFrame(wrappers);
wrapSphMap(wrappers);
wrapStream(wrappers);
wrapTimeFrame(wrappers);
wrapTimeMap(wrappers);
wrapTranMap(wrappers);
wrapUnitMap(wrappers);
wrapUnitNormMap(wrappers);
wrapWcsMap(wrappers);
wrapWinMap(wrappers);
wrapXmlChan(wrappers);
wrapZoomMap(wrappers);
wrappers.finish();
}

} // namespace astshim
38 changes: 19 additions & 19 deletions python/astshim/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "lsst/cpputils/python.h"

#include "ndarray/pybind11.h"
#include "astshim/base.h"
Expand All @@ -29,34 +30,33 @@ namespace py = pybind11;
using namespace pybind11::literals;

namespace ast {
namespace {

PYBIND11_MODULE(base, mod) {
mod.def("assertOK", &assertOK, "rawObj1"_a = nullptr, "rawObj2"_a = nullptr);
mod.def("escapes", &escapes, "include"_a = -1);
mod.def("astVersion", &ast_version);
void wrapBase(lsst::cpputils::python::WrapperCollection &wrappers) {
wrappers.module.def("assertOK", &assertOK, "rawObj1"_a = nullptr, "rawObj2"_a = nullptr);
wrappers.module.def("escapes", &escapes, "include"_a = -1);
wrappers.module.def("astVersion", &ast_version);

// Make a deep copy to avoid memory issues in Python
mod.def("arrayFromVector", [](std::vector<double> const& data, int nAxes) {
wrappers.module.def("arrayFromVector", [](std::vector<double> const& data, int nAxes) {
auto const arrayShallow = arrayFromVector(data, nAxes);
Array2D arrayDeep = allocate(arrayShallow.getShape());
arrayDeep.deep() = arrayShallow;
return arrayDeep;
}, "vec"_a, "nAxes"_a);

py::enum_<DataType>(mod, "DataType")
.value("IntType", DataType::IntType)
.value("ShortIntType", DataType::ShortIntType)
.value("ByteType", DataType::ByteType)
.value("DoubleType", DataType::DoubleType)
.value("FloatType", DataType::FloatType)
.value("StringType", DataType::StringType)
.value("ObjectType", DataType::ObjectType)
.value("PointerType", DataType::PointerType)
.value("UndefinedType", DataType::UndefinedType)
.value("BadType", DataType::BadType)
.export_values();
wrappers.wrapType(py::enum_<DataType>(wrappers.module, "DataType"), [](auto &mod, auto &enm) {
enm.value("IntType", DataType::IntType);
enm.value("ShortIntType", DataType::ShortIntType);
enm.value("ByteType", DataType::ByteType);
enm.value("DoubleType", DataType::DoubleType);
enm.value("FloatType", DataType::FloatType);
enm.value("StringType", DataType::StringType);
enm.value("ObjectType", DataType::ObjectType);
enm.value("PointerType", DataType::PointerType);
enm.value("UndefinedType", DataType::UndefinedType);
enm.value("BadType", DataType::BadType);
enm.export_values();
});
}

} // namespace
} // namespace ast
34 changes: 16 additions & 18 deletions python/astshim/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <memory>

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "lsst/cpputils/python.h"

#include "astshim/Channel.h"
#include "astshim/KeyMap.h"
Expand All @@ -32,27 +32,25 @@ namespace py = pybind11;
using namespace pybind11::literals;

namespace ast {
namespace {

PYBIND11_MODULE(channel, mod) {
py::module::import("astshim.object");
void wrapChannel(lsst::utils::python::WrapperCollection &wrappers) {
using PyChannel = py::class_<Channel, std::shared_ptr<Channel>, Object>;
wrappers.wrapType(PyChannel(wrappers.module, "Channel"), [](auto &mod, auto &cls) {

py::class_<Channel, std::shared_ptr<Channel>, Object> cls(mod, "Channel");
cls.def(py::init<Stream &, std::string const &>(), "stream"_a, "options"_a = "");

cls.def(py::init<Stream &, std::string const &>(), "stream"_a, "options"_a = "");
cls.def_property("comment", &Channel::getComment, &Channel::setComment);
cls.def_property("full", &Channel::getFull, &Channel::setFull);
cls.def_property("indent", &Channel::getIndent, &Channel::setIndent);
cls.def_property("reportLevel", &Channel::getReportLevel, &Channel::setReportLevel);
cls.def_property("skip", &Channel::getSkip, &Channel::setSkip);
cls.def_property("strict", &Channel::getStrict, &Channel::setStrict);

cls.def_property("comment", &Channel::getComment, &Channel::setComment);
cls.def_property("full", &Channel::getFull, &Channel::setFull);
cls.def_property("indent", &Channel::getIndent, &Channel::setIndent);
cls.def_property("reportLevel", &Channel::getReportLevel, &Channel::setReportLevel);
cls.def_property("skip", &Channel::getSkip, &Channel::setSkip);
cls.def_property("strict", &Channel::getStrict, &Channel::setStrict);

cls.def("copy", &Channel::copy);
cls.def("read", &Channel::read);
cls.def("write", &Channel::write, "object"_a);
cls.def("warnings", &Channel::warnings);
cls.def("copy", &Channel::copy);
cls.def("read", &Channel::read);
cls.def("write", &Channel::write, "object"_a);
cls.def("warnings", &Channel::warnings);
});
}

} // namespace
} // namespace ast