41 #ifndef __has_c2_function_hh
42 #define __has_c2_function_hh 1
47 #define _USE_MATH_DEFINES
48 #define c2_isnan _isnan
49 #define c2_isfinite _finite
51 #define c2_isnan std::isnan
52 #define c2_isfinite std::isfinite
73 virtual const char*
what()
const throw() {
return info.c_str(); }
86 template <
typename float_type>
class c2_ptr;
98 template <
typename float_type>
class c2_fblock
143 "c2_function.hh 490 2012-04-10 19:05:40Z marcus ";
156 std::ostringstream outstr;
157 outstr <<
"attempt to delete an object with non-zero ownership in class ";
158 outstr <<
typeid(*this).name() << std::endl;
206 float_type
find_root(float_type lower_bracket, float_type upper_bracket, float_type start,
207 float_type value,
int *
error=0,
208 float_type *final_yprime=0, float_type *final_yprime2=0 )
const throw(
c2_exception) ;
229 float_type abs_tol=1e-12, float_type rel_tol=1e-12,
int derivs=2,
bool adapt=true,
bool extrapolate=true)
230 const throw(c2_exception);
251 float_type
integral(float_type amin, float_type amax,
std::vector<float_type> *partials = 0,
252 float_type abs_tol=1e-12, float_type rel_tol=1e-12,
int derivs=2,
bool adapt=true,
bool extrapolate=true)
253 const throw(c2_exception);
293 float_type abs_tol=1e-12, float_type rel_tol=1e-12,
294 int derivs=2,
std::vector<float_type> *xvals=0,
std::vector<float_type> *yvals=0) const throw(c2_exception);
340 virtual void get_sampling_grid(float_type amin, float_type amax, std::vector<float_type> &grid)
const ;
370 float_type amin, float_type amax, const
c2_function<float_type> &weight, float_type norm=1.0)
371 const throw(c2_exception);
411 std::ostringstream outstr;
412 outstr <<
"attempt to release ownership of an unowned function in class ";
413 outstr <<
typeid(*this).name() << std::endl;
414 throw c2_exception(outstr.str().c_str());
544 if(!
func)
throw c2_exception(
"c2_classic_function called with null function");
545 if(yprime) *yprime=0;
546 if(yprime2) *yprime2=0;
553 const float_type (*
func)(float_type);
603 if(
func)
func->release_ownership_for_return();
646 {
return get().value_with_derivatives(x, yprime, yprime2); }
750 operator c2_class<float_type>&()
const {
return get(); }
794 func.set_function(f);
801 if(!
func.valid())
throw c2_exception(
"c2_plugin_function_p called uninitialized");
802 return func->value_with_derivatives(x, yprime, yprime2);
810 virtual void get_sampling_grid(float_type amin, float_type amax, std::vector<float_type> &grid)
const
812 if(!
func.valid())
throw c2_exception(
"c2_plugin_function_p called uninitialized");
814 else func->get_sampling_grid(amin, amax, grid);
839 {
return this->
func.get(); }
852 if(
stub)
throw c2_exception(
"attempt to evaluate a c2_binary_function stub");
853 return this->
combine(*
Left.get_ptr(), *
Right.get_ptr(), x, yprime, yprime2);
867 float_type x, float_type *yprime, float_type *yprime2),
881 float_type x, float_type *yprime, float_type *yprime2)
886 float_type x, float_type *yprime, float_type *yprime2);
917 float_type y=this->
func->value_with_derivatives(x, yprime, yprime2);
918 if(yprime) (*yprime)*=
yscale;
919 if(yprime2) (*yprime2)*=
yscale;
951 y=this->
func->value_with_derivatives(x, &
yp, &
ypp);
955 if(yprime) *yprime=
yp;
956 if(yprime2) *yprime2=
ypp;
987 float_type x, float_type *yprime, float_type *yprime2)
throw(
c2_exception)
990 if(yprime || yprime2) {
991 float_type yp0, ypp0, yp1, ypp1;
992 y0=
right.value_with_derivatives(x, &yp0, &ypp0);
993 y1=
left.value_with_derivatives(y0, &yp1, &ypp1);
994 if(yprime) *yprime=yp1*yp0;
995 if(yprime2) *yprime2=ypp0*yp1+yp0*yp0*ypp1;
1018 float_type x, float_type *yprime, float_type *yprime2)
throw(
c2_exception)
1021 if(yprime || yprime2) {
1022 float_type yp0, ypp0, yp1, ypp1;
1023 y0=
left.value_with_derivatives(x, &yp0, &ypp0);
1024 y1=
right.value_with_derivatives(x, &yp1, &ypp1);
1025 if(yprime) *yprime=yp0+yp1;
1026 if(yprime2) *yprime2=ypp0+ypp1;
1050 float_type x, float_type *yprime, float_type *yprime2)
throw(
c2_exception)
1053 if(yprime || yprime2) {
1054 float_type yp0, ypp0, yp1, ypp1;
1055 y0=
left.value_with_derivatives(x, &yp0, &ypp0);
1056 y1=
right.value_with_derivatives(x, &yp1, &ypp1);
1057 if(yprime) *yprime=yp0-yp1;
1058 if(yprime2) *yprime2=ypp0-ypp1;
1082 float_type x, float_type *yprime, float_type *yprime2)
throw(
c2_exception)
1085 if(yprime || yprime2) {
1086 float_type yp0, ypp0, yp1, ypp1;
1087 y0=
left.value_with_derivatives(x, &yp0, &ypp0);
1088 y1=
right.value_with_derivatives(x, &yp1, &ypp1);
1089 if(yprime) *yprime=y1*yp0+y0*yp1;
1090 if(yprime2) *yprime2=ypp0*y1+2.0*yp0*yp1+ypp1*y0;
1114 float_type x, float_type *yprime, float_type *yprime2)
throw(
c2_exception)
1117 if(yprime || yprime2) {
1118 float_type yp0, ypp0, yp1, ypp1;
1119 y0=
left.value_with_derivatives(x, &yp0, &ypp0);
1120 y1=
right.value_with_derivatives(x, &yp1, &ypp1);
1121 if(yprime) *yprime=(yp0*y1-y0*yp1)/(y1*y1);
1122 if(yprime2) *yprime2=(y1*y1*ypp0+y0*(2*yp1*yp1-y1*ypp1)-2*y1*yp0*yp1)/(y1*y1*y1);
1141 {
if(yprime) *yprime=0;
if(yprime2) *yprime2=0;
return value; }
1158 float_type (*xin)(float_type), float_type (*xinp)(float_type), float_type (*xinpp)(float_type), float_type (*xout)(float_type)
1178 float_type (*
const pIn)(float_type);
1184 float_type (*
const pOut)(float_type);
1187 virtual float_type
fIn(float_type x)
const {
return pIn(x); }
1193 virtual float_type
fOut(float_type x)
const {
return pOut(x); }
1199 static float_type
ident(float_type x) {
return x; }
1201 static float_type
one(float_type) {
return 1; }
1203 static float_type
zero(float_type) {
return 0; }
1205 static float_type
recip(float_type x) {
return 1.0/x; }
1246 template <
typename float_type>
1254 isIdentity(!(xx.fTransformed || yy.fTransformed)),
X(xx),
Y(yy) { }
1265 virtual float_type
evaluate(float_type xraw,
1266 float_type y, float_type yp0, float_type ypp0,
1267 float_type *yprime, float_type *yprime2)
const;
1402 bool lowerSlopeNatural, float_type lowerSlope,
1403 bool upperSlopeNatural, float_type upperSlope,
bool splined=
true
1415 std::vector<
std::pair<float_type, float_type> > &data,
1416 bool lowerSlopeNatural, float_type lowerSlope,
1417 bool upperSlopeNatural, float_type upperSlope,
bool splined=true
1418 ) throw(c2_exception);
1438 float_type amin, float_type amax, float_type abs_tol, float_type rel_tol,
1439 bool lowerSlopeNatural, float_type lowerSlope,
1440 bool upperSlopeNatural, float_type upperSlope
1441 ) throw(c2_exception);
1458 const
std::vector<float_type> &bincenters, const
c2_function<float_type> &binheights)
1459 throw(c2_exception);
1479 const
std::vector<float_type> &bins, const
std::vector<float_type> &binheights,
bool splined=true)
1480 throw(c2_exception);
1482 virtual float_type
value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const throw(c2_exception);
1497 void get_data(std::vector<float_type> &xvals, std::vector<float_type> &yvals)
const throw() ;
1506 std::vector<float_type> &xvals,
1507 std::vector<float_type> &yvals,
1508 std::vector<float_type> &y2vals)
const
1509 { xvals=
X; yvals=
F; y2vals=
y2; }
1578 bool lowerSlopeNatural, float_type lowerSlope,
1579 bool upperSlopeNatural, float_type upperSlope
1583 static bool comp_pair(std::pair<float_type,float_type>
const &i, std::pair<float_type,float_type>
const &j) {
return i.first<j.first;}
1670 { float_type q=std::sin(x);
if(yprime) *yprime=std::cos(x);
if(yprime2) *yprime2=-q;
return q; }
1676 virtual void get_sampling_grid(float_type amin, float_type amax, std::vector<float_type> &grid)
const;
1689 { float_type q=std::cos(x);
if(yprime) *yprime=-std::sin(x);
if(yprime2) *yprime2=-q;
return q; }
1703 float_type c=std::cos(x), ss=std::sin(x);
1705 float_type yp=1/(c*c);
1706 if(yprime) *yprime=yp;
if(yprime2) *yprime2=2*t*yp;
1721 {
if(yprime) *yprime=1.0/x;
if(yprime2) *yprime2=-1.0/(x*x);
return std::log(x); }
1734 { float_type q=std::exp(x);
if(yprime) *yprime=q;
if(yprime2) *yprime2=q;
return q; }
1747 { float_type q=std::sqrt(x);
if(yprime) *yprime=0.5/q;
if(yprime2) *yprime2=-0.25/(x*q);
return q; }
1763 if(yprime) *yprime=-y*q;
1764 if(yprime2) *yprime2=2*y*q*q;
1784 {
if(yprime) *yprime=1.0;
if(yprime2) *yprime2=0;
return x; }
1812 {
if(yprime) *yprime=
m;
if(yprime2) *yprime2=0;
return m*(x-
xint)+
intercept; }
1847 void reset(float_type x0, float_type y0, float_type xcoef, float_type x2coef) {
intercept=y0;
center=x0;
a=x2coef;
b=xcoef; }
1849 { float_type dx=x-
center;
if(yprime) *yprime=2*
a*dx+
b;
if(yprime2) *yprime2=2*
a;
return a*dx*dx+b*dx+
intercept; }
1879 void reset(float_type scale, float_type power) {
a=scale;
b=power; }
1881 { float_type q=
a*std::pow(x,
b-2);
if(yprime) *yprime=
b*q*x;
if(yprime2) *yprime2=
b*(
b-1)*q;
return q*x*x; }
1976 accumulated_histogram(
const std::vector<float_type>binedges,
const std::vector<float_type> binheights,
1977 bool normalize=
false,
bool inverse_function=
false,
bool drop_zeros=
true);
2007 bool auto_center, float_type y1);
2022 float_type x0, float_type y0, float_type yp0, float_type ypp0,
2023 float_type x2, float_type y2, float_type yp2, float_type ypp2,
2024 bool auto_center, float_type y1);
2034 bool auto_center, float_type y1);
2044 bool auto_center, float_type y1);
const c2_function< float_type > * func
c2_recip_p(float_type scale)
constructor.
interpolating_function_p< float_type > & load_random_generator_bins(const std::vector< float_type > &bins, const std::vector< float_type > &binheights, bool splined=true)
initialize from a grid of points and an std::vector of probability densities (un-normalized) to an in...
create a non-generic container for a c2_function which handles the reference counting.
float_type operator()(float_type x) const
evaluate the function in the classic way, ignoring derivatives.
const std::string cvs_file_vers() const
get versioning information for the source file
void reset(float_type scale)
set a new scale factor
c2_typed_ptr(c2_class< float_type > &f)
construct the container with a pre-defined function
bool ypbad
flag, filled in by c2_function::fill_fblock(), indicating the derivative is NaN of Inf ...
bool stub
if true, we don't own any functions, we are just a source of a combining function.
log_log_interpolating_function_p()
an empty log-log cubic-spline interpolating_function_p
c2_plugin_function_p(c2_function< float_type > &f)
construct the container with a pre-defined function
c2_linear_p(float_type x0, float_type y0, float_type slope)
Construct the operator f=y0 + slope * (x-x0)
void reset(float_type x0, float_type y0, float_type xcoef, float_type x2coef)
Modify the coefficients after construction.
void set_start_hint(float_type hint) const
give the function a hint as to where to look for its inverse
interpolating_function_p< float_type > & multiply_pointwise(const c2_function< float_type > &rhs) const
produce a newly resampled interpolating_function_p which is the specified product.
c2_piecewise_function_p()
construct the container
c2_function< float_type > * operator->() const
get a checked pointer to our owned function
virtual void get_sampling_grid(float_type amin, float_type amax, std::vector< float_type > &grid) const
return a grid dynamically, suitable for use with trig functions with period 2*pi
void get_internal_data(std::vector< float_type > &xvals, std::vector< float_type > &yvals, std::vector< float_type > &y2vals) const
retrieve copies of the transformed x, y and y2 tables from which this was built
static float_type combine(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
execute math necessary to do subtraction
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
function to manage the binary operation, used by c2_binary_function::value_with_derivatives() ...
create a c2_function which is the ratio of two other c2_functions.This should always be constructed u...
Create a very lightweight method to return a scalar multiple of another function. \ \The factory func...
a container into which any conventional c-style function can be dropped, to create a degenerate c2_fu...
const c2_const_ptr< float_type > Left
c2_ptr(const c2_ptr< float_type > &src)
copy constructor
compute tan(x) with its derivatives.The factory function c2_factory::tan() creates *new c2_tan_p ...
interpolating_function_p< float_type > & add_pointwise(const c2_function< float_type > &rhs) const
produce a newly resampled interpolating_function_p which is the specified sum.
float_type ypp
the second derivative at x
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
create the formal inverse function of another functionfor example, given a c2_function f ...
c2_const_plugin_function_p(const c2_function< float_type > &f)
construct the container with a pre-defined function
c2_const_ptr< float_type > sampler_function
c2_quadratic_p(float_type x0, float_type y0, float_type xcoef, float_type x2coef)
Construct the operator.
void claim_ownership() const
increment our reference count. Destruction is only legal if the count is zero.
std::vector< float_type > * xvals
c2_diff_p(const c2_function< float_type > &left, const c2_function< float_type > &right)
construct left - right
std::vector< float_type > y2
create a c2_function which is the difference of two other c2_functions.This should always be construc...
size_t get_evaluations() const
this is a counter owned by the function but which can be used to monitor efficiency of algorithms...
virtual float_type value_with_derivatives(float_type, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
create a linear mapping of another functionfor example, given a c2_function f
virtual ~c2_connector_function_p()
destructor
c2_ratio_p< float_type > & operator/(const c2_function< float_type > &rhs) const
factory function to create a c2_ratio_p from a regular algebraic expression.
const c2_const_ptr< float_type > Right
create a container for a c2_function which handles the reference counting.
A spline with X in reciprocal space and Y transformed in log space.Most useful for thermodynamic type...
c2_fblock< float_type > * f1
void preen_sampling_grid(std::vector< float_type > *result) const
clean up endpoints on a grid of points
interpolating_function_p< float_type > & divide_pointwise(const c2_function< float_type > &rhs) const
produce a newly resampled interpolating_function_p which is the specified ratio.
float_type(*const combine)(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
c2_function< float_type > & normalized_function(float_type amin, float_type amax, float_type norm=1.0) const
create a new c2_function from this one which is normalized on the interval
c2_diff_p< float_type > & operator-(const c2_function< float_type > &rhs) const
factory function to create a c2_diff_p from a regular algebraic expression.
virtual const char * what() const
Returns a C-style character string describing the general cause of the current error.
c2_function< float_type > & square_normalized_function(float_type amin, float_type amax, float_type norm=1.0) const
create a new c2_function from this one which is square-normalized on the interval ...
interpolating_function_p< float_type > & subtract_pointwise(const c2_function< float_type > &rhs) const
produce a newly resampled interpolating_function_p which is the specified difference.
c2_const_plugin_function_p()
construct the container with no function
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
c2_fblock< float_type > upper
interpolating_function_p(const c2_function_transformation< float_type > &transform)
an empty cubic-spline interpolating_function_p with a specific transform
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
c2_ratio_p()
Create a stub just for the combiner to avoid statics.
interpolating_function_p< float_type > & load(const std::vector< float_type > &x, const std::vector< float_type > &f, bool lowerSlopeNatural, float_type lowerSlope, bool upperSlopeNatural, float_type upperSlope, bool splined=true)
do the dirty work of constructing the spline from a function.
float_type get_trouble_point() const
Find out where a calculation ran into trouble, if it got a nan. If the most recent computation did no...
c2_diff_p< float_type > & operator-(const c2_function< float_type > &rhs) const
factory function to create a c2_diff_p from a regular algebraic expression.
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
virtual void get_sampling_grid(float_type amin, float_type amax, std::vector< float_type > &grid) const
return the grid of 'interesting' points along this function which lie in the region requested ...
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
c2_fblock< float_type > f1
c2_cached_function_p(const c2_function< float_type > &f)
construct the container
virtual ~c2_piecewise_function_p()
destructor
static float_type combine(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
execute math necessary to do composition
compute cos(x) with its derivatives.The factory function c2_factory::cos() creates *new c2_cos_p ...
c2_classic_function_p(const float_type(*c_func)(float_type))
construct the container
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
compute exp(x) with its derivatives.The factory function c2_factory::exp() creates *new c2_exp_p ...
c2_piecewise_function_p< float_type > * out
virtual void get_sampling_grid(float_type amin, float_type amax, std::vector< float_type > &grid) const
return the grid of 'interesting' points along this function which lie in the region requested ...
const c2_function< float_type > * operator->() const
get a checked pointer to our owned function
float_type integrate_step(struct c2_integrate_recur &rb) const
Carry out the recursive subdivision and integration.
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer
c2_class< float_type > * operator->() const
get a checked pointer to our owned function
c2_constant_p(float_type x)
float_type partial_integrals(std::vector< float_type > xgrid, std::vector< float_type > *partials=0, float_type abs_tol=1e-12, float_type rel_tol=1e-12, int derivs=2, bool adapt=true, bool extrapolate=true) const
for points in xgrid, adaptively return Integral[f(x),{x,xgrid[i],xgrid[i+1]}] and return in vector...
interpolating_function_p< float_type > & load_pairs(std::vector< std::pair< float_type, float_type > > &data, bool lowerSlopeNatural, float_type lowerSlope, bool upperSlopeNatural, float_type upperSlope, bool splined=true)
do the dirty work of constructing the spline from a function.
static float_type combine(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
execute math necessary to do multiplication
c2_product_p< float_type > & operator*(const c2_function< float_type > &rhs) const
factory function to create a c2_product_p from a regular algebraic expression.
std::vector< float_type > F
c2_plugin_function_p()
construct the container with no function
bool check_monotonicity(const std::vector< float_type > &data, const char message[]) const
check that a vector is monotonic, throw an exception if not, and return a flag if it is reversed ...
virtual ~c2_const_plugin_function_p()
destructor
c2_function(const c2_function< float_type > &src)
interpolating_function_p< float_type > & binary_operator(const c2_function< float_type > &rhs, const c2_binary_function< float_type > *combining_stub) const
create a new interpolating_function_p which is the parent interpolating_function_p combined with rhs ...
std::vector< float_type > * get_sampling_grid_pointer() const
get the sampling grid, which may be a null pointer
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
virtual interpolating_function_p< float_type > & clone() const
create a new, empty interpolating function of this type (virtual constructor)
void set_hinting_function(const c2_function< float_type > *hint_func)
set or unset the approximate function used to start the root finder
virtual void set_sampling_grid(const std::vector< float_type > &grid)
establish a grid of 'interesting' points on the function.
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
size_t release_ownership_for_return() const
decrement our reference count. Do not destroy at zero.
A spline with X and Y transformed into log space.Most useful for functions looking like y=x^n or any ...
compute scale/x with its derivatives.The factory function c2_factory::recip() creates *new c2_recip_p...
void spline(bool lowerSlopeNatural, float_type lowerSlope, bool upperSlopeNatural, float_type upperSlope)
create the spline coefficients
void reset(float_type scale)
reset the scale factor
c2_sum_p(const c2_function< float_type > &left, const c2_function< float_type > &right)
construct left + right
const c2_function_transformation< float_type > & fTransform
create a cubic spline interpolation of a set of (x,y) pairsThis is one of the main reasons for c2_fun...
log_lin_interpolating_function_p()
an empty log-linear cubic-spline interpolating_function_p
bool valid() const
check if we have a valid function
A spline with X transformed into log space.Most useful for functions looking like y=log(x) or any oth...
void set_hinting_function(const c2_const_ptr< float_type > hint_func)
set the hinting function from a pointer.
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
A container into which any other c2_function can be dropped.It allows a function to be pre-evaluated ...
c2_ptr()
construct the container with no function
structure used to hold evaluated function data at a point.
create a quadratic mapping of another functionfor example, given a c2_function f
void reset(float_type x0, float_type y0, float_type slope)
Change the slope and intercepts after construction.
a c2_plugin_function_p which promises not to fiddle with the plugged function.The factory function c2...
c2_piecewise_function_p< float_type > * adaptively_sample(float_type amin, float_type amax, float_type abs_tol=1e-12, float_type rel_tol=1e-12, int derivs=2, std::vector< float_type > *xvals=0, std::vector< float_type > *yvals=0) const
create a c2_piecewise_function_p from c2_connector_function_p segments which is a representation of t...
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
void append_function(const c2_function< float_type > &func)
append a new function to the sequence
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
void set_function(c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer and copy our domain ...
compute x with its derivatives.The factory function c2_factory::identity() creates *new c2_identity_p...
void set_upper_extrapolation(float_type bound)
enable extrapolation of the function above the tabulated data.
c2_const_ptr(const c2_const_ptr< float_type > &src)
copy constructor
void set_domain(float_type amin, float_type amax)
set the domain for this function.
create a c2_function which is the product of two other c2_functions.This should always be constructed...
virtual interpolating_function_p< float_type > & clone() const
create a new, empty interpolating function of this type (virtual constructor)
c2_binary_function(float_type(*combiner)(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2), const c2_function< float_type > &left, const c2_function< float_type > &right)
construct the binary function
virtual ~c2_function()
destructor
structure used to hold root bracketing information
void release_for_return()
release the function without destroying it, so it can be returned from a function ...
std::vector< float_type > X
const c2_const_ptr< float_type > func
const c2_const_ptr< float_type > & operator=(const c2_const_ptr< float_type > &f)
fill the container from another container
std::vector< recur_item > * rb_stack
a container into which any other c2_function can be dropped, to allow expressions with replacable com...
const c2_function< float_type > & get() const
get a reference to our owned function
c2_product_p()
Create a stub just for the combiner to avoid statics.
float_type yp
the derivative at x
structure used to pass information recursively in integrator.
create a container for a c2_function which handles the reference counting.It is useful as a smart con...
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
std::vector< float_type > Xraw
const c2_const_ptr< float_type > func
const float_type(* func)(float_type)
pointer to our function
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
interpolating_function_p< float_type > & sample_function(const c2_function< float_type > &func, float_type amin, float_type amax, float_type abs_tol, float_type rel_tol, bool lowerSlopeNatural, float_type lowerSlope, bool upperSlopeNatural, float_type upperSlope)
do the dirty work of constructing the spline from a function.
const std::string cvs_header_vers() const
get versioning information for the header file
the exception class for c2_function operations.
float_type integral(float_type amin, float_type amax, std::vector< float_type > *partials=0, float_type abs_tol=1e-12, float_type rel_tol=1e-12, int derivs=2, bool adapt=true, bool extrapolate=true) const
a fully-automated integrator which uses the information provided by the get_sampling_grid() function ...
void sample_step(struct c2_sample_recur &rb) const
Carry out the recursive subdivision for sampling.
float_type find_root(float_type lower_bracket, float_type upper_bracket, float_type start, float_type value, int *error=0, float_type *final_yprime=0, float_type *final_yprime2=0) const
solve f(x)==value very efficiently, with explicit knowledge of derivatives of the function ...
const c2_function< float_type > * get_ptr() const
get an unchecked pointer to our owned function
c2_sum_p()
Create a stub just for the combiner to avoid statics.
create a c2_function which smoothly connects two other c2_functions.This takes two points and generat...
bool yppbad
flag, filled in by c2_function::fill_fblock(), indicating the second derivative is NaN of Inf ...
std::vector< c2_const_ptr< float_type > > functions
the parent class for all c2_functions.
arrhenius_interpolating_function_p()
an empty arrhenius cubic-spline interpolating_function_p
create a c2_function which is a piecewise assembly of other c2_functions.The functions must have incr...
c2_typed_ptr(const c2_typed_ptr< float_type, c2_class > &src)
copy constructor
T max(const T t1, const T t2)
brief Return the largest of the two arguments
c2_const_ptr(const c2_function< float_type > &f)
construct the container with a pre-defined function
c2_exception(const char msgcode[])
construct the exception with an error message
the data element for the internal recursion stack for the sampler and integrator
c2_diff_p()
Create a stub just for the combiner to avoid statics.
interpolating_function_p< float_type > & unary_operator(const c2_function< float_type > &source) const
create a new interpolating_function_p which is the source function applied to every point in the inte...
c2_ratio_p(const c2_function< float_type > &left, const c2_function< float_type > &right)
construct left / right
structure used to pass information recursively in sampler.
c2_class< float_type > * get_ptr() const
get an unchecked pointer to our owned function
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
A spline with Y transformed into log space.Most useful for functions looking like y=exp(x) ...
c2_product_p< float_type > & operator*(const c2_function< float_type > &rhs) const
factory function to create a c2_product_p from a regular algebraic expression.
c2_power_law_p(float_type scale, float_type power)
Construct the operator.
float_type operator()(float_type x, float_type *yprime, float_type *yprime2) const
convenience operator to make us look like a function
c2_binary_function(float_type(*combiner)(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2))
construct a 'stub' c2_binary_function, which provides access to the combine() function ...
c2_scaled_function_p(const c2_function< float_type > &outer, float_type scale)
construct the function with its scale factor.
virtual interpolating_function_p< float_type > & clone() const
create a new, empty interpolating function of this type (virtual constructor)
~c2_const_ptr()
destructor
c2_ptr< float_type > func
const c2_const_ptr< float_type > func
the scaling factor for the function
c2_sum_p< float_type > & operator+(const c2_function< float_type > &rhs) const
factory function to create a c2_sum_p from a regular algebraic expression.
c2_product_p(const c2_function< float_type > &left, const c2_function< float_type > &right)
construct left * right
c2_const_ptr()
construct the container with no function
An interpolating_function_p which is the cumulative integral of a histogram.
std::vector< recur_item > * rb_stack
virtual float_type get_start_hint(float_type x) const
get the starting hint.
size_t count_owners() const
get the reference count, mostly for debugging
virtual interpolating_function_p< float_type > & clone() const
create a new, empty interpolating function of this type (virtual constructor)
lin_log_interpolating_function_p()
an empty linear-log cubic-spline interpolating_function_p
c2_fblock< float_type > * f0
c2_fblock< float_type > * f0
float_type y
the value of the function at x
c2_connector_function_p(float_type x0, const c2_function< float_type > &f0, float_type x2, const c2_function< float_type > &f2, bool auto_center, float_type y1)
construct the container from two functions
void operator=(const c2_typed_ptr< float_type, c2_class > &f)
fill the container from another container
accumulated_histogram(const std::vector< float_type >binedges, const std::vector< float_type > binheights, bool normalize=false, bool inverse_function=false, bool drop_zeros=true)
Construct the integrated histogram.
void reset(float_type val)
virtual ~c2_plugin_function_p()
destructor
static float_type combine(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
execute math necessary to do addition
void refine_sampling_grid(std::vector< float_type > &grid, size_t refinement) const
refine a grid by splitting each interval into more intervals
c2_function< float_type > * get_ptr() const
get an unchecked pointer to our owned function
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
static PROLOG_HANDLER error
std::vector< float_type > * sampling_grid
compute sqrt(x) with its derivatives.The factory function c2_factory::sqrt() creates *new c2_sqrt_p()...
interpolating_function_p< float_type > & load_random_generator_function(const std::vector< float_type > &bincenters, const c2_function< float_type > &binheights)
initialize from a grid of points and a c2_function (un-normalized) to an interpolator which...
virtual ~c2_binary_function()
destructor releases ownership of member functions
c2_ratio_p< float_type > & operator/(const c2_function< float_type > &rhs) const
factory function to create a c2_ratio_p from a regular algebraic expression.
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
void increment_evaluations() const
count evaluations
Provides function composition (nesting)This allows evaluation of f(g(x)) where f and g are c2_functio...
float_type bad_x_point
this point may be used to record where a calculation ran into trouble
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const =0
get the value and derivatives.
create a c2_function which is the sum of two other c2_function objects.This should always be construc...
struct c2_root_info * root_info
this carry a memory of the last root bracketing, to avoid the necessity of evaluating the function on...
void release_ownership() const
decrement our reference count. If the count reaches zero, destroy ourself.
void clone_data(const interpolating_function_p< float_type > &rhs)
copy data from another interpolating function. This only makes sense if the source function has the s...
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
void fill_fblock(c2_fblock< float_type > &fb) const
fill in a c2_fblock... a shortcut for the integrator & sampler
std::vector< float_type > * yvals
float_type operator()(float_type x) const
convenience operator to make us look like a function
virtual interpolating_function_p< float_type > & clone() const
create a new, empty interpolating function of this type (virtual constructor)
float_type xmax() const
return the upper bound of the domain for this function as set by set_domain()
c2_composed_function_p(const c2_function< float_type > &outer, const c2_function< float_type > &inner)
construct outer( inner (x))
c2_composed_function_p()
Create a stub just for the combiner to avoid statics.
void reset_evaluations() const
reset the counter
void set_lower_extrapolation(float_type bound)
enable extrapolation of the function below the tabulated data.
c2_identity_p()
constructor.
void reset(float_type scale, float_type power)
Modify the mapping after construction.
compute sin(x) with its derivatives.The factory function c2_factory::sin() creates *new c2_sin_p ...
interpolating_function_p()
an empty linear-linear cubic-spline interpolating_function_p
void unset_function()
clear our function
const c2_ptr< float_type > & operator=(const c2_ptr< float_type > &f)
fill the container from another container
c2_const_ptr< float_type > hinting_function
virtual float_type value_with_derivatives(float_type x, float_type *yprime, float_type *yprime2) const
get the value and derivatives.
float_type xmin() const
return the lower bound of the domain for this function as set by set_domain()
void init(const c2_fblock< float_type > &fb0, const c2_fblock< float_type > &fb2, bool auto_center, float_type y1)
fill container numerically
virtual ~c2_classic_function_p()
c2_typed_ptr()
construct the container with no function
c2_fblock< float_type > lower
c2_ptr(c2_function< float_type > &f)
construct the container with a pre-defined function
create a power law mapping of another functionfor example, given a c2_function f
Provides support for c2_function objects which are constructed from two other c2_function objects...
virtual void set_sampling_grid_pointer(std::vector< float_type > &grid)
void get_data(std::vector< float_type > &xvals, std::vector< float_type > &yvals) const
retrieve copies of the x & y tables from which this was built
a c2_function which is constantThe factory function c2_factory::constant() creates *new c2_constant_p...
static bool comp_pair(std::pair< float_type, float_type > const &i, std::pair< float_type, float_type > const &j)
float_type previous_estimate
void unset_function(void)
clear the function
static float_type combine(const c2_function< float_type > &left, const c2_function< float_type > &right, float_type x, float_type *yprime, float_type *yprime2)
execute math necessary to do division
compute log(x) with its derivatives.The factory function c2_factory::log() creates *new c2_log_p ...
c2_fblock< float_type > * f1
void set_function(const c2_function< float_type > *f)
fill the container with a new function, or clear it with a null pointer