From: Giovanni Mascellani Subject: [PATCH] patch/jama This patch fixes the import used to work with the JAMA library. Signed-off-by: Giovanni Mascellani --- geogebra/kernel/AlgoInvert.java | 2 +- geogebra/kernel/AlgoTranspose.java | 2 +- geogebra/kernel/jama/GgbMat.java | 74 ++++++++++++------------ geogebra/kernel/statistics/RegressionMath.java | 2 +- 4 files changed, 39 insertions(+), 41 deletions(-) diff --git a/geogebra/kernel/AlgoInvert.java b/geogebra/kernel/AlgoInvert.java index b7493eb..ce611f3 100644 --- a/geogebra/kernel/AlgoInvert.java +++ b/geogebra/kernel/AlgoInvert.java @@ -81,7 +81,7 @@ public class AlgoInvert extends AlgoElement { return; }*/ - matrix.inverseImmediate(); + matrix = matrix.ggbInverse(); if (matrix.isUndefined()) { //outputList.setUndefined(); diff --git a/geogebra/kernel/AlgoTranspose.java b/geogebra/kernel/AlgoTranspose.java index 4147a4f..d0b99b8 100644 --- a/geogebra/kernel/AlgoTranspose.java +++ b/geogebra/kernel/AlgoTranspose.java @@ -63,7 +63,7 @@ public class AlgoTranspose extends AlgoElement { return; } - matrix.transposeImmediate(); + matrix = matrix.ggbTranspose(); // Transpose[{{1,2},{3,4}}] outputList = matrix.getGeoList(outputList, cons); diff --git a/geogebra/kernel/jama/GgbMat.java b/geogebra/kernel/jama/GgbMat.java index 80ee214..db01f23 100644 --- a/geogebra/kernel/jama/GgbMat.java +++ b/geogebra/kernel/jama/GgbMat.java @@ -1,44 +1,59 @@ package geogebra.kernel.jama; +import java.awt.Dimension; + import geogebra.kernel.Construction; import geogebra.kernel.GeoElement; import geogebra.kernel.GeoList; import geogebra.kernel.GeoNumeric; import geogebra.main.Application; +import Jama.Matrix; public class GgbMat extends Matrix{ private boolean isUndefined = false; - public GgbMat (GeoList inputList) { + public GgbMat (Matrix m) { + super(m.getArray()); + } + + public GgbMat(int row, int col) { + super(row, col); + } + + public static Dimension calcDim(GeoList inputList) { int rows = inputList.size(); if (!inputList.isDefined() || rows == 0) { - setIsUndefined(true); - return; + return new Dimension(0, 0); } GeoElement geo = inputList.get(0); if (!geo.isGeoList()) { - setIsUndefined(true); - return; + return new Dimension(0, 0); } int cols = ((GeoList)geo).size(); if (cols == 0) { - setIsUndefined(true); - return; + return new Dimension(0, 0); } - A = new double[rows][cols]; - m = rows; - n = cols; + return new Dimension(rows, cols); + + } + + public GgbMat (GeoList inputList) { + super(calcDim(inputList).width, calcDim(inputList).height); + + int rows = this.getRowDimension(); + int cols = this.getColumnDimension(); GeoList rowList; + GeoElement geo; for (int r = 0 ; r < rows ; r++) { geo = inputList.get(r); if (!geo.isGeoList()) { @@ -62,35 +77,18 @@ public class GgbMat extends Matrix{ } } - public void inverseImmediate() { - + public GgbMat ggbInverse() { try { - Matrix ret = inverse(); - A = ret.A; - m = ret.m; - n = ret.n; - } - catch (Exception e) { // can't invert - setIsUndefined(true); + return new GgbMat(((Matrix) this).inverse()); + } catch (Exception e) { + GgbMat mat = new GgbMat(this.getRowDimension(), this.getColumnDimension()); + mat.setIsUndefined(true); + return mat; } - } - - - public void transposeImmediate() { - - double[][] C = new double[n][m]; - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - C[j][i] = A[i][j]; - } - } - A = C; - int temp = n; - n = m; - m = temp; - //Application.debug(""+A[0][0]); + public GgbMat ggbTranspose() { + return new GgbMat(((Matrix) this).transpose()); } /* @@ -106,9 +104,9 @@ public class GgbMat extends Matrix{ outputList.clear(); outputList.setDefined(true); - for (int r = 0 ; r < m ; r++) { + for (int r = 0 ; r < this.getRowDimension() ; r++) { GeoList columnList = new GeoList(cons); - for (int c = 0 ; c < n ; c++) { + for (int c = 0 ; c < this.getColumnDimension() ; c++) { //Application.debug(get(r, c)+""); columnList.add(new GeoNumeric(cons, get(r, c))); } @@ -131,7 +129,7 @@ public class GgbMat extends Matrix{ } public boolean isSquare() { - return (n == m); + return (this.getColumnDimension() == this.getRowDimension()); } diff --git a/geogebra/kernel/statistics/RegressionMath.java b/geogebra/kernel/statistics/RegressionMath.java index 55ee4fc..8d4ff23 100644 --- a/geogebra/kernel/statistics/RegressionMath.java +++ b/geogebra/kernel/statistics/RegressionMath.java @@ -2,7 +2,7 @@ package geogebra.kernel.statistics; import geogebra.kernel.GeoList; import geogebra.kernel.GeoPoint; import geogebra.kernel.GeoElement; -import geogebra.kernel.jama.*; +import Jama.*; /* GeoGebra - Dynamic Mathematics for Everyone -- tg: (6d6be1c..) patch/jama (depends on: master)