public ParallelColtDenseDoubleMatrix2D(int rows, int columns) { super(rows, columns); this.matrix = new cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D(rows, columns); }
public void setDouble(double value, int row, int column) { matrix.setQuick(row, column, value); }
public DoubleMatrix2D assign(final float[] values) { if (values.length != size()) throw new IllegalArgumentException("Must have same length: length=" + values.length + "rows()*columns()=" + rows() * columns()); final int zero = (int) index(0, 0); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { nthreads = Math.min(nthreads, rows); Future<?>[] futures = new Future[nthreads];
C = new DenseDoubleMatrix2D(rowsC, columnsC); return viewDice().zMult(B, C, alpha, beta, false, transposeB); if (B instanceof SparseDoubleMatrix2D || B instanceof SparseRCDoubleMatrix2D) { return this.zMult(B.viewDice(), C, alpha, beta, transposeA, false); throw new IllegalArgumentException("Matrix2D inner dimensions must agree:" + this.toStringShort() + ", " + B.toStringShort()); if (C.rows() != rowsA || C.columns() != columnsB) throw new IllegalArgumentException("Incompatibe result matrix: " + this.toStringShort() + ", " + B.toStringShort() + ", " + C.toStringShort()); if (this == C || B == C) return this.zMultSequential(B, C, alpha, beta, transposeA, transposeB); } else { AA = this.viewPart(offset, 0, span, columnsA); BB = B; CC = C.viewPart(offset, 0, span, columnsB);
private DoubleMatrix2D zMultSequential(DoubleMatrix2D B, DoubleMatrix2D C, double alpha, double beta, boolean transposeA, boolean transposeB) { if (transposeA) return viewDice().zMult(B, C, alpha, beta, false, transposeB); if (B instanceof SparseDoubleMatrix2D || B instanceof SparseRCDoubleMatrix2D || B instanceof SparseCCDoubleMatrix2D) { return this.zMult(B.viewDice(), C, alpha, beta, transposeA, false); int p = B.columns(); if (C == null) { C = new DenseDoubleMatrix2D(rowsA, p); throw new IllegalArgumentException("Matrix2D inner dimensions must agree:" + toStringShort() + ", " + B.toStringShort()); if (C.rows() != rowsA || C.columns() != p) throw new IllegalArgumentException("Incompatibel result matrix: " + toStringShort() + ", " + B.toStringShort() + ", " + C.toStringShort()); if (this == C || B == C) blocks++; for (; --blocks >= 0;) { int jB = (int) BB.index(0, 0); int indexA = (int) index(rr, 0); int jC = (int) CC.index(rr, 0); rr += m_optimal; if (blocks == 0)
/** * Computes the 2D discrete Hartley transform (DHT) of this matrix. * */ public void dht2() { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); if (dht2 == null) { dht2 = new DoubleDHT_2D(rows, columns); } if (isNoView == true) { dht2.forward(elements); } else { DoubleMatrix2D copy = this.copy(); dht2.forward((double[]) copy.elements()); this.assign((double[]) copy.elements()); } ConcurrencyUtils.setNumberOfThreads(oldNthreads); }
public DoubleMatrix2D getRealPart() { final DenseDoubleMatrix2D R = new DenseDoubleMatrix2D(rows, columns); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { for (int c = 0; c < columns; c++) { tmp = getQuick(r, c); R.setQuick(r, c, tmp[0]);
if (other == this) return this; // nothing to do checkShape(other); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if (this.isNoView && other.isNoView) { // quickest return this; if (haveSharedCells(other)) { DoubleMatrix2D c = other.copy(); if (!(c instanceof DenseDoubleMatrix2D)) { // should not happen super.assign(other); if (elements == null || elementsOther == null) throw new InternalError(); final int zeroOther = (int) other.index(0, 0); final int zero = (int) index(0, 0); final int columnStrideOther = other.columnStride; final int rowStrideOther = other.rowStride; if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { nthreads = Math.min(nthreads, rows); Future<?>[] futures = new Future[nthreads];
/** * Returns the right singular vectors <tt>V</tt>. * * @return <tt>V</tt> */ public DoubleMatrix2D getV() { if (wantUV == false) { throw new IllegalAccessError("Matrix V was not computed"); } else { if (V == null) { if (wantWholeUV == false) { if (columnMatrix) { V = new DenseColumnDoubleMatrix2D(mn, n).assign(elementsVt).viewDice(); } else { V = new DenseDoubleMatrix2D(n, mn).assign(elementsVt); } } else { if (columnMatrix) { V = new DenseColumnDoubleMatrix2D(n, n).assign(elementsVt).viewDice(); } else { V = new DenseDoubleMatrix2D(n, n).assign(elementsVt); } } } return V.copy(); } }
public Matrix mtimes(Matrix m) { if (m instanceof ParallelColtDenseDoubleMatrix2D) { cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D ret = new cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D( (int) getRowCount(), (int) m.getColumnCount()); matrix.zMult(((ParallelColtDenseDoubleMatrix2D) m).matrix, ret); Matrix result = new ParallelColtDenseDoubleMatrix2D(ret); MapMatrix<String, Object> a = getMetaData(); if (a != null) { result.setMetaData(a.clone()); } return result; } else { return super.mtimes(m); } }
public DoubleMatrix1D zMult(final DoubleMatrix1D y, DoubleMatrix1D z, final double alpha, final double beta, final boolean transposeA) { if (transposeA) return viewDice().zMult(y, z, alpha, beta, false); if (z == null) { z = new DenseDoubleMatrix1D(rows); throw new IllegalArgumentException("Incompatible args: " + toStringShort() + ", " + y.toStringShort() + ", " + z.toStringShort()); final int strideY = y.stride(); final int strideZ = z.stride(); final int zero = (int) index(0, 0); final int zeroY = (int) y.index(0); final int zeroZ = (int) z.index(0); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { nthreads = Math.min(nthreads, rows); Future<?>[] futures = new Future[nthreads];
public Matrix copy() { Matrix m = new ParallelColtDenseDoubleMatrix2D( (cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D) matrix.copy()); if (getMetaData() != null) { m.setMetaData(getMetaData().clone()); } return m; }
checkShape(y); final double[] elementsOther = other.elements; if (elements == null || elementsOther == null) throw new InternalError(); final int zeroOther = (int) other.index(0, 0); final int zero = (int) index(0, 0); final int columnStrideOther = other.columnStride; final int rowStrideOther = other.rowStride; int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { if (function instanceof cern.jet.math.tdouble.DoublePlusMultSecond) { double multiplicator = ((cern.jet.math.tdouble.DoublePlusMultSecond) function).multiplicator;
public void run() { int idx = zero + firstRow * rowStride; for (int r = firstRow; r < lastRow; r++) { double[] currentRow = values[r]; if (currentRow.length != columns) throw new IllegalArgumentException( "Must have same number of columns in every row: columns=" + currentRow.length + "columns()=" + columns()); for (int i = idx, c = 0; c < columns; c++) { elements[i] = currentRow[c]; i += columnStride; } idx += rowStride; } } });
checkShape(B); int r = rows - 1; int c = columns - 1; throw new InternalError(); int A_index = (int) index(1, 1); int B_index = (int) BB.index(1, 1); for (int i = 1; i < r; i++) { double a00, a01, a02;
public Matrix invSPD() { DenseDoubleCholeskyDecomposition chol = new DenseDoubleCholeskyDecomposition(matrix); DoubleMatrix2D ret = DoubleFactory2D.dense.identity(matrix.rows()); chol.solve(ret); return new ParallelColtDenseDoubleMatrix2D(ret); }
public Matrix transpose() { return new ParallelColtDenseDoubleMatrix2D((cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D) matrix .viewDice().copy()); }
/** * Constructs a matrix with a copy of the given values. <tt>values</tt> is * required to have the form <tt>values[row][column]</tt> and have exactly * the same number of columns in every row. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not * reflected in the matrix, and vice-versa. * * @param values * The values to be filled into the new matrix. * @throws IllegalArgumentException * if * <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length</tt> * . */ public DenseDoubleMatrix2D(double[][] values) { this(values.length, values.length == 0 ? 0 : values[0].length); assign(values); }
public DoubleMatrix2D assign(final float[] values) { if (values.length != size()) throw new IllegalArgumentException("Must have same length: length=" + values.length + "rows()*columns()=" + rows() * columns()); final int zero = (int) index(0, 0); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (size() >= ConcurrencyUtils.getThreadsBeginN_2D())) { nthreads = Math.min(nthreads, rows); Future<?>[] futures = new Future[nthreads];