![]() |
MAOS
Multithreaded Adaptive Optics Simulator
|
Macros | |
| #define | AOS_LIB_TYPE |
| #define | AOS_SMAT(A) |
Typedefs | |
| typedef float(* | sminsearch_fun) (const float *x, void *info) |
Functions | |
| smat * | snew (long nx, long ny) |
| smat * | snew_file (long nx, long ny, const char *keywords, const char *format,...) |
| smat * | snew_do (long nx, long ny, float *p, mem_t *mem) |
| smat * | smat_cast (const_anyarray A) |
| int | sinit (smat **A, long nx, long ny) |
| void | sfree_content (smat *A) |
| void | sfree_do (smat *A) |
| smat * | sref (const smat *in) |
| smat * | sref_reshape (const smat *in, long nx, long ny) |
| smat * | srefcols (const smat *in, long icol, long ncol) |
| void | scols (smat *out, const smat *in, long icol, long ncol) |
| int | sresize (smat *A, long nx, long ny) |
| smat * | ssub (const smat *in, long sx, long nx, long sy, long ny) |
| smat * | scat (const smat *in1, const smat *in2, int dim) |
| smat * | sdup (const smat *in) |
| void | szero (smat *A) |
| int | szerocol (smat *A, int icol) |
| uint32_t | shash (const smat *A, uint32_t key) |
| void | scp (smat **out0, const smat *in) |
| smat * | strans (const smat *A) |
| void | sset (smat *A, const float val) |
| void | sshow (const smat *A, const char *format,...) |
| void | sshow_diag (const smat *A, const char *format,...) |
| void | svecperm (smat *out, const smat *in, const long *perm) |
| void | svecpermi (smat *out, const smat *in, const long *perm) |
| int | sflip (smat *A, int axis) |
| float | svecsum (const float *__restrict p, long np) |
| float | ssum (const smat *A) |
| void | snormalize_sum (smat *A, float sum) |
| normalize the sum of A to sum. | |
| void | snormalize_sumabs (smat *A, float sum) |
| normalize the sum of abs(A) to sum. | |
| float | smean (const smat *A) |
| float | strace (const smat *A) |
| void | ssort (smat *A, int ascend) |
| void | svecmaxmin (const float *__restrict p, long N, float *max, float *min) |
| float | svecdot (const float *__restrict p1, const float *__restrict p2, const float *__restrict p3, long n) |
| void | svecnormalize_sum (float *__restrict p, long nloc, float norm) |
| void | svecnormalize_sumabs (float *__restrict p, long nloc, float norm) |
| float | svecmaxabs (const float *__restrict p, long n) |
| void | smaxmin (const smat *A, float *max, float *min) |
| float | smax (const smat *A) |
| float | smaxabs (const smat *A) |
| float | smin (const smat *A) |
| float | ssumabs (const smat *in) |
| float | ssumsq (const smat *in) |
| float | ssumdiffsq (const smat *A, const smat *B) |
| smat * | sunique (const smat *input, int ascend) |
| Find unique values and sort from small to large. | |
| void | sfftshift (smat *A) |
| int | scpcorner2center (smat *A, const smat *B) |
| int | sshift (smat **B0, const smat *A, int sx, int sy) |
| scell * | scell_cast (const cell *A) |
| scell * | scellnew2 (const scell *A) |
| scell * | scellnew3 (long nx, long ny, long *nnx, long *nny) |
| scell * | scellnew_same (long nx, long ny, long mx, long my) |
| scell * | scellnew_file (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...) |
| scell * | scellnewsame_file (long nx, long ny, long mx, long my, const char *keywords, const char *format,...) |
| void | scellzero (scell *dc) |
| void | scellset (scell *dc, float alpha) |
| scell * | scelltrans (const scell *A) |
| scell * | scellref (const scell *in) |
| scell * | scelldup (const scell *in) |
| void | scellcp (scell **out0, const scell *in) |
| scell * | scellreduce (const scell *A, int dim) |
| scell * | scellcat (const scell *A, const scell *B, int dim) |
| void | scellcat2 (scell **A, const scell *B, int dim) |
| scell * | scellcat_each (const scell *A, const scell *B, int dim) |
| scell * | s2cellref (const smat *A, long *dims, long ndim) |
| void | s2cell (scell **B, const smat *A, const scell *ref) |
| smat * | scell_col (scell *input, long icol) |
| float | scellsum (const scell *A) |
| smat * | scellsum_each (const scell *A) |
| int | sisnan (const smat *A) |
| float | snorm (const smat *in) |
| float | sstd (const smat *in) |
| void | srandu (smat *A, const float mean, rand_t *rstat) |
| void | srandn (smat *A, const float sigma, rand_t *rstat) |
| void | sscale (smat *A, float w) |
| float | sdot (const smat *A, const smat *B) |
| float | swdot (const float *a, const smat *w, const float *b) |
| void | scwm (smat *A, const smat *B) |
| void | scwm2 (smat *A, const smat *B1, float wt1, const smat *B2, float wt2) |
| void | scwm3 (smat *__restrict A, const smat *__restrict W, const smat *__restrict B1, const float wt1, const smat *__restrict B2, const float wt2) |
| void | scwmcol (smat *__restrict A, const smat *__restrict B) |
| void | scwmrow (smat *__restrict A, const smat *__restrict B) |
| void | scwdiv (smat *B, const smat *A, float value) |
| void | smulvec (float *__restrict y, const smat *__restrict A, const float *__restrict x, const float alpha) |
| void | smm (smat **C0, const float beta, const smat *A, const smat *B, const char trans[2], const float alpha) |
| void | smm3 (smat **pout, float beta, const smat *A, const smat *B, const smat *C, const char trans[4], float alpha) |
| Compute 3 matrix multipliation: out=out*alpha+beta*op(A)*op(B)*op(C). | |
| void | sinvspd_inplace (smat *A) |
| smat * | sinvspd (const smat *A) |
| void | sinv_inplace (smat *A) |
| smat * | sinv (const smat *A) |
| smat * | schol (const smat *A) |
| smat * | smcc (const smat *A, const smat *wt) |
| smat * | simcc (const smat *A, const smat *wt) |
| smat * | stmcc (const smat *A, const smat *wt) |
| smat * | spinv2 (const smat *A, const_anyarray W, float thres1, float thres2) |
| smat * | spinv (const smat *A, const_anyarray W) |
| Wrap dpinv2 with default parameters. | |
| float | sdiff (const smat *A, const smat *B) |
| int | scircle (smat *A, float cx, float cy, float dx, float dy, float r, float val) |
| int | srectangle (smat *A, float cx, float cy, float rx, float ry, float theta, float val) |
| void | srotvec (smat *A, const float theta) |
| void | srotvect (smat *A, const float theta) |
| void | srotvecnn (smat **B0, const smat *A, float theta) |
| void | smulvec3 (float *y, const smat *A, const float *x) |
| void | scorr (smat **corr, const smat *A, const smat *B) |
| void | spara3 (float *grad, const smat *corr) |
| void | scog (float *grad, const smat *i0, float offsetx, float offsety, float thres, float bkgrnd, float flux, const smat *mask) |
| void | sshift2center (smat *A, float offsetx, float offsety) |
| int | sclip (smat *A, float min, float max) |
| void | sgramschmidt (smat *Mod, float *amp) |
| void | smuldiag (smat *A, const smat *s) |
| void | scwpow (smat *A, float power) |
| void | scwexp (smat *A, float alpha) |
| void | scwpow_thres (smat *A, float power, float thres) |
| void | ssvd (smat **U, smat **Sdiag, smat **VT, const smat *A) |
| void | ssvd_cache (smat **U, smat **Sdiag, smat **VT, const smat *A) |
| void | ssvd_pow2 (smat *A, float power, float thres1, float thres2) |
| void | ssvd_pow (smat *A, float power) |
| Wrap svd_pow with default parameters. | |
| void | sexpm (smat **out, float alpha, const smat *A, float beta) |
| void | spolyval (smat *A, smat *p) |
| void | saddI (smat *A, float val) |
| void | sadd (smat **B0, float bc, const smat *A, const float ac) |
| void | sadd_relax (smat **B0, float bc, const smat *A, const float ac) |
| void | saddcol (smat *B, long icol, float bc, const smat *A, const float ac) |
| void | sadds (smat *A, const float ac) |
| smat * | slogspace (float emin, float emax, long n) |
| smat * | slinspace (float min, float dx, long n) |
| smat * | sinterp1 (const smat *xin, const smat *yin, const smat *xnew, float y0) |
| smat * | sinterp1_2 (const smat *xyin, const smat *xnew) |
| smat * | sinterp1linear (const smat *xin, const smat *yin, const smat *xnew, float y0) |
| smat * | sinterp1log (const smat *xin, const smat *yin, const smat *xnew, float y0) |
| void | sblend (smat *__restrict A, smat *__restrict B, int overlap) |
| void | shistfill (smat **out, const smat *A, float center, float spacing, int n) |
| smat * | sspline_prep (smat *x, smat *y) |
| smat * | sspline_eval (smat *coeff, smat *x, smat *xnew) |
| smat * | sspline (smat *x, smat *y, smat *xnew) |
| void | scwlog10 (smat *A) |
| void | scwlog (smat *A) |
| void | sembed (smat *__restrict A, const smat *__restrict B, const float theta) |
| void | sembedd (smat *__restrict A, const smat *__restrict B, const float theta) |
| float | sfwhm (smat *A) |
| void | sgauss_fit (float *mr, float *ma, float *mb, float *theta, float *amp, smat **img, smat *A, float thres) |
| float | sgauss_sigma (smat *A, float thres) |
| float | sfwhm_gauss (smat *A) |
| smat * | senc (const smat *A, const smat *dvec, int type, int nthread) |
| int | sminsearch (float *x, int nmod, float ftol, int nmax, sminsearch_fun fun, void *info) |
| void | sbessik (float x, float xnu, float *ri, float *rk, float *rip, float *rkp) |
| float | strapz (const smat *x, const smat *y) |
| float | scellnorm (const scell *in) |
| void | scellscale (anyarray A, float w) |
| void | scelldropempty (scell **A0, int dim) |
| float | scelldot (const scell *A, const scell *B) |
| void | scellcwm (scell *B, const scell *A) |
| scell * | scellinvspd (scell *A) |
| scell * | scellinv (scell *A) |
| scell * | scellinvspd_each (scell *A) |
| scell * | scellpinv2 (const scell *A, const_anyarray W, float thres1, float thres2) |
| scell * | scellpinv (const scell *A, const_anyarray W) |
| Wrap cellpinv2 with default parameters. | |
| void | scellsvd_pow2 (scell *A, float power, float thres1, float thres2) |
| void | scellsvd_pow (scell *A, float power) |
| wrap cellsvd_pow2. | |
| void | scellcwpow (scell *A, float power) |
| void | scelldropzero (scell *B, float thres) |
| float | scelldiff (const scell *A, const scell *B) |
| int | scellclip (scell *Ac, float min, float max) |
| scell * | scellsub (const scell *in, long sx, long nx, long sy, long ny) |
| scell * | sbspline_prep (smat *x, smat *y, smat *z) |
| smat * | sbspline_eval (scell *coeff, smat *x, smat *y, smat *xnew, smat *ynew) |
| void | smaprot (anyarray A_, real theta) |
| void | swritedata (file_t *fp, const smat *A, long ncol) |
| smat * | sreaddata (file_t *fp, header_t *header) |
| smat * | snew_mmap (long nx, long ny, const char *keywords, const char *format,...) |
| scell * | scellnew_mmap (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...) |
| scell * | scellnewsame_mmap (long nx, long ny, long mx, long my, const char *keywords, const char *format,...) |
| smat * | sread_mmap (const char *format,...) |
| scell * | scellread_mmap (const char *format,...) |
| ssp * | sspnew (long nx, long ny, long nzmax) |
| ssp * | sspref (const ssp *A) |
| ssp * | sspdup (const ssp *A) |
| ssp * | sspnew2 (const ssp *A) |
| ssp * | sspnewrandu (long nx, long ny, const float mean, float fill, rand_t *rstat) |
| void | sspsetnzmax (ssp *sp, long nzmax) |
| ssp * | ssp_cast (const cell *A) |
| void | sspfree_do (ssp *sp) |
| void | sspdisp (const ssp *sp) |
| int | sspcheck (const ssp *sp) |
| void | sspscale (ssp *A, const float beta) |
| void | sspscalex (ssp *A, const smat *xs) |
| void | sspscaley (ssp *A, const smat *ys) |
| sspcell * | sspcellref (const sspcell *in) |
| sspcell * | sspcell_cast (const cell *A) |
| void | sspcellscale (sspcell *A, const float beta) |
| ssp * | sspnewdiag (long N, float *vec, float alpha) |
| smat * | sspdiag (const ssp *A) |
| void | sspmuldiag (ssp *__restrict A, const float *w, float alpha) |
| void | sspmv (smat *y, const ssp *A, const smat *__restrict x, char trans, float alpha) |
| void | sspmulcreal (float *__restrict y, const ssp *A, const fcomplex *__restrict x, float alpha) |
| void | sspmm (smat **yout, const ssp *A, const smat *x, const char trans[2], const float alpha) |
| void | smulsp (smat **yout, const smat *x, const ssp *A, const char trans[2], const float alpha) |
| float | sspwdot (const smat *y, const ssp *A, const smat *x) |
| float | sspcellwdot (const scell *y, const sspcell *A, const scell *x) |
| void | scellmm (panyarray C0, const_anyarray A, const_anyarray B, const char trans[2], const float alpha) |
| scell * | scellmm2 (const scell *A, const scell *B, const char trans[2]) |
| ssp * | s2sp (smat *A, float thres) |
| void | sspfull (smat **out0, const ssp *A, const char trans, const float alpha) |
| void | sspcellfull (scell **out0, const sspcell *A, const char trans, const float alpha) |
| ssp * | sspadd2 (const ssp *A, float a, const ssp *B, float b) |
| void | sspadd (ssp **A0, float alpha, const ssp *B, float beta) |
| void | scelladd (panyarray pA, float ac, const_anyarray B, float bc) |
| ssp * | sspaddI (const ssp *A0, float alpha) |
| void | scelladdI (anyarray A, float alpha) |
| ssp * | ssptrans (const ssp *A) |
| void | sspconj (ssp *) |
| ssp * | sspmulsp (const ssp *A, const ssp *B, const char trans[2]) |
| void | sspmulsp2 (ssp **C0, const ssp *A, const ssp *B, const char trans[2], const float scale) |
| sspcell * | sspcelltrans (const sspcell *spc) |
| ssp * | sspcat (const ssp *A, const ssp *B, int type) |
| ssp * | sspcell2sp (const sspcell *A) |
| smat * | sspsum (const ssp *A, int col) |
| smat * | sspsumabs (const ssp *A, int col) |
| float | ssptrace (const ssp *A, float power) |
| Compute the sum of diagonal items (trace) with power. | |
| void | sspclean (ssp *A) |
| void | sspdroptol (ssp *A, float thres) |
| void | sspcelldroptol (sspcell *A, float thres) |
| lmat * | sspdropemptycol (ssp *A) |
| void | sspsort (ssp *A) |
| void | sspcellsort (sspcell *A) |
| void | sspsym (ssp **A) |
| void | sspcellsym (sspcell **A) |
| ssp * | sspconvolvop (smat *A) |
| ssp * | sspperm (ssp *A, int reverse, long *pcol, long *prow) |
| ssp * | sspinvbdiag (const ssp *A, long bs) |
| scell * | sspblockextract (const ssp *A, long bs) |
| smat * | scell2m (const_anyarray A) |
| void | sspwritedata (file_t *fp, const ssp *sp) |
| ssp * | sspreaddata (file_t *fp, header_t *header) |
| #define AOS_SMAT | ( | A | ) |
Calls SX(new) with a filename to be saved to.
| smat * smat_cast | ( | const_anyarray | A | ) |
check and cast an object to matrix
check the size of matrix if exist. Otherwise create it. content is not zeroed if already exists.
| void sfree_content | ( | smat * | A | ) |
free content of a matrix object.
| void sfree_do | ( | smat * | A | ) |
free a matrix object.
creat a reference to an existing matrix. header is duplicated if exists.
create an new reference another with different shape.
creat a new matrix referencing columns in existing matrix. reference counted.
Override a stack matrix struct with pointers to columns of another matrix. Does not add reference count the original data.
Resize a matrix by adding or removing columns or rows. Data is kept whenever possible.
Create a new sub matrix of nx*ny starting from(sx,sy) and copy the data.
Concatenate two matrixes into 1 along "dim" (1 for x, 2 for y)
| void szero | ( | smat * | A | ) |
Set elements to zero.
| int szerocol | ( | smat * | A, |
| int | icol ) |
Set column elements to zero.
| uint32_t shash | ( | const smat * | A, |
| uint32_t | key ) |
Compute the hashlittle
| void sset | ( | smat * | A, |
| const float | val ) |
set values of each element in an matrix to val.
| void sshow | ( | const smat * | A, |
| const char * | format, | ||
| ... ) |
display a matrix.
| void sshow_diag | ( | const smat * | A, |
| const char * | format, | ||
| ... ) |
display diagonal of a matrix.
Permute the vector so that out(:)=in(p);
Reverse permute the vector so that out(p)=in(:);
| int sflip | ( | smat * | A, |
| int | axis ) |
Flip the matrix along the set axis. 0 to flip both, 1 along x, 2 along y.
| float ssum | ( | const smat * | A | ) |
Calculate sum of all the elements in A.
| float smean | ( | const smat * | A | ) |
Calculate average of all the elements in A.
| float strace | ( | const smat * | A | ) |
compute the trace (sum of diagonal elements)
| void ssort | ( | smat * | A, |
| int | ascend ) |
Sort all columns of A, in ascending order if ascend is non zero, otherwise in descending order.
| void smaxmin | ( | const smat * | A, |
| float * | max, | ||
| float * | min ) |
find the maximum and minimum value
| float smax | ( | const smat * | A | ) |
find the maximum value
| float smaxabs | ( | const smat * | A | ) |
find the maximum of abs of all elements
| float smin | ( | const smat * | A | ) |
find the minimum value
| float ssumabs | ( | const smat * | A | ) |
compute the sum of abs of all elements
| float ssumsq | ( | const smat * | A | ) |
compute the sum of A.*A
Find unique values and sort from small to large.
| input | input array |
| ascend | sorting direction |
| void sfftshift | ( | smat * | A | ) |
shift frequency components by n/2
reorder B and embed/crop into center of A .
4 * * 3 * * * * * * * * 2 * * 1
to
1 2 3 4
cyclic shift A by nx and ny to B.
4 3 1 2 2 1 to 3 4
create an new cell similar to A in shape. When a cell is empty, it is created with an emtry matrix and cannot be overriden.
Create an new cell with matrix specified. Each block is stored continuously in memory.
Create an new cell with matrix specified. Each block is stored continuously in memory.
| scell * scellnew_file | ( | long | nx, |
| long | ny, | ||
| long * | nnx, | ||
| long * | nny, | ||
| const char * | keywords, | ||
| const char * | format, | ||
| ... ) |
Calls cellnew3 with a filename to be saved to.
| scell * scellnewsame_file | ( | long | nx, |
| long | ny, | ||
| long | mx, | ||
| long | my, | ||
| const char * | keywords, | ||
| const char * | format, | ||
| ... ) |
Calls cellnew_same with a filename to be saved to.
| void scellzero | ( | scell * | dc | ) |
Setting all elements of a cell to zero.
| void scellset | ( | scell * | dc, |
| float | val ) |
setting all elements of a cell to alpha.
creat a cell reference an existing cell by referencing the elements.
duplicate a SX(cell) object. Not implemented for lmat or imat as SX(cellcp) is defined in spmm.c
Copy B to A.
Takes parameters of matrix, sparse matrix, or cell array of them.
reduce nx*ny cell matrix to 1*ny if dim=1 and nx*1 if dim=2 by merging the cells.
concatenate two cell matrices along dimenstion 'dim'.
concatenate two cell matrices along dimenstion 'dim'.
concatenate coresponding elements of each SX(cell). They must have the same shape.
convert a vector to cell using dimensions specified in dims. Reference the vector
make A a cell array using shape information from ref if *B is NULL.
Notice that empty cells may be replaced by zeros if it is within valid column or row.
input is nsa*ncol cell. each cell has npix=nx*ny elements. Extract icol of cell as npix*nsa array.
| float scellsum | ( | const scell * | A | ) |
create sum of all the elements in A.
| int sisnan | ( | const smat * | A | ) |
Check for NaN in elements
| float snorm | ( | const smat * | A | ) |
compute the norm(2) of A
| float sstd | ( | const smat * | A | ) |
compute the standard deviation of A
| void srandu | ( | smat * | A, |
| const float | max, | ||
| rand_t * | rstat ) |
Fill A with random uniform numbers between [0, 1]*max
| void srandn | ( | smat * | A, |
| const float | sigma, | ||
| rand_t * | rstat ) |
Fill A with random normal distribution numbers with standard deviation of sigma.
| void sscale | ( | smat * | A, |
| float | w ) |
scale each element of A by w.
| float swdot | ( | const float * | a, |
| const smat * | w, | ||
| const float * | b ) |
compute weighted dot product a'*(w*b)
Compute component wise multiply A=A.*(B1*wt1+B2*wt2) component-wise multiply of three matrices. A=A.*W.*(B1*wt1+B2*wt2) Component-wise multiply each column of A with B A(:,i)=A(:,i).*B;
component-wise multiply of columns of A with combination of B1 and B2: A(:,i)=A(:,i)*(B1*wt1+B2*wt2); component wise multiply of 2d complex matrix A,W and 1d vector B. A(:,i)=A(:,i).*W(:,i).*B; Component wise multiply each row of A with B. A(i,:)=A(i,:)*B
component-wise multiply of rows of A with combination of B1 and B2: A(i,:)=A(i,:).*(B1*wt1+B2*wt2); Component wise division B=B./A. 0/0 is replace by 'value';
| void smulvec | ( | float *__restrict | y, |
| const smat *__restrict | A, | ||
| const float *__restrict | x, | ||
| const float | alpha ) |
multiply a SX(mat) matrix with a vector and accumulate to y: y+=A*x*alpha
| void smm | ( | smat ** | C0, |
| const float | beta, | ||
| const smat * | A, | ||
| const smat * | B, | ||
| const char | trans[2], | ||
| const float | alpha ) |
compute matrix product using blas dgemm.; C=beta*C+ alpha *trans(A)*trans(B); if C exist.
| void sinvspd_inplace | ( | smat * | A | ) |
inplace invert a small square SPD matrix using lapack dposv_, usually (A'*w*A). by solving Ax=I; copy x to A. dposv_ modifies A also. be careful
| void sinv_inplace | ( | smat * | A | ) |
inplace invert a general square matrix using lapack dgesv_
Compute the cholesky decomposition of a symmetric semi-definit dense matrix.
compute the pseudo inverse of matrix A with weigthing of full matrix W or sparse matrix weighting Wsp. For full matrix, wt can be either W or diag (W) for diagonal weighting. B=inv(A'*W*A+tikcr)*A'*W; thres is the threshold to truncate eigenvalues.
compute the relative difference betwee two vectors. sqrt(||A-B||/||A||) using norm2. for debugging purpose.
| int scircle | ( | smat * | A, |
| float | cx, | ||
| float | cy, | ||
| float | dx, | ||
| float | dy, | ||
| float | r, | ||
| float | val ) |
Generate a new gray pixel map based on bilinear influence functions used in mkw. It creates slightly larger map than an filled circle to account for the sampling effect. The Center and Radius cx,cy,r are in unit of meter, The sampling dx,dy specify spacing of the points in meter along x or y dimension. Each full point received value of 'val'
| int srectangle | ( | smat * | A, |
| float | cx, | ||
| float | cy, | ||
| float | rx, | ||
| float | ry, | ||
| float | theta, | ||
| float | val ) |
Generate a new gray pixel map based on bilinear influence functions used in mkw. It creates slightly larger map than an filled rectangle to account for the sampling effect. The Center and half width cx,cy,rx,ry are in unit of meter, The sampling dx,dy specify spacing of the points in meter along x or y dimension. Each full point received value of 'val'
| void srotvec | ( | smat * | A, |
| const float | theta ) |
rotate the column vectors CCW, equivalent as rotate coordinate theta CW. A is nx2 while A(:,0) is x, A(:,1) is y.
| void srotvect | ( | smat * | A, |
| const float | theta ) |
rotate the row vectors CCW. same as rotate coordinate theta CW. A is 2xn A(0, :) is x, A(1, :) is y.
rotate a 2x2 covariance matrix A by theta CCW (coordinate rotate -theta CCW) or from ra to xy coordinate. R*A*R';
| void smulvec3 | ( | float * | y, |
| const smat * | A, | ||
| const float * | x ) |
T matrix vector multiply optimized for just three values. y=A*x;
| void spara3 | ( | float * | grad, |
| const smat * | corr ) |
Compute the parabolic fit center using 3x3 points around the peak.
| void scog | ( | float * | grad, |
| const smat * | im, | ||
| float | offsetx, | ||
| float | offsety, | ||
| float | thres, | ||
| float | bkgrnd, | ||
| float | flux, | ||
| const smat * | mask ) |
Compute thresholded center of gravity. The threshold is absolute value. bkgrnd is removed from i0 when computing cog. offset is the offset of the reference point (cog=0) from the physical center. all length are given in terms of pixel.
| void sshift2center | ( | smat * | A, |
| float | offsetx, | ||
| float | offsety ) |
Shift the image in A to center on physical center+[offsetx,offsety] using cog and fft.
| void scwpow | ( | smat * | A, |
| float | power ) |
Raise all elements to power 'power'
| void scwexp | ( | smat * | A, |
| float | alpha ) |
compute exponential of all elements after scaling by alpha
Compute SVD of a general matrix A. A=U*diag(S)*V'; diag(S) is returned.
| void ssvd_pow2 | ( | smat * | A, |
| float | power, | ||
| float | thres1, | ||
| float | thres2 ) |
computes pow(A,power) in place using svd. positive thres: Drop eigenvalues that are smaller than thres * max eigen value negative thres: Drop eigenvalues that are smaller than thres * previous eigen value (sorted descendantly).
| A | [in/out] The matrix | |
| [in] | power | power of eigen values. usually -1 for inverse |
| [in] | thres1 | SVD inverse absolute threshold |
| [in] | thres2 | SVD inverse relative threshold |
computes out=out*alpha+exp(A*beta) using scaling and squaring method. Larger scaling is more accurate but slower. Tested against matlab expm
First, scaling the matrix by 2^-n times so it is smaller than 1/threshold. Then compute exp(A*beta*2^-n) using Tylor expansion. Then compute the final answer by taking exponential of 2^n.
compute B=bc*B+ac*A behavior changed on 2009-11-02. if A is NULL, don't do anything.
compute B=bc*B+ac*A. Use smallest dimension of both. behavior changed on 2009-11-02. if A is NULL, don't do anything.
Compute B[:,icol]=bc*B[:,icol]+ac*A where A is vector.
Interpolation of 1d array
Interpolate using linear interp. xin is the coordinate of yin. xnew is the coordinate of the output.
Interpolate using log(xin) and log(xnew) xin is the coordinate of yin. xnew is the coordinate of the output.
blend B into center of A with width of overlap. The center (size is B->nx-overlap, B->ny-overlap) of A is replaced by center of B . The overlapping area is blended
For each entry in A, call repeatly to collect its histogram, centered at center, spaced by spacing, for n bins in total. center if at bin n/2.
1D Cubic spline interpolation preparation. if x has only 1 column: x is the coordinate. y is the function value. if x has two columns: first column is the coordinate, y is null.
It is upto the user to make sure that the coordinate is increasingly ordered and evenly spaced .
If the values of a function \(f(x)\) and its derivative are know at x=0, and x=1 (normalized coordinate), then the function can be interpolated on the interval [0,1] using a third degree polynomial. This is called cubic interpolation. The formula of this polynomial can be easily derived.
A third degree polynomial and its derivative:
\[f(x)=ax^3+bx^2+cx+d \]
\[f(x)=3ax^3+2bx+c \]
The coefficients can be derived from the value and derivatives:
\begin{eqnarray*}a&=&2f(0)-2f(1)+f^\prime (0)+f^\prime(1)\\ b&=&-3f(0)+3f(1)-2f^\prime(0)-f^\prime(0)\\ c&=&f^\prime(0)\\ d&=&f(0)\\ \end{eqnarray*}
the derivatives can be computed as
\begin{eqnarray*}f^\prime(0)&=&\frac{f(1)-f(-1)}{2}\\ f^\prime(1)&=&\frac{f(2)-f(0)}{2}\\ \end{eqnarray*}
so we have the formula
\begin{eqnarray*}a&=&-0.5 f(-1) + 1.5 f(0) - 1.5 f(1) + 0.5 f(2)\\ b&=& f(-1) - 2.5 f(0) + 2 f(1) - 0.5 f(2)\\ c&=&-0.5 f(-1) + 0.5 f(1) \\ d&=& f(0) \\ \end{eqnarray*}
for the boundary pints, replace
\[f^\prime(0)=(f(1)-f(-1))/2\]
by
\[f^\prime(0)=(f(1)-f(0))\]
Otehr type of boundaries are handled in the same way.
see www.paulinternet.nl/?page=bicubicx
Evluate the cubic spline represented by nx5 matrix coeff, at location array xnew.
Do 1D cubic spline all at once by calling SX(spline_prep) and SX(spline_evald)
| void scwlog10 | ( | smat * | A | ) |
Do a component wise log10 on each element of A.
| void scwlog | ( | smat * | A | ) |
Do a component wise log10 on each element of A.
Embed a ninx*niny matrix in into A with optional rotation by theta CCW (output points are rotated by theta -CCW) around the fft center. Used to rotate the PSF from x-y to radial-azimuthal coordinate in radial format CCD. A may be bigger or smaller than B.
embed a ninx*niny matrix in into A with optional rotation by -theta CCW (coordinate rotate theta CCW) around the fft center. Used to rotate the PSF from x-y to radial-azimuthal coordinate in radial format CCD. A may be bigger or smaller than B.
| float sfwhm | ( | smat * | A | ) |
Calculate number of pixels having values larger than or equal to half of maximum and convert to diameter.
For more accurate calculation of Gaussian beams, use the 2*sqrt(2*log(2))*SX(gauss_sigma).
| void sgauss_fit | ( | float * | mr, |
| float * | ma, | ||
| float * | mb, | ||
| float * | angle, | ||
| float * | amp, | ||
| smat ** | img, | ||
| smat * | A, | ||
| float | thres ) |
Calculate D4s width of Gaussian 2D function
| mr | Equivalent radius of the same area |
| ma | major axis |
| mb | minor axi |
| angle | angle |
| amp | Amplitude |
| img | Return the fitting image |
| A | The irradiance (intensity) |
| thres | The threshold relative to peak. |
| float sgauss_sigma | ( | smat * | A, |
| float | thres ) |
Determine the sigma_r of 2d gauss function.
| float sfwhm_gauss | ( | smat * | A | ) |
Use gauss fit to compute fwhm
Compute the enclosed energy or azimuthal average of a.
| psf | The input array |
| dvec | The diameter for enclosed energy, or radius for azimuthal average |
| type | The type. -1: azimuthal average, 0: within a square, 1: within a circle, 2: within a slit |
| nthread | Number of CPU threads to use. |
| int sminsearch | ( | float * | x, |
| int | nmod, | ||
| float | ftol, | ||
| int | nmax, | ||
| sminsearch_fun | fun, | ||
| void * | info ) |
Search minimum along multiple dimenstions. scale contains the scale of each dimension. x contains initial warm restart values.
| void sbessik | ( | float | x, |
| float | xnu, | ||
| float * | ri, | ||
| float * | rk, | ||
| float * | rip, | ||
| float * | rkp ) |
Returns the modified Bessel functions ri = Iν , rk = Kν and their derivatives rip = Iν , rkp = Kν, for positive x and for xnu = ν ≥ 0.
| float scellnorm | ( | const scell * | A | ) |
compute norm2.
| void scellscale | ( | anyarray | A_, |
| float | w ) |
scale each element of A.
| void scelldropempty | ( | scell ** | A0, |
| int | dim ) |
drop empty rows or columns. size of *A0 is changed.
invert each component of the dcell. Each cell is treated as an individual matrix.
compute the pseudo inverse of block matrix A. A is n*p cell, wt n*n cell or sparse cell. \(B=inv(A'*W*A)*A'*W\)
| [in] | A | The matrix to pseudo invert |
| [in] | W_ | The weighting matrix. dense or sparse |
| [in] | thres1 | SVD absolute inverse threshold |
| [in] | thres2 | SVD relative inverse threshold |
| void scellsvd_pow2 | ( | scell * | A, |
| float | power, | ||
| float | thres1, | ||
| float | thres2 ) |
compute the power of a block matrix using svd method. First convert it do SX(mat), do the power, and convert back to block matrix.
| void scellcwpow | ( | scell * | A, |
| float | power ) |
raise each cell in the cell array to power of power.
| void scelldropzero | ( | scell * | B, |
| float | thres ) |
drop empty blocks (zero). Size of B is not modified.
| int scellclip | ( | scell * | Ac, |
| float | min, | ||
| float | max ) |
clip a SX(cell) array to max at 'max', min at 'min'
Create a new sub cell matrix of nx*ny starting from(sx,sy)
2D cubic spline interpolation preparation. x is the x coordinate vector of the 2-d grid. y is the y coordinate vector of the 2-d grid. z is defined on the 2-d grid. It is upto the user to make sure that the coordinate is increasingly ordered and evenly spaced .
The boundaries are handled in the same way is SX(spline). i.e. replace
\[f^\prime(0)=(f(1)-f(-1))/2\]
by
\[f^\prime(0)=(f(1)-f(0))\]
Otehr type of boundaries are handled in the same way.
Evaluate 2D cubic spline at location defined 2-d arrays by xnew, ynew
| void smaprot | ( | anyarray | A_, |
| real | theta ) |
Rotate a or multiple 2d array ccw by angle
Routines for input/output to bin/fits file. Function to write dense matrix data into a file pointer. Generally used by library developer
Function to read dense matrix into memory from file pointer. Generally used by library developer.
Create a new SX(mat) matrix object, mmapped from file. The file is truncated if already exists in rw mode.
| scell * scellnew_mmap | ( | long | nx, |
| long | ny, | ||
| long * | nnx, | ||
| long * | nny, | ||
| const char * | keywords, | ||
| const char * | format, | ||
| ... ) |
Create a new dense matrix cell object, mmapped from file. The file is truncated if already exists.
| scell * scellnewsame_mmap | ( | long | nx, |
| long | ny, | ||
| long | mx, | ||
| long | my, | ||
| const char * | keywords, | ||
| const char * | format, | ||
| ... ) |
Create a new dense matrix cell object, with identical blocks, mmapped from file. be aware that the data is not 8-byte aligned. The file is truncated if already exists.
| smat * sread_mmap | ( | const char * | format, |
| ... ) |
Map the file to memory in read only, shared mode.
| scell * scellread_mmap | ( | const char * | format, |
| ... ) |
Map the file to memory in read only, shared mode.
Create a nx*ny sparse matrix with memory for nmax max elements allocated.
Create a new sparse matrix and fill in uniform random numbers with filling factor of 'fill'
| void sspfree_do | ( | ssp * | sp | ) |
free a sparse matrix
| void sspdisp | ( | const ssp * | sp | ) |
Display a sparse array
| int sspcheck | ( | const ssp * | sp | ) |
Check a sparse array for wrong orders. Return 1 if is lower triangle, 2 if upper triangle, and 3 if diagonal.
| void sspscale | ( | ssp * | A, |
| const float | beta ) |
inplace scale sparse matrix elements.
| void sspcellscale | ( | sspcell * | A, |
| const float | beta ) |
inplace scale a SX(dspcell) object
Create a new sparse matrix with diagonal elements set to vec*alpha
| void sspmuldiag | ( | ssp *__restrict | A, |
| const float * | w, | ||
| float | alpha ) |
Multiply a sparse matrix inplace with a diagonal weighting matrix whose diagonal values are stored in w. W_ii=w_i; W_ij=0 if i!=j A=A*W*alpha; W is a diagonal sparse matrix. diag(W) is w multiply w[i] to all numbers in column[i]
sparse matrix multiply with a vector: y=y+op(A)*x*alpha op(A)=A if trans=='n' op(A)=A' if trans=='t' op(A)=conj(A') if trans=='c'
| void sspmulcreal | ( | float *__restrict | y, |
| const ssp * | A, | ||
| const fcomplex *__restrict | x, | ||
| float | alpha ) |
Multiply a sparse matrix with the real part of a complex vector: y=y+A*creal(x)*alpha
sparse matrix multiply with dense matrix
dense matrix multiply with sparse matrix, implemented by transpose all: y=x*A-->y'=A'*x'; conjugation is handled carefully.
Multiply two vectors with weighting by sparse matrix. return y'*(A*x)
Multiply two cell arrays with weighting by sparse matrix
| void scellmm | ( | panyarray | C0_, |
| const_anyarray | A_, | ||
| const_anyarray | B_, | ||
| const char | trans[2], | ||
| const float | alpha ) |
Compute A*B and add to C0.
C0=C0+op(A)*op(B)*alpha; op(A)=A if trans[0]=='n' op(A)=A' if trans[0]=='t' op(A)=conj(A') if trans[0]=='c'
op(B)=B if trans[1]=='n' op(B)=B' if trans[1]=='t' op(B)=conj(B') if trans[1]=='c'
A may be dense or sparse matrix.
2009-11-09: There was initially a beta parameter It was implemented wrongly for beta!=1 because for every call to dmm, the already accumulated ones are scaled. removed beta.
a different interface for multiplying cells.
Convert sparse matrix into dense matrix and add to output: out0=out0+full(A)*alpha
Expand sparse matrix cell to dense matrix cell.
Added two sparse matrices: return A*a+B*b
Add a sparse matrix to another: A0=A0+B
| void scelladd | ( | panyarray | pA_, |
| float | ac, | ||
| const_anyarray | B_, | ||
| float | bc ) |
Calculate A_=A_*ac+B_*bc;
Takes parameters of matrix, sparse matrix, or cell array of them.
Add alpha times identity to a sparse matrix. If SX(sp) is not symmetric, only add diagonal to first nm*nm block for nm=min(nx,ny)
| void scelladdI | ( | anyarray | A_, |
| float | alpha ) |
Add alpha to diagnonal elements of A_. A_ can be matrix or sparse matrix.
| void sspconj | ( | ssp * | A | ) |
Take conjugation elementwise.
Multiply two sparse arrays and return the result op(A)*op(B)
Multiply two sparse arrays and add to the third: C0=C0+op(A)*op(B)*scale
Concatenate two sparse array along dim dimension
Sum abs of elements of sparse array along dimension dim
| void sspclean | ( | ssp * | A | ) |
Clean up a sparse array by dropping zeros
| void sspdroptol | ( | ssp * | A, |
| float | thres ) |
Drop elements that are EPS times the largest value.
| void sspcelldroptol | ( | sspcell * | A, |
| float | thres ) |
Drop elements that are EPS times the largest value.
| void sspsort | ( | ssp * | A | ) |
Make sure the elements are sorted correctly. Does not change the location of data. can be done without harm.
| void sspcellsort | ( | sspcell * | A | ) |
Make sure the elements are sorted correctly.
| void sspsym | ( | ssp ** | A | ) |
symmetricize a sparse matrix and drop values below a threshold.
| void sspcellsym | ( | sspcell ** | A | ) |
symmetricize a sparse cell and drop values below a threshold.
Create a sparse convolution operator C with C(i,j)=A(i-j); A must be very sparse with only a view non-zero value otherwise C will be too full.
Permute rows and columns of sparse matrix A;
Invert a SPD sparse matrix that is block diagonal with block sizes of bs.
Extrat the diagonal blocks of size bs into cell arrays.
| smat * scell2m | ( | const_anyarray | A_ | ) |
Convert dense or sparse matrix cell to matrix.
| void sspwritedata | ( | file_t * | fp, |
| const ssp * | sp ) |
Function to write sparse matrix data into file pointed using a file pointer. Generally used by library developer. We do not convert data during saving, but rather do the conversion during reading.