Mult div = Mult.div(0);
PlusMult minusMult = PlusMult.minusMult(0);
IntArrayList nonZeroIndexes =
new IntArrayList(); // sparsity
DoubleMatrix1D Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(nx); // blocked row k
// Solve L*Y = B(piv,:)
int CUT_OFF = 10;
for (int k = 0; k < n; k++) {
// blocking (make copy of k-th row to localize references)
Browk.assign(Brows[k]);
// sparsity detection
int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
int cardinality = nonZeroIndexes.size();
boolean sparse = (cardinality < maxCardinality);
for (int i = k + 1; i < n; i++) {
//for (int j = 0; j < nx; j++) B[i][j] -= B[k][j]*LU[i][k];
//for (int j = 0; j < nx; j++) B.set(i,j, B.get(i,j) - B.get(k,j)*LU.get(i,k));
minusMult.setMultiplicator(-LU.getQuick(i, k));
if (minusMult.getMultiplicator() != 0) {
if (sparse) {
Brows[i].assign(Browk, minusMult, nonZeroIndexes);
} else {
Brows[i].assign(Browk, minusMult);
}
}
}
}
// Solve U*B = Y;
for (int k = n - 1; k >= 0; k--) {
// for (int j = 0; j < nx; j++) B[k][j] /= LU[k][k];
// for (int j = 0; j < nx; j++) B.set(k,j, B.get(k,j) / LU.get(k,k));
div.setMultiplicator(1 / LU.getQuick(k, k));
Brows[k].assign(div);
// blocking
if (Browk == null) {
Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(B.columns());
}
Browk.assign(Brows[k]);
// sparsity detection
int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
int cardinality = nonZeroIndexes.size();
boolean sparse = (cardinality < maxCardinality);
//Browk.getNonZeros(nonZeroIndexes,null);
//boolean sparse = nonZeroIndexes.size() < nx/10;