24#ifndef FPSURFACE_HPP_INCLUDED
25#define FPSURFACE_HPP_INCLUDED
27#include "fitpack_config.h"
30#include "fxArrays.hpp"
33#include "fitpack_surface_c.h"
45static_assert(
sizeof(fitpack_surface_c) ==
sizeof(fitpack_fitter_c),
46 "C descriptor layout mismatch: fitpack_surface_c vs fitpack_fitter_c");
107 if (
this != &other) {
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, std::vector<double>&
z,
double*
w =
nullptr) {
213 int32_t n =
static_cast<int32_t
>(
x.size());
221 virtual int32_t
new_fit(std::vector<double>&
x, std::vector<double>&
y, std::vector<double>&
z,
double*
w =
nullptr,
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;
250 fitpack_surface_c_surface_eval_many(
as<fitpack_surface_c>(), n,
x.data(),
y.data(), ierr, result.data(), &n_result, n);
251 result.resize(n_result);
259 virtual std::vector<double>
eval_ongrid(std::vector<double>&
x, std::vector<double>&
y, int32_t* ierr =
nullptr) {
260 int32_t n =
static_cast<int32_t
>(
x.size());
261 std::vector<double> result(n * n);
262 int32_t n_result = 0;
263 fitpack_surface_c_surface_eval_gridded(
as<fitpack_surface_c>(), n,
x.data(),
y.data(), ierr, result.data(), &n_result, n * n);
264 result.resize(n_result);
269 virtual double dfdx(
double x,
double y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
276 virtual std::vector<double>
dfdx(std::vector<double>&
x, std::vector<double>&
y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
277 int32_t n =
static_cast<int32_t
>(
x.size());
278 std::vector<double> result(n);
279 int32_t n_result = 0;
280 fitpack_surface_c_surface_derivatives_many(
as<fitpack_surface_c>(), n,
x.data(),
y.data(), dx, dy, ierr, result.data(), &n_result, n);
281 result.resize(n_result);
289 virtual std::vector<double>
dfdx_ongrid(std::vector<double>&
x, std::vector<double>&
y, int32_t dx, int32_t dy, int32_t* ierr =
nullptr) {
290 int32_t n =
static_cast<int32_t
>(
x.size());
291 std::vector<double> result(n * n);
292 int32_t n_result = 0;
293 fitpack_surface_c_surface_derivatives_gridded(
as<fitpack_surface_c>(), n,
x.data(),
y.data(), dx, dy, ierr, result.data(), &n_result, n * n);
294 result.resize(n_result);
302 virtual double integral(std::vector<double>& lower, std::vector<double>& upper)
const {
303 int32_t n =
static_cast<int32_t
>(lower.size());
309 fitpack_curve_c result_c;
311 return fpCurve(result_c,
true);
315 fitpack_surface_c result_c;
327 void comm_pack(std::vector<double>& buffer)
const override {
328 int32_t n =
static_cast<int32_t
>(buffer.size());
337 int32_t n =
static_cast<int32_t
>(buffer.size());
342 double mse()
const override {
354 int32_t n =
static_cast<int32_t
>(buffer.size());
363 int32_t n =
static_cast<int32_t
>(buffer.size());
381 double* raw =
nullptr;
382 int64_t extents[1] = {0};
384 const int64_t total = extents[0];
385 if (raw ==
nullptr || total <= 0)
return {};
386 const double* first =
reinterpret_cast<const double*
>(raw);
387 return std::vector<double>(first, first + total);
403 fxArray<double>
x()
const {
404 double* raw =
nullptr;
405 int64_t extents[1] = {0};
408 for (
int k = 0; k < 1; ++k) {
410 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
412 array_c descr = array_c_null;
413 array_c_from_ptr(&descr,
"x",
static_cast<void*
>(raw),
414 getCFITypeFlag<double>(),
415 static_cast<FX_SIZE
>(
sizeof(
double)),
416 static_cast<FX_RANK
>(1), bounds);
417 return fxArray<double>(descr);
426 double* raw =
nullptr;
427 int64_t extents[1] = {0};
429 const int64_t total = extents[0];
430 if (raw ==
nullptr || total <= 0)
return {};
431 const double* first =
reinterpret_cast<const double*
>(raw);
432 return std::vector<double>(first, first + total);
448 fxArray<double>
y()
const {
449 double* raw =
nullptr;
450 int64_t extents[1] = {0};
453 for (
int k = 0; k < 1; ++k) {
455 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
457 array_c descr = array_c_null;
458 array_c_from_ptr(&descr,
"y",
static_cast<void*
>(raw),
459 getCFITypeFlag<double>(),
460 static_cast<FX_SIZE
>(
sizeof(
double)),
461 static_cast<FX_RANK
>(1), bounds);
462 return fxArray<double>(descr);
471 double* raw =
nullptr;
472 int64_t extents[1] = {0};
474 const int64_t total = extents[0];
475 if (raw ==
nullptr || total <= 0)
return {};
476 const double* first =
reinterpret_cast<const double*
>(raw);
477 return std::vector<double>(first, first + total);
493 fxArray<double>
z()
const {
494 double* raw =
nullptr;
495 int64_t extents[1] = {0};
498 for (
int k = 0; k < 1; ++k) {
500 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
502 array_c descr = array_c_null;
503 array_c_from_ptr(&descr,
"z",
static_cast<void*
>(raw),
504 getCFITypeFlag<double>(),
505 static_cast<FX_SIZE
>(
sizeof(
double)),
506 static_cast<FX_RANK
>(1), bounds);
507 return fxArray<double>(descr);
516 double* raw =
nullptr;
517 int64_t extents[1] = {0};
519 const int64_t total = extents[0];
520 if (raw ==
nullptr || total <= 0)
return {};
521 const double* first =
reinterpret_cast<const double*
>(raw);
522 return std::vector<double>(first, first + total);
538 fxArray<double>
w()
const {
539 double* raw =
nullptr;
540 int64_t extents[1] = {0};
543 for (
int k = 0; k < 1; ++k) {
545 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
547 array_c descr = array_c_null;
548 array_c_from_ptr(&descr,
"w",
static_cast<void*
>(raw),
549 getCFITypeFlag<double>(),
550 static_cast<FX_SIZE
>(
sizeof(
double)),
551 static_cast<FX_RANK
>(1), bounds);
552 return fxArray<double>(descr);
561 double* raw =
nullptr;
562 int64_t extents[1] = {0};
564 const int64_t total = extents[0];
565 if (raw ==
nullptr || total <= 0)
return {};
566 const double* first =
reinterpret_cast<const double*
>(raw);
567 return std::vector<double>(first, first + total);
584 double* raw =
nullptr;
585 int64_t extents[1] = {0};
588 for (
int k = 0; k < 1; ++k) {
590 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
592 array_c descr = array_c_null;
593 array_c_from_ptr(&descr,
"wrk2",
static_cast<void*
>(raw),
594 getCFITypeFlag<double>(),
595 static_cast<FX_SIZE
>(
sizeof(
double)),
596 static_cast<FX_RANK
>(1), bounds);
597 return fxArray<double>(descr);
610 double* raw =
nullptr;
611 int64_t extents[2] = {0, 0};
613 const int64_t total = extents[0] * extents[1];
614 if (raw ==
nullptr || total <= 0)
return {};
615 const double* first =
reinterpret_cast<const double*
>(raw);
616 return std::vector<double>(first, first + total);
624 double* raw =
nullptr;
625 int64_t extents[2] = {0, 0};
627 return { extents[0], extents[1] };
643 fxArray<double>
t()
const {
644 double* raw =
nullptr;
645 int64_t extents[2] = {0, 0};
648 for (
int k = 0; k < 2; ++k) {
650 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
652 array_c descr = array_c_null;
653 array_c_from_ptr(&descr,
"t",
static_cast<void*
>(raw),
654 getCFITypeFlag<double>(),
655 static_cast<FX_SIZE
>(
sizeof(
double)),
656 static_cast<FX_RANK
>(2), bounds);
657 return fxArray<double>(descr);
668 const int32_t&
m()
const {
689 const int32_t&
bc()
const {
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 > t() const
Zero-copy fxArray view of component 't'.
Definition fpSurface.hpp:643
std::vector< double > y_vector() const
Deep copy of component 'y' as a std::vector.
Definition fpSurface.hpp:425
int32_t & nmax()
Definition fpSurface.hpp:672
void core_comm_expand(std::vector< double > &buffer) override
core_comm_expand
Definition fpSurface.hpp:362
int32_t & bc()
Definition fpSurface.hpp:686
virtual fpSurface derivative_spline(int32_t nux, int32_t nuy, int32_t *ierr=nullptr)
Definition fpSurface.hpp:314
~fpSurface() override
Destructor - deallocates if owned.
Definition fpSurface.hpp:72
fpSurface(const fpSurface &other)
Copy constructor - deep copy.
Definition fpSurface.hpp:79
const int32_t & nmax() const
Definition fpSurface.hpp:675
fpSurface()
Default constructor - allocates new fitpack_surface.
Definition fpSurface.hpp:65
virtual double integral(std::vector< double > &lower, std::vector< double > &upper) const
integral
Definition fpSurface.hpp:302
void comm_expand(std::vector< double > &buffer) override
comm_expand
Definition fpSurface.hpp:336
fpSurface(NoAlloc tag)
Definition fpSurface.hpp:694
virtual void new_points(std::vector< double > &x, std::vector< double > &y, std::vector< double > &z, double *w=nullptr)
new_points
Definition fpSurface.hpp:212
int32_t comm_size() const override
Definition fpSurface.hpp:320
const int32_t & lwrk2() const
Definition fpSurface.hpp:682
fpSurface(fitpack_surface_c &c_wrapper, ViewTag)
Non-owning view ctor: bit-copy the C handle, mark is_pointer=true. Used by parent classes' polymorphi...
Definition fpSurface.hpp:131
void comm_pack(std::vector< double > &buffer) const override
comm_pack
Definition fpSurface.hpp:327
const fpFitter & as_parent() const
Definition fpSurface.hpp:201
virtual int32_t interpolate(bool *reset_knots=nullptr)
Definition fpSurface.hpp:231
std::array< int64_t, 2 > t_shape() const
Extents of component 't', leading dimension first.
Definition fpSurface.hpp:623
virtual int32_t fit(double *smoothing=nullptr, int32_t *order=nullptr, bool *keep_knots=nullptr)
Definition fpSurface.hpp:227
bool is_pointer() const override
Check if this is a non-owning pointer.
Definition fpSurface.hpp:150
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 fpSurface.hpp:289
virtual double dfdx(double x, double y, int32_t dx, int32_t dy, int32_t *ierr=nullptr)
Definition fpSurface.hpp:269
virtual std::vector< double > eval(std::vector< double > &x, std::vector< double > &y, int32_t *ierr=nullptr)
eval
Definition fpSurface.hpp:246
std::vector< double > w_vector() const
Deep copy of component 'w' as a std::vector.
Definition fpSurface.hpp:515
fxArray< double > x() const
Zero-copy fxArray view of component 'x'.
Definition fpSurface.hpp:403
virtual std::vector< double > eval_ongrid(std::vector< double > &x, std::vector< double > &y, int32_t *ierr=nullptr)
eval_ongrid
Definition fpSurface.hpp:259
double mse() const override
Definition fpSurface.hpp:342
fpSurface & operator=(const fpSurface &other)
Copy assignment - deep copy.
Definition fpSurface.hpp:87
fxArray< double > wrk2() const
Zero-copy fxArray view of component 'wrk2'.
Definition fpSurface.hpp:583
fpFitter & as_parent()
Upcast to parent type (reference, no copy)
Definition fpSurface.hpp:198
int32_t & lwrk2()
Definition fpSurface.hpp:679
const int32_t & m() const
Definition fpSurface.hpp:668
void destroy_base() override
Definition fpSurface.hpp:368
const char * c_type_name() const override
Return the C wrapper struct name for this class (e.g. "fitpack_surface_c").
Definition fpSurface.hpp:157
virtual int32_t new_fit(std::vector< double > &x, std::vector< double > &y, std::vector< double > &z, double *w=nullptr, double *smoothing=nullptr, int32_t *order=nullptr)
new_fit
Definition fpSurface.hpp:221
fitpack_surface_c & c_handle()
Get underlying C wrapper (for interop)
Definition fpSurface.hpp:172
virtual fpCurve cross_section(double u, bool along_y, int32_t *ierr=nullptr)
Definition fpSurface.hpp:308
std::vector< double > x_vector() const
Deep copy of component 'x' as a std::vector.
Definition fpSurface.hpp:380
std::vector< double > wrk2_vector() const
Deep copy of component 'wrk2' as a std::vector.
Definition fpSurface.hpp:560
static fpSurface make_view()
Construct an empty (non-owning) wrapper, for use as a view target.
Definition fpSurface.hpp:191
void core_comm_pack(std::vector< double > &buffer) const override
core_comm_pack
Definition fpSurface.hpp:353
const int32_t & bc() const
Definition fpSurface.hpp:689
int32_t & m()
Definition fpSurface.hpp:665
virtual int32_t least_squares(double *smoothing=nullptr, bool *reset_knots=nullptr)
Definition fpSurface.hpp:235
std::vector< double > t_vector() const
Deep copy of component 't' as a std::vector.
Definition fpSurface.hpp:609
fpSurface(fpSurface &&other) noexcept
Move constructor - transfer ownership.
Definition fpSurface.hpp:98
const fitpack_surface_c & c_handle() const
Get underlying C wrapper (const, for interop)
Definition fpSurface.hpp:179
std::vector< double > z_vector() const
Deep copy of component 'z' as a std::vector.
Definition fpSurface.hpp:470
int32_t core_comm_size() const override
Definition fpSurface.hpp:346
fpSurface & operator=(fpSurface &&other) noexcept
Move assignment - transfer ownership.
Definition fpSurface.hpp:106
fpSurface(fitpack_surface_c &c_wrapper, bool move=false)
Construct from existing C wrapper (takes ownership if move=true)
Definition fpSurface.hpp:117
bool is_allocated() const override
Check if object is allocated.
Definition fpSurface.hpp:143
fxArray< double > y() const
Zero-copy fxArray view of component 'y'.
Definition fpSurface.hpp:448
virtual double eval(double x, double y, int32_t *ierr=nullptr)
Definition fpSurface.hpp:239
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 fpSurface.hpp:276
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 fpSurface.hpp:165
fxArray< double > z() const
Zero-copy fxArray view of component 'z'.
Definition fpSurface.hpp:493
fxArray< double > w() const
Zero-copy fxArray view of component 'w'.
Definition fpSurface.hpp:538
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