Skip to content

Commit

Permalink
Merge branch 'master' of github.com:0xdata/h2o
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalohlava committed Dec 5, 2013
2 parents f35328e + 6ea8f48 commit 563389b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/hex/gram/Gram.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import jsr166y.RecursiveAction;
import water.*;
import water.util.Log;
import water.util.Utils;
import Jama.CholeskyDecomposition;
import Jama.Matrix;
Expand Down Expand Up @@ -66,7 +67,7 @@ public String toString(){
} else return Utils.pprint(getXX());
}
static public class InPlaceCholesky {
final double _xx[][]; // Lower triagle of the symmetric matrix.
final double _xx[][]; // Lower triangle of the symmetric matrix.
private boolean _isSPD;
private InPlaceCholesky(double xx[][], boolean isspd) { _xx = xx; _isSPD = isspd; }
static private class BlockTask extends RecursiveAction {
Expand All @@ -77,8 +78,6 @@ public BlockTask(double xx[][], int ifr, int ito, int jfr, int jto) {
_i0 = ifr; _i1 = ito; _j0 = jfr; _j1 = jto;
}
@Override public void compute() {
//Log.info("TASK THREAD ID -- " + Thread.currentThread().getName());
//Log.info(" BLOCK SIZE " + (_i1 - _i0));
for (int i=_i0; i < _i1; i++) {
double rowi[] = _xx[i];
for (int k=_j0; k < _j1; k++) {
Expand Down Expand Up @@ -164,7 +163,6 @@ public Cholesky cholesky(Cholesky chol, int parallelize) {
final Cholesky fchol = chol;
final int sparseN = _diag.length;
final int denseN = _fullN - sparseN;
boolean spd=true;
// compute the cholesky of the diagonal and diagonal*dense parts
if( _diag != null ) for( int i = 0; i < sparseN; ++i ) {
double d = 1.0 / (chol._diag[i] = Math.sqrt(_diag[i]));
Expand All @@ -173,18 +171,25 @@ public Cholesky cholesky(Cholesky chol, int parallelize) {
}
Futures fs = new Futures();
// compute the outer product of diagonal*dense
final int chk = Math.max(denseN/10, 1);
//Log.info("SPARSEN = " + sparseN + " DENSEN = " + denseN);

for( int i = 0; i < denseN; ++i ) {
final int fi = i;
fs.add(new RecursiveAction() {
@Override protected void compute() {
double[] rowi = fchol._xx[fi];
int[] nz = new int[sparseN];
int n = 0;
for( int k = 0; k < sparseN; ++k )
if (rowi[k] != .0) nz[n++] = k;
for( int j = 0; j <= fi; ++j ) {
double[] rowj = fchol._xx[j];
double s = 0;
for( int k = 0; k < sparseN; ++k )
s += fchol._xx[fi][k] * fchol._xx[j][k];
fchol._xx[fi][j + sparseN] = _xx[fi][j + sparseN] - s;
for ( int z = 0; z < n; z++) {
int k = nz[z];
s += rowi[k] * rowj[k];
}
rowi[j + sparseN] = _xx[fi][j + sparseN] - s;
}
}
}.fork());
Expand Down

0 comments on commit 563389b

Please sign in to comment.