benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.benchmark.matrixmul;
20 //import java.io.PrintStream;
21 //import java.util.Random;
25 private final int rank;
26 private float data[][];
28 public Matrix(int r) {
30 data = new float[r][r];
33 public void setElement(int i, int j, float value) {
36 public float getElement(int i, int j) {
40 public void generateData() {
41 //final Random rand = new Random();
43 for (int i = 0; i < rank; i++) {
44 for (int j = 0; j < rank; j++) {
50 public Matrix multiply(Matrix m) {
52 throw new IllegalArgumentException("Rank doesn't match");
55 final float res[][] = new float[rank][rank];
56 for (int i = 0; i < rank; i++) {
57 for (int j = 0; j < rank; j++) {
59 for (int q = 0; q < rank; q++) {
60 ij += data[i][q] * m.data[q][j];
71 public void printOn(PrintStream s) {
72 for (int i = 0; i < rank; i++) {
73 for (int j = 0; j < rank; j++) {
74 s.printf("%f ", data[i][j]);