{
returnpow( x, 1.0/3.0 ); }
66 #if __cplusplus <= 199711L 71{
returnpow( x, 1.0/3.0 ); }
94 for( integer k = 1; k < npts-1; ++k )
95 t[k] =
static_cast<real_type
>(k)/
static_cast<real_type
>(npts);
103real_type
constpnts[],
107real_type
const* p0 = pnts;
108 for( integer k = 1; k < npts; ++k ) {
109real_type
const* p1 = p0 + ld_pnts;
111 for( integer j = 0; j < dim; ++j ) {
112real_type c = p1[j] - p0[j];
115 t[k] =
t[k-1] + sqrt(dst);
117 for( integer k = 1; k < npts-1; ++k )
t[k] /=
t[npts-1];
126real_type
constpnts[],
128real_type
constalpha,
131real_type
const* p0 = pnts;
132 for( integer k = 1; k < npts; ++k ) {
133real_type
const* p1 = p0 + ld_pnts;
135 for( integer j = 0; j < dim; ++j ) {
136real_type c = p1[j] - p0[j];
139 t[k] =
t[k-1] + pow(dst,alpha/2);
141 for( integer k = 1; k < npts-1; ++k )
t[k] /=
t[npts-1];
150real_type
constpnts[],
159real_type
constpnts[],
168real_type
constpnts[],
194 for(
size_tj = 0;
spline_type[j] !=
nullptr; ++j ) {
197std::ostringstream ost;
198ost <<
"string_to_splineType("<<
n<<
") unknown type\n";
199 throwstd::runtime_error(ost.str());
203 staticreal_type
const m_2pi= 6.28318530717958647692528676656;
225real_type imag[2] ) {
228real_type
const&
C=
a[0];
229real_type
const&
B=
a[1];
230real_type
const&
A=
a[2];
232real[0] = real[1] = imag[0] = imag[1] = 0;
234pair<int,int> res(0,0);
235 if( isZero(
a[0]) ) {
239real_type twoA = 2*
A;
240real_type d =
B*
B- 4*
A*
C;
241real_type absd =
abs(d);
246real_type
r= sqrt(absd);
248real[0] = real[1] = -
B/twoA;
249imag[0] =
abs(
r/twoA);
255real[0] =
abs(
r/twoA);
259 if( w > 0 ) w +=
r;
elsew -=
r;
284real_type imag[3] ) {
287real[0] = real[1] = real[2] =
288imag[0] = imag[1] = imag[2] = 0;
291 if( isZero(
a[0]) ) {
301real_type
const C=
a[0]/
a[3];
302real_type
const B=
a[1]/
a[3];
303real_type
const A=
a[2]/
a[3];
306real_type
const A3=
A/3;
307real_type
constp =
B-
A*
A3;
308real_type
constq =
C+
A3*(2*(
A3*
A3)-
B);
316 returnpair<int,int>(1,0);
319real_type
const P= (p/3)/
S/
S;
320real_type
constsqrtP = sqrt(
abs(p/3))/
S;
321real_type
constQ = (q/2)/
S/
S/
S;
323real_type
constd =
P*
P*
P+ Q*Q;
324real_type
constsqrtd = sqrt(
abs(d));
326pair<int,int> res(0,0);
331real_type
tmp= Q > 0 ? sqrtP : -sqrtP;
335}
else if( d > 0 ) {
340w2 = - pow( sqrtd + Q, 1.0 / 3.0 );
343w1 = pow( sqrtd - Q, 1.0 / 3.0 );
348real[2] = -0.5*real[0];
349imag[1] = (w1-w2)*sqrt(3.0/4.0);
356real_type angle = atan2( sqrtd, -Q );
357 if( angle < 0 ) angle +=
m_2pi;
359real_type re = sqrtP * cos(angle);
360real_type im = sqrtP * sin(angle);
363real[1] = real[2] = -re;
364real[1] += sqrt(3.0) * im;
365real[2] -= sqrt(3.0) * im;
369 for( integer
i= 0;
i< res.first+res.second; ++
i) {
389real_type
constYp[],
393 for(
size_t i= 1;
i< size_t(npts); ++
i) {
394 if( Y[
i-1] > Y[
i] )
return-2;
395 if( isZero(Y[
i-1]-Y[
i]) && X[
i-1] < X[
i] ) flag = 0;
398 for(
size_t i= 1;
i< size_t(npts); ++
i) {
399 if( X[
i] <= X[
i-1] )
continue;
400real_type dd = (Y[
i]-Y[
i-1])/(X[
i]-X[
i-1]);
401real_type m0 = Yp[
i-1]/dd;
402real_type m1 = Yp[
i]/dd;
403 if( m0 < 0 || m1 < 0 )
return-1;
404 if( m0 <= 3 && m1 <= 3 ) {
405 if( flag > 0 &&
i> 1 && (isZero(m0) || isZero(m0-3) ) ) flag = 0;
406 if( flag > 0 &&
i<
size_t(npts-1) && (isZero(m1) || isZero(m1-3) ) ) flag = 0;
408real_type
tmp1= 2*m0+m1-3;
409real_type tmp2 = 2*(m0+m1-2);
410real_type tmp3 = m0*tmp2-(
tmp1*
tmp1);
412 if( tmp3 < 0 )
return-1;
414 if( tmp3 > 0 )
return-1;
416 if( isZero(tmp3) ) flag = 0;
430 if( npts <= 2 ) { lastInterval = 0;
return; }
433real_type
const* XL = X+lastInterval;
435 if( x >= X[npts-2] ) {
436lastInterval = npts-2;
437}
else if( x < XL[2] ) {
440real_type
const* XE = X+npts;
441lastInterval += integer(std::lower_bound( XL, XE, x )-XL);
442 if( X[lastInterval] > x ) --lastInterval;
444}
else if( x < XL[0] ) {
447}
else if( XL[-1] <= x ) {
450lastInterval = integer(std::lower_bound( X, XL, x )-X);
451 if( X[lastInterval] > x ) --lastInterval;
461Spline::build( real_type
constx[], integer incx,
462real_type
consty[], integer incy,
465 for( integer
i= 0;
i<
n; ++
i) X[
i] = x[
i*incx];
466 for( integer
i= 0;
i<
n; ++
i) Y[
i] = y[
i*incy];
475s <<
"Spline `"<< _name
477<<
" of order: "<< order();
479s <<
"\nxMin = "<< xMin() <<
" xMax = "<< xMax()
480<<
"\nyMin = "<< yMin() <<
" yMax = "<< yMax();
487Spline::pushBack( real_type x, real_type y ) {
489SPLINE_ASSERT( x >= X[
size_t(npts-1)],
490 "Spline::pushBack, non monotone insert at insert N. "<< npts <<
491 "\nX[ "<< npts-1 <<
"] = "<< X[
size_t(npts-1)] <<
492 "\nX[ "<< npts <<
"] = "<< x );
494 if( npts_reserved == 0 ) {
496}
else if( npts >= npts_reserved ) {
498integer saved_npts = npts;
499vector<real_type> Xsaved, Ysaved;
500Xsaved.resize(
size_t(npts) );
501Ysaved.resize(
size_t(npts) );
505reserve( (npts+1) * 2 );
507 std::copy( Xsaved.begin(), Xsaved.end(), X );
508 std::copy( Ysaved.begin(), Ysaved.end(), Y );
518Spline::setOrigin( real_type x0 ) {
519real_type Tx = x0 - X[0];
521 while( ix < X+npts ) *ix++ += Tx;
527Spline::setRange( real_type xmin, real_type xmax ) {
528SPLINE_ASSERT( xmax > xmin,
529 "Spline::setRange( "<< xmin <<
530 " , "<< xmax <<
" ) bad range ");
531real_type
S= (xmax - xmin) / ( X[npts-1] - X[0] );
532real_type Tx = xmin -
S* X[0];
533 for( real_type *ix = X; ix < X+npts; ++ix ) *ix = *ix *
S+ Tx;
541 char constheader[] )
const{
542s << header <<
'\n';
543real_type dx = (xMax()-xMin())/nintervals;
544 for( integer
i= 0;
i<= nintervals; ++
i) {
545real_type x = xMin() +
i*dx;
546s << x <<
'\t'<< (*this)(x) <<
'\n';
559 #ifndef SPLINES_DO_NOT_USE_GENERIC_CONTAINER 561 usingGenericContainerNamespace::GC_VEC_REAL;
562 usingGenericContainerNamespace::vec_real_type;
573SPLINE_ASSERT( gc.exists(
"x"),
574 "Spline["<< _name <<
"]::setup missing `x` field!");
575SPLINE_ASSERT( gc.exists(
"y"),
576 "Spline["<< _name <<
"]::setup missing `y` field!");
578GenericContainer
const& gc_x = gc(
"x");
579GenericContainer
const& gc_y = gc(
"y");
583std::ostringstream ost;
584ost <<
"Spline["<< _name <<
"]::setup, field `x'";
585gc_x.copyto_vec_real ( x, ost.str().c_str() );
588std::ostringstream ost;
589ost <<
"Spline["<< _name <<
"]::setup, field `y'";
590gc_y.copyto_vec_real ( y, ost.str().c_str() );
void transform(Container &c, UnaryFunction *op)
void FangHung(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
pair< int, int > quadraticRoots(real_type const a[3], real_type real[2], real_type imag[2])
quadratic polinomial roots
void centripetal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type const alpha, real_type t[])
static real_type const m_2pi
void uniform(integer, integer npts, real_type const [], integer, real_type t[])
static real_type cbrt(real_type x)
void universal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
static real_type const machineEps
char const * spline_type[]
void chordal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
void FoleyNielsen(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
pair< int, int > cubicRoots(real_type const a[4], real_type real[3], real_type imag[3])
cubic polinomial roots
SplineType string_to_splineType(std::string const &nin)
void updateInterval(integer &lastInterval, real_type x, real_type const X[], integer npts)
integer checkCubicSplineMonotonicity(real_type const X[], real_type const Y[], real_type const Yp[], integer npts)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
static const char * type_name(CS_INT value)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4