X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fmath%2FMatrix.java;h=b22bf4e1d27558fc09c6e59e64a45733f12d75cf;hb=187269da0130408d24901c88acb10c217f6284f9;hp=b910a7edb4229221c06ea32549489d604b3fcb63;hpb=11ec9d4540710b65b82b8b901de07b441c130887;p=jalview.git diff --git a/src/jalview/math/Matrix.java b/src/jalview/math/Matrix.java index b910a7e..b22bf4e 100755 --- a/src/jalview/math/Matrix.java +++ b/src/jalview/math/Matrix.java @@ -24,6 +24,7 @@ import jalview.util.Format; import jalview.util.MessageManager; import java.io.PrintStream; +import java.util.Arrays; /** * A class to model rectangular matrices of double values and operations on them @@ -215,7 +216,17 @@ public class Matrix implements MatrixI System.arraycopy(value[i], 0, newmat[i], 0, value[i].length); } - return new Matrix(newmat); + Matrix m = new Matrix(newmat); + if (this.d != null) + { + m.d = Arrays.copyOf(this.d, this.d.length); + } + if (this.e != null) + { + m.e = Arrays.copyOf(this.e, this.e.length); + } + + return m; } /** @@ -961,4 +972,54 @@ public class Matrix implements MatrixI } } } + + @Override + public void setD(double[] v) + { + d = v; + } + + @Override + public void setE(double[] v) + { + e = v; + } + + public double getTotal() + { + double d = 0d; + for (int i = 0; i < this.height(); i++) + { + for (int j = 0; j < this.width(); j++) + { + d += value[i][j]; + } + } + return d; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(MatrixI m2, double delta) + { + if (m2 == null || this.height() != m2.height() + || this.width() != m2.width()) + { + return false; + } + for (int i = 0; i < this.height(); i++) + { + for (int j = 0; j < this.width(); j++) + { + double diff = this.getValue(i, j) - m2.getValue(i, j); + if (Math.abs(diff) > delta) + { + return false; + } + } + } + return true; + } }