예제 #1
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;
 }
예제 #2
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;
 }
예제 #3
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;
 }
예제 #4
0
 public static Matrix subtract(Matrix a, Matrix b) {
   return ((Matrix) a.clone()).subtract(b);
 }
예제 #5
0
 public static Matrix add(Matrix a, Matrix b) {
   return ((Matrix) a.clone()).add(b);
 }