Exemplo n.º 1
0
 public static Matrix multiply(Matrix a, Matrix b) {
   if (a.getWidth() != b.getHeight())
     throw new ArrayIndexOutOfBoundsException("Matrix size mismatch!");
   Matrix result = new Matrix(a.getHeight(), b.getWidth());
   for (int x = 0; x < result.getWidth(); x++) {
     for (int y = 0; y < result.getHeight(); y++) {
       for (int i = 0; i < a.getWidth(); i++) {
         result.data[x][y] += (a.data[i][y] * b.data[x][i]);
       }
     }
   }
   return result;
 }
Exemplo n.º 2
0
 public Matrix subtract(Matrix m) {
   if (m.getWidth() != getWidth() || m.getHeight() != getHeight())
     throw new ArrayIndexOutOfBoundsException("Matrix size mismatch!");
   for (int x = 0; x < getWidth(); x++) {
     for (int y = 0; y < getHeight(); y++) {
       data[x][y] -= m.data[x][y];
     }
   }
   return this;
 }
Exemplo n.º 3
0
 @Override
 public boolean equals(Object o) {
   if (o instanceof Matrix) {
     Matrix m = (Matrix) o;
     if (m.getWidth() == getWidth() && m.getHeight() == getHeight()) {
       return Arrays.deepEquals(m.data, data);
     }
   }
   return false;
 }