diff -r 42c6e5a05360 -r 826eb936c9a8 benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java --- a/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java Sat Dec 26 08:59:42 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012-2015 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.benchmark.matrixmul; - -import java.io.IOException; -import java.util.Arrays; - -public class Matrix { - private final int rank; - private final float data[][]; - - public Matrix(int r) { - this(r, new float[r][r]); - } - - private Matrix(int r, float[][] data) { - this.rank = r; - this.data = data; - } - - public void setElement(int i, int j, float value) { - data[i][j] = value; - } - public float getElement(int i, int j) { - return data[i][j]; - } - - public void generateData() { - //final Random rand = new Random(); - //final int x = 10; - for (int i = 0; i < rank; i++) { - for (int j = 0; j < rank; j++) { - data[i][j] = 1 / (1 + i + j); - } - } - } - - public Matrix multiply(Matrix m) { - if (rank != m.rank) { - throw new IllegalArgumentException("Rank doesn't match"); - } - - final float res[][] = new float[rank][rank]; - for (int i = 0; i < rank; i++) { - for (int j = 0; j < rank; j++) { - float ij = 0; - for (int q = 0; q < rank; q++) { - ij += data[i][q] * m.data[q][j]; - } - res[i][j] = ij; - } - } - return new Matrix(rank, res); - } - - public void printOn(Appendable s) throws IOException { - for (int i = 0; i < rank; i++) { - String sep = ""; - for (int j = 0; j < rank; j++) { - s.append(sep + data[i][j]); - sep = " "; - } - s.append("\n"); - } - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Matrix) { - Matrix snd = (Matrix)obj; - if (snd.rank != rank) { - return false; - } - for (int i = 0; i < rank; i++) { - for (int j = 0; j < rank; j++) { - if (data[i][j] != snd.data[i][j]) { - return false; - } - } - } - return true; - } - return false; - } - - @Override - public int hashCode() { - int hash = 3; - hash = 97 * hash + this.rank; - hash = 97 * hash + Arrays.deepHashCode(this.data); - return hash; - } -}