24#ifndef FPSPHERE_HPP_INCLUDED
25#define FPSPHERE_HPP_INCLUDED
27#include "fitpack_config.h"
30#include "fxArrays.hpp"
33#include "fitpack_sphere_c.h"
44static_assert(
sizeof(fitpack_sphere_c) ==
sizeof(fitpack_fitter_c),
45 "C descriptor layout mismatch: fitpack_sphere_c vs fitpack_fitter_c");
106 if (
this != &other) {
198 return static_cast<fpFitter&
>(*this);
201 return static_cast<const fpFitter&
>(*this);
211 virtual void new_points(std::vector<double>&
theta, std::vector<double>&
phi, std::vector<double>&
r,
double*
w =
nullptr) {
212 int32_t n =
static_cast<int32_t
>(
theta.size());
220 virtual int32_t
new_fit(std::vector<double>&
theta, std::vector<double>&
phi, std::vector<double>&
r,
double*
w =
nullptr,
double*
smoothing =
nullptr) {
221 int32_t n =
static_cast<int32_t
>(
theta.size());
226 virtual int32_t
fit(
double*
smoothing =
nullptr,
bool* keep_knots =
nullptr) {
238 virtual double eval(
double theta,
double phi, int32_t* ierr =
nullptr) {
245 virtual std::vector<double>
eval(std::vector<double>&
theta, std::vector<double>&
phi, int32_t* ierr =
nullptr) {
246 int32_t n =
static_cast<int32_t
>(
theta.size());
247 std::vector<double> result(n * n);
248 int32_t n_result = 0;
250 result.resize(n_result);
262 void comm_pack(std::vector<double>& buffer)
const override {
263 int32_t n =
static_cast<int32_t
>(buffer.size());
272 int32_t n =
static_cast<int32_t
>(buffer.size());
277 double mse()
const override {
289 int32_t n =
static_cast<int32_t
>(buffer.size());
298 int32_t n =
static_cast<int32_t
>(buffer.size());
316 double* raw =
nullptr;
317 int64_t extents[1] = {0};
319 const int64_t total = extents[0];
320 if (raw ==
nullptr || total <= 0)
return {};
321 const double* first =
reinterpret_cast<const double*
>(raw);
322 return std::vector<double>(first, first + total);
339 double* raw =
nullptr;
340 int64_t extents[1] = {0};
343 for (
int k = 0; k < 1; ++k) {
345 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
347 array_c descr = array_c_null;
348 array_c_from_ptr(&descr,
"theta",
static_cast<void*
>(raw),
349 getCFITypeFlag<double>(),
350 static_cast<FX_SIZE
>(
sizeof(
double)),
351 static_cast<FX_RANK
>(1), bounds);
352 return fxArray<double>(descr);
361 double* raw =
nullptr;
362 int64_t extents[1] = {0};
364 const int64_t total = extents[0];
365 if (raw ==
nullptr || total <= 0)
return {};
366 const double* first =
reinterpret_cast<const double*
>(raw);
367 return std::vector<double>(first, first + total);
383 fxArray<double>
phi()
const {
384 double* raw =
nullptr;
385 int64_t extents[1] = {0};
388 for (
int k = 0; k < 1; ++k) {
390 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
392 array_c descr = array_c_null;
393 array_c_from_ptr(&descr,
"phi",
static_cast<void*
>(raw),
394 getCFITypeFlag<double>(),
395 static_cast<FX_SIZE
>(
sizeof(
double)),
396 static_cast<FX_RANK
>(1), bounds);
397 return fxArray<double>(descr);
406 double* raw =
nullptr;
407 int64_t extents[1] = {0};
409 const int64_t total = extents[0];
410 if (raw ==
nullptr || total <= 0)
return {};
411 const double* first =
reinterpret_cast<const double*
>(raw);
412 return std::vector<double>(first, first + total);
428 fxArray<double>
r()
const {
429 double* raw =
nullptr;
430 int64_t extents[1] = {0};
433 for (
int k = 0; k < 1; ++k) {
435 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
437 array_c descr = array_c_null;
438 array_c_from_ptr(&descr,
"r",
static_cast<void*
>(raw),
439 getCFITypeFlag<double>(),
440 static_cast<FX_SIZE
>(
sizeof(
double)),
441 static_cast<FX_RANK
>(1), bounds);
442 return fxArray<double>(descr);
451 double* raw =
nullptr;
452 int64_t extents[1] = {0};
454 const int64_t total = extents[0];
455 if (raw ==
nullptr || total <= 0)
return {};
456 const double* first =
reinterpret_cast<const double*
>(raw);
457 return std::vector<double>(first, first + total);
473 fxArray<double>
w()
const {
474 double* raw =
nullptr;
475 int64_t extents[1] = {0};
478 for (
int k = 0; k < 1; ++k) {
480 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
482 array_c descr = array_c_null;
483 array_c_from_ptr(&descr,
"w",
static_cast<void*
>(raw),
484 getCFITypeFlag<double>(),
485 static_cast<FX_SIZE
>(
sizeof(
double)),
486 static_cast<FX_RANK
>(1), bounds);
487 return fxArray<double>(descr);
496 double* raw =
nullptr;
497 int64_t extents[1] = {0};
499 const int64_t total = extents[0];
500 if (raw ==
nullptr || total <= 0)
return {};
501 const double* first =
reinterpret_cast<const double*
>(raw);
502 return std::vector<double>(first, first + total);
519 double* raw =
nullptr;
520 int64_t extents[1] = {0};
523 for (
int k = 0; k < 1; ++k) {
525 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
527 array_c descr = array_c_null;
528 array_c_from_ptr(&descr,
"wrk2",
static_cast<void*
>(raw),
529 getCFITypeFlag<double>(),
530 static_cast<FX_SIZE
>(
sizeof(
double)),
531 static_cast<FX_RANK
>(1), bounds);
532 return fxArray<double>(descr);
545 double* raw =
nullptr;
546 int64_t extents[2] = {0, 0};
548 const int64_t total = extents[0] * extents[1];
549 if (raw ==
nullptr || total <= 0)
return {};
550 const double* first =
reinterpret_cast<const double*
>(raw);
551 return std::vector<double>(first, first + total);
559 double* raw =
nullptr;
560 int64_t extents[2] = {0, 0};
562 return { extents[0], extents[1] };
578 fxArray<double>
t()
const {
579 double* raw =
nullptr;
580 int64_t extents[2] = {0, 0};
583 for (
int k = 0; k < 2; ++k) {
585 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
587 array_c descr = array_c_null;
588 array_c_from_ptr(&descr,
"t",
static_cast<void*
>(raw),
589 getCFITypeFlag<double>(),
590 static_cast<FX_SIZE
>(
sizeof(
double)),
591 static_cast<FX_RANK
>(2), bounds);
592 return fxArray<double>(descr);
603 const int32_t&
m()
const {
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
virtual int32_t least_squares(double *smoothing=nullptr, bool *reset_knots=nullptr)
Definition fpSphere.hpp:230
fxArray< double > phi() const
Zero-copy fxArray view of component 'phi'.
Definition fpSphere.hpp:383
std::vector< double > wrk2_vector() const
Deep copy of component 'wrk2' as a std::vector.
Definition fpSphere.hpp:495
const int32_t & lwrk2() const
Definition fpSphere.hpp:610
fxArray< double > theta() const
Zero-copy fxArray view of component 'theta'.
Definition fpSphere.hpp:338
std::vector< double > phi_vector() const
Deep copy of component 'phi' as a std::vector.
Definition fpSphere.hpp:360
std::vector< double > theta_vector() const
Deep copy of component 'theta' as a std::vector.
Definition fpSphere.hpp:315
virtual int32_t fit(double *smoothing=nullptr, bool *keep_knots=nullptr)
Definition fpSphere.hpp:226
const int32_t & m() const
Definition fpSphere.hpp:603
const int32_t & nmax() const
Definition fpSphere.hpp:617
void comm_pack(std::vector< double > &buffer) const override
comm_pack
Definition fpSphere.hpp:262
fxArray< double > wrk2() const
Zero-copy fxArray view of component 'wrk2'.
Definition fpSphere.hpp:518
fitpack_sphere_c & c_handle()
Get underlying C wrapper (for interop)
Definition fpSphere.hpp:171
fpSphere & operator=(const fpSphere &other)
Copy assignment - deep copy.
Definition fpSphere.hpp:86
int32_t comm_size() const override
Definition fpSphere.hpp:255
std::vector< double > t_vector() const
Deep copy of component 't' as a std::vector.
Definition fpSphere.hpp:544
void comm_expand(std::vector< double > &buffer) override
comm_expand
Definition fpSphere.hpp:271
fpSphere()
Default constructor - allocates new fitpack_sphere.
Definition fpSphere.hpp:64
virtual int32_t interpolate(bool *reset_knots=nullptr)
Definition fpSphere.hpp:234
fxArray< double > r() const
Zero-copy fxArray view of component 'r'.
Definition fpSphere.hpp:428
fpSphere(fitpack_sphere_c &c_wrapper, ViewTag)
Non-owning view ctor: bit-copy the C handle, mark is_pointer=true. Used by parent classes' polymorphi...
Definition fpSphere.hpp:130
~fpSphere() override
Destructor - deallocates if owned.
Definition fpSphere.hpp:71
std::array< int64_t, 2 > t_shape() const
Extents of component 't', leading dimension first.
Definition fpSphere.hpp:558
int32_t & m()
Definition fpSphere.hpp:600
fpSphere(const fpSphere &other)
Copy constructor - deep copy.
Definition fpSphere.hpp:78
void destroy_base() override
Definition fpSphere.hpp:303
void core_comm_pack(std::vector< double > &buffer) const override
core_comm_pack
Definition fpSphere.hpp:288
const fpFitter & as_parent() const
Definition fpSphere.hpp:200
fpSphere & operator=(fpSphere &&other) noexcept
Move assignment - transfer ownership.
Definition fpSphere.hpp:105
virtual double eval(double theta, double phi, int32_t *ierr=nullptr)
Definition fpSphere.hpp:238
const char * c_type_name() const override
Return the C wrapper struct name for this class (e.g. "fitpack_sphere_c").
Definition fpSphere.hpp:156
std::vector< double > w_vector() const
Deep copy of component 'w' as a std::vector.
Definition fpSphere.hpp:450
fxArray< double > t() const
Zero-copy fxArray view of component 't'.
Definition fpSphere.hpp:578
std::vector< double > r_vector() const
Deep copy of component 'r' as a std::vector.
Definition fpSphere.hpp:405
int32_t & lwrk2()
Definition fpSphere.hpp:607
fpSphere(NoAlloc tag)
Definition fpSphere.hpp:622
bool is_pointer() const override
Check if this is a non-owning pointer.
Definition fpSphere.hpp:149
void core_comm_expand(std::vector< double > &buffer) override
core_comm_expand
Definition fpSphere.hpp:297
virtual void new_points(std::vector< double > &theta, std::vector< double > &phi, std::vector< double > &r, double *w=nullptr)
new_points
Definition fpSphere.hpp:211
virtual int32_t new_fit(std::vector< double > &theta, std::vector< double > &phi, std::vector< double > &r, double *w=nullptr, double *smoothing=nullptr)
new_fit
Definition fpSphere.hpp:220
int32_t core_comm_size() const override
Definition fpSphere.hpp:281
fpSphere(fitpack_sphere_c &c_wrapper, bool move=false)
Construct from existing C wrapper (takes ownership if move=true)
Definition fpSphere.hpp:116
fxArray< double > w() const
Zero-copy fxArray view of component 'w'.
Definition fpSphere.hpp:473
static fpSphere make_view()
Construct an empty (non-owning) wrapper, for use as a view target.
Definition fpSphere.hpp:190
virtual std::vector< double > eval(std::vector< double > &theta, std::vector< double > &phi, int32_t *ierr=nullptr)
eval
Definition fpSphere.hpp:245
bool is_allocated() const override
Check if object is allocated.
Definition fpSphere.hpp:142
fpSphere(fpSphere &&other) noexcept
Move constructor - transfer ownership.
Definition fpSphere.hpp:97
fpFitter & as_parent()
Upcast to parent type (reference, no copy)
Definition fpSphere.hpp:197
double mse() const override
Definition fpSphere.hpp:277
int32_t & nmax()
Definition fpSphere.hpp:614
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 fpSphere.hpp:164
const fitpack_sphere_c & c_handle() const
Get underlying C wrapper (const, for interop)
Definition fpSphere.hpp:178
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