\doxysection{matrix.\+c}
\label{matrix_8c_source}\index{src/libsphinxbase/util/matrix.c@{src/libsphinxbase/util/matrix.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1997-\/2006\ Carnegie\ Mellon\ University.\ \ All\ rights\ }}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#ifdef\ HAVE\_CONFIG\_H}}
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#include\ "{}config.h"{}}}
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/clapack\_lite.h"{}}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/matrix.h"{}}}
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ckd\_alloc.h"{}}}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00050\ norm\_3d(float32\ ***arr,}
\DoxyCodeLine{00051\ \ \ \ \ \ \ \ \ uint32\ d1,}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ uint32\ d2,}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ uint32\ d3)}
\DoxyCodeLine{00054\ \{}
\DoxyCodeLine{00055\ \ \ \ \ uint32\ i,\ j,\ k;}
\DoxyCodeLine{00056\ \ \ \ \ float64\ s;}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ d1;\ i++)\ \{}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ d2;\ j++)\ \{}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ compute\ sum\ (i,\ j)\ as\ over\ all\ k\ */}}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (k\ =\ 0,\ s\ =\ 0;\ k\ <\ d3;\ k++)\ \{}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ s\ +=\ arr[i][j][k];}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ do\ 1\ floating\ point\ divide\ */}}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \ \ \ \ s\ =\ 1.0\ /\ s;}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ divide\ all\ k\ by\ sum\ over\ k\ */}}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (k\ =\ 0;\ k\ <\ d3;\ k++)\ \{}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ arr[i][j][k]\ *=\ s;}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00074\ \ \ \ \ \}}
\DoxyCodeLine{00075\ \}}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00078\ accum\_3d(float32\ ***out,}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ \ float32\ ***in,}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \ uint32\ d1,}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \ uint32\ d2,}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ \ uint32\ d3)}
\DoxyCodeLine{00083\ \{}
\DoxyCodeLine{00084\ \ \ \ \ uint32\ i,\ j,\ k;}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00086\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ d1;\ i++)\ \{}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ d2;\ j++)\ \{}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (k\ =\ 0;\ k\ <\ d3;\ k++)\ \{}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ out[i][j][k]\ +=\ in[i][j][k];}
\DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00092\ \ \ \ \ \}}
\DoxyCodeLine{00093\ \}}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00096\ floor\_nz\_3d(float32\ ***m,}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ d1,}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ d2,}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ d3,}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \ \ float32\ floor)}
\DoxyCodeLine{00101\ \{}
\DoxyCodeLine{00102\ \ \ \ \ uint32\ i,\ j,\ k;}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ d1;\ i++)\ \{}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ d2;\ j++)\ \{}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (k\ =\ 0;\ k\ <\ d3;\ k++)\ \{}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((m[i][j][k]\ !=\ 0)\ \&\&\ (m[i][j][k]\ <\ floor))}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ m[i][j][k]\ =\ floor;}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00111\ \ \ \ \ \}}
\DoxyCodeLine{00112\ \}}
\DoxyCodeLine{00113\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00114\ floor\_nz\_1d(float32\ *v,}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ d1,}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \ \ \ \ float32\ floor)}
\DoxyCodeLine{00117\ \{}
\DoxyCodeLine{00118\ \ \ \ \ uint32\ i;}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ d1;\ i++)\ \{}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((v[i]\ !=\ 0)\ \&\&\ (v[i]\ <\ floor))}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ \ \ \ \ v[i]\ =\ floor;}
\DoxyCodeLine{00123\ \ \ \ \ \}}
\DoxyCodeLine{00124\ \}}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00127\ band\_nz\_1d(float32\ *v,}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ uint32\ d1,}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ float32\ band)}
\DoxyCodeLine{00130\ \{}
\DoxyCodeLine{00131\ \ \ \ \ uint32\ i;}
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00133\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ d1;\ i++)\ \{}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (v[i]\ !=\ 0)\ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((v[i]\ >\ 0)\ \&\&\ (v[i]\ <\ band))\ \{}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ v[i]\ =\ band;}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ ((v[i]\ <\ 0)\ \&\&\ (v[i]\ >\ -\/band))\ \{}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ v[i]\ =\ -\/band;}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00142\ \ \ \ \ \}}
\DoxyCodeLine{00143\ \}}
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00145\ \textcolor{preprocessor}{\#ifndef\ WITH\_LAPACK}}
\DoxyCodeLine{00146\ float64}
\DoxyCodeLine{00147\ determinant(float32\ **a,\ int32\ n)}
\DoxyCodeLine{00148\ \{}
\DoxyCodeLine{00149\ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}No\ LAPACK\ library\ available,\ cannot\ compute\ determinant\ (FIXME)\(\backslash\)n"{}});}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordflow}{return}\ 0.0;}
\DoxyCodeLine{00151\ \}}
\DoxyCodeLine{00152\ int32}
\DoxyCodeLine{00153\ invert(float32\ **ainv,\ float32\ **a,\ int32\ n)}
\DoxyCodeLine{00154\ \{}
\DoxyCodeLine{00155\ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}No\ LAPACK\ library\ available,\ cannot\ compute\ matrix\ inverse\ (FIXME)\(\backslash\)n"{}});}
\DoxyCodeLine{00156\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00157\ \}}
\DoxyCodeLine{00158\ int32}
\DoxyCodeLine{00159\ solve(float32\ **a,\ float32\ *b,\ float32\ *out\_x,\ int32\ \ \ n)}
\DoxyCodeLine{00160\ \{}
\DoxyCodeLine{00161\ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}No\ LAPACK\ library\ available,\ cannot\ solve\ linear\ equations\ (FIXME)\(\backslash\)n"{}});}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00163\ \}}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00166\ matrixmultiply(float32\ **\ c,\ float32\ **\ a,\ float32\ **\ b,\ int32\ n)}
\DoxyCodeLine{00167\ \{}
\DoxyCodeLine{00168\ \ \ \ \ int32\ i,\ j,\ k;}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00170\ \ \ \ \ memset(c[0],\ 0,\ n*n*\textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00171\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n;\ ++i)\ \{}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ n;\ ++j)\ \{}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (k\ =\ 0;\ k\ <\ n;\ ++k)\ \{}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ c[i][k]\ +=\ a[i][j]\ *\ b[j][k];}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00177\ \ \ \ \ \}}
\DoxyCodeLine{00178\ \}}
\DoxyCodeLine{00179\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ WITH\_LAPACK\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00180\ \textcolor{comment}{/*\ Find\ determinant\ through\ LU\ decomposition.\ */}}
\DoxyCodeLine{00181\ float64}
\DoxyCodeLine{00182\ determinant(float32\ **\ a,\ int32\ n)}
\DoxyCodeLine{00183\ \{}
\DoxyCodeLine{00184\ \ \ \ \ float32\ **tmp\_a;}
\DoxyCodeLine{00185\ \ \ \ \ float64\ det;}
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{keywordtype}{char}\ uplo;}
\DoxyCodeLine{00187\ \ \ \ \ int32\ info,\ i;}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{comment}{/*\ a\ is\ assumed\ to\ be\ symmetric,\ so\ we\ don't\ need\ to\ switch\ the}}
\DoxyCodeLine{00190\ \textcolor{comment}{\ \ \ \ \ *\ ordering\ of\ the\ data.\ \ But\ we\ do\ need\ to\ copy\ it\ since\ it\ is}}
\DoxyCodeLine{00191\ \textcolor{comment}{\ \ \ \ \ *\ overwritten\ by\ LAPACK.\ */}}
\DoxyCodeLine{00192\ \ \ \ \ tmp\_a\ =\ (float32\ **)ckd\_calloc\_2d(n,\ n,\ \textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00193\ \ \ \ \ memcpy(tmp\_a[0],\ a[0],\ n*n*\textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \ \ \ \ uplo\ =\ \textcolor{charliteral}{'L'};}
\DoxyCodeLine{00196\ \ \ \ \ spotrf\_(\&uplo,\ \&n,\ tmp\_a[0],\ \&n,\ \&info);}
\DoxyCodeLine{00197\ \ \ \ \ det\ =\ tmp\_a[0][0];}
\DoxyCodeLine{00198\ \ \ \ \ \textcolor{comment}{/*\ det\ =\ prod(diag(l))\string^2\ */}}
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 1;\ i\ <\ n;\ ++i)}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ det\ *=\ tmp\_a[i][i];}
\DoxyCodeLine{00201\ \ \ \ \ ckd\_free\_2d((\textcolor{keywordtype}{void}\ **)tmp\_a);}
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{keywordflow}{if}\ (info\ >\ 0)}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1.0;\ \textcolor{comment}{/*\ Generic\ "{}not\ positive-\/definite"{}\ answer\ */}}
\DoxyCodeLine{00204\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ det\ *\ det;}
\DoxyCodeLine{00206\ \}}
\DoxyCodeLine{00207\ }
\DoxyCodeLine{00208\ int32}
\DoxyCodeLine{00209\ solve(float32\ **a,\ \textcolor{comment}{/*Input\ :\ an\ n*n\ matrix\ A\ */}}
\DoxyCodeLine{00210\ \ \ \ \ \ \ float32\ *b,\ \ \textcolor{comment}{/*Input\ :\ a\ n\ dimesion\ vector\ b\ */}}
\DoxyCodeLine{00211\ \ \ \ \ \ \ float32\ *out\_x,\ \ \textcolor{comment}{/*Output\ :\ a\ n\ dimesion\ vector\ x\ */}}
\DoxyCodeLine{00212\ \ \ \ \ \ \ int32\ \ \ n)}
\DoxyCodeLine{00213\ \{}
\DoxyCodeLine{00214\ \ \ \ \ \textcolor{keywordtype}{char}\ uplo;}
\DoxyCodeLine{00215\ \ \ \ \ float32\ **tmp\_a;}
\DoxyCodeLine{00216\ \ \ \ \ int32\ info,\ nrhs;}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{comment}{/*\ a\ is\ assumed\ to\ be\ symmetric,\ so\ we\ don't\ need\ to\ switch\ the}}
\DoxyCodeLine{00219\ \textcolor{comment}{\ \ \ \ \ *\ ordering\ of\ the\ data.\ \ But\ we\ do\ need\ to\ copy\ it\ since\ it\ is}}
\DoxyCodeLine{00220\ \textcolor{comment}{\ \ \ \ \ *\ overwritten\ by\ LAPACK.\ */}}
\DoxyCodeLine{00221\ \ \ \ \ tmp\_a\ =\ (float32\ **)ckd\_calloc\_2d(n,\ n,\ \textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00222\ \ \ \ \ memcpy(tmp\_a[0],\ a[0],\ n*n*\textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00223\ \ \ \ \ memcpy(out\_x,\ b,\ n*\textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00224\ \ \ \ \ uplo\ =\ \textcolor{charliteral}{'L'};}
\DoxyCodeLine{00225\ \ \ \ \ nrhs\ =\ 1;}
\DoxyCodeLine{00226\ \ \ \ \ sposv\_(\&uplo,\ \&n,\ \&nrhs,\ tmp\_a[0],\ \&n,\ out\_x,\ \&n,\ \&info);}
\DoxyCodeLine{00227\ \ \ \ \ ckd\_free\_2d((\textcolor{keywordtype}{void}\ **)tmp\_a);}
\DoxyCodeLine{00228\ }
\DoxyCodeLine{00229\ \ \ \ \ \textcolor{keywordflow}{if}\ (info\ !=\ 0)}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00231\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ info;}
\DoxyCodeLine{00233\ \}}
\DoxyCodeLine{00234\ }
\DoxyCodeLine{00235\ \textcolor{comment}{/*\ Find\ inverse\ by\ solving\ AX=I.\ */}}
\DoxyCodeLine{00236\ int32}
\DoxyCodeLine{00237\ invert(float32\ **\ ainv,\ float32\ **\ a,\ int32\ n)}
\DoxyCodeLine{00238\ \{}
\DoxyCodeLine{00239\ \ \ \ \ \textcolor{keywordtype}{char}\ uplo;}
\DoxyCodeLine{00240\ \ \ \ \ float32\ **tmp\_a;}
\DoxyCodeLine{00241\ \ \ \ \ int32\ info,\ nrhs,\ i;}
\DoxyCodeLine{00242\ }
\DoxyCodeLine{00243\ \ \ \ \ \textcolor{comment}{/*\ Construct\ an\ identity\ matrix.\ */}}
\DoxyCodeLine{00244\ \ \ \ \ memset(ainv[0],\ 0,\ \textcolor{keyword}{sizeof}(float32)\ *\ n\ *\ n);}
\DoxyCodeLine{00245\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n;\ i++)}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ ainv[i][i]\ =\ 1.0;}
\DoxyCodeLine{00247\ \ \ \ \ \textcolor{comment}{/*\ a\ is\ assumed\ to\ be\ symmetric,\ so\ we\ don't\ need\ to\ switch\ the}}
\DoxyCodeLine{00248\ \textcolor{comment}{\ \ \ \ \ *\ ordering\ of\ the\ data.\ \ But\ we\ do\ need\ to\ copy\ it\ since\ it\ is}}
\DoxyCodeLine{00249\ \textcolor{comment}{\ \ \ \ \ *\ overwritten\ by\ LAPACK.\ */}}
\DoxyCodeLine{00250\ \ \ \ \ tmp\_a\ =\ (float32\ **)ckd\_calloc\_2d(n,\ n,\ \textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00251\ \ \ \ \ memcpy(tmp\_a[0],\ a[0],\ n*n*\textcolor{keyword}{sizeof}(float32));}
\DoxyCodeLine{00252\ \ \ \ \ uplo\ =\ \textcolor{charliteral}{'L'};}
\DoxyCodeLine{00253\ \ \ \ \ nrhs\ =\ n;}
\DoxyCodeLine{00254\ \ \ \ \ sposv\_(\&uplo,\ \&n,\ \&nrhs,\ tmp\_a[0],\ \&n,\ ainv[0],\ \&n,\ \&info);}
\DoxyCodeLine{00255\ \ \ \ \ ckd\_free\_2d((\textcolor{keywordtype}{void}\ **)tmp\_a);}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \ \ \ \ \textcolor{keywordflow}{if}\ (info\ !=\ 0)}
\DoxyCodeLine{00258\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00259\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00260\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ info;}
\DoxyCodeLine{00261\ \}}
\DoxyCodeLine{00262\ }
\DoxyCodeLine{00263\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00264\ matrixmultiply(float32\ **\ c,\ float32\ **\ a,\ float32\ **\ b,\ int32\ n)}
\DoxyCodeLine{00265\ \{}
\DoxyCodeLine{00266\ \ \ \ \ \textcolor{keywordtype}{char}\ side,\ uplo;}
\DoxyCodeLine{00267\ \ \ \ \ float32\ alpha;}
\DoxyCodeLine{00268\ }
\DoxyCodeLine{00269\ \ \ \ \ side\ =\ \textcolor{charliteral}{'L'};}
\DoxyCodeLine{00270\ \ \ \ \ uplo\ =\ \textcolor{charliteral}{'L'};}
\DoxyCodeLine{00271\ \ \ \ \ alpha\ =\ 1.0;}
\DoxyCodeLine{00272\ \ \ \ \ ssymm\_(\&side,\ \&uplo,\ \&n,\ \&n,\ \&alpha,\ a[0],\ \&n,\ b[0],\ \&n,\ \&alpha,\ c[0],\ \&n);}
\DoxyCodeLine{00273\ \}}
\DoxyCodeLine{00274\ }
\DoxyCodeLine{00275\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ WITH\_LAPACK\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00278\ outerproduct(float32\ **\ a,\ float32\ *\ x,\ float32\ *\ y,\ int32\ len)}
\DoxyCodeLine{00279\ \{}
\DoxyCodeLine{00280\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00281\ }
\DoxyCodeLine{00282\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ len;\ ++i)\ \{}
\DoxyCodeLine{00283\ \ \ \ \ \ \ \ \ a[i][i]\ =\ x[i]\ *\ y[i];}
\DoxyCodeLine{00284\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ i\ +\ 1;\ j\ <\ len;\ ++j)\ \{}
\DoxyCodeLine{00285\ \ \ \ \ \ \ \ \ \ \ \ \ a[i][j]\ =\ x[i]\ *\ y[j];}
\DoxyCodeLine{00286\ \ \ \ \ \ \ \ \ \ \ \ \ a[j][i]\ =\ x[j]\ *\ y[i];}
\DoxyCodeLine{00287\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00288\ \ \ \ \ \}}
\DoxyCodeLine{00289\ \}}
\DoxyCodeLine{00290\ }
\DoxyCodeLine{00291\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00292\ scalarmultiply(float32\ **\ a,\ float32\ x,\ int32\ n)}
\DoxyCodeLine{00293\ \{}
\DoxyCodeLine{00294\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00295\ }
\DoxyCodeLine{00296\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n;\ ++i)\ \{}
\DoxyCodeLine{00297\ \ \ \ \ \ \ \ \ a[i][i]\ *=\ x;}
\DoxyCodeLine{00298\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ i+1;\ j\ <\ n;\ ++j)\ \{}
\DoxyCodeLine{00299\ \ \ \ \ \ \ \ \ \ \ \ \ a[i][j]\ *=\ x;}
\DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ \ \ \ \ a[j][i]\ *=\ x;}
\DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00302\ \ \ \ \ \}}
\DoxyCodeLine{00303\ \}}
\DoxyCodeLine{00304\ }
\DoxyCodeLine{00305\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00306\ matrixadd(float32\ **\ a,\ float32\ **\ b,\ int32\ n)}
\DoxyCodeLine{00307\ \{}
\DoxyCodeLine{00308\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00309\ }
\DoxyCodeLine{00310\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n;\ ++i)}
\DoxyCodeLine{00311\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ n;\ ++j)}
\DoxyCodeLine{00312\ \ \ \ \ \ \ \ \ \ \ \ \ a[i][j]\ +=\ b[i][j];}
\DoxyCodeLine{00313\ \}}
\DoxyCodeLine{00314\ }
\DoxyCodeLine{00315\ }
\DoxyCodeLine{00316\ \textcolor{comment}{/*}}
\DoxyCodeLine{00317\ \textcolor{comment}{\ *\ Log\ record.\ \ Maintained\ by\ RCS.}}
\DoxyCodeLine{00318\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00319\ \textcolor{comment}{\ *\ \$Log\$}}
\DoxyCodeLine{00320\ \textcolor{comment}{\ *\ Revision\ 1.4\ \ 2004/07/21\ \ 18:05:40\ \ egouvea}}
\DoxyCodeLine{00321\ \textcolor{comment}{\ *\ Changed\ the\ license\ terms\ to\ make\ it\ the\ same\ as\ sphinx2\ and\ sphinx3.}}
\DoxyCodeLine{00322\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00323\ \textcolor{comment}{\ *\ Revision\ 1.3\ \ 2001/04/05\ 20:02:30\ \ awb}}
\DoxyCodeLine{00324\ \textcolor{comment}{\ *\ ***\ empty\ log\ message\ ***}}
\DoxyCodeLine{00325\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00326\ \textcolor{comment}{\ *\ Revision\ 1.2\ \ 2000/09/29\ 22:35:13\ \ awb}}
\DoxyCodeLine{00327\ \textcolor{comment}{\ *\ ***\ empty\ log\ message\ ***}}
\DoxyCodeLine{00328\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00329\ \textcolor{comment}{\ *\ Revision\ 1.1\ \ 2000/09/24\ 21:38:31\ \ awb}}
\DoxyCodeLine{00330\ \textcolor{comment}{\ *\ ***\ empty\ log\ message\ ***}}
\DoxyCodeLine{00331\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00332\ \textcolor{comment}{\ *\ Revision\ 1.1\ \ 97/07/16\ \ 11:36:22\ \ eht}}
\DoxyCodeLine{00333\ \textcolor{comment}{\ *\ Initial\ revision}}
\DoxyCodeLine{00334\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00335\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00336\ \textcolor{comment}{\ */}}

\end{DoxyCode}
