Search in sources :

Example 1 with IntIntDoubleFunction

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;
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 2 with IntIntDoubleFunction

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;
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 3 with IntIntDoubleFunction

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;
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 4 with IntIntDoubleFunction

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;
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 5 with IntIntDoubleFunction

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));
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DoubleMatrix1D(cern.colt.matrix.tdouble.DoubleMatrix1D) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

IntIntDoubleFunction (cern.colt.function.tdouble.IntIntDoubleFunction)8 DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)8 DoubleMatrix1D (cern.colt.matrix.tdouble.DoubleMatrix1D)1 ExecutorService (java.util.concurrent.ExecutorService)1