\doxysection{include/sphinxbase/matrix.h File Reference}
\label{matrix_8h}\index{include/sphinxbase/matrix.h@{include/sphinxbase/matrix.h}}


Matrix and linear algebra functions.  


{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/prim\+\_\+type.\+h$>$}\newline
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ norm\+\_\+3d} (float32 $\ast$$\ast$$\ast$arr, uint32 d1, uint32 d2, uint32 d3)
\begin{DoxyCompactList}\small\item\em Norm an array. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ accum\+\_\+3d} (float32 $\ast$$\ast$$\ast$out, float32 $\ast$$\ast$$\ast$in, uint32 d1, uint32 d2, uint32 d3)
\begin{DoxyCompactList}\small\item\em Floor 3-\/d array. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ band\+\_\+nz\+\_\+1d} (float32 $\ast$v, uint32 d1, float32 band)
\begin{DoxyCompactList}\small\item\em Ensures that non-\/zero values x such that -\/band $<$ x $<$ band, band $>$ 0 are set to -\/band if x $<$ 0 and band if x $>$ 0. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ floor\+\_\+nz\+\_\+3d} (float32 $\ast$$\ast$$\ast$m, uint32 d1, uint32 d2, uint32 d3, float32 floor)
\begin{DoxyCompactList}\small\item\em Floor 3-\/d array. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ floor\+\_\+nz\+\_\+1d} (float32 $\ast$v, uint32 d1, float32 floor)
\begin{DoxyCompactList}\small\item\em Floor 1-\/d array. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT float64 \textbf{ determinant} (float32 $\ast$$\ast$a, int32 len)
\begin{DoxyCompactList}\small\item\em Calculate the determinant of a positive definite matrix. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int32 \textbf{ invert} (float32 $\ast$$\ast$out\+\_\+ainv, float32 $\ast$$\ast$a, int32 len)
\begin{DoxyCompactList}\small\item\em Invert (if possible) a positive definite matrix. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int32 \textbf{ solve} (float32 $\ast$$\ast$a, float32 $\ast$b, float32 $\ast$out\+\_\+x, int32 n)
\begin{DoxyCompactList}\small\item\em Solve (if possible) a positive-\/definite system of linear equations AX=B for X. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ outerproduct} (float32 $\ast$$\ast$out\+\_\+a, float32 $\ast$x, float32 $\ast$y, int32 len)
\begin{DoxyCompactList}\small\item\em Calculate the outer product of two vectors. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ matrixmultiply} (float32 $\ast$$\ast$out\+\_\+c, float32 $\ast$$\ast$a, float32 $\ast$$\ast$b, int32 n)
\begin{DoxyCompactList}\small\item\em Multiply C=AB where A and B are symmetric matrices. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ scalarmultiply} (float32 $\ast$$\ast$inout\+\_\+a, float32 x, int32 n)
\begin{DoxyCompactList}\small\item\em Multiply a symmetric matrix by a constant in-\/place. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT void \textbf{ matrixadd} (float32 $\ast$$\ast$inout\+\_\+a, float32 $\ast$$\ast$b, int32 n)
\begin{DoxyCompactList}\small\item\em Add A += B. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Matrix and linear algebra functions. 

This file contains some basic matrix and linear algebra operations. In general these operate on positive definite matrices ONLY, because all matrices we\textquotesingle{}re likely to encounter are either covariance matrices or are derived from them, and therefore a non-\/positive-\/definite matrix indicates some kind of pathological condition. 

Definition in file \textbf{ matrix.\+h}.



\doxysubsection{Function Documentation}
\label{matrix_8h_abf02a99f3dac599148c0e1ee5640b568} 
\index{matrix.h@{matrix.h}!accum\_3d@{accum\_3d}}
\index{accum\_3d@{accum\_3d}!matrix.h@{matrix.h}}
\doxysubsubsection{accum\_3d()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void accum\+\_\+3d (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$$\ast$}]{out,  }\item[{float32 $\ast$$\ast$$\ast$}]{in,  }\item[{uint32}]{d1,  }\item[{uint32}]{d2,  }\item[{uint32}]{d3 }\end{DoxyParamCaption})}



Floor 3-\/d array. 


\begin{DoxyParams}{Parameters}
{\em out} & output array @para in input array \\
\hline
{\em d1} & dimension \\
\hline
{\em d2} & dimension \\
\hline
{\em d3} & dimension \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 78} of file \textbf{ matrix.\+c}.



References \textbf{ accum\+\_\+3d()}.



Referenced by \textbf{ accum\+\_\+3d()}.

\label{matrix_8h_a859d32f6b8e86fb215f676245c8deeaf} 
\index{matrix.h@{matrix.h}!band\_nz\_1d@{band\_nz\_1d}}
\index{band\_nz\_1d@{band\_nz\_1d}!matrix.h@{matrix.h}}
\doxysubsubsection{band\_nz\_1d()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void band\+\_\+nz\+\_\+1d (\begin{DoxyParamCaption}\item[{float32 $\ast$}]{v,  }\item[{uint32}]{d1,  }\item[{float32}]{band }\end{DoxyParamCaption})}



Ensures that non-\/zero values x such that -\/band $<$ x $<$ band, band $>$ 0 are set to -\/band if x $<$ 0 and band if x $>$ 0. 


\begin{DoxyParams}{Parameters}
{\em v} & array \\
\hline
{\em d1} & array size \\
\hline
{\em band} & band value \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 127} of file \textbf{ matrix.\+c}.



References \textbf{ band\+\_\+nz\+\_\+1d()}.



Referenced by \textbf{ band\+\_\+nz\+\_\+1d()}.

\label{matrix_8h_a0c810028195f6078c9e99f3b5c29c42b} 
\index{matrix.h@{matrix.h}!determinant@{determinant}}
\index{determinant@{determinant}!matrix.h@{matrix.h}}
\doxysubsubsection{determinant()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT float64 determinant (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{a,  }\item[{int32}]{len }\end{DoxyParamCaption})}



Calculate the determinant of a positive definite matrix. 


\begin{DoxyParams}{Parameters}
{\em a} & The input matrix, must be positive definite. \\
\hline
{\em len} & The dimension of the input matrix. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The determinant of the input matrix, or -\/1.\+0 if the matrix is not positive definite.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
These can be vanishingly small hence the float64 return type. Also note that only the upper triangular portion of a is considered, therefore the check for positive-\/definiteness is not reliable. 
\end{DoxyNote}


Definition at line \textbf{ 147} of file \textbf{ matrix.\+c}.



References \textbf{ determinant()}, and \textbf{ E\+\_\+\+FATAL}.



Referenced by \textbf{ determinant()}.

\label{matrix_8h_a0ec7000944b98cce317e0b63ce437b99} 
\index{matrix.h@{matrix.h}!floor\_nz\_1d@{floor\_nz\_1d}}
\index{floor\_nz\_1d@{floor\_nz\_1d}!matrix.h@{matrix.h}}
\doxysubsubsection{floor\_nz\_1d()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void floor\+\_\+nz\+\_\+1d (\begin{DoxyParamCaption}\item[{float32 $\ast$}]{v,  }\item[{uint32}]{d1,  }\item[{float32}]{floor }\end{DoxyParamCaption})}



Floor 1-\/d array. 


\begin{DoxyParams}{Parameters}
{\em m} & array \\
\hline
{\em d1} & dimension \\
\hline
{\em floor} & floor value \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 114} of file \textbf{ matrix.\+c}.



References \textbf{ floor\+\_\+nz\+\_\+1d()}.



Referenced by \textbf{ floor\+\_\+nz\+\_\+1d()}.

\label{matrix_8h_a7b18b907fca64a8057f7406b8996d9c9} 
\index{matrix.h@{matrix.h}!floor\_nz\_3d@{floor\_nz\_3d}}
\index{floor\_nz\_3d@{floor\_nz\_3d}!matrix.h@{matrix.h}}
\doxysubsubsection{floor\_nz\_3d()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void floor\+\_\+nz\+\_\+3d (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$$\ast$}]{m,  }\item[{uint32}]{d1,  }\item[{uint32}]{d2,  }\item[{uint32}]{d3,  }\item[{float32}]{floor }\end{DoxyParamCaption})}



Floor 3-\/d array. 


\begin{DoxyParams}{Parameters}
{\em m} & array \\
\hline
{\em d1} & dimension \\
\hline
{\em d2} & dimension \\
\hline
{\em d3} & dimension \\
\hline
{\em floor} & floor value \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 96} of file \textbf{ matrix.\+c}.



References \textbf{ floor\+\_\+nz\+\_\+3d()}.



Referenced by \textbf{ floor\+\_\+nz\+\_\+3d()}.

\label{matrix_8h_aa20f437dbe9fcd6f0adda31f181bfbea} 
\index{matrix.h@{matrix.h}!invert@{invert}}
\index{invert@{invert}!matrix.h@{matrix.h}}
\doxysubsubsection{invert()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int32 invert (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{out\+\_\+ainv,  }\item[{float32 $\ast$$\ast$}]{a,  }\item[{int32}]{len }\end{DoxyParamCaption})}



Invert (if possible) a positive definite matrix. 


\begin{DoxyParams}{Parameters}
{\em out\+\_\+ainv} & The inverse of a will be stored here. \\
\hline
{\em a} & The input matrix, must be positive definite. \\
\hline
{\em len} & The dimension of the input matrix. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 for success or -\/1 for a non-\/positive-\/definite matrix.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
Only the upper triangular portion of a is considered, therefore the check for positive-\/definiteness is not reliable. 
\end{DoxyNote}


Definition at line \textbf{ 153} of file \textbf{ matrix.\+c}.



References \textbf{ E\+\_\+\+FATAL}, and \textbf{ invert()}.



Referenced by \textbf{ invert()}.

\label{matrix_8h_a545d251a51cc473bad38a83b2a05f61c} 
\index{matrix.h@{matrix.h}!matrixadd@{matrixadd}}
\index{matrixadd@{matrixadd}!matrix.h@{matrix.h}}
\doxysubsubsection{matrixadd()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void matrixadd (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{inout\+\_\+a,  }\item[{float32 $\ast$$\ast$}]{b,  }\item[{int32}]{n }\end{DoxyParamCaption})}



Add A += B. 


\begin{DoxyParams}{Parameters}
{\em inout\+\_\+a} & The A matrix to add. \\
\hline
{\em b} & The B matrix to add to A. \\
\hline
{\em n} & dimension of a and b. \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 306} of file \textbf{ matrix.\+c}.



References \textbf{ matrixadd()}.



Referenced by \textbf{ matrixadd()}.

\label{matrix_8h_acaaf5d2c02d9d12f10abc462ac65cde9} 
\index{matrix.h@{matrix.h}!matrixmultiply@{matrixmultiply}}
\index{matrixmultiply@{matrixmultiply}!matrix.h@{matrix.h}}
\doxysubsubsection{matrixmultiply()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void matrixmultiply (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{out\+\_\+c,  }\item[{float32 $\ast$$\ast$}]{a,  }\item[{float32 $\ast$$\ast$}]{b,  }\item[{int32}]{n }\end{DoxyParamCaption})}



Multiply C=AB where A and B are symmetric matrices. 


\begin{DoxyParams}{Parameters}
{\em out\+\_\+c} & The output matrix C. \\
\hline
{\em a} & The input matrix A. \\
\hline
{\em b} & The input matrix B. \\
\hline
{\em n} & Dimensionality of A and B. \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 166} of file \textbf{ matrix.\+c}.



References \textbf{ matrixmultiply()}.



Referenced by \textbf{ matrixmultiply()}.

\label{matrix_8h_af209fc89926fd184f5a02919ec7c9818} 
\index{matrix.h@{matrix.h}!norm\_3d@{norm\_3d}}
\index{norm\_3d@{norm\_3d}!matrix.h@{matrix.h}}
\doxysubsubsection{norm\_3d()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void norm\+\_\+3d (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$$\ast$}]{arr,  }\item[{uint32}]{d1,  }\item[{uint32}]{d2,  }\item[{uint32}]{d3 }\end{DoxyParamCaption})}



Norm an array. 


\begin{DoxyParams}{Parameters}
{\em arr} & array \\
\hline
{\em d1} & dimension \\
\hline
{\em d2} & dimension \\
\hline
{\em d3} & dimension \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 50} of file \textbf{ matrix.\+c}.



References \textbf{ norm\+\_\+3d()}.



Referenced by \textbf{ norm\+\_\+3d()}.

\label{matrix_8h_aa2d31d63ec277fd389d4ef51d3b2bc2b} 
\index{matrix.h@{matrix.h}!outerproduct@{outerproduct}}
\index{outerproduct@{outerproduct}!matrix.h@{matrix.h}}
\doxysubsubsection{outerproduct()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void outerproduct (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{out\+\_\+a,  }\item[{float32 $\ast$}]{x,  }\item[{float32 $\ast$}]{y,  }\item[{int32}]{len }\end{DoxyParamCaption})}



Calculate the outer product of two vectors. 


\begin{DoxyParams}{Parameters}
{\em out\+\_\+a} & A (pre-\/allocated) len x len array. The outer product will be stored here. \\
\hline
{\em x} & A vector of length len. \\
\hline
{\em y} & A vector of length len. \\
\hline
{\em len} & The length of the input vectors. \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 278} of file \textbf{ matrix.\+c}.



References \textbf{ outerproduct()}.



Referenced by \textbf{ outerproduct()}.

\label{matrix_8h_adc8ee5f4e4792328e4f33309bc99ebfb} 
\index{matrix.h@{matrix.h}!scalarmultiply@{scalarmultiply}}
\index{scalarmultiply@{scalarmultiply}!matrix.h@{matrix.h}}
\doxysubsubsection{scalarmultiply()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT void scalarmultiply (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{inout\+\_\+a,  }\item[{float32}]{x,  }\item[{int32}]{n }\end{DoxyParamCaption})}



Multiply a symmetric matrix by a constant in-\/place. 


\begin{DoxyParams}{Parameters}
{\em inout\+\_\+a} & The matrix to multiply. \\
\hline
{\em x} & The constant to multiply it by. \\
\hline
{\em n} & dimension of a. \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 292} of file \textbf{ matrix.\+c}.



References \textbf{ scalarmultiply()}.



Referenced by \textbf{ scalarmultiply()}.

\label{matrix_8h_a174a82dac39a15828af6c87edcba3708} 
\index{matrix.h@{matrix.h}!solve@{solve}}
\index{solve@{solve}!matrix.h@{matrix.h}}
\doxysubsubsection{solve()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int32 solve (\begin{DoxyParamCaption}\item[{float32 $\ast$$\ast$}]{a,  }\item[{float32 $\ast$}]{b,  }\item[{float32 $\ast$}]{out\+\_\+x,  }\item[{int32}]{n }\end{DoxyParamCaption})}



Solve (if possible) a positive-\/definite system of linear equations AX=B for X. 


\begin{DoxyParams}{Parameters}
{\em a} & The A matrix on the left-\/hand side of the equation, must be positive-\/definite. \\
\hline
{\em b} & The B vector on the right-\/hand side of the equation. \\
\hline
{\em out\+\_\+x} & The X vector will be stored here. \\
\hline
{\em n} & The dimension of the A matrix (n by n) and the B and X vectors. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 for success or -\/1 for a non-\/positive-\/definite matrix.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
Only the upper triangular portion of a is considered, therefore the check for positive-\/definiteness is not reliable. 
\end{DoxyNote}


Definition at line \textbf{ 159} of file \textbf{ matrix.\+c}.



References \textbf{ E\+\_\+\+FATAL}, and \textbf{ solve()}.



Referenced by \textbf{ solve()}.

