lgamma(float x)
logarithm of gamma function
atan2(float y, float x)
return angle of point (x,y) with origin. Result is between -PI and PI (inclusive).
dfermi(float x)
derivative of fermi function
dtanh(float x)
derivative of tanh function
argmax(float a, float b, float f(float), int steps=10)
argmin(float a, float b, float f(float), int steps=10)
find location of maximum (minimum) of f() in [a,b]. If there is no local extremum, either a or b (whatever is more appropriate) is returned.
In both cases, there is no guarantee that the location of the global extremum in [a,b] is found. Instead, the routines subdivide [a,b] into steps equal-sized subintervals and start the minimum search at the subdivision point where f() is maximal (minimal). Therefore, large values of steps increase the chances that the global extremum will be found.
argmax(.float *vec, int stride=1)
argmin(.float *vec, int stride=1)
the analog functions for locating the maximal (minimal) element of a vector. Return value is the index of that element. In this case, the global extremum, of course, is found (in case of several that with the smallest index is picked). The last parameter permits to restrict the calculation to a subset of the vector elements spaced at stride stride.

Coloring a data array:

void colorize(float *data, byte *rgb, char *options=NULL):
fill rgb with a colored display of array data. Array data is taken to consist of n concatenated subvectors v[] of d elements each ( n=dimof(rgb)/3 is the number of pixels). From each subvector, up to three elements can be selected (by their relative offset i to the start of the block) to determine the color of the associated pixel. The details of the coloring are specified with directives in options as follows:
%a:b:iH:
use v[i] as hue value
%a:b:iS:
use v[i] as saturation value
%a:b:iI:
use v[i] as intensity value
%a:b:iR:
use v[i] as red intensity
%a:b:iG:
use v[i] as green intensity
%a:b:iB:
use v[i] as blue intensity In all these cases, the optional parameters a and b determine the data range [a..b] that becomes mapped to the available range of the chosen color parameter (outside values are clipped). If a is omitted, a=0 is assumed. If both a and b are omitted, the proper range [a..b] will be taken as the smallest interval that encloses the data v[i]. NOT YET IMPLEMENTED: To exclude a percentage of p/2 outliers at both ends of the range, specify a=b=p instead (with p in [0..100]).
It is assumed that either only the first or the last three directives are used (the result is undefined, if both are mixed). The full hue range is a rainbow sequence traversing a closed path on the RGB color cube connecting the points 0 = blue->cyan->green->yellow->red->magenta->blue = 1. The saturation and intensity ranges are both [0..1] (white->full saturation and black->full intensity). Option %a:b:c:dP ("color pie") can be used to configure a subrange of the full color space as the target range: [a..b] selects a subpath from the hue cycle (for HSI, defaults are a=-0.05 [blue],b=0.75 [red], for RGB the defaults are always 0 and 1). c and d (defaults 0,0) permit to set min values for saturation and intensity. If only one parameter is specified, it is taken as b, two and more as a,b,[c,d].

Sorting blocks of a vector:

void qsort(float *vec, int blockdim, float (*cmp)(float*,float*), int gap=0):
(analogous to C stdlib qsort() function) consider vector vec as consisting of blocks of length blockdim (optionally separated by gaps of width gap). Rearrange these blocks in increasing order. Here, order is defined by the user-supplied comparison function cmp(a,b) which is called with pointers to block pairs (i.e., vectors of blockdim elements) and which must return a positive value, if a<b, zero if a==b and a negative value otherwise. If gaps are defined, the rearranged parts always consist of a block together with the adjacent (towards higher index positions) gap.
void qsort(float *vec, int blockdim, float (*val)(float*), int gap=0):
similar as before, but now sorting is simply according to the scalar value returned by the single-argument function val(), which will be called once for each block.
void qsort(float *vec, int blockdim, int offset=0):
similar as before, but instead of a user-supplied val() function sorting now simply uses for each block the value block[offset] of the offset-th block element (note that in this case there is no need to define any gaps).
In all three functions, sorting order can be controlled with the sign of blockdim: blockdim>0 yields ascending, blockdim<0 descending sorting order.

Solving Differential Equations:

class diffeqn(int d, char *options)
solving differential equation for d-dimensional state space. Uses 4-th order step-size controlled Runge-Kutta scheme (default) or 2nd order step-size controlled modified midpoint rule (option %M). Truncation error scales as O(power(step size,order+1)).
String options can contain:
%V or %cV:
set verbose level of diagnostics to c. c=0 silences all diagnostics. c=1 sends diagnostics to stderr. c=2 sends diagnostics to a pop-up window. %V chooses the built-in default (currently equivalent to c=1);
%M:
choose step-size controlled modified midpoint rule (truncation order is 3) instead of step-size controlled Runge-Kutta method (truncation order is 5). Depending on the smoothness of F and the requested precision, %M can be up to twice as fast as Runge-Kutta.

Variables:

float x[d]
current value of state vector (must be initialized with starting value).
float t
current value of integration parameter. (default is t=0)
float dt
step size parameter (default is dt=0.1)
float dt0
minimum allowed step size (default is 0.001, zero is permitted)
float eps
required accuracy (default is eps=0.001)
int nok,nbad
nr of good (nok) and bad (nbad) steps

Methods:

void timestep(F(float,float*,float*))
integrate differential equation from current state x(t) to future state x(t1=t+dt) and replace x and t by their new values. Internally, dt will be subdivided into smaller steps, if the requested accuracy requires so. However, the internal steps are not permitted to get smaller than dt0.
Function F(t,x,y) is passed to compute vector y of derivatives from current time t and state vector x. F() can be either of return type void or float. In the latter case, a negative return value of F() can be used to stop integration (and trigger immediate return to the caller level) when the state vector x has entered a forbidden domain (a non-negative return value will continue normal integration; the magnitude of the value is unimportant).
int trajectory(F(float,float*,float*), float *result, int stride=0)
fill trajectory with result from n=dimof(result)/MAX(stride,d)-1 repeated calls of timestep. The first d values of result will be filled with the initial state vector, the remaining n blocks of length MAX(stride,d) will be filled (from the left) with the computed state vectors. Return value is n, the number of time intervals progressed, or -1, if dimof(result)<stride (in which case nothing is stored). Function (void|float) F() is as described before.
convolve(int dx, float *inp, float *out, float *msk)
convolution of input image inp of width dx with square mask msk. Result is written into out.
convolve(int dx, float *inp, float *out, int m, float *msk)
dito, but convolution with square mask msk of width and height 2*m+1.
convolve(int dx, float *inp, float *out, float *xmsk, float *ymsk)
dito, but convolution with separable mask given by xmsk and ymsk.
convolve(int dx, float *inp, float *out, float sig, float fscale=1)
dito, but convolution with gaussian of standard deviation sig and optional scaling factor fscale.
Algorithm of all convolve functions is naive (i.e., non-FFT) multiply+add convolution. The case of a separable mask is treated as 2 successive 1D convolutions, which is rather fast.
laplacian(int dx,dy, float *vec, *result, int nonperiodic=0):
compute the discrete laplacian (pointwise north+south+east+west-4*center) of a rectangle vec holding data for a dx x dy sized rectangle and deposit the result in result. The dimensions of vec and result may be an integral multiple m of dx*dy, in which case vec and result are considered as grids with m-long data blocks per grid point. The last argument parameter allows to enforce various nonperiodic boundary conditions. Currently, any non-zero value makes the boundary conditions non-periodic in both directions.

CLASSES:

class grid_iterator(int dim))
simple grid iterator class
class grid_iterator(int nx, ny, ..)
simple grid iterator class

Methods:

void set_limits(float xmin, xmax,...)
void set_points(int nx, ..)
void set_points(float *pnts, int gap=0)
float *for_points(void f(float *in, float *out), float *result, int stride=1)
iterate function f with first arg successively set to the grid point locations and last arg set to result+num*stride, where num is the linear count of the current grid point. Depending on how f fills its result vector out, this permits many ways of filling the result vector while avoiding redundant copyings. If result=NULL, the routine will allocate a suitable sized vector and return it, otherwise the return value is NULL and the provided result buffer is used.

FILE

/local/homes/rhaschke/nst7/man/../o.linx86_64//../nstsrc/nst_prog_libs.c