/** * 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. Only the values on the main * diagonal, i.e. values[i][i] are used. * <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. * @param dindex * index of the diagonal. * @throws IllegalArgumentException * if * * <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length || index < -rows+1 || index > columns - 1</tt> * . */ public DiagonalDoubleMatrix2D(double[][] values, int dindex) { this(values.length, values.length == 0 ? 0 : values[0].length, dindex); assign(values); }
public DoubleMatrix2D assign(DoubleMatrix2D source) { // overriden for performance only if (source == this) return this; // nothing to do checkShape(source); if (source instanceof DiagonalDoubleMatrix2D) { DiagonalDoubleMatrix2D other = (DiagonalDoubleMatrix2D) source; if ((dindex != other.dindex) || (dlength != other.dlength)) { throw new IllegalArgumentException("source is DiagonalDoubleMatrix2D with different diagonal stored."); } // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; } else { return super.assign(source); } }
public boolean equals(Object obj) { if (content instanceof DiagonalDoubleMatrix2D && obj instanceof DiagonalDoubleMatrix2D) { double epsilon = cern.colt.matrix.tdouble.algo.DoubleProperty.DEFAULT.tolerance(); if (this == obj) return true; if (!(this != null && obj != null)) return false; DiagonalDoubleMatrix2D A = (DiagonalDoubleMatrix2D) content; DiagonalDoubleMatrix2D B = (DiagonalDoubleMatrix2D) obj; if (A.columns() != B.columns() || A.rows() != B.rows() || A.diagonalIndex() != B.diagonalIndex() || A.diagonalLength() != B.diagonalLength()) return false; double[] AElements = A.elements(); double[] BElements = B.elements(); for (int r = 0; r < AElements.length; r++) { double x = AElements[r]; double value = BElements[r]; double diff = Math.abs(value - x); if ((diff != diff) && ((value != value && x != x) || value == x)) diff = 0; if (!(diff <= epsilon)) { return false; } } return true; } else { return super.equals(obj); } }
public DoubleMatrix2D assign(final double[][] values) { if (values.length != rows) throw new IllegalArgumentException("Must have same number of rows: rows=" + values.length + "rows()=" + rows()); int r, c; if (dindex >= 0) { r = 0; c = dindex; } else { r = -dindex; c = 0; } for (int i = 0; i < dlength; i++) { if (values[i].length != columns) { throw new IllegalArgumentException("Must have same number of columns in every row: columns=" + values[r].length + "columns()=" + columns()); } elements[i] = values[r++][c++]; } return this; }
/** * Returns the diagonal matrix of singular values. * * @return S */ public DoubleMatrix2D getS() { if (S == null) { if (wantWholeUV == false) { S = new DiagonalDoubleMatrix2D(mn, mn, 0); } else { S = new DiagonalDoubleMatrix2D(m, n, 0); } for (int i = 0; i < mn; i++) { S.setQuick(i, i, elementsS[i]); } } return S.copy(); }
+ ((transposeA ? viewDice() : this).toStringShort()) + ", " + y.toStringShort() + ", " + z.toStringShort());
super(null); try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage()))
public DoubleMatrix2D assign(final double[][] values) { if (values.length != rows) throw new IllegalArgumentException("Must have same number of rows: rows=" + values.length + "rows()=" + rows()); int r, c; if (dindex >= 0) { r = 0; c = dindex; } else { r = -dindex; c = 0; } for (int i = 0; i < dlength; i++) { if (values[i].length != columns) { throw new IllegalArgumentException("Must have same number of columns in every row: columns=" + values[r].length + "columns()=" + columns()); } elements[i] = values[r++][c++]; } return this; }
/** * Returns the diagonal matrix of singular values. * * @return S */ public DoubleMatrix2D getS() { if (S == null) { if (wantWholeUV == false) { S = new DiagonalDoubleMatrix2D(mn, mn, 0); } else { S = new DiagonalDoubleMatrix2D(m, n, 0); } for (int i = 0; i < mn; i++) { S.setQuick(i, i, elementsS[i]); } } return S.copy(); }
+ ((transposeA ? viewDice() : this).toStringShort()) + ", " + y.toStringShort() + ", " + z.toStringShort());
super(null); try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage()))
public boolean equals(Object obj) { if (content instanceof DiagonalDoubleMatrix2D && obj instanceof DiagonalDoubleMatrix2D) { double epsilon = cern.colt.matrix.tdouble.algo.DoubleProperty.DEFAULT.tolerance(); if (this == obj) return true; if (!(this != null && obj != null)) return false; DiagonalDoubleMatrix2D A = (DiagonalDoubleMatrix2D) content; DiagonalDoubleMatrix2D B = (DiagonalDoubleMatrix2D) obj; if (A.columns() != B.columns() || A.rows() != B.rows() || A.diagonalIndex() != B.diagonalIndex() || A.diagonalLength() != B.diagonalLength()) return false; double[] AElements = A.elements(); double[] BElements = B.elements(); for (int r = 0; r < AElements.length; r++) { double x = AElements[r]; double value = BElements[r]; double diff = Math.abs(value - x); if ((diff != diff) && ((value != value && x != x) || value == x)) diff = 0; if (!(diff <= epsilon)) { return false; } } return true; } else { return super.equals(obj); } }
public DoubleMatrix2D assign(DoubleMatrix2D source) { // overriden for performance only if (source == this) return this; // nothing to do checkShape(source); if (source instanceof DiagonalDoubleMatrix2D) { DiagonalDoubleMatrix2D other = (DiagonalDoubleMatrix2D) source; if ((dindex != other.dindex) || (dlength != other.dlength)) { throw new IllegalArgumentException("source is DiagonalDoubleMatrix2D with different diagonal stored."); } // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; } else { return super.assign(source); } }
/** * 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. Only the values on the main * diagonal, i.e. values[i][i] are used. * <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. * @param dindex * index of the diagonal. * @throws IllegalArgumentException * if * * <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length || index < -rows+1 || index > columns - 1</tt> * . */ public DiagonalDoubleMatrix2D(double[][] values, int dindex) { this(values.length, values.length == 0 ? 0 : values[0].length, dindex); assign(values); }
public DoubleMatrix2D assign(final DoubleMatrix2D y, final cern.colt.function.tdouble.DoubleDoubleFunction function) { checkShape(y); if (y instanceof DiagonalDoubleMatrix2D) { DiagonalDoubleMatrix2D other = (DiagonalDoubleMatrix2D) y;
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. for (int j = dlength; --j >= 0;) { elements[j] *= alpha; } } else { for (int j = dlength; --j >= 0;) { elements[j] = function.apply(elements[j]); } } return this; }
public DoubleMatrix2D assign(final DoubleMatrix2D y, final cern.colt.function.tdouble.DoubleDoubleFunction function) { checkShape(y); if (y instanceof DiagonalDoubleMatrix2D) { DiagonalDoubleMatrix2D other = (DiagonalDoubleMatrix2D) y;
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. for (int j = dlength; --j >= 0;) { elements[j] *= alpha; } } else { for (int j = dlength; --j >= 0;) { elements[j] = function.apply(elements[j]); } } return this; }