public DoubleMatrix2D getL() { if (L == null) { L = new SparseCCDoubleMatrix2D(N.L); if (rcMatrix) { L = ((SparseCCDoubleMatrix2D) L).getRowCompressed(); } } return L.copy(); }
public DoubleMatrix2D assign(final cern.colt.function.tdouble.DoubleFunction function) { if (function instanceof cern.jet.math.tdouble.DoubleMult) { // x[i] = mult*x[i] final double alpha = ((cern.jet.math.tdouble.DoubleMult) function).multiplicator; if (alpha == 1) return this; if (alpha == 0) return assign(0); if (alpha != alpha) return assign(alpha); // the funny definition of isNaN(). This should better not happen. final double[] valuesE = dcs.x; int nz = cardinality(); for (int j = 0; j < nz; j++) { valuesE[j] *= alpha; } } else { forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() { public double apply(int i, int j, double value) { return function.apply(value); } }); } return this; }
int n = I.rows(), c = I.columns(); SparseRCMDoubleMatrix2D Ac = new SparseRCMDoubleMatrix2D(c, c); DenseDoubleMatrix1D itaiV = new DenseDoubleMatrix1D(c, itaiCol, 0, 1, false); int[] colptr = I.getColumnPointers(); int[] rowind = I.getRowIndexes(); double[] Idata = I.getValues(); I.zMult(aiV, itaiV, 1, 0, true);
public DoubleMatrix2D assign(DoubleMatrix2D source) { if (source == this) return this; // nothing to do checkShape(source); System.arraycopy(other.getColumnPointers(), 0, this.dcs.p, 0, columns + 1); int nzmax = other.getRowIndexes().length; if (dcs.nzmax < nzmax) { dcs.i = new int[nzmax]; dcs.x = new double[nzmax]; System.arraycopy(other.getRowIndexes(), 0, this.dcs.i, 0, nzmax); System.arraycopy(other.getValues(), 0, this.dcs.x, 0, nzmax); rowIndexesSorted = other.rowIndexesSorted; } else if (source instanceof SparseRCDoubleMatrix2D) { rowIndexesSorted = true; } else { assign(0); source.forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() { public double apply(int i, int j, double value) {
if (C == null) { if (B instanceof SparseCCDoubleMatrix2D) { C = new SparseCCDoubleMatrix2D(rowsA, p, (rowsA * p)); } else { C = new DenseDoubleMatrix2D(rowsA, p); throw new IllegalArgumentException("Matrix2D inner dimensions must agree:" + toStringShort() + ", " + (transposeB ? B.viewDice() : B).toStringShort()); if (C.rows() != rowsA || C.columns() != p) throw new IllegalArgumentException("Incompatible result matrix: " + toStringShort() + ", " + (transposeB ? B.viewDice() : B).toStringShort() + ", " + C.toStringShort()); if (this == C || B == C) SparseCCDoubleMatrix2D AA; if (transposeA) { AA = getTranspose(); } else { AA = this; SparseCCDoubleMatrix2D AA; if (transposeA) { AA = getTranspose(); } else { AA = this; BB = BB.getTranspose(); CC.assign(cern.jet.math.tdouble.DoubleFunctions.mult(alpha));
public DoubleMatrix2D like(int rows, int columns) { return new SparseCCDoubleMatrix2D(rows, columns); }
/** * * Returns the triangular factor, <tt>L'</tt>. * * @return <tt>L'</tt> */ public DoubleMatrix2D getLtranspose() { if (L == null) { L = new SparseCCDoubleMatrix2D(N.L); if (rcMatrix) { L = ((SparseCCDoubleMatrix2D) L).getRowCompressed(); } } if (rcMatrix) { return ((SparseRCDoubleMatrix2D) L).getTranspose(); } else { return ((SparseCCDoubleMatrix2D) L).getTranspose(); } }
columnIndexesSorted = other.columnIndexesSorted; } else if (source instanceof SparseCCDoubleMatrix2D) { SparseCCDoubleMatrix2D other = ((SparseCCDoubleMatrix2D) source).getTranspose(); rowPointers = other.getColumnPointers(); columnIndexes = other.getRowIndexes(); values = other.getValues(); columnIndexesSorted = true; } else {
/** * Creates the interpolation (prolongation) matrix based on the * non-smoothed aggregates */ private SparseCCDoubleMatrix2D createInterpolationMatrix(int[] pt, int c) { SparseCCMDoubleMatrix2D If = new SparseCCMDoubleMatrix2D(pt.length, c); for (int i = 0; i < pt.length; ++i) if (pt[i] != -1) If.setQuick(i, pt[i], 1); return (SparseCCDoubleMatrix2D) (new SparseCCDoubleMatrix2D(If.rows(), If.columns()).assign(If)); }
/** * Creates the interpolation (prolongation) matrix based on the smoothed * aggregates */ private SparseCCDoubleMatrix2D createInterpolationMatrix(List<Map<Integer, Double>> P, int n) { // Determine the sparsity pattern of I int c = P.size(); // int[][] nz = new int[c][]; // for (int j = 0; j < c; ++j) { // // Map<Integer, Double> Pj = P.get(j); // nz[j] = new int[Pj.size()]; // // int l = 0; // for (int k : Pj.keySet()) // nz[j][l++] = k; // } I = new SparseCCDoubleMatrix2D(n, c); // Populate it with numerical entries for (int j = 0; j < c; ++j) { Map<Integer, Double> Pj = P.get(j); for (Map.Entry<Integer, Double> e : Pj.entrySet()) I.setQuick(e.getKey(), j, e.getValue()); } return I; }
public DoubleMatrix2D assign(final DoubleMatrix2D y, cern.colt.function.tdouble.DoubleDoubleFunction function) { checkShape(y); final double alpha = ((cern.jet.math.tdouble.DoublePlusMultFirst) function).multiplicator; if (alpha == 0) return assign(y); y.forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() { public double apply(int i, int j, double value) { valuesA[k] *= y.getQuick(i, j); if (valuesA[k] == 0) remove(i, j); valuesA[k] /= y.getQuick(i, j); if (valuesA[k] == 0) remove(i, j);
if (A instanceof SparseRCDoubleMatrix2D) { rcMatrix = true; dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().elements(); } else { dcs = (Dcs) A.elements();
rcMatrix = true; if (m >= n) { dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().elements(); } else { dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().getTranspose().elements(); dcs = (Dcs) A.elements(); } else { dcs = ((SparseCCDoubleMatrix2D) A).getTranspose().elements();
+ ((transposeA ? viewDice() : this).toStringShort()) + ", " + y.toStringShort() + ", " + z.toStringShort()); if ((nthreads > 1) && (cardinality() >= ConcurrencyUtils.getThreadsBeginN_2D())) { nthreads = 2; Future<?>[] futures = new Future[nthreads]; if ((nthreads > 1) && (cardinality() >= ConcurrencyUtils.getThreadsBeginN_2D())) { Future<?>[] futures = new Future[nthreads]; int k = columns / nthreads;
public DoubleMatrix2D assign(double value) { if (value == 0) { Arrays.fill(dcs.i, 0); Arrays.fill(dcs.p, 0); Arrays.fill(dcs.x, 0); } else { int nnz = cardinality(); for (int i = 0; i < nnz; i++) { dcs.x[i] = value; } } return this; }
public double apply(int i, int j, double value) { dense.setQuick(i, j, getQuick(i, j)); return value; } });
/** * Returns the infinity norm of matrix <tt>A</tt>, which is the maximum * absolute row sum. */ public double normInfinity(DoubleMatrix2D A) { DoubleProperty.DEFAULT.checkSparse(A); double norm; if (A instanceof SparseRCDoubleMatrix2D) { norm = normInfinityRC((SparseRCDoubleMatrix2D) A); } else { norm = normInfinityRC(((SparseCCDoubleMatrix2D) A).getRowCompressed()); } return norm; }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a dense form. This method creates a new object (not a view), so changes * in the returned matrix are NOT reflected in this matrix. * * @return this matrix in a dense form */ public DenseDoubleMatrix2D getDense() { final DenseDoubleMatrix2D dense = new DenseDoubleMatrix2D(rows, columns); forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() { public double apply(int i, int j, double value) { dense.setQuick(i, j, getQuick(i, j)); return value; } }); return dense; }
/** * 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 SparseCCDoubleMatrix2D(double[][] values) { this(values.length, values[0].length); assign(values); }