24#ifndef FPGRIDSPHERE_HPP_INCLUDED
25#define FPGRIDSPHERE_HPP_INCLUDED
27#include "fitpack_config.h"
30#include "fxArrays.hpp"
33#include "fitpack_grid_sphere_c.h"
44static_assert(
sizeof(fitpack_grid_sphere_c) ==
sizeof(fitpack_fitter_c),
45 "C descriptor layout mismatch: fitpack_grid_sphere_c vs fitpack_fitter_c");
106 if (
this != &other) {
165 return "fpGridSphere";
198 return static_cast<fpFitter&
>(*this);
201 return static_cast<const fpFitter&
>(*this);
211 virtual void new_points(std::vector<double>&
u, std::vector<double>&
v, int32_t z_n1, int32_t z_n2, std::vector<double>&
z) {
212 int32_t n =
static_cast<int32_t
>(
u.size());
220 virtual int32_t
new_fit(std::vector<double>&
u, std::vector<double>&
v, int32_t z_n1, int32_t z_n2, std::vector<double>&
z,
double*
smoothing =
nullptr) {
221 int32_t n =
static_cast<int32_t
>(
u.size());
226 virtual void BC_north_pole(
double* z0 =
nullptr,
bool* exact =
nullptr,
bool* differentiable =
nullptr,
bool* zero_grad =
nullptr) {
230 virtual void BC_south_pole(
double* z0 =
nullptr,
bool* exact =
nullptr,
bool* differentiable =
nullptr,
bool* zero_grad =
nullptr) {
234 virtual int32_t
fit(
double*
smoothing =
nullptr,
bool* keep_knots =
nullptr) {
246 virtual double eval(
double u,
double v, int32_t* ierr =
nullptr) {
253 virtual std::vector<double>
eval(std::vector<double>&
u, std::vector<double>&
v, int32_t* ierr =
nullptr) {
254 int32_t n =
static_cast<int32_t
>(
u.size());
255 std::vector<double> result(n * n);
256 int32_t n_result = 0;
257 fitpack_grid_sphere_c_gridded_eval_many(
as<fitpack_grid_sphere_c>(), n,
u.data(),
v.data(), ierr, result.data(), &n_result, n * n);
258 result.resize(n_result);
270 void comm_pack(std::vector<double>& buffer)
const override {
271 int32_t n =
static_cast<int32_t
>(buffer.size());
280 int32_t n =
static_cast<int32_t
>(buffer.size());
285 virtual void write(
const char* filename) {
289 double mse()
const override {
301 int32_t n =
static_cast<int32_t
>(buffer.size());
310 int32_t n =
static_cast<int32_t
>(buffer.size());
328 double* raw =
nullptr;
329 int64_t extents[1] = {0};
331 const int64_t total = extents[0];
332 if (raw ==
nullptr || total <= 0)
return {};
333 const double* first =
reinterpret_cast<const double*
>(raw);
334 return std::vector<double>(first, first + total);
350 fxArray<double>
u()
const {
351 double* raw =
nullptr;
352 int64_t extents[1] = {0};
355 for (
int k = 0; k < 1; ++k) {
357 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
359 array_c descr = array_c_null;
360 array_c_from_ptr(&descr,
"u",
static_cast<void*
>(raw),
361 getCFITypeFlag<double>(),
362 static_cast<FX_SIZE
>(
sizeof(
double)),
363 static_cast<FX_RANK
>(1), bounds);
364 return fxArray<double>(descr);
373 double* raw =
nullptr;
374 int64_t extents[1] = {0};
376 const int64_t total = extents[0];
377 if (raw ==
nullptr || total <= 0)
return {};
378 const double* first =
reinterpret_cast<const double*
>(raw);
379 return std::vector<double>(first, first + total);
395 fxArray<double>
v()
const {
396 double* raw =
nullptr;
397 int64_t extents[1] = {0};
400 for (
int k = 0; k < 1; ++k) {
402 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
404 array_c descr = array_c_null;
405 array_c_from_ptr(&descr,
"v",
static_cast<void*
>(raw),
406 getCFITypeFlag<double>(),
407 static_cast<FX_SIZE
>(
sizeof(
double)),
408 static_cast<FX_RANK
>(1), bounds);
409 return fxArray<double>(descr);
422 double* raw =
nullptr;
423 int64_t extents[2] = {0, 0};
425 const int64_t total = extents[0] * extents[1];
426 if (raw ==
nullptr || total <= 0)
return {};
427 const double* first =
reinterpret_cast<const double*
>(raw);
428 return std::vector<double>(first, first + total);
436 double* raw =
nullptr;
437 int64_t extents[2] = {0, 0};
439 return { extents[0], extents[1] };
455 fxArray<double>
z()
const {
456 double* raw =
nullptr;
457 int64_t extents[2] = {0, 0};
460 for (
int k = 0; k < 2; ++k) {
462 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
464 array_c descr = array_c_null;
465 array_c_from_ptr(&descr,
"z",
static_cast<void*
>(raw),
466 getCFITypeFlag<double>(),
467 static_cast<FX_SIZE
>(
sizeof(
double)),
468 static_cast<FX_RANK
>(2), bounds);
469 return fxArray<double>(descr);
482 double* raw =
nullptr;
483 int64_t extents[2] = {0, 0};
485 const int64_t total = extents[0] * extents[1];
486 if (raw ==
nullptr || total <= 0)
return {};
487 const double* first =
reinterpret_cast<const double*
>(raw);
488 return std::vector<double>(first, first + total);
496 double* raw =
nullptr;
497 int64_t extents[2] = {0, 0};
499 return { extents[0], extents[1] };
515 fxArray<double>
t()
const {
516 double* raw =
nullptr;
517 int64_t extents[2] = {0, 0};
520 for (
int k = 0; k < 2; ++k) {
522 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
524 array_c descr = array_c_null;
525 array_c_from_ptr(&descr,
"t",
static_cast<void*
>(raw),
526 getCFITypeFlag<double>(),
527 static_cast<FX_SIZE
>(
sizeof(
double)),
528 static_cast<FX_RANK
>(2), bounds);
529 return fxArray<double>(descr);
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 > v() const
Zero-copy fxArray view of component 'v'.
Definition fpGridSphere.hpp:395
fpGridSphere(const fpGridSphere &other)
Copy constructor - deep copy.
Definition fpGridSphere.hpp:78
std::vector< double > t_vector() const
Deep copy of component 't' as a std::vector.
Definition fpGridSphere.hpp:481
virtual void new_points(std::vector< double > &u, std::vector< double > &v, int32_t z_n1, int32_t z_n2, std::vector< double > &z)
new_points
Definition fpGridSphere.hpp:211
fpGridSphere(fitpack_grid_sphere_c &c_wrapper, bool move=false)
Construct from existing C wrapper (takes ownership if move=true)
Definition fpGridSphere.hpp:116
fpGridSphere & operator=(fpGridSphere &&other) noexcept
Move assignment - transfer ownership.
Definition fpGridSphere.hpp:105
std::vector< double > u_vector() const
Deep copy of component 'u' as a std::vector.
Definition fpGridSphere.hpp:327
void core_comm_pack(std::vector< double > &buffer) const override
core_comm_pack
Definition fpGridSphere.hpp:300
virtual void BC_south_pole(double *z0=nullptr, bool *exact=nullptr, bool *differentiable=nullptr, bool *zero_grad=nullptr)
Definition fpGridSphere.hpp:230
const int32_t & nmax() const
Definition fpGridSphere.hpp:540
void core_comm_expand(std::vector< double > &buffer) override
core_comm_expand
Definition fpGridSphere.hpp:309
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 fpGridSphere.hpp:164
int32_t comm_size() const override
Definition fpGridSphere.hpp:263
virtual double eval(double u, double v, int32_t *ierr=nullptr)
Definition fpGridSphere.hpp:246
bool is_allocated() const override
Check if object is allocated.
Definition fpGridSphere.hpp:142
virtual std::vector< double > eval(std::vector< double > &u, std::vector< double > &v, int32_t *ierr=nullptr)
eval
Definition fpGridSphere.hpp:253
fpGridSphere()
Default constructor - allocates new fitpack_grid_sphere.
Definition fpGridSphere.hpp:64
virtual void BC_north_pole(double *z0=nullptr, bool *exact=nullptr, bool *differentiable=nullptr, bool *zero_grad=nullptr)
Definition fpGridSphere.hpp:226
const fpFitter & as_parent() const
Definition fpGridSphere.hpp:200
virtual int32_t fit(double *smoothing=nullptr, bool *keep_knots=nullptr)
Definition fpGridSphere.hpp:234
const fitpack_grid_sphere_c & c_handle() const
Get underlying C wrapper (const, for interop)
Definition fpGridSphere.hpp:178
void destroy_base() override
Definition fpGridSphere.hpp:315
fitpack_grid_sphere_c & c_handle()
Get underlying C wrapper (for interop)
Definition fpGridSphere.hpp:171
fpGridSphere(NoAlloc tag)
Definition fpGridSphere.hpp:545
fpGridSphere(fitpack_grid_sphere_c &c_wrapper, ViewTag)
Non-owning view ctor: bit-copy the C handle, mark is_pointer=true. Used by parent classes' polymorphi...
Definition fpGridSphere.hpp:130
virtual int32_t least_squares(double *smoothing=nullptr, bool *reset_knots=nullptr)
Definition fpGridSphere.hpp:238
int32_t & nmax()
Definition fpGridSphere.hpp:537
bool is_pointer() const override
Check if this is a non-owning pointer.
Definition fpGridSphere.hpp:149
void comm_expand(std::vector< double > &buffer) override
comm_expand
Definition fpGridSphere.hpp:279
const char * c_type_name() const override
Return the C wrapper struct name for this class (e.g. "fitpack_grid_sphere_c").
Definition fpGridSphere.hpp:156
virtual int32_t new_fit(std::vector< double > &u, std::vector< double > &v, int32_t z_n1, int32_t z_n2, std::vector< double > &z, double *smoothing=nullptr)
new_fit
Definition fpGridSphere.hpp:220
std::array< int64_t, 2 > t_shape() const
Extents of component 't', leading dimension first.
Definition fpGridSphere.hpp:495
static fpGridSphere make_view()
Construct an empty (non-owning) wrapper, for use as a view target.
Definition fpGridSphere.hpp:190
virtual int32_t interpolate(bool *reset_knots=nullptr)
Definition fpGridSphere.hpp:242
~fpGridSphere() override
Destructor - deallocates if owned.
Definition fpGridSphere.hpp:71
int32_t core_comm_size() const override
Definition fpGridSphere.hpp:293
void comm_pack(std::vector< double > &buffer) const override
comm_pack
Definition fpGridSphere.hpp:270
fxArray< double > t() const
Zero-copy fxArray view of component 't'.
Definition fpGridSphere.hpp:515
fpGridSphere & operator=(const fpGridSphere &other)
Copy assignment - deep copy.
Definition fpGridSphere.hpp:86
fpFitter & as_parent()
Upcast to parent type (reference, no copy)
Definition fpGridSphere.hpp:197
fxArray< double > z() const
Zero-copy fxArray view of component 'z'.
Definition fpGridSphere.hpp:455
std::vector< double > v_vector() const
Deep copy of component 'v' as a std::vector.
Definition fpGridSphere.hpp:372
std::vector< double > z_vector() const
Deep copy of component 'z' as a std::vector.
Definition fpGridSphere.hpp:421
fpGridSphere(fpGridSphere &&other) noexcept
Move constructor - transfer ownership.
Definition fpGridSphere.hpp:97
fxArray< double > u() const
Zero-copy fxArray view of component 'u'.
Definition fpGridSphere.hpp:350
double mse() const override
Definition fpGridSphere.hpp:289
std::array< int64_t, 2 > z_shape() const
Extents of component 'z', leading dimension first.
Definition fpGridSphere.hpp:435
virtual void write(const char *filename)
Definition fpGridSphere.hpp:285
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