22 #ifndef ASTSHIM_POLYMAP_H
23 #define ASTSHIM_POLYMAP_H
31 #include "astshim/base.h"
32 #include "astshim/Mapping.h"
97 ndarray::Array<double, 2, 2>
const & coeff_f,
98 ndarray::Array<double, 2, 2>
const & coeff_i,
99 std::string
const & options=
"IterInverse=0"
101 Mapping(reinterpret_cast<AstMapping *>(_makeRawPolyMap(coeff_f, coeff_i, options)))
126 ndarray::Array<double, 2, 2>
const & coeff_f,
128 std::string
const & options=
"IterInverse=0"
130 Mapping(reinterpret_cast<AstMapping *>(_makeRawPolyMap(coeff_f, nout, options)))
141 std::shared_ptr<PolyMap>
copy()
const {
233 std::vector<double>
const & lbnd,
234 std::vector<double>
const & ubnd
236 auto const desSize =
static_cast<unsigned int>(forward ?
getNin() :
getNout());
237 if (lbnd.size() != desSize) {
238 std::ostringstream os;
239 os <<
"lbnd.size() = " << lbnd.size() <<
" != " << desSize
240 <<
" = " << (forward ?
"getNin()" :
"getNout()");
241 throw std::invalid_argument(os.str());
243 if (ubnd.size() != desSize) {
244 std::ostringstream os;
245 os <<
"ubnd.size() = " << ubnd.size() <<
" != " << desSize
246 <<
" = " << (forward ?
"getNin()" :
"getNout()");
247 throw std::invalid_argument(os.str());
250 void *map = astPolyTran(this->
getRawPtr(), static_cast<int>(forward), acc, maxacc, maxorder,
251 lbnd.data(), ubnd.data());
254 assertOK(reinterpret_cast<AstObject *>(map));
256 throw std::runtime_error(
"Could not compute an inverse mapping");
258 return PolyMap(reinterpret_cast<AstPolyMap *>(map));
263 return _copyImpl<PolyMap, AstPolyMap>();
268 Mapping(reinterpret_cast<AstMapping *>(map))
271 std::ostringstream os;
272 os <<
"this is a " <<
getClass() <<
", which is not a PolyMap";
273 throw std::invalid_argument(os.str());
279 AstPolyMap * _makeRawPolyMap(
280 ndarray::Array<double, 2, 2>
const & coeff_f,
281 ndarray::Array<double, 2, 2>
const & coeff_i,
282 std::string
const & options=
""
284 const int nin = coeff_f.getSize<1>() - 2;
285 const int ncoeff_f = coeff_f.getSize<0>();
286 const int nout = coeff_i.getSize<1>() - 2;
287 const int ncoeff_i = coeff_i.getSize<0>();
290 std::ostringstream os;
291 os <<
"coeff_f row length = " << nin + 2
292 <<
", which is too short; length = nin + 2 and nin must be > 0";
293 throw std::invalid_argument(os.str());
296 std::ostringstream os;
297 os <<
"coeff_i row length " << nout + 2
298 <<
", which is too short; length = nout + 2 and nout must be > 0";
299 throw std::invalid_argument(os.str());
302 return astPolyMap(nin, nout, ncoeff_f, coeff_f.getData(),
303 ncoeff_i, coeff_i.getData(), options.c_str());
307 AstPolyMap * _makeRawPolyMap(
308 ndarray::Array<double, 2, 2>
const & coeff_f,
310 std::string
const & options=
""
312 const int nin = coeff_f.getSize<1>() - 2;
313 const int ncoeff_f = coeff_f.getSize<0>();
315 std::ostringstream os;
316 os <<
"coeff_f row length = " << nin + 2
317 <<
", which is too short; length = nin + 2 and nin must be > 0";
318 throw std::invalid_argument(os.str());
321 std::ostringstream os;
322 os <<
"nout = " << nout <<
" <0 =";
323 throw std::invalid_argument(os.str());
326 return astPolyMap(nin, nout, ncoeff_f, coeff_f.getData(), 0,
nullptr, options.c_str());
std::shared_ptr< PolyMap > copy() const
Return a deep copy of this object.
Definition: PolyMap.h:141
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:53
std::string getClass() const
Definition: Object.h:117
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: PolyMap.h:262
PolyMap(AstPolyMap *map)
Construct a PolyMap from an raw AST pointer.
Definition: PolyMap.h:267
PolyMap(ndarray::Array< double, 2, 2 > const &coeff_f, int nout, std::string const &options="IterInverse=0")
Definition: PolyMap.h:125
int getNout() const
Definition: Mapping.h:81
int getNin() const
Definition: Mapping.h:76
bool getIterInverse() const
Get IterInverse: does this provide an iterative inverse transformation?
Definition: PolyMap.h:146
double getD(std::string const &attrib) const
Definition: Object.h:360
int getNiterInverse() const
Get NiterInverse: maximum number of iterations for iterative inverse.
Definition: PolyMap.h:149
double getTolInverse() const
Get TolInverse: target relative error for iterative inverse.
Definition: PolyMap.h:152
PolyMap polyTran(bool forward, double acc, double maxacc, int maxorder, std::vector< double > const &lbnd, std::vector< double > const &ubnd) const
Definition: PolyMap.h:228
int getI(std::string const &attrib) const
Definition: Object.h:386
bool getB(std::string const &attrib) const
Definition: Object.h:334
PolyMap(ndarray::Array< double, 2, 2 > const &coeff_f, ndarray::Array< double, 2, 2 > const &coeff_i, std::string const &options="IterInverse=0")
Definition: PolyMap.h:96
AstObject const * getRawPtr() const
Definition: Object.h:260