From e8b765f24913520d23f4526d815587853094b3f4 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 1 May 2018 12:20:54 +0100 Subject: [PATCH] JAL-1767 include d and e vectors in Matrix.copy() --- src/jalview/math/Matrix.java | 13 ++++++++++++- test/jalview/math/MatrixTest.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/jalview/math/Matrix.java b/src/jalview/math/Matrix.java index b910a7e..804421b 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; } /** diff --git a/test/jalview/math/MatrixTest.java b/test/jalview/math/MatrixTest.java index 97ded5a..6e9c0f1 100644 --- a/test/jalview/math/MatrixTest.java +++ b/test/jalview/math/MatrixTest.java @@ -188,9 +188,23 @@ public class MatrixTest } } Matrix m1 = new Matrix(in); + Matrix m2 = (Matrix) m1.copy(); assertNotSame(m1, m2); assertTrue(matrixEquals(m1, m2)); + assertNull(m2.d); + assertNull(m2.e); + + /* + * now add d and e vectors and recopy + */ + m1.d = Arrays.copyOf(in[2], in[2].length); + m1.e = Arrays.copyOf(in[4], in[4].length); + m2 = (Matrix) m1.copy(); + assertNotSame(m2.d, m1.d); + assertNotSame(m2.e, m1.e); + assertEquals(m2.d, m1.d); + assertEquals(m2.e, m1.e); } /** -- 1.7.10.2