public CholMatrix(Matrix Arg){
  final double[][] A=Arg.toDoubleArray();
  n=(int)Arg.getRowCount();
  L=new double[n][n];
  isspd=(Arg.getColumnCount() == n);
  double[] Lrowj=null;
  double[] Lrowk=null;
  double[] Aj=null;
  for (int j=0; j < n; j++) {
    Lrowj=L[j];
    Aj=A[j];
    double d=0.0;
    for (int k=0; k < j; k++) {
      Lrowk=L[k];
      double s=0.0;
      for (int i=0; i < k; i++) {
        s+=Lrowk[i] * Lrowj[i];
      }
      Lrowj[k]=s=(Aj[k] - s) / Lrowk[k];
      d=d + s * s;
      isspd=isspd & (A[k][j] == Aj[k]);
    }
    d=Aj[j] - d;
    isspd=isspd & (d > 0.0);
    Lrowj[j]=Math.sqrt(Math.max(d,0.0));
    for (int k=j + 1; k < n; k++) {
      Lrowj[k]=0.0;
    }
  }
}

public CholMatrix ( Matrix Arg ) { final double [ ] [ ] A = Arg . toDoubleArray ( ) ; n = ( int ) Arg . getRowCount ( ) ; L = new double [ n ] [ n ] ; isspd = ( Arg . getColumnCount ( ) == n ) ; double [ ] Lrowj = null ; double [ ] Lrowk = null ; double [ ] Aj = null ; for ( int j = 0 ; j < n ; j ++ ) { Lrowj = L [ j ] ; Aj = A [ j ] ; double d = 0.0 ; for ( int k = 0 ; k < j ; k ++ ) { Lrowk = L [ k ] ; double s = 0.0 ; for ( int i = 0 ; i < k ; i ++ ) { s += Lrowk [ i ] * Lrowj [ i ] ; } Lrowj [ k ] = s = ( Aj [ k ] - s ) / Lrowk [ k ] ; d = d + s * s ; isspd = isspd & ( A [ k ] [ j ] == Aj [ k ] ) ; } d = Aj [ j ] - d ; isspd = isspd & ( d > 0.0 ) ; Lrowj [ j ] = Math . sqrt ( Math . max ( d , 0.0 ) ) ; for ( int k = j + 1 ; k < n ; k ++ ) { Lrowj [ k ] = 0.0 ; } } }
cholesky algorithm for symmetric and positive definite matrix .
