MAOS
Multithreaded Adaptive Optics Simulator
lmath.h File Reference

Macros

#define AOS_LIB_TYPE
 
#define AOS_LMAT(A)   l##A
 

Functions

lmatlnew (long nx, long ny)
 
lmatlnew_file (long nx, long ny, const char *keywords, const char *format,...)
 
lmatlnew_do (long nx, long ny, long *p, mem_t *mem)
 
lmatlmat_cast (const void *A)
 
int linit (lmat **A, long nx, long ny)
 
void lfree_content (lmat *A)
 
void lfree_do (lmat *A)
 
lmatlref (const lmat *in)
 
lmatlref_reshape (const lmat *in, long nx, long ny)
 
lmatlrefcols (const lmat *in, long icol, long ncol)
 
void lcols (lmat *out, const lmat *in, long icol, long ncol)
 
int lresize (lmat *A, long nx, long ny)
 
lmatlsub (const lmat *in, long sx, long nx, long sy, long ny)
 
lmatlcat (const lmat *in1, const lmat *in2, int dim)
 
lmatldup (const lmat *in)
 
void lzero (lmat *A)
 
int lzerocol (lmat *A, int icol)
 
uint32_t lhash (const lmat *A, uint32_t key)
 
void lcp (lmat **out0, const lmat *in)
 
lmatltrans (const lmat *A)
 
void lset (lmat *A, const long val)
 
void lshow (const lmat *A, const char *format,...)
 
void lvecperm (lmat *out, const lmat *in, const long *perm)
 
void lvecpermi (lmat *out, const lmat *in, const long *perm)
 
int lflip (lmat *A, int axis)
 
long lvecsum (const long *__restrict p, long np)
 
long lsum (const lmat *A)
 
long ltrace (const lmat *A)
 
void lsort (lmat *A, int ascend)
 
void lmaxmin (const long *__restrict p, long N, long *max, long *min)
 
long lvecdot (const long *__restrict p1, const long *__restrict p2, const long *__restrict p3, long n)
 
void lnormalize_sum (long *__restrict p, long nloc, long norm)
 
void lnormalize_sumabs (long *__restrict p, long nloc, long norm)
 
void lnormalize_rms (long *__restrict p, long nx, long norm)
 
void lnormalize_max (long *__restrict p, long nloc, long max)
 
long lmax (const lmat *A)
 
long lvecmaxabs (const long *__restrict p, long n)
 
long lmaxabs (const lmat *A)
 
long lmin (const lmat *A)
 
long lsumabs (const lmat *in)
 
long lsumsq (const lmat *in)
 
long lsumdiffsq (const lmat *A, const lmat *B)
 
void lfftshift (lmat *A)
 
int lcpcorner2center (lmat *A, const lmat *B)
 
int lshift (lmat **B0, const lmat *A, int sx, int sy)
 
lcelllcell_cast (const cell *A)
 
lcelllcellnew2 (const lcell *A)
 
lcelllcellnew3 (long nx, long ny, long *nnx, long *nny)
 
lcelllcellnew_same (long nx, long ny, long mx, long my)
 
lcelllcellnew_file (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...)
 
lcelllcellnewsame_file (long nx, long ny, long mx, long my, const char *keywords, const char *format,...)
 
void lcellzero (lcell *dc)
 
void lcellset (lcell *dc, long alpha)
 
lcelllcelltrans (const lcell *A)
 
lcelllcellref (const lcell *in)
 
lcelllcelldup (const lcell *in)
 
void lcellcp (lcell **out0, const lcell *in)
 
lcelllcellreduce (const lcell *A, int dim)
 
lcelllcellcat (const lcell *A, const lcell *B, int dim)
 
void lcellcat2 (lcell **A, const lcell *B, int dim)
 
lcelllcellcat_each (const lcell *A, const lcell *B, int dim)
 
lcelll2cellref (const lmat *A, long *dims, long ndim)
 
void l2cell (lcell **B, const lmat *A, const lcell *ref)
 
lmatlcell_col (lcell *input, long icol)
 
long lcellsum (const lcell *A)
 
lmatlcellsum_each (const lcell *A)
 
uint32_t lcellhash (const lcell *A, uint32_t key)
 
void lwritedata (file_t *fp, const lmat *A, long ncol)
 
lmatlreaddata (file_t *fp, header_t *header)
 
lmatlnew_mmap (long nx, long ny, const char *keywords, const char *format,...)
 
lcelllcellnew_mmap (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...)
 
lcelllcellnewsame_mmap (long nx, long ny, long mx, long my, const char *keywords, const char *format,...)
 
lmatlread_mmap (const char *format,...)
 
lcelllcellread_mmap (const char *format,...)
 

Function Documentation

◆ lnew()

lmat* lnew ( long  nx,
long  ny 
)

Create a new LX(mat). Initialized to zero.

◆ lnew_file()

lmat* lnew_file ( long  nx,
long  ny,
const char *  keywords,
const char *  format,
  ... 
)

Calls LX(new) with a filename to be saved to.

◆ lmat_cast()

lmat* lmat_cast ( const void *  A)

check and cast an object to matrix

◆ linit()

int linit ( lmat **  A,
long  nx,
long  ny 
)

check the size of matrix if exist. Otherwise create it. content is not zeroed if already exists.

  • empty matrix is initialized.
  • existing matrix is not resized.

◆ lfree_content()

void lfree_content ( lmat A)

free content of a matrix object.

◆ lfree_do()

void lfree_do ( lmat A)

free a matrix object.

◆ lref()

lmat* lref ( const lmat in)

creat a reference to an existing matrix. header is duplicated if exists.

◆ lref_reshape()

lmat* lref_reshape ( const lmat in,
long  nx,
long  ny 
)

create an new reference another with different shape.

  • total number of elements must be preserved
  • set ny to 1 or 0 to return a vector.

◆ lrefcols()

lmat* lrefcols ( const lmat in,
long  icol,
long  ncol 
)

creat a new matrix referencing columns in existing matrix. reference counted.

◆ lcols()

void lcols ( lmat out,
const lmat in,
long  icol,
long  ncol 
)

Override a stack matrix struct with pointers to columns of another matrix. Does not add reference count the original data.

◆ lresize()

int lresize ( lmat A,
long  nx,
long  ny 
)

Resize a matrix by adding or removing columns or rows. Data is kept whenever possible.

  • 0 in dimension preserves original value.

◆ lsub()

lmat* lsub ( const lmat in,
long  sx,
long  nx,
long  sy,
long  ny 
)

Create a new sub matrix of nx*ny starting from(sx,sy) and copy the data.

◆ lcat()

lmat* lcat ( const lmat in1,
const lmat in2,
int  dim 
)

Concatenate two matrixes into 1 along "dim" (1 for x, 2 for y)

◆ ldup()

lmat* ldup ( const lmat in)

duplicate a matrix

◆ lzero()

void lzero ( lmat A)

Set elements to zero.

◆ lzerocol()

int lzerocol ( lmat A,
int  icol 
)

Set column elements to zero.

◆ lhash()

uint32_t lhash ( const lmat A,
uint32_t  key 
)

Compute the hashlittle

◆ lcp()

void lcp ( lmat **  out0,
const lmat in 
)

copy the values from one matrix to another.

◆ ltrans()

lmat* ltrans ( const lmat A)

transpose a matrix

◆ lshow()

void lshow ( const lmat A,
const char *  format,
  ... 
)

display a matrix.

◆ lvecperm()

void lvecperm ( lmat out,
const lmat in,
const long perm 
)

Permute the vector so that out(:)=in(p);

◆ lvecpermi()

void lvecpermi ( lmat out,
const lmat in,
const long perm 
)

Reverse permute the vector so that out(p)=in(:);

◆ lflip()

int lflip ( lmat A,
int  axis 
)

Flip the matrix along the set axis. 0 to flip both, 1 along x, 2 along y.

◆ lsum()

long lsum ( const lmat A)

create sum of all the elements in A.

◆ ltrace()

long ltrace ( const lmat A)

compute the trace (sum of diagonal elements)

◆ lsort()

void lsort ( lmat A,
int  ascend 
)

Sort all columns of A, in ascending order if ascend is non zero, otherwise in descending order.

◆ lmax()

long lmax ( const lmat A)

find the maximum value

◆ lmaxabs()

long lmaxabs ( const lmat A)

find the maximum of abs of all elements

◆ lmin()

long lmin ( const lmat A)

find the minimum value

◆ lsumabs()

long lsumabs ( const lmat A)

compute the sum of abs of all elements

◆ lsumsq()

long lsumsq ( const lmat A)

compute the sum of A.*A

◆ lsumdiffsq()

long lsumdiffsq ( const lmat A,
const lmat B 
)

compute the sum of (A-B)^2

◆ lfftshift()

void lfftshift ( lmat A)

shift frequency components by n/2

◆ lcpcorner2center()

int lcpcorner2center ( lmat A,
const lmat B 
)

reorder B and embed/crop into center of A .

4 * * 3
* * * *
* * * *
2 * * 1

to

1 2
3 4

◆ lshift()

int lshift ( lmat **  B0,
const lmat A,
int  sx,
int  sy 
)

cyclic shift A by nx and ny to B.

4   3     1   2

2   1 to  3   4

◆ lcell_cast()

lcell* lcell_cast ( const cell A)

cast a cell object to actual cell after checking.

◆ lcellnew2()

lcell* lcellnew2 ( const lcell A)

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.

◆ lcellnew3()

lcell* lcellnew3 ( long  nx,
long  ny,
long nnx,
long nny 
)

Create an new cell with matrix specified. Each block is stored continuously in memory.

◆ lcellnew_same()

lcell* lcellnew_same ( long  nx,
long  ny,
long  mx,
long  my 
)

Create an new cell with matrix specified. Each block is stored continuously in memory.

◆ lcellnew_file()

lcell* lcellnew_file ( long  nx,
long  ny,
long nnx,
long nny,
const char *  keywords,
const char *  format,
  ... 
)

Calls cellnew3 with a filename to be saved to.

◆ lcellnewsame_file()

lcell* lcellnewsame_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.

◆ lcelltrans()

lcell* lcelltrans ( const lcell A)

transpose a cell object

◆ lcellref()

lcell* lcellref ( const lcell in)

creat a cell reference an existing cell by referencing the elements.

◆ lcellreduce()

lcell* lcellreduce ( const lcell A,
int  dim 
)

reduce nx*ny cell matrix to 1*ny if dim=1 and nx*1 if dim=2 by merging the cells.

◆ l2cellref()

lcell* l2cellref ( const lmat A,
long dims,
long  ndim 
)

convert a vector to cell using dimensions specified in dims. Reference the vector

◆ l2cell()

void l2cell ( lcell **  B,
const lmat A,
const lcell ref 
)

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.

◆ lcell_col()

lmat* lcell_col ( lcell input,
long  icol 
)

input is nsa*ncol cell. each cell has npix=nx*ny elements. Extract icol of cell as npix*nsa array.

◆ lcellsum()

long lcellsum ( const lcell A)

create sum of all the elements in A.

◆ lcellsum_each()

lmat* lcellsum_each ( const lcell A)

return sum of each cell in a LX(mat)

◆ lcellhash()

uint32_t lcellhash ( const lcell A,
uint32_t  key 
)

Compute the hashlittle

◆ lwritedata()

void lwritedata ( file_t *  fp,
const lmat A,
long  ncol 
)

Routines for input/output to bin/fits file. Function to write dense matrix data into a file pointer. Generally used by library developer

◆ lreaddata()

lmat* lreaddata ( file_t *  fp,
header_t header 
)

Function to read dense matrix into memory from file pointer. Generally used by library developer.

◆ lnew_mmap()

lmat* lnew_mmap ( long  nx,
long  ny,
const char *  keywords,
const char *  format,
  ... 
)

Create a new LX(mat) matrix object, mmapped from file. The file is truncated if already exists in rw mode.

◆ lcellnew_mmap()

lcell* lcellnew_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.

◆ lcellnewsame_mmap()

lcell* lcellnewsame_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.

◆ lread_mmap()

lmat* lread_mmap ( const char *  format,
  ... 
)

Map the file to memory in read only, shared mode.

◆ lcellread_mmap()

lcell* lcellread_mmap ( const char *  format,
  ... 
)

Map the file to memory in read only, shared mode.