/** * Returns the sum of all rows hash codes. */ public int hashCode() { int hash = 0; for (int i = 0; i < rows(); ++i) hash += getRowVector(i).hashCode(); return hash; }
/** * Returns the sum of all rows hash codes. */ public int hashCode() { int hash = 0; for (int i = 0; i < rows(); ++i) hash += getRowVector(i).hashCode(); return hash; }
public String toString() { int rows = rows(); int columns = columns(); StringBuilder sb = new StringBuilder(rows * columns * 2); for (int r = 0; r < rows; ++r) { sb.append('['); for (int c = 0; c < columns; ++c) { sb.append(get(r, c)); if (c + 1 < columns) sb.append(", "); } sb.append("]\n"); } return sb.toString(); } }
/** * Returns {@code} if the object is a {@link Matrix} with the same * dimensions as whose values are equivalent. Value equivalence is computed * using {@link Vector} equality on the row vectors of each matrix. */ public boolean equals(Object o) { if (o instanceof Matrix) { Matrix m = (Matrix)o; if (m.rows() == rows() && m.columns() == columns()) { for (int row = 0; row < rows(); ++row) { if (!getRowVector(row).equals(m.getRowVector(row))) return false; } } } return false; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the length of {@code values} is not * equal to the number of rows */ public void setColumn(int column, DoubleVector values) { if (values.length() != rows()) throw new IllegalArgumentException( "Number of values is not equal the number of rows"); for (int r = 0; r < values.length(); ++r) set(r, column, values.get(r)); }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the length of {@code values} is not * equal to the number of rows */ public void setColumn(int column, DoubleVector values) { if (values.length() != rows()) throw new IllegalArgumentException( "Number of values is not equal the number of rows"); for (int r = 0; r < values.length(); ++r) set(r, column, values.get(r)); }
/** * Returns {@code} if the object is a {@link Matrix} with the same * dimensions as whose values are equivalent. Value equivalence is computed * using {@link Vector} equality on the row vectors of each matrix. */ public boolean equals(Object o) { if (o instanceof Matrix) { Matrix m = (Matrix)o; int rows = rows(); if (m.rows() != rows) return false; int cols = columns(); if (m.columns() != cols) return false; // REMINDER: this could potentially be optimized for sparse // matrices. for (int r = 0; r < rows; ++r) { for (int c = 0; c < cols; ++c) { if (m.get(r, c) != get(r, c)) return false; } } return true; } return false; }