use of cern.colt.function.tdouble.IntIntDoubleFunction in project clusterMaker2 by RBVI.
the class ColtOps method divideScalar.
/**
* divide all cells in the matrix by a value
*
* @param matrix our matrix
* @param value to divide each cell by
*/
public void divideScalar(double value) {
DoubleMatrix2D data = getData();
data.forEachNonZero(new IntIntDoubleFunction() {
public double apply(int row, int column, double v) {
return v / value;
}
});
}
use of cern.colt.function.tdouble.IntIntDoubleFunction in project clusterMaker2 by RBVI.
the class ColtOps method addScalar.
/**
* add a value to all cells in the matrix
*
* @param value to add to each cell
*/
public void addScalar(double value) {
DoubleMatrix2D data = getData();
data.forEachNonZero(new IntIntDoubleFunction() {
public double apply(int row, int column, double v) {
return v + value;
}
});
}
use of cern.colt.function.tdouble.IntIntDoubleFunction in project clusterMaker2 by RBVI.
the class ColtOps method subtractElement.
/**
* subtract a matrix from this matrix
*
* @param subtrahend the matrix to subtract from our matrix
*/
public void subtractElement(Matrix subtrahend) {
DoubleMatrix2D data = getData();
data.forEachNonZero(new IntIntDoubleFunction() {
public double apply(int row, int column, double v) {
double subValue = subtrahend.doubleValue(row, column);
if (!Double.isNaN(subValue))
return v - subValue;
else
return v;
}
});
}
use of cern.colt.function.tdouble.IntIntDoubleFunction in project clusterMaker2 by RBVI.
the class ColtOps method multiplyScalar.
/**
* multiple all cells in the matrix by a value
*
* @param matrix our matrix
* @param value to multiply each cell by
*/
public void multiplyScalar(double value) {
DoubleMatrix2D data = getData();
data.forEachNonZero(new IntIntDoubleFunction() {
public double apply(int row, int column, double v) {
return v * value;
}
});
}
use of cern.colt.function.tdouble.IntIntDoubleFunction in project clusterMaker2 by RBVI.
the class ColtOps method multiplyMatrix.
// For some reason, the parallelcolt version of zMult doesn't
// really take advantage of the available cores. This version does, but
// it seems like it only works for multiplying matrices of the same
// size.
public Matrix multiplyMatrix(Matrix matrix2) {
// return mult(matrix);
// if (matrix2.nRows() != matrix.nRows() || matrix2.nColumns() != matrix.nColumns()())
// return mult(matrix);
DoubleMatrix2D A = getData();
DoubleMatrix2D B = matrix2.getColtMatrix();
int m = A.rows();
int n = A.columns();
int p = B.columns();
// Create views into B
final DoubleMatrix1D[] Brows = new DoubleMatrix1D[n];
for (int i = n; --i >= 0; ) Brows[i] = B.viewRow(i);
// Create a series of 1D vectors
final DoubleMatrix1D[] Crows = new DoubleMatrix1D[m];
for (int i = m; --i >= 0; ) Crows[i] = B.like1D(p);
// Create the thread pools
final ExecutorService[] threadPools = new ExecutorService[nThreads];
for (int pool = 0; pool < threadPools.length; pool++) {
threadPools[pool] = Executors.newFixedThreadPool(1);
}
A.forEachNonZero(new IntIntDoubleFunction() {
public double apply(int row, int column, double value) {
Runnable r = new ThreadedDotProduct(value, Brows[column], Crows[row]);
threadPools[row % nThreads].submit(r);
return value;
}
});
for (int pool = 0; pool < threadPools.length; pool++) {
threadPools[pool].shutdown();
try {
boolean result = threadPools[pool].awaitTermination(7, TimeUnit.DAYS);
} catch (Exception e) {
}
}
// Recreate C
return new ColtMatrix(matrix, create2DMatrix(Crows));
}
Aggregations