24#ifndef FPPARAMETRICCURVE_HPP_INCLUDED
25#define FPPARAMETRICCURVE_HPP_INCLUDED
27#include "fitpack_config.h"
30#include "fxArrays.hpp"
33#include "fitpack_parametric_curve_c.h"
45static_assert(
sizeof(fitpack_parametric_curve_c) ==
sizeof(fitpack_fitter_c),
46 "C descriptor layout mismatch: fitpack_parametric_curve_c vs fitpack_fitter_c");
107 if (
this != &other) {
166 return "fpParametricCurve";
179 const fitpack_parametric_curve_c&
c_handle()
const {
199 return static_cast<fpFitter&
>(*this);
202 return static_cast<const fpFitter&
>(*this);
212 virtual void new_points(int32_t x_n1, int32_t x_n2, std::vector<double>&
x,
double*
u =
nullptr,
double*
w =
nullptr) {
224 virtual int32_t
new_fit(int32_t x_n1, int32_t x_n2, std::vector<double>&
x,
double*
u =
nullptr,
double*
w =
nullptr,
double*
smoothing =
nullptr, int32_t*
order =
nullptr) {
229 virtual int32_t
fit(
double*
smoothing =
nullptr, int32_t*
order =
nullptr,
bool* keep_knots =
nullptr) {
244 virtual std::vector<double>
eval_one(
double u, int32_t n_result, int32_t* ierr =
nullptr) {
245 std::vector<double> result(n_result);
254 virtual std::vector<double>
eval_many(std::vector<double>&
u, int32_t n_result, int32_t* ierr =
nullptr) {
255 int32_t n =
static_cast<int32_t
>(
u.size());
256 std::vector<double> result(n_result);
265 virtual std::vector<double>
dfdx(
double u, int32_t
order, int32_t n_result, int32_t* ierr =
nullptr) {
266 std::vector<double> result(n_result);
275 virtual std::vector<double>
dfdx(std::vector<double>&
u, int32_t
order, int32_t n_result, int32_t* ierr =
nullptr) {
276 int32_t n =
static_cast<int32_t
>(
u.size());
277 std::vector<double> result(n_result);
286 virtual std::vector<double>
dfdx_all(
double u, int32_t n_result, int32_t* ierr =
nullptr) {
287 std::vector<double> result(n_result);
300 void comm_pack(std::vector<double>& buffer)
const override {
301 int32_t n =
static_cast<int32_t
>(buffer.size());
310 int32_t n =
static_cast<int32_t
>(buffer.size());
315 double mse()
const override {
327 int32_t n =
static_cast<int32_t
>(buffer.size());
336 int32_t n =
static_cast<int32_t
>(buffer.size());
358 double* raw =
nullptr;
359 int64_t extents[2] = {0, 0};
361 const int64_t total = extents[0] * extents[1];
362 if (raw ==
nullptr || total <= 0)
return {};
363 const double* first =
reinterpret_cast<const double*
>(raw);
364 return std::vector<double>(first, first + total);
372 double* raw =
nullptr;
373 int64_t extents[2] = {0, 0};
375 return { extents[0], extents[1] };
391 fxArray<double>
x()
const {
392 double* raw =
nullptr;
393 int64_t extents[2] = {0, 0};
396 for (
int k = 0; k < 2; ++k) {
398 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
400 array_c descr = array_c_null;
401 array_c_from_ptr(&descr,
"x",
static_cast<void*
>(raw),
402 getCFITypeFlag<double>(),
403 static_cast<FX_SIZE
>(
sizeof(
double)),
404 static_cast<FX_RANK
>(2), bounds);
405 return fxArray<double>(descr);
414 double* raw =
nullptr;
415 int64_t extents[1] = {0};
417 const int64_t total = extents[0];
418 if (raw ==
nullptr || total <= 0)
return {};
419 const double* first =
reinterpret_cast<const double*
>(raw);
420 return std::vector<double>(first, first + total);
436 fxArray<double>
u()
const {
437 double* raw =
nullptr;
438 int64_t extents[1] = {0};
441 for (
int k = 0; k < 1; ++k) {
443 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
445 array_c descr = array_c_null;
446 array_c_from_ptr(&descr,
"u",
static_cast<void*
>(raw),
447 getCFITypeFlag<double>(),
448 static_cast<FX_SIZE
>(
sizeof(
double)),
449 static_cast<FX_RANK
>(1), bounds);
450 return fxArray<double>(descr);
459 double* raw =
nullptr;
460 int64_t extents[1] = {0};
462 const int64_t total = extents[0];
463 if (raw ==
nullptr || total <= 0)
return {};
464 const double* first =
reinterpret_cast<const double*
>(raw);
465 return std::vector<double>(first, first + total);
481 fxArray<double>
sp()
const {
482 double* raw =
nullptr;
483 int64_t extents[1] = {0};
486 for (
int k = 0; k < 1; ++k) {
488 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
490 array_c descr = array_c_null;
491 array_c_from_ptr(&descr,
"sp",
static_cast<void*
>(raw),
492 getCFITypeFlag<double>(),
493 static_cast<FX_SIZE
>(
sizeof(
double)),
494 static_cast<FX_RANK
>(1), bounds);
495 return fxArray<double>(descr);
504 double* raw =
nullptr;
505 int64_t extents[1] = {0};
507 const int64_t total = extents[0];
508 if (raw ==
nullptr || total <= 0)
return {};
509 const double* first =
reinterpret_cast<const double*
>(raw);
510 return std::vector<double>(first, first + total);
526 fxArray<double>
w()
const {
527 double* raw =
nullptr;
528 int64_t extents[1] = {0};
531 for (
int k = 0; k < 1; ++k) {
533 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
535 array_c descr = array_c_null;
536 array_c_from_ptr(&descr,
"w",
static_cast<void*
>(raw),
537 getCFITypeFlag<double>(),
538 static_cast<FX_SIZE
>(
sizeof(
double)),
539 static_cast<FX_RANK
>(1), bounds);
540 return fxArray<double>(descr);
553 double* raw =
nullptr;
554 int64_t extents[2] = {0, 0};
556 const int64_t total = extents[0] * extents[1];
557 if (raw ==
nullptr || total <= 0)
return {};
558 const double* first =
reinterpret_cast<const double*
>(raw);
559 return std::vector<double>(first, first + total);
567 double* raw =
nullptr;
568 int64_t extents[2] = {0, 0};
570 return { extents[0], extents[1] };
586 fxArray<double>
dd()
const {
587 double* raw =
nullptr;
588 int64_t extents[2] = {0, 0};
591 for (
int k = 0; k < 2; ++k) {
593 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
595 array_c descr = array_c_null;
596 array_c_from_ptr(&descr,
"dd",
static_cast<void*
>(raw),
597 getCFITypeFlag<double>(),
598 static_cast<FX_SIZE
>(
sizeof(
double)),
599 static_cast<FX_RANK
>(2), bounds);
600 return fxArray<double>(descr);
609 double* raw =
nullptr;
610 int64_t extents[1] = {0};
612 const int64_t total = extents[0];
613 if (raw ==
nullptr || total <= 0)
return {};
614 const double* first =
reinterpret_cast<const double*
>(raw);
615 return std::vector<double>(first, first + total);
631 fxArray<double>
t()
const {
632 double* raw =
nullptr;
633 int64_t extents[1] = {0};
636 for (
int k = 0; k < 1; ++k) {
638 bounds[2 * k + 1] =
static_cast<FX_SIZE
>(extents[k]);
640 array_c descr = array_c_null;
641 array_c_from_ptr(&descr,
"t",
static_cast<void*
>(raw),
642 getCFITypeFlag<double>(),
643 static_cast<FX_SIZE
>(
sizeof(
double)),
644 static_cast<FX_RANK
>(1), bounds);
645 return fxArray<double>(descr);
656 const int32_t&
m()
const {
729 template <FP_SIZE dim>
737 template <FP_SIZE dim>
746 template <FP_SIZE dim>
748 const std::vector<FP_REAL>&
w, FP_REAL
smoothing = 1000.0, FP_SIZE
order = 3)
762 template <FP_SIZE dim>
766 if (
idim() != dim) {
if (ierr) *ierr = FITPACK_INPUT_ERROR;
return y; }
768 FP_FLAG ierr0 = FITPACK_OK;
769 const std::vector<FP_REAL> flat =
eval_one(
u, dim, &ierr0);
770 if (ierr) *ierr = ierr0;
771 for (FP_SIZE j = 0; j < dim; ++j) y[j] = flat[static_cast<std::size_t>(j)];
776 template <FP_SIZE dim>
777 std::vector<fpPoint<dim>>
eval(
const std::vector<FP_REAL>&
u, FP_FLAG* ierr =
nullptr)
779 if (
idim() != dim) {
if (ierr) *ierr = FITPACK_INPUT_ERROR;
return {}; }
781 std::vector<FP_REAL> uw(
u);
782 FP_FLAG ierr0 = FITPACK_OK;
783 const std::vector<FP_REAL> flat =
eval_many(uw, dim *
static_cast<FP_SIZE
>(
u.size()), &ierr0);
784 if (ierr) *ierr = ierr0;
789 template <FP_SIZE dim>
793 if (
idim() != dim) {
if (ierr) *ierr = FITPACK_INPUT_ERROR;
return d; }
795 FP_FLAG ierr0 = FITPACK_OK;
796 const std::vector<FP_REAL> flat =
dfdx(
u,
order, dim, &ierr0);
797 if (ierr) *ierr = ierr0;
798 for (FP_SIZE j = 0; j < dim; ++j) d[j] = flat[static_cast<std::size_t>(j)];
803 template <FP_SIZE dim>
804 std::vector<fpPoint<dim>>
ddu_all(FP_REAL
u, FP_FLAG* ierr =
nullptr)
806 if (
idim() != dim) {
if (ierr) *ierr = FITPACK_INPUT_ERROR;
return {}; }
808 FP_FLAG ierr0 = FITPACK_OK;
809 const std::vector<FP_REAL> flat =
dfdx_all(
u, dim * (
degree() + 1), &ierr0);
810 if (ierr) *ierr = ierr0;
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
const double & ubegin() const
Definition fpParametricCurve.hpp:684
const char * c_type_name() const override
Return the C wrapper struct name for this class (e.g. "fitpack_parametric_curve_c").
Definition fpParametricCurve.hpp:157
fxArray< double > dd() const
Zero-copy fxArray view of component 'dd'.
Definition fpParametricCurve.hpp:586
fpParametricCurve()
Default constructor - allocates new fitpack_parametric_curve.
Definition fpParametricCurve.hpp:65
int32_t & m()
Definition fpParametricCurve.hpp:653
void core_comm_expand(std::vector< double > &buffer) override
core_comm_expand
Definition fpParametricCurve.hpp:335
virtual int32_t fit(double *smoothing=nullptr, int32_t *order=nullptr, bool *keep_knots=nullptr)
Definition fpParametricCurve.hpp:229
FP_FLAG fit(FP_REAL smoothing)
Refit the current points with a new smoothing.
Definition fpParametricCurve.hpp:757
const fitpack_parametric_curve_c & c_handle() const
Get underlying C wrapper (const, for interop)
Definition fpParametricCurve.hpp:179
virtual void new_points(int32_t x_n1, int32_t x_n2, std::vector< double > &x, double *u=nullptr, double *w=nullptr)
new_points
Definition fpParametricCurve.hpp:212
const int32_t & order() const
Definition fpParametricCurve.hpp:677
int32_t core_comm_size() const override
Definition fpParametricCurve.hpp:319
const int32_t & knots() const
Definition fpParametricCurve.hpp:705
fpParametricCurve(const fpParametricCurve &other)
Copy constructor - deep copy.
Definition fpParametricCurve.hpp:79
std::vector< double > u_vector() const
Deep copy of component 'u' as a std::vector.
Definition fpParametricCurve.hpp:413
int32_t & knots()
Definition fpParametricCurve.hpp:702
static fpParametricCurve make_view()
Construct an empty (non-owning) wrapper, for use as a view target.
Definition fpParametricCurve.hpp:191
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 fpParametricCurve.hpp:165
std::vector< fpPoint< dim > > ddu_all(FP_REAL u, FP_FLAG *ierr=nullptr)
All derivatives (orders 0..k) at the parameter value u.
Definition fpParametricCurve.hpp:804
void destroy_base() override
Definition fpParametricCurve.hpp:341
std::vector< fpPoint< dim > > eval(const std::vector< FP_REAL > &u, FP_FLAG *ierr=nullptr)
Evaluate the curve at every parameter value in u.
Definition fpParametricCurve.hpp:777
const int32_t & nest() const
Definition fpParametricCurve.hpp:698
void comm_pack(std::vector< double > &buffer) const override
comm_pack
Definition fpParametricCurve.hpp:300
double & uend()
Definition fpParametricCurve.hpp:688
fxArray< double > t() const
Zero-copy fxArray view of component 't'.
Definition fpParametricCurve.hpp:631
int32_t & idim()
Definition fpParametricCurve.hpp:660
fxArray< double > u() const
Zero-copy fxArray view of component 'u'.
Definition fpParametricCurve.hpp:436
std::vector< double > sp_vector() const
Deep copy of component 'sp' as a std::vector.
Definition fpParametricCurve.hpp:458
virtual std::vector< double > eval_many(std::vector< double > &u, int32_t n_result, int32_t *ierr=nullptr)
eval_many
Definition fpParametricCurve.hpp:254
fxArray< double > x() const
Zero-copy fxArray view of component 'x'.
Definition fpParametricCurve.hpp:391
FP_FLAG new_fit(const std::vector< fpPoint< dim > > &x, FP_REAL smoothing=1000.0, FP_SIZE order=3)
Fit a new curve through the points, choosing u by cumulative Euclidean distance.
Definition fpParametricCurve.hpp:730
bool is_pointer() const override
Check if this is a non-owning pointer.
Definition fpParametricCurve.hpp:150
std::vector< double > dd_vector() const
Deep copy of component 'dd' as a std::vector.
Definition fpParametricCurve.hpp:552
std::array< int64_t, 2 > dd_shape() const
Extents of component 'dd', leading dimension first.
Definition fpParametricCurve.hpp:566
virtual std::vector< double > dfdx(double u, int32_t order, int32_t n_result, int32_t *ierr=nullptr)
dfdx
Definition fpParametricCurve.hpp:265
fpParametricCurve(fitpack_parametric_curve_c &c_wrapper, bool move=false)
Construct from existing C wrapper (takes ownership if move=true)
Definition fpParametricCurve.hpp:117
fpParametricCurve & operator=(fpParametricCurve &&other) noexcept
Move assignment - transfer ownership.
Definition fpParametricCurve.hpp:106
fpPoint< dim > ddu(FP_REAL u, FP_SIZE order, FP_FLAG *ierr=nullptr)
Derivative of the given order at the parameter value u.
Definition fpParametricCurve.hpp:790
virtual void set_default_parameters()
Definition fpParametricCurve.hpp:217
bool has_params() const
Definition fpParametricCurve.hpp:667
int32_t & nest()
Definition fpParametricCurve.hpp:695
const int32_t & idim() const
Definition fpParametricCurve.hpp:663
double & ubegin()
Definition fpParametricCurve.hpp:681
fxArray< double > sp() const
Zero-copy fxArray view of component 'sp'.
Definition fpParametricCurve.hpp:481
void core_comm_pack(std::vector< double > &buffer) const override
core_comm_pack
Definition fpParametricCurve.hpp:326
fitpack_parametric_curve_c & c_handle()
Get underlying C wrapper (for interop)
Definition fpParametricCurve.hpp:172
void set_has_params(bool value)
Definition fpParametricCurve.hpp:670
~fpParametricCurve() override
Destructor - deallocates if owned.
Definition fpParametricCurve.hpp:72
FP_FLAG new_fit(const std::vector< fpPoint< dim > > &x, const std::vector< FP_REAL > &u, FP_REAL smoothing=1000.0, FP_SIZE order=3)
Fit a new curve through the points at the given parameter values u.
Definition fpParametricCurve.hpp:738
virtual int32_t interpolate(int32_t *order=nullptr, bool *reset_knots=nullptr)
Definition fpParametricCurve.hpp:233
std::vector< double > t_vector() const
Deep copy of component 't' as a std::vector.
Definition fpParametricCurve.hpp:608
virtual std::vector< double > dfdx(std::vector< double > &u, int32_t order, int32_t n_result, int32_t *ierr=nullptr)
dfdx
Definition fpParametricCurve.hpp:275
std::array< int64_t, 2 > x_shape() const
Extents of component 'x', leading dimension first.
Definition fpParametricCurve.hpp:371
double mse() const override
Definition fpParametricCurve.hpp:315
virtual int32_t least_squares(double *smoothing=nullptr, bool *reset_knots=nullptr)
Definition fpParametricCurve.hpp:237
int32_t comm_size() const override
Definition fpParametricCurve.hpp:293
FP_FLAG fit(FP_REAL smoothing, FP_SIZE order)
Refit the current points with a new smoothing and spline order.
Definition fpParametricCurve.hpp:759
FP_SIZE degree() const
Spline degree k of the current fit.
Definition fpParametricCurve.hpp:723
fpParametricCurve(NoAlloc tag)
Definition fpParametricCurve.hpp:815
fpParametricCurve(fitpack_parametric_curve_c &c_wrapper, ViewTag)
Non-owning view ctor: bit-copy the C handle, mark is_pointer=true. Used by parent classes' polymorphi...
Definition fpParametricCurve.hpp:131
const int32_t & m() const
Definition fpParametricCurve.hpp:656
virtual std::vector< double > dfdx_all(double u, int32_t n_result, int32_t *ierr=nullptr)
dfdx_all
Definition fpParametricCurve.hpp:286
std::vector< double > x_vector() const
Deep copy of component 'x' as a std::vector.
Definition fpParametricCurve.hpp:357
bool is_allocated() const override
Check if object is allocated.
Definition fpParametricCurve.hpp:143
std::vector< double > w_vector() const
Deep copy of component 'w' as a std::vector.
Definition fpParametricCurve.hpp:503
fpParametricCurve & operator=(const fpParametricCurve &other)
Copy assignment - deep copy.
Definition fpParametricCurve.hpp:87
virtual int32_t new_fit(int32_t x_n1, int32_t x_n2, std::vector< double > &x, double *u=nullptr, double *w=nullptr, double *smoothing=nullptr, int32_t *order=nullptr)
new_fit
Definition fpParametricCurve.hpp:224
const fpFitter & as_parent() const
Definition fpParametricCurve.hpp:201
fpPoint< dim > eval(FP_REAL u, FP_FLAG *ierr=nullptr)
Evaluate the curve at the parameter value u.
Definition fpParametricCurve.hpp:763
FP_SIZE ndim() const
Number of space dimensions of the fitted curve.
Definition fpParametricCurve.hpp:726
fpFitter & as_parent()
Upcast to parent type (reference, no copy)
Definition fpParametricCurve.hpp:198
fxArray< double > w() const
Zero-copy fxArray view of component 'w'.
Definition fpParametricCurve.hpp:526
fpParametricCurve(fpParametricCurve &&other) noexcept
Move constructor - transfer ownership.
Definition fpParametricCurve.hpp:98
FP_FLAG fit(FP_SIZE order)
Refit the current points with a new spline order.
Definition fpParametricCurve.hpp:755
int32_t & order()
Definition fpParametricCurve.hpp:674
void comm_expand(std::vector< double > &buffer) override
comm_expand
Definition fpParametricCurve.hpp:309
FP_FLAG new_fit(const std::vector< fpPoint< dim > > &x, const std::vector< FP_REAL > &u, const std::vector< FP_REAL > &w, FP_REAL smoothing=1000.0, FP_SIZE order=3)
Fit a new curve through the points at parameter values u, with weights w.
Definition fpParametricCurve.hpp:747
virtual std::vector< double > eval_one(double u, int32_t n_result, int32_t *ierr=nullptr)
eval_one
Definition fpParametricCurve.hpp:244
const double & uend() const
Definition fpParametricCurve.hpp:691
std::vector< fpPoint< dims > > fpPointGather(const std::vector< FP_REAL > &flat)
Rebuild a vector of points from a Fortran x(dims,m) buffer.
Definition fpPoint.hpp:127
std::vector< FP_REAL > fpPointFlatten(const std::vector< fpPoint< dims > > &points)
Flatten a vector of points into Fortran x(dims,m) order. One contiguous copy.
Definition fpPoint.hpp:117
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
A point in dims-dimensional space.
Definition fpPoint.hpp:45