24#ifndef FPGRIDSURFACE_HPP_INCLUDED
25#define FPGRIDSURFACE_HPP_INCLUDED
27#include "fitpack_config.h"
30#include "fxArrays.hpp"
33#include "fitpack_grid_surface_c.h"
45static_assert(
sizeof(fitpack_grid_surface_c) ==
sizeof(fitpack_fitter_c),
46 "C descriptor layout mismatch: fitpack_grid_surface_c vs fitpack_fitter_c");
107 if (
this != &other) {
166 return "fpGridSurface";
199 return static_cast<fpFitter&
>(*this);
202 return static_cast<const fpFitter&
>(*this);
212 virtual void new_points(std::vector<double>&
x, std::vector<double>&
y, int32_t z_n1, int32_t z_n2, std::vector<double>&
z) {
213 int32_t n =
static_cast<int32_t
>(
x.size());
221 virtual int32_t
new_fit(std::vector<double>&
x, std::vector<double>&
y, int32_t z_n1, int32_t z_n2, std::vector<double>&
z,
double*
smoothing =
nullptr, int32_t* order =
nullptr) {
222 int32_t n =
static_cast<int32_t
>(
x.size());
227 virtual int32_t
fit(
double*
smoothing =
nullptr, int32_t* order =
nullptr,
bool* keep_knots =
nullptr) {
239 virtual double eval(
double x,
double y, int32_t* ierr =
nullptr) {
246 virtual std::vector<double>
eval(std::vector<double>&
x, std::vector<double>&
y, int32_t* ierr =
nullptr) {
247 int32_t n =
static_cast<int32_t
>(
x.size());
248 std::vector<double> result(n);
249 int32_t n_result = 0;
251 result.resize(n_result);
263 virtual std::vector<double>
eval_ongrid(std::vector<double>&
x, std::vector<double>&
y, int32_t* ierr =
nullptr) {
264 int32_t n =
static_cast<int32_t
>(
x.size());
265 std::vector<double> result(n * n);
266 int32_t n_result = 0;
268 result.resize(n_result);
273 virtual double dfdx(
double x,
double y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
280 virtual std::vector<double>
dfdx(std::vector<double>&
x, std::vector<double>&
y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
281 int32_t n =
static_cast<int32_t
>(
x.size());
282 std::vector<double> result(n);
283 int32_t n_result = 0;
284 fitpack_grid_surface_c_gridded_derivatives_many(
as<fitpack_grid_surface_c>(), n,
x.data(),
y.data(), dx, dy, ierr, result.data(), &n_result, n);
285 result.resize(n_result);
293 virtual std::vector<double>
dfdx_ongrid(std::vector<double>&
x, std::vector<double>&
y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
294 int32_t n =
static_cast<int32_t
>(
x.size());
295 std::vector<double> result(n * n);
296 int32_t n_result = 0;
297 fitpack_grid_surface_c_gridded_derivatives_gridded(
as<fitpack_grid_surface_c>(), n,
x.data(),
y.data(), dx, dy, ierr, result.data(), &n_result, n * n);
298 result.resize(n_result);
306 virtual double integral(std::vector<double>& lower, std::vector<double>& upper)
const {
307 int32_t n =
static_cast<int32_t
>(lower.size());
313 fitpack_curve_c result_c;
315 return fpCurve(result_c,
true);
319 fitpack_grid_surface_c result_c;
331 void comm_pack(std::vector<double>& buffer)
const override {
332 int32_t n =
static_cast<int32_t
>(buffer.size());
341 int32_t n =
static_cast<int32_t
>(buffer.size());
346 double mse()
const override {
358 int32_t n =
static_cast<int32_t
>(buffer.size());
367 int32_t n =
static_cast<int32_t
>(buffer.size());
385 double* raw =
nullptr;
386 int64_t extents[1] = {0};
388 const int64_t total = extents[0];
389 if (raw ==
nullptr || total <= 0)
return {};
390 const double* first =
reinterpret_cast<const double*
>(raw);
391 return std::vector<double>(first, first + total);
407 fxArray<double>
x()
const {
408 double* raw =
nullptr;
409 int64_t extents[1] = {0};
412 for (
int k = 0; k < 1; ++k) {
414 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
416 array_c descr = array_c_null;
417 array_c_from_ptr(&descr,
"x",
static_cast<void*
>(raw),
418 getCFITypeFlag<double>(),
419 static_cast<FX_SIZE
>(
sizeof(
double)),
420 static_cast<FX_RANK
>(1), bounds);
421 return fxArray<double>(descr);
430 double* raw =
nullptr;
431 int64_t extents[1] = {0};
433 const int64_t total = extents[0];
434 if (raw ==
nullptr || total <= 0)
return {};
435 const double* first =
reinterpret_cast<const double*
>(raw);
436 return std::vector<double>(first, first + total);
452 fxArray<double>
y()
const {
453 double* raw =
nullptr;
454 int64_t extents[1] = {0};
457 for (
int k = 0; k < 1; ++k) {
459 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
461 array_c descr = array_c_null;
462 array_c_from_ptr(&descr,
"y",
static_cast<void*
>(raw),
463 getCFITypeFlag<double>(),
464 static_cast<FX_SIZE
>(
sizeof(
double)),
465 static_cast<FX_RANK
>(1), bounds);
466 return fxArray<double>(descr);
479 double* raw =
nullptr;
480 int64_t extents[2] = {0, 0};
482 const int64_t total = extents[0] * extents[1];
483 if (raw ==
nullptr || total <= 0)
return {};
484 const double* first =
reinterpret_cast<const double*
>(raw);
485 return std::vector<double>(first, first + total);
493 double* raw =
nullptr;
494 int64_t extents[2] = {0, 0};
496 return { extents[0], extents[1] };
512 fxArray<double>
z()
const {
513 double* raw =
nullptr;
514 int64_t extents[2] = {0, 0};
517 for (
int k = 0; k < 2; ++k) {
519 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
521 array_c descr = array_c_null;
522 array_c_from_ptr(&descr,
"z",
static_cast<void*
>(raw),
523 getCFITypeFlag<double>(),
524 static_cast<FX_SIZE
>(
sizeof(
double)),
525 static_cast<FX_RANK
>(2), bounds);
526 return fxArray<double>(descr);
539 double* raw =
nullptr;
540 int64_t extents[2] = {0, 0};
542 const int64_t total = extents[0] * extents[1];
543 if (raw ==
nullptr || total <= 0)
return {};
544 const double* first =
reinterpret_cast<const double*
>(raw);
545 return std::vector<double>(first, first + total);
553 double* raw =
nullptr;
554 int64_t extents[2] = {0, 0};
556 return { extents[0], extents[1] };
572 fxArray<double>
t()
const {
573 double* raw =
nullptr;
574 int64_t extents[2] = {0, 0};
577 for (
int k = 0; k < 2; ++k) {
579 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
581 array_c descr = array_c_null;
582 array_c_from_ptr(&descr,
"t",
static_cast<void*
>(raw),
583 getCFITypeFlag<double>(),
584 static_cast<FX_SIZE
>(
sizeof(
double)),
585 static_cast<FX_RANK
>(2), bounds);
586 return fxArray<double>(descr);
Standalone C++ RAII wrapper for Fortran fitpack_curve.
Definition fpCurve.hpp:56
double & smoothing()
Definition fpFitter.hpp:317
fpFitter(NoAlloc)
Protected constructor for derived classes (does not allocate)
Definition fpFitter.hpp:354
T * as()
Definition fpFitter.hpp:360
fxArray< double > z() const
Zero-copy fxArray view of component 'z'.
Definition fpGridSurface.hpp:512
bool is_allocated() const override
Check if object is allocated.
Definition fpGridSurface.hpp:143
void comm_pack(std::vector< double > &buffer) const override
comm_pack
Definition fpGridSurface.hpp:331
virtual std::vector< double > dfdx(std::vector< double > &x, std::vector< double > &y, int32_t dx, int32_t dy, int32_t *ierr=nullptr)
dfdx
Definition fpGridSurface.hpp:280
virtual void new_points(std::vector< double > &x, std::vector< double > &y, int32_t z_n1, int32_t z_n2, std::vector< double > &z)
new_points
Definition fpGridSurface.hpp:212
fxArray< double > x() const
Zero-copy fxArray view of component 'x'.
Definition fpGridSurface.hpp:407
const fitpack_grid_surface_c & c_handle() const
Get underlying C wrapper (const, for interop)
Definition fpGridSurface.hpp:179
double mse() const override
Definition fpGridSurface.hpp:346
fpGridSurface(const fpGridSurface &other)
Copy constructor - deep copy.
Definition fpGridSurface.hpp:79
virtual std::vector< double > eval_ongrid(std::vector< double > &x, std::vector< double > &y, int32_t *ierr=nullptr)
eval_ongrid
Definition fpGridSurface.hpp:263
fxArray< double > y() const
Zero-copy fxArray view of component 'y'.
Definition fpGridSurface.hpp:452
std::vector< double > t_vector() const
Deep copy of component 't' as a std::vector.
Definition fpGridSurface.hpp:538
int32_t comm_size() const override
Definition fpGridSurface.hpp:324
int32_t & nmax()
Definition fpGridSurface.hpp:594
virtual std::vector< double > dfdx_ongrid(std::vector< double > &x, std::vector< double > &y, int32_t dx, int32_t dy, int32_t *ierr=nullptr)
dfdx_ongrid
Definition fpGridSurface.hpp:293
virtual double eval(double x, double y, int32_t *ierr=nullptr)
Definition fpGridSurface.hpp:239
std::array< int64_t, 2 > z_shape() const
Extents of component 'z', leading dimension first.
Definition fpGridSurface.hpp:492
const int32_t & nmax() const
Definition fpGridSurface.hpp:597
virtual double dfdx(double x, double y, int32_t dx, int32_t dy, int32_t *ierr=nullptr)
Definition fpGridSurface.hpp:273
bool is_pointer() const override
Check if this is a non-owning pointer.
Definition fpGridSurface.hpp:150
fpFitter & as_parent()
Upcast to parent type (reference, no copy)
Definition fpGridSurface.hpp:198
fpGridSurface(fpGridSurface &&other) noexcept
Move constructor - transfer ownership.
Definition fpGridSurface.hpp:98
fpGridSurface(NoAlloc tag)
Definition fpGridSurface.hpp:602
std::vector< double > y_vector() const
Deep copy of component 'y' as a std::vector.
Definition fpGridSurface.hpp:429
virtual int32_t least_squares(double *smoothing=nullptr, bool *reset_knots=nullptr)
Definition fpGridSurface.hpp:231
std::vector< double > z_vector() const
Deep copy of component 'z' as a std::vector.
Definition fpGridSurface.hpp:478
void core_comm_pack(std::vector< double > &buffer) const override
core_comm_pack
Definition fpGridSurface.hpp:357
static fpGridSurface make_view()
Construct an empty (non-owning) wrapper, for use as a view target.
Definition fpGridSurface.hpp:191
virtual double integral(std::vector< double > &lower, std::vector< double > &upper) const
integral
Definition fpGridSurface.hpp:306
void comm_expand(std::vector< double > &buffer) override
comm_expand
Definition fpGridSurface.hpp:340
void destroy_base() override
Definition fpGridSurface.hpp:372
fpGridSurface(fitpack_grid_surface_c &c_wrapper, bool move=false)
Construct from existing C wrapper (takes ownership if move=true)
Definition fpGridSurface.hpp:117
virtual double eval_ongrid(double x, double y, int32_t *ierr=nullptr)
Definition fpGridSurface.hpp:256
virtual fpCurve cross_section(double u, bool along_y, int32_t *ierr=nullptr)
Definition fpGridSurface.hpp:312
fpGridSurface()
Default constructor - allocates new fitpack_grid_surface.
Definition fpGridSurface.hpp:65
const char * cpp_type_name() const override
Return the fully-qualified C++ class name for this class. Owned by the C++ layer — does not round-tri...
Definition fpGridSurface.hpp:165
std::vector< double > x_vector() const
Deep copy of component 'x' as a std::vector.
Definition fpGridSurface.hpp:384
int32_t core_comm_size() const override
Definition fpGridSurface.hpp:350
virtual int32_t interpolate(bool *reset_knots=nullptr)
Definition fpGridSurface.hpp:235
fpGridSurface & operator=(const fpGridSurface &other)
Copy assignment - deep copy.
Definition fpGridSurface.hpp:87
const fpFitter & as_parent() const
Definition fpGridSurface.hpp:201
virtual int32_t fit(double *smoothing=nullptr, int32_t *order=nullptr, bool *keep_knots=nullptr)
Definition fpGridSurface.hpp:227
fpGridSurface(fitpack_grid_surface_c &c_wrapper, ViewTag)
Non-owning view ctor: bit-copy the C handle, mark is_pointer=true. Used by parent classes' polymorphi...
Definition fpGridSurface.hpp:131
fxArray< double > t() const
Zero-copy fxArray view of component 't'.
Definition fpGridSurface.hpp:572
fitpack_grid_surface_c & c_handle()
Get underlying C wrapper (for interop)
Definition fpGridSurface.hpp:172
~fpGridSurface() override
Destructor - deallocates if owned.
Definition fpGridSurface.hpp:72
std::array< int64_t, 2 > t_shape() const
Extents of component 't', leading dimension first.
Definition fpGridSurface.hpp:552
virtual fpGridSurface derivative_spline(int32_t nux, int32_t nuy, int32_t *ierr=nullptr)
Definition fpGridSurface.hpp:318
virtual std::vector< double > eval(std::vector< double > &x, std::vector< double > &y, int32_t *ierr=nullptr)
eval
Definition fpGridSurface.hpp:246
virtual int32_t new_fit(std::vector< double > &x, std::vector< double > &y, int32_t z_n1, int32_t z_n2, std::vector< double > &z, double *smoothing=nullptr, int32_t *order=nullptr)
new_fit
Definition fpGridSurface.hpp:221
fpGridSurface & operator=(fpGridSurface &&other) noexcept
Move assignment - transfer ownership.
Definition fpGridSurface.hpp:106
void core_comm_expand(std::vector< double > &buffer) override
core_comm_expand
Definition fpGridSurface.hpp:366
const char * c_type_name() const override
Return the C wrapper struct name for this class (e.g. "fitpack_grid_surface_c").
Definition fpGridSurface.hpp:157
Tag type for derived class constructors (no allocation)
Definition fpFitter.hpp:349
Tag type for non-owning view constructors of polymorphic concrete subtypes. Declared on roots and abs...
Definition fpFitter.hpp:103