benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java
changeset 1854 826eb936c9a8
parent 1853 42c6e5a05360
child 1855 34efbdde4eca
child 1950 71e5cd5b29bc
     1.1 --- a/benchmarks/matrix-multiplication/src/main/java/org/apidesign/benchmark/matrixmul/Matrix.java	Sat Dec 26 08:59:42 2015 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,108 +0,0 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.benchmark.matrixmul;
    1.22 -
    1.23 -import java.io.IOException;
    1.24 -import java.util.Arrays;
    1.25 -
    1.26 -public class Matrix {
    1.27 -    private final int rank;
    1.28 -    private final float data[][];
    1.29 -    
    1.30 -    public Matrix(int r) {
    1.31 -        this(r, new float[r][r]);
    1.32 -    }
    1.33 -    
    1.34 -    private Matrix(int r, float[][] data) {
    1.35 -        this.rank = r;
    1.36 -        this.data = data;
    1.37 -    }
    1.38 -    
    1.39 -    public void setElement(int i, int j, float value) {
    1.40 -        data[i][j] = value;
    1.41 -    }
    1.42 -    public float getElement(int i, int j) {
    1.43 -        return data[i][j];
    1.44 -    }
    1.45 -    
    1.46 -    public void generateData() {
    1.47 -        //final Random rand = new Random();
    1.48 -        //final int x = 10;
    1.49 -        for (int i = 0; i < rank; i++) {
    1.50 -            for (int j = 0; j < rank; j++) {
    1.51 -                data[i][j] = 1 / (1 + i + j);
    1.52 -            }
    1.53 -        }
    1.54 -    }
    1.55 -
    1.56 -    public Matrix multiply(Matrix m) {
    1.57 -        if (rank != m.rank) {
    1.58 -            throw new IllegalArgumentException("Rank doesn't match");
    1.59 -        }
    1.60 -        
    1.61 -        final float res[][] = new float[rank][rank];
    1.62 -        for (int i = 0; i < rank; i++) {
    1.63 -            for (int j = 0; j < rank; j++) {
    1.64 -                float ij = 0;
    1.65 -                for (int q = 0; q < rank; q++) {
    1.66 -                    ij += data[i][q] * m.data[q][j];
    1.67 -                }
    1.68 -                res[i][j] = ij;
    1.69 -            }
    1.70 -        }
    1.71 -        return new Matrix(rank, res);
    1.72 -    }
    1.73 -    
    1.74 -    public void printOn(Appendable s) throws IOException {
    1.75 -        for (int i = 0; i < rank; i++) {
    1.76 -            String sep = "";
    1.77 -            for (int j = 0; j < rank; j++) {
    1.78 -                s.append(sep + data[i][j]);
    1.79 -                sep = " ";
    1.80 -            }
    1.81 -            s.append("\n");
    1.82 -        }
    1.83 -    }
    1.84 -
    1.85 -    @Override
    1.86 -    public boolean equals(Object obj) {
    1.87 -        if (obj instanceof Matrix) {
    1.88 -            Matrix snd = (Matrix)obj;
    1.89 -            if (snd.rank != rank) {
    1.90 -                return false;
    1.91 -            }
    1.92 -            for (int i = 0; i < rank; i++) {
    1.93 -                for (int j = 0; j < rank; j++) {
    1.94 -                    if (data[i][j] != snd.data[i][j]) {
    1.95 -                        return false;
    1.96 -                    }
    1.97 -                }
    1.98 -            }
    1.99 -            return true;
   1.100 -        }
   1.101 -        return false;
   1.102 -    }
   1.103 -
   1.104 -    @Override
   1.105 -    public int hashCode() {
   1.106 -        int hash = 3;
   1.107 -        hash = 97 * hash + this.rank;
   1.108 -        hash = 97 * hash + Arrays.deepHashCode(this.data);
   1.109 -        return hash;
   1.110 -    }
   1.111 -}