public abstract class Matrix { protected final int rows ; // 10 000 protected final int cols ; // 8 protected Matrix(int rows, int cols) { this.rows = rows ; this.cols = cols ; } public abstract void set(int i, int j, double d) ; public abstract double get(int i, int j) ; public void patricia(double[] v, double[] tmp, double[] out) { multiplyLeft(v, tmp) ; multiplyRight(tmp, out) ; } public abstract void multiplyLeft(double[] v, double[] out) ; public abstract void multiplyRight(double[] v, double[] out) ; public final int hashCode() { int hash = 0 ; for (int i = 0 ; i < rows ; ++i) { for (int j = 0 ; j < cols ; ++j) { long dBits = Double.doubleToLongBits(get(i, j)) ; hash = (hash >> 1) + ((int)dBits) + ((int)(dBits >> 32)) ; } } return hash ; } public static int hashCode(double[] v) { int hash = 0 ; for (int i = 0 ; i < v.length ; ++i) { long dBits = Double.doubleToLongBits(v[i]) ; hash = (hash >> 1) + ((int)dBits) + ((int)(dBits >> 32)) ; } return hash ; } public final boolean equals(Object obj) { if ((obj == null) || (!(obj instanceof Matrix))) return false ; Matrix that = (Matrix)obj ; if (this.rows != that.rows) return false ; if (this.cols != that.cols) return false ; for (int i = 0 ; i < rows ; ++i) { for (int j = 0 ; j < cols ; ++j) { if (this.get(i, j) != that.get(i, j)) return false ; } } return true ; } public String toString() { return getClass().getName() + " " + rows + " x " + cols ; } }