26 #include "ndarray/eigen.h"
47 if (factors.size() < 1u) {
49 pex::exceptions::LengthError,
50 "ProductBoundedField requires at least one BoundedField factor."
53 auto iter = factors.begin();
54 auto bbox = (**iter).getBBox();
56 for (;
iter != factors.end(); ++
iter) {
57 if ((**iter).getBBox() !=
bbox) {
59 pex::exceptions::InvalidParameterError,
60 (
boost::format(
"Inconsistency in ProductBoundedField bboxes: %s != %s") %
61 bbox % (**iter).getBBox()).str()
71 BoundedField(checkAndExtractBBox(factors)), _factors(factors)
80 for (
auto const &
field : _factors) {
81 product *=
field->evaluate(position);
87 ndarray::Array<double const, 1>
const&
x,
88 ndarray::Array<double const, 1>
const&
y
90 if (
x.getShape() !=
y.getShape()) {
93 (
boost::format(
"Inconsistent shapes: %s != %s") %
x.getShape() %
y.getShape()).str()
96 ndarray::Array<double, 1, 1>
z = ndarray::allocate(
x.getShape());
98 for (
auto const &
field : _factors) {
99 ndarray::asEigenArray(
z) *= ndarray::asEigenArray(
field->evaluate(
x,
y));
108 struct PersistenceHelper {
112 static PersistenceHelper
const & get() {
113 static PersistenceHelper
const instance;
119 PersistenceHelper() :
121 id(
schema.addField<int>(
"id",
"Archive ID of a BoundedField factor."))
124 PersistenceHelper(PersistenceHelper
const &) =
delete;
125 PersistenceHelper(PersistenceHelper &&) =
delete;
126 PersistenceHelper &
operator=(PersistenceHelper
const &) =
delete;
127 PersistenceHelper &
operator=(PersistenceHelper &&) =
delete;
129 ~PersistenceHelper() noexcept = default;
133 class ProductBoundedFieldFactory : public table::io::PersistableFactory {
136 :
afw::table::io::PersistableFactory(
name) {}
139 CatalogVector
const& catalogs)
const override {
141 auto const &
keys = PersistenceHelper::get();
142 auto const & cat = catalogs.front();
145 for (
auto const & record : cat) {
146 factors.
push_back(archive.get<BoundedField>(record.get(
keys.id)));
148 return std::make_shared<ProductBoundedField>(factors);
152 std::string getProductBoundedFieldPersistenceName() {
return "ProductBoundedField"; }
154 ProductBoundedFieldFactory registration(getProductBoundedFieldPersistenceName());
159 return std::all_of(_factors.begin(), _factors.end(),
160 [](
auto const &
field) { return field->isPersistable(); });
164 return getProductBoundedFieldPersistenceName();
170 auto const &
keys = PersistenceHelper::get();
172 catalog.
reserve(_factors.size());
173 for (
auto const &
field : _factors) {
183 bool multiplied =
false;
184 for (
auto &
field : factors) {
192 ndarray::Array<double, 2, 2>
coefficients = ndarray::allocate(1, 1);
196 return std::make_shared<ProductBoundedField>(factors);
201 if (!rhsCasted)
return false;
203 return (
getBBox() == rhsCasted->getBBox()) &&
205 rhsCasted->_factors.begin(), rhsCasted->_factors.end(),
206 [](
auto const &
a,
auto const &
b) {
return *
a == *
b; });
209 std::string ProductBoundedField::toString()
const {
211 os <<
"ProductBoundedField([";
212 for (
auto const &
field : _factors) {
213 os << (*field) <<
", ";
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
An abstract base class for 2-d functions defined on an integer bounding boxes.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
A BoundedField that lazily multiplies a sequence of other BoundedFields.
bool operator==(BoundedField const &rhs) const override
BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal.
bool isPersistable() const noexcept override
ProductBoundedField is persistable if and only if all of its factors are.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
ProductBoundedField(std::vector< std::shared_ptr< BoundedField const >> const &factors)
Construct from a sequence of BoundedField factors.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< BoundedField > operator*(double const scale) const override
Return a scaled BoundedField.
~ProductBoundedField() override
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
virtual double evaluate(lsst::geom::Point2D const &position) const=0
Evaluate the field at the given point.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
An integer coordinate rectangle.
Reports invalid arguments.
Reports errors in the logical structure of the program.
def scale(algorithm, min, max=None, frame=None)
FilterProperty & operator=(FilterProperty const &)=default
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.
ndarray::Array< double const, 2, 2 > coefficients