%macro mat_chol(input=, cholesky=);
/**********************************************************************/
/* This macro computes the Cholesky decomposition for a square matrix */
/* */
/* Macro variables: */
/* input - the matrix that is to be inverted */
/* cholesky - cholesky decomposition of the matrix to be inverted */
/* */
/* Author: Dale McLerran */
/* Fred Hutchinson Cancer Research Center */
/* */
/**********************************************************************/

_n_dim = dim(&input,1);
/* Initialize to 0 */
do i=1 to _n_dim;
do j=1 to _n_dim;
&cholesky{i,j} = 0;
end;
end;

do j=1 to _n_dim;
do i=1 to j-1;
tmp_sum = 0;
do k=1 to i-1;
tmp_sum + &cholesky{k,i}*&cholesky{k,j};
end;
&cholesky{i,j} = (&input{i,j} - tmp_sum) / &cholesky{i,i};
&cholesky{j,i} = &cholesky{i,j} * 0;
end;

tmp_sum = 0;
do k=1 to j-1;
tmp_sum + &cholesky{k,j}**2;
end;
&cholesky{j,j} = sqrt(&input{j,j} - tmp_sum);
end;
%mend;