slach is a simple linear algebra libraries desigined for low-coupling used C89, and it is convient for portability. slach has main parts: base, operation, QR decomposition, LU decomposition, SVD decomposition and Fast Fourier Transform(FFT). All other parts except for base all depend on base, rather than compelx dependency. If users want to just use the library, the users don't need to know inner data structures, instead you can use arraies to achieve results. If users want to implement the algorithms, it's easy to transfer programs. In the program, I seperate the inner and outer clearly, so a lot of wrapper functions employed in the program.
The interface of slach basically like:
float* src
size_t row
,size_t col
ORsize_t len
float* dest
size_t height
,size_t width
ORsize_t len
- other paramaters
The meaning is: use this function on src
and save in dest
.
base declares and defines basic data structures: vector and matrix, it can be easily used in other applications. base also defines some utilities: safe malloc and free, print function and random numbers generation.
Matrix
andVector
provide some basic functions: create, destroy, deep copy, array to matrix, matrix to array, vector to array, array to vector.slach_malloc
andslach_free
are safe memory control functions.slach_rand_seed
sets rand seed,slach_rand_int_range_*
generates integer r.v. in different range,uRand
generates uniform distribution,gaussrand
generates Gaussian distribution,expRand
generates exponential distribution.perr
print error and exit program,print*
print vectors and matrices.
operation declares and defines operation functions: element-wise math function, matrix multiplication, add, transpose, vector inner product, vector l-p norm and matrix norm, slice like matlab.
*m
and*v
are element-wise math functions.slicev
andslicem
do slice like matlab.mmMul
,mvMul
,mmAdd
,vvAdd
,dot
,vnorm
andmnorm
do matrix multiplication, add, transpose, vector inner product, vector l-p norm and matrix norm.
LUD implements LU decomposition, and offers LUD interface, solving linear equations using LUD and matrix inverse using LUD.
getL
andgetU
getL
andU
matrix.LUsolvem
andLUsolvev
solve linear equations: AX=b, AX=Binv
inverse square matrix using LU decomposition.
QRD implements QR decomposition, and offers QRD interface, solving linear equations using QRD.
getQ
andgetR
getQ
andR
matrix.QRsolvem
andQRsolvev
solve linear equations: AX=b, AX=B
SVD implements SVD decomposition, and offers SVD interface. And also we can do eigenvalue decomposition using SVD.
getS
, getV
and getUs
get S
vector, V
and U
matrix.
FFT implements naive Discrete Fourier Transform and Cooley-Turkey FFT. Besides, we provide abs and phase using FFT--often we use in reality is abs and pahse after FFT. And we also provide DFT_naive
and FFT_CooleyTukey
.
fftAbs
andfftPhase
do FFT and then calculate abs and pahse.DFT_naive
andFFT_CooleyTukey
return complex value of FFT.fftshift
do like matlabfftshift
.