MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
lmath.h File Reference

Macros

#define AOS_LIB_TYPE
#define AOS_LMAT(A)

Functions

lmat * lnew (long nx, long ny)
lmat * lnew_file (long nx, long ny, const char *keywords, const char *format,...)
lmat * lnew_do (long nx, long ny, long *p, mem_t *mem)
lmat * lmat_cast (const_anyarray A)
int linit (lmat **A, long nx, long ny)
void lfree_content (lmat *A)
void lfree_do (lmat *A)
lmat * lref (const lmat *in)
lmat * lref_reshape (const lmat *in, long nx, long ny)
lmat * lrefcols (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)
lmat * lsub (const lmat *in, long sx, long nx, long sy, long ny)
lmat * lcat (const lmat *in1, const lmat *in2, int dim)
lmat * ldup (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)
lmat * ltrans (const lmat *A)
void lset (lmat *A, const long val)
void lshow (const lmat *A, const char *format,...)
void lshow_diag (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)
void lnormalize_sum (lmat *A, long sum)
void lnormalize_sumabs (lmat *A, long sum)
long lmean (const lmat *A)
long ltrace (const lmat *A)
void lsort (lmat *A, int ascend)
void lvecmaxmin (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 lvecnormalize_sum (long *__restrict p, long nloc, long norm)
void lvecnormalize_sumabs (long *__restrict p, long nloc, long norm)
long lvecmaxabs (const long *__restrict p, long n)
void lmaxmin (const lmat *A, long *max, long *min)
long lmax (const lmat *A)
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)
lmat * lunique (const lmat *input, int ascend)
 Find unique values and sort from small to large.
void lfftshift (lmat *A)
int lcpcorner2center (lmat *A, const lmat *B)
int lshift (lmat **B0, const lmat *A, int sx, int sy)
lcell * lcell_cast (const cell *A)
lcell * lcellnew2 (const lcell *A)
lcell * lcellnew3 (long nx, long ny, long *nnx, long *nny)
lcell * lcellnew_same (long nx, long ny, long mx, long my)
lcell * lcellnew_file (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...)
lcell * lcellnewsame_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)
lcell * lcelltrans (const lcell *A)
lcell * lcellref (const lcell *in)
lcell * lcelldup (const lcell *in)
void lcellcp (lcell **out0, const lcell *in)
lcell * lcellreduce (const lcell *A, int dim)
lcell * lcellcat (const lcell *A, const lcell *B, int dim)
void lcellcat2 (lcell **A, const lcell *B, int dim)
lcell * lcellcat_each (const lcell *A, const lcell *B, int dim)
lcell * l2cellref (const lmat *A, long *dims, long ndim)
void l2cell (lcell **B, const lmat *A, const lcell *ref)
lmat * lcell_col (lcell *input, long icol)
long lcellsum (const lcell *A)
lmat * lcellsum_each (const lcell *A)
void lwritedata (file_t *fp, const lmat *A, long ncol)
lmat * lreaddata (file_t *fp, header_t *header)
lmat * lnew_mmap (long nx, long ny, const char *keywords, const char *format,...)
lcell * lcellnew_mmap (long nx, long ny, long *nnx, long *nny, const char *keywords, const char *format,...)
lcell * lcellnewsame_mmap (long nx, long ny, long mx, long my, const char *keywords, const char *format,...)
lmat * lread_mmap (const char *format,...)
lcell * lcellread_mmap (const char *format,...)

Macro Definition Documentation

◆ AOS_LMAT

#define AOS_LMAT ( A)
Value:
l##A

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_anyarray 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.

  • -1 in dimension preserves original value.
  • 0 in dimension will free array.

◆ 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

◆ lset()

void lset ( lmat * A,
const long val )

set values of each element in an matrix to val.

◆ lshow()

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

display a matrix.

◆ lshow_diag()

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

display diagonal of 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)

Calculate sum of all the elements in A.

◆ lmean()

long lmean ( const lmat * A)

Calculate average 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.

◆ lmaxmin()

void lmaxmin ( const lmat * A,
long * max,
long * min )

find the maximum and minimum value

◆ 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

◆ lunique()

lmat * lunique ( const lmat * input,
int ascend )

Find unique values and sort from small to large.

Parameters
inputinput array
ascendsorting direction
Returns
LX(mat)* unique values

◆ 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.

◆ lcellset()

void lcellset ( lcell * dc,
long val )

setting all elements of a cell to alpha.

◆ 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)

◆ 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.