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 cutOff = 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 / cutOff; // == 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 / cutOff; // == 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;