Skip to content

Commit 7b778fa

Browse files
committed
Merge branch 'master' of https://github.com/tweimer/java-matrix into development
2 parents b9f5e33 + 0f33d8c commit 7b778fa

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/jama2/Matrix.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,19 @@ public static Matrix constructWithCopy(final double A[][])
8686
{
8787
final int m = A.length;
8888
final int n = A[0].length;
89-
final Matrix X = new Matrix(m, n);
90-
final double[][] C = X.getArray();
91-
for (int i = 0; i < m; i++)
89+
final double C[][] = new double[m][];
90+
for (int i = 0; i < C.length; i++)
9291
{
93-
if (A[i].length != n)
94-
{
95-
throw new IllegalArgumentException("All rows must have the same length."); //$NON-NLS-1$
96-
}
97-
for (int j = 0; j < n; j++)
98-
{
99-
C[i][j] = A[i][j];
100-
}
92+
if (A[i].length != n)
93+
{
94+
throw new IllegalArgumentException("All rows must have the same length."); //$NON-NLS-1$
95+
}
96+
else
97+
{
98+
C[i] = Arrays.copyOf(A[i], n);
99+
}
101100
}
102-
return X;
101+
return new Matrix(m, n, C);
103102
}
104103

105104
/**
@@ -713,10 +712,10 @@ public double[][] getArray()
713712
*/
714713
public double[][] getArrayCopy()
715714
{
716-
final double C[][] = new double[this.A.length][];
715+
final double C[][] = new double[this.m][];
717716
for (int i = 0; i < C.length; i++)
718717
{
719-
C[i] = Arrays.copyOf(this.A[i], this.A[i].length);
718+
C[i] = Arrays.copyOf(this.A[i], this.n);
720719
}
721720
return C;
722721
}

src/jama2/QRDecomposition.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ else if (!this.isFullRank())
221221
}
222222

223223
// Copy right hand side
224-
final int nx = B.getColumnDimension();
225-
final double[][] X = B.getArrayCopy();
224+
final Matrix M = new Matrix(B);
225+
final double[][] X = M.getArray();
226226

227227
// Compute Y = transpose(Q)*B
228+
final int nx = B.getColumnDimension();
228229
for (int k = 0; k < this.n; k++)
229230
{
230231
for (int j = 0; j < nx; j++)
@@ -256,6 +257,6 @@ else if (!this.isFullRank())
256257
}
257258
}
258259
}
259-
return new Matrix(this.n, nx, X).getMatrix(0, this.n - 1, 0, nx - 1);
260+
return M.getMatrix(0, this.n - 1, 0, nx - 1);
260261
}
261262
}

0 commit comments

Comments
 (0)