commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r728186 [1/2] - in /commons/proper/math/trunk/src: java/org/apache/commons/math/estimation/ java/org/apache/commons/math/linear/ java/org/apache/commons/math/random/ java/org/apache/commons/math/stat/descriptive/moment/ java/org/apache/comm...
Date Sat, 20 Dec 2008 00:03:15 GMT
Author: luc
Date: Fri Dec 19 16:03:13 2008
New Revision: 728186

URL: http://svn.apache.org/viewvc?rev=728186&view=rev
Log:
removed direct references to RealMatrixImpl and use factory

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BiDiagonalTransformer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenDecompositionImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/BiDiagonalTransformerTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenSolverTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUDecompositionImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUSolverTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRSolverTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueSolverTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/TriDiagonalTransformerTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java Fri Dec 19 16:03:13 2008
@@ -22,8 +22,8 @@
 import org.apache.commons.math.linear.InvalidMatrixException;
 import org.apache.commons.math.linear.LUDecompositionImpl;
 import org.apache.commons.math.linear.LUSolver;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
 
 /**
  * Base class for implementing estimators.
@@ -183,8 +183,8 @@
         try {
             // compute the covariances matrix
             RealMatrix inverse =
-                new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(jTj, false))).getInverse();
-            return ((RealMatrixImpl) inverse).getDataRef();
+                new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj))).getInverse();
+            return inverse.getData();
         } catch (InvalidMatrixException ime) {
             throw new EstimationException("unable to compute covariances: singular problem",
                                           null);

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java Fri Dec 19 16:03:13 2008
@@ -22,8 +22,8 @@
 import org.apache.commons.math.linear.InvalidMatrixException;
 import org.apache.commons.math.linear.LUDecompositionImpl;
 import org.apache.commons.math.linear.LUSolver;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
 import org.apache.commons.math.linear.RealVector;
 import org.apache.commons.math.linear.RealVectorImpl;
 
@@ -112,8 +112,7 @@
         double[] grad             = new double[parameters.length];
         RealVectorImpl bDecrement = new RealVectorImpl(parameters.length);
         double[] bDecrementData   = bDecrement.getDataRef();
-        RealMatrixImpl wGradGradT = new RealMatrixImpl(parameters.length, parameters.length);
-        double[][] wggData        = wGradGradT.getDataRef();
+        RealMatrix wGradGradT     = MatrixUtils.createRealMatrix(parameters.length, parameters.length);
 
         // iterate until convergence is reached
         double previous = Double.POSITIVE_INFINITY;
@@ -122,7 +121,7 @@
             // build the linear problem
             incrementJacobianEvaluationsCounter();
             RealVector b = new RealVectorImpl(parameters.length);
-            RealMatrix a = new RealMatrixImpl(parameters.length, parameters.length);
+            RealMatrix a = MatrixUtils.createRealMatrix(parameters.length, parameters.length);
             for (int i = 0; i < measurements.length; ++i) {
                 if (! measurements [i].isIgnored()) {
 
@@ -137,10 +136,9 @@
 
                     // build the contribution matrix for measurement i
                     for (int k = 0; k < parameters.length; ++k) {
-                        double[] wggRow = wggData[k];
                         double gk = grad[k];
                         for (int l = 0; l < parameters.length; ++l) {
-                            wggRow[l] =  weight * gk * grad[l];
+                            wGradGradT.setEntry(k, l, weight * gk * grad[l]);
                         }
                     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BiDiagonalTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BiDiagonalTransformer.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BiDiagonalTransformer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BiDiagonalTransformer.java Fri Dec 19 16:03:13 2008
@@ -96,38 +96,35 @@
             final int p = main.length;
             final int diagOffset    = (m >= n) ? 0 : 1;
             final double[] diagonal = (m >= n) ? main : secondary;
-            final double[][] uData  = new double[m][m];
+            cachedU = MatrixUtils.createRealMatrix(m, m);
 
             // fill up the part of the matrix not affected by Householder transforms
             for (int k = m - 1; k >= p; --k) {
-                uData[k][k] = 1;
+                cachedU.setEntry(k, k, 1);
             }
 
             // build up first part of the matrix by applying Householder transforms
             for (int k = p - 1; k >= diagOffset; --k) {
                 final double[] hK = householderVectors[k];
-                uData[k][k] = 1;
+                cachedU.setEntry(k, k, 1);
                 if (hK[k - diagOffset] != 0.0) {
                     for (int j = k; j < m; ++j) {
                         double alpha = 0;
                         for (int i = k; i < m; ++i) {
-                            alpha -= uData[i][j] * householderVectors[i][k - diagOffset];
+                            alpha -= cachedU.getEntry(i, j) * householderVectors[i][k - diagOffset];
                         }
                         alpha /= diagonal[k - diagOffset] * hK[k - diagOffset];
 
                         for (int i = k; i < m; ++i) {
-                            uData[i][j] -= alpha * householderVectors[i][k - diagOffset];
+                            cachedU.addToEntry(i, j, -alpha * householderVectors[i][k - diagOffset]);
                         }
                     }
                 }
             }
             if (diagOffset > 0) {
-                uData[0][0] = 1;
+                cachedU.setEntry(0, 0, 1);
             }
 
-            // cache the matrix for subsequent calls
-            cachedU = new RealMatrixImpl(uData, false);
-
         }
 
         // return the cached matrix
@@ -145,24 +142,20 @@
 
             final int m = householderVectors.length;
             final int n = householderVectors[0].length;
-            double[][] bData = new double[m][n];
+            cachedB = MatrixUtils.createRealMatrix(m, n);
             for (int i = 0; i < main.length; ++i) {
-                double[] bDataI = bData[i];
-                bDataI[i] = main[i];
+                cachedB.setEntry(i, i, main[i]);
                 if (m < n) {
                     if (i > 0) {
-                        bDataI[i - 1] = secondary[i - 1];
+                        cachedB.setEntry(i, i - 1, secondary[i - 1]);
                     }
                 } else {
                     if (i < main.length - 1) {
-                        bDataI[i + 1] = secondary[i];
+                        cachedB.setEntry(i, i + 1, secondary[i]);
                     }
                 }
             }
 
-            // cache the matrix for subsequent calls
-            cachedB = new RealMatrixImpl(bData, false);
-
         }
 
         // return the cached matrix
@@ -184,38 +177,35 @@
             final int p = main.length;
             final int diagOffset    = (m >= n) ? 1 : 0;
             final double[] diagonal = (m >= n) ? secondary : main;
-            final double[][] vData  = new double[n][n];
+            cachedV = MatrixUtils.createRealMatrix(n, n);
 
             // fill up the part of the matrix not affected by Householder transforms
             for (int k = n - 1; k >= p; --k) {
-                vData[k][k] = 1;
+                cachedV.setEntry(k, k, 1);
             }
 
             // build up first part of the matrix by applying Householder transforms
             for (int k = p - 1; k >= diagOffset; --k) {
                 final double[] hK = householderVectors[k - diagOffset];
-                vData[k][k] = 1;
+                cachedV.setEntry(k, k, 1);
                 if (hK[k] != 0.0) {
                     for (int j = k; j < n; ++j) {
                         double beta = 0;
                         for (int i = k; i < n; ++i) {
-                            beta -= vData[i][j] * hK[i];
+                            beta -= cachedV.getEntry(i, j) * hK[i];
                         }
                         beta /= diagonal[k - diagOffset] * hK[k];
 
                         for (int i = k; i < n; ++i) {
-                            vData[i][j] -= beta * hK[i];
+                            cachedV.addToEntry(i, j, -beta * hK[i]);
                         }
                     }
                 }
             }
             if (diagOffset > 0) {
-                vData[0][0] = 1;
+                cachedV.setEntry(0, 0, 1);
             }
 
-            // cache the matrix for subsequent calls
-            cachedV = new RealMatrixImpl(vData, false);
-
         }
 
         // return the cached matrix

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenDecompositionImpl.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenDecompositionImpl.java Fri Dec 19 16:03:13 2008
@@ -228,7 +228,17 @@
         throws InvalidMatrixException {
 
         if (cachedV == null) {
-            cachedV = getVT().transpose();
+
+            if (eigenvectors == null) {
+                findEigenVectors();
+            }
+
+            final int m = eigenvectors.length;
+            cachedV = MatrixUtils.createRealMatrix(m, m);
+            for (int k = 0; k < m; ++k) {
+                cachedV.setColumnVector(k, eigenvectors[k]);
+            }
+
         }
 
         // return the cached matrix
@@ -239,18 +249,9 @@
     /** {@inheritDoc} */
     public RealMatrix getD()
         throws InvalidMatrixException {
-
         if (cachedD == null) {
-
-            final int m = eigenvalues.length;
-            final double[][] sData = new double[m][m];
-            for (int i = 0; i < m; ++i) {
-                sData[i][i] = eigenvalues[i];
-            }
-
             // cache the matrix for subsequent calls
-            cachedD = new RealMatrixImpl(sData, false);
-
+            cachedD = MatrixUtils.createRealDiagonalMatrix(eigenvalues);
         }
         return cachedD;
     }
@@ -265,14 +266,12 @@
                 findEigenVectors();
             }
 
-            final double[][] vtData = new double[eigenvectors.length][];
-            for (int k = 0; k < eigenvectors.length; ++k) {
-                vtData[k] = eigenvectors[k].getData();
+            final int m = eigenvectors.length;
+            cachedVt = MatrixUtils.createRealMatrix(m, m);
+            for (int k = 0; k < m; ++k) {
+                cachedVt.setRowVector(k, eigenvectors[k]);
             }
 
-            // cache the matrix for subsequent calls
-            cachedVt = new RealMatrixImpl(vtData, false);
-
         }
 
         // return the cached matrix

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenSolver.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenSolver.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/EigenSolver.java Fri Dec 19 16:03:13 2008
@@ -147,7 +147,7 @@
             }
         }
 
-        return new RealMatrixImpl(bp, false);
+        return MatrixUtils.createRealMatrix(bp);
 
     }
 
@@ -203,7 +203,7 @@
                 invI[j] = invIJ;
             }
         }
-        return new RealMatrixImpl(invData, false);
+        return MatrixUtils.createRealMatrix(invData);
 
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java Fri Dec 19 16:03:13 2008
@@ -178,12 +178,14 @@
         throws IllegalStateException {
         if ((cachedL == null) && !singular) {
             final int m = pivot.length;
-            final double[][] lData = new double[m][m];
+            cachedL = MatrixUtils.createRealMatrix(m, m);
             for (int i = 0; i < m; ++i) {
-                System.arraycopy(lu[i], 0, lData[i], 0, i);
-                lData[i][i] = 1.0;
+                final double[] luI = lu[i];
+                for (int j = 0; j < i; ++j) {
+                    cachedL.setEntry(i, j, luI[j]);
+                }
+                cachedL.setEntry(i, i, 1.0);
             }
-            cachedL = new RealMatrixImpl(lData, false);
         }
         return cachedL;
     }
@@ -193,11 +195,13 @@
         throws IllegalStateException {
         if ((cachedU == null) && !singular) {
             final int m = pivot.length;
-            final double[][] uData = new double[m][m];
+            cachedU = MatrixUtils.createRealMatrix(m, m);
             for (int i = 0; i < m; ++i) {
-                System.arraycopy(lu[i], i, uData[i], i, m - i);
+                final double[] luI = lu[i];
+                for (int j = i; j < m; ++j) {
+                    cachedU.setEntry(i, j, luI[j]);
+                }
             }
-            cachedU = new RealMatrixImpl(uData, false);
         }
         return cachedU;
     }
@@ -207,11 +211,10 @@
         throws IllegalStateException {
         if ((cachedP == null) && !singular) {
             final int m = pivot.length;
-            final double[][] pData = new double[m][m];
+            cachedP = MatrixUtils.createRealMatrix(m, m);
             for (int i = 0; i < m; ++i) {
-                pData[i][pivot[i]] = 1.0;
+                cachedP.setEntry(i, pivot[i], 1.0);
             }
-            cachedP = new RealMatrixImpl(pData, false);
         }
         return cachedP;
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUSolver.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUSolver.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/LUSolver.java Fri Dec 19 16:03:13 2008
@@ -201,7 +201,7 @@
             }
         }
 
-        return new RealMatrixImpl(bp, false);
+        return MatrixUtils.createRealMatrix(bp);
 
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java Fri Dec 19 16:03:13 2008
@@ -153,20 +153,16 @@
             // R is supposed to be m x n
             final int n = qrt.length;
             final int m = qrt[0].length;
-            double[][] r = new double[m][n];
+            cachedR = MatrixUtils.createRealMatrix(m, n);
 
             // copy the diagonal from rDiag and the upper triangle of qr
             for (int row = Math.min(m, n) - 1; row >= 0; row--) {
-                double[] rRow = r[row];
-                rRow[row] = rDiag[row];
+                cachedR.setEntry(row, row, rDiag[row]);
                 for (int col = row + 1; col < n; col++) {
-                    rRow[col] = qrt[col][row];
+                    cachedR.setEntry(row, col, qrt[col][row]);
                 }
             }
 
-            // cache the matrix for subsequent calls
-            cachedR = new RealMatrixImpl(r, false);
-
         }
 
         // return the cached matrix
@@ -192,7 +188,7 @@
             // QT is supposed to be m x m
             final int n = qrt.length;
             final int m = qrt[0].length;
-            double[][] qT = new double[m][m];
+            cachedQT = MatrixUtils.createRealMatrix(m, m);
 
             /* 
              * Q = Q1 Q2 ... Q_m, so Q is formed by first constructing Q_m and then 
@@ -200,31 +196,27 @@
              * succession to the result 
              */ 
             for (int minor = m - 1; minor >= Math.min(m, n); minor--) {
-                qT[minor][minor]=1;
+                cachedQT.setEntry(minor, minor, 1.0);
             }
 
-            for (int minor = Math.min(m,n)-1; minor >= 0; minor--){
+            for (int minor = Math.min(m, n)-1; minor >= 0; minor--){
                 final double[] qrtMinor = qrt[minor];
-                qT[minor][minor] = 1;
+                cachedQT.setEntry(minor, minor, 1.0);
                 if (qrtMinor[minor] != 0.0) {
                     for (int col = minor; col < m; col++) {
-                        final double[] qTCol = qT[col];
                         double alpha = 0;
                         for (int row = minor; row < m; row++) {
-                            alpha -= qTCol[row] * qrtMinor[row];
+                            alpha -= cachedQT.getEntry(col, row) * qrtMinor[row];
                         }
                         alpha /= rDiag[minor] * qrtMinor[minor];
 
                         for (int row = minor; row < m; row++) {
-                            qTCol[row] -= alpha * qrtMinor[row];
+                            cachedQT.addToEntry(col, row, -alpha * qrtMinor[row]);
                         }
                     }
                 }
             }
 
-            // cache the matrix for subsequent calls
-            cachedQT = new RealMatrixImpl(qT, false);
-
         }
 
         // return the cached matrix
@@ -240,17 +232,13 @@
 
             final int n = qrt.length;
             final int m = qrt[0].length;
-            double[][] hData = new double[m][n];
+            cachedH = MatrixUtils.createRealMatrix(m, n);
             for (int i = 0; i < m; ++i) {
-                final double[] hDataI = hData[i];
                 for (int j = 0; j < Math.min(i + 1, n); ++j) {
-                    hDataI[j] = qrt[j][i] / -rDiag[j];
+                    cachedH.setEntry(i, j, qrt[j][i] / -rDiag[j]);
                 }
             }
 
-            // cache the matrix for subsequent calls
-            cachedH = new RealMatrixImpl(hData, false);
-
         }
 
         // return the cached matrix

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRSolver.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRSolver.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/QRSolver.java Fri Dec 19 16:03:13 2008
@@ -136,7 +136,7 @@
             }
         }
 
-        return new RealMatrixImpl(xData, false);
+        return MatrixUtils.createRealMatrix(xData);
 
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java Fri Dec 19 16:03:13 2008
@@ -1112,38 +1112,40 @@
             return outerProduct((RealVectorImpl) v);
         } catch (ClassCastException cce) {
             checkVectorDimensions(v);
-            double[][] out = new double[data.length][data.length];
+            final int m = data.length;
+            final RealMatrix out = MatrixUtils.createRealMatrix(m, m);
             for (int i = 0; i < data.length; i++) {
                 for (int j = 0; j < data.length; j++) {
-                    out[i][j] = data[i] * v.getEntry(j);
+                    out.setEntry(i, j, data[i] * v.getEntry(j));
                 }
             }
-            return new RealMatrixImpl(out);
+            return out;
         }
     }
 
+    /**
+     * Compute the outer product.
+     * @param v vector with which outer product should be computed
+     * @return the square matrix outer product between instance and v
+     * @exception IllegalArgumentException if v is not the same size as this
+     */
+    public RealMatrix outerProduct(RealVectorImpl v)
+        throws IllegalArgumentException {
+        return outerProduct(v.data);
+    }
+
     /** {@inheritDoc} */
     public RealMatrix outerProduct(double[] v)
         throws IllegalArgumentException {
         checkVectorDimensions(v.length);
-        double[][] out = new double[data.length][data.length];
+        final int m = data.length;
+        final RealMatrix out = MatrixUtils.createRealMatrix(m, m);
         for (int i = 0; i < data.length; i++) {
             for (int j = 0; j < data.length; j++) {
-                out[i][j] = data[i] * v[j];
+                out.setEntry(i, j, data[i] * v[j]);
             }
         }
-        return new RealMatrixImpl(out);
-    }
-
-    /**
-     * Compute the outer product.
-     * @param v vector with which outer product should be computed
-     * @return the square matrix outer product between instance and v
-     * @exception IllegalArgumentException if v is not the same size as this
-     */
-    public RealMatrixImpl outerProduct(RealVectorImpl v)
-        throws IllegalArgumentException {
-        return (RealMatrixImpl) outerProduct(v.data);
+        return out;
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java Fri Dec 19 16:03:13 2008
@@ -157,7 +157,7 @@
                     iData[i] = new double[n];
                 }
                 cachedU =
-                    transformer.getU().multiply(new RealMatrixImpl(iData, false));
+                    transformer.getU().multiply(MatrixUtils.createRealMatrix(iData));
             } else {
                 // the tridiagonal matrix is B.Bt, where B is lower bidiagonal
                 cachedU = transformer.getU().multiply(eigenDecomposition.getV());
@@ -189,14 +189,8 @@
 
         if (cachedS == null) {
 
-            final int p = singularValues.length;
-            final double[][] sData = new double[p][p];
-            for (int i = 0; i < p; ++i) {
-                sData[i][i] = singularValues[i];
-            }
-
             // cache the matrix for subsequent calls
-            cachedS = new RealMatrixImpl(sData, false);
+            cachedS = MatrixUtils.createRealDiagonalMatrix(singularValues);
 
         }
         return cachedS;
@@ -243,7 +237,7 @@
                     iData[i] = new double[m];
                 }
                 cachedV =
-                    transformer.getV().multiply(new RealMatrixImpl(iData, false));
+                    transformer.getV().multiply(MatrixUtils.createRealMatrix(iData));
             }
 
         }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueSolver.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueSolver.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueSolver.java Fri Dec 19 16:03:13 2008
@@ -115,17 +115,15 @@
             throw new IllegalArgumentException("Incorrect row dimension");
         }
 
-        final RealMatrixImpl w = (RealMatrixImpl) decomposition.getUT().multiply(b);
-        final double[][] wData = w.getDataRef();
+        final RealMatrix w = decomposition.getUT().multiply(b);
         for (int i = 0; i < singularValues.length; ++i) {
             final double si  = singularValues[i];
             if (si == 0) {
                 throw new SingularMatrixException();
             }
             final double inv = 1.0 / si;
-            final double[] wi = wData[i];
             for (int j = 0; j < b.getColumnDimension(); ++j) {
-                wi[j] *= inv;
+                w.multiplyEntry(i, j, inv);
             }
         }
         return decomposition.getV().multiply(w);

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java Fri Dec 19 16:03:13 2008
@@ -175,6 +175,36 @@
         }
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public void addToEntry(int row, int column, double increment)
+            throws MatrixIndexException {
+        checkRowIndex(row);
+        checkColumnIndex(column);
+        final int key = computeKey(row, column);
+        final double value = entries.get(key) + increment;
+        if (value == 0.0) {
+            entries.remove(key);
+        } else {
+            entries.put(key, value);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void multiplyEntry(int row, int column, double factor)
+            throws MatrixIndexException {
+        checkRowIndex(row);
+        checkColumnIndex(column);
+        final int key = computeKey(row, column);
+        final double value = entries.get(key) * factor;
+        if (value == 0.0) {
+            entries.remove(key);
+        } else {
+            entries.put(key, value);
+        }
+    }
+
     /**
      * Compute the key to access a matrix element
      * @param row row index of the matrix element

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/TriDiagonalTransformer.java Fri Dec 19 16:03:13 2008
@@ -106,38 +106,33 @@
         if (cachedQt == null) {
 
             final int m = householderVectors.length;
-            final double[][] qtData  = new double[m][m];
+            cachedQt = MatrixUtils.createRealMatrix(m, m);
 
             // build up first part of the matrix by applying Householder transforms
             for (int k = m - 1; k >= 1; --k) {
                 final double[] hK = householderVectors[k - 1];
                 final double inv = 1.0 / (secondary[k - 1] * hK[k]);
-                qtData[k][k] = 1;
+                cachedQt.setEntry(k, k, 1);
                 if (hK[k] != 0.0) {
-                    final double[] qtK = qtData[k];
                     double beta = 1.0 / secondary[k - 1];
-                    qtK[k] = 1 + beta * hK[k];
+                    cachedQt.setEntry(k, k, 1 + beta * hK[k]);
                     for (int i = k + 1; i < m; ++i) {
-                        qtK[i] = beta * hK[i];
+                        cachedQt.setEntry(k, i, beta * hK[i]);
                     }
                     for (int j = k + 1; j < m; ++j) {
-                        final double[] qtJ = qtData[j];
                         beta = 0;
                         for (int i = k + 1; i < m; ++i) {
-                            beta += qtJ[i] * hK[i];
+                            beta += cachedQt.getEntry(j, i) * hK[i];
                         }
                         beta *= inv;
-                        qtJ[k] = beta * hK[k];
+                        cachedQt.setEntry(j, k, beta * hK[k]);
                         for (int i = k + 1; i < m; ++i) {
-                            qtJ[i] += beta * hK[i];
+                            cachedQt.addToEntry(j, i, beta * hK[i]);
                         }
                     }
                 }
             }
-            qtData[0][0] = 1;
-
-            // cache the matrix for subsequent calls
-            cachedQt = new RealMatrixImpl(qtData, false);
+            cachedQt.setEntry(0, 0, 1);
 
         }
 
@@ -155,21 +150,17 @@
         if (cachedT == null) {
 
             final int m = main.length;
-            double[][] tData = new double[m][m];
+            cachedT = MatrixUtils.createRealMatrix(m, m);
             for (int i = 0; i < m; ++i) {
-                double[] tDataI = tData[i];
-                tDataI[i] = main[i];
+                cachedT.setEntry(i, i, main[i]);
                 if (i > 0) {
-                    tDataI[i - 1] = secondary[i - 1];
+                    cachedT.setEntry(i, i - 1, secondary[i - 1]);
                 }
                 if (i < main.length - 1) {
-                    tDataI[i + 1] = secondary[i];
+                    cachedT.setEntry(i, i + 1, secondary[i]);
                 }
             }
 
-            // cache the matrix for subsequent calls
-            cachedT = new RealMatrixImpl(tData, false);
-
         }
 
         // return the cached matrix

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java Fri Dec 19 16:03:13 2008
@@ -18,8 +18,8 @@
 package org.apache.commons.math.random;
 
 import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
 
 /** 
  * A {@link RandomVectorGenerator} that generates vectors with with 
@@ -251,9 +251,11 @@
         }
 
         // build the root matrix
-        root = new RealMatrixImpl(order, rank);
+        root = MatrixUtils.createRealMatrix(order, rank);
         for (int i = 0; i < order; ++i) {
-            System.arraycopy(b[i], 0, root.getDataRef()[index[i]], 0, rank);
+            for (int j = 0; j < rank; ++j) {
+                root.setEntry(index[i], j, b[i][j]);
+            }
         }
 
     }
@@ -286,7 +288,7 @@
     private double[] mean;
 
     /** Permutated Cholesky root of the covariance matrix. */
-    private RealMatrixImpl root;
+    private RealMatrix root;
 
     /** Rank of the covariance matrix. */
     private int rank;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java Fri Dec 19 16:03:13 2008
@@ -20,8 +20,8 @@
 import java.util.Arrays;
 
 import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
 
 /**
  * Returns the covariance matrix of the available vectors.
@@ -83,17 +83,16 @@
     public RealMatrix getResult() {
 
         int dimension = sums.length;
-        RealMatrixImpl result = new RealMatrixImpl(dimension, dimension);
+        RealMatrix result = MatrixUtils.createRealMatrix(dimension, dimension);
 
         if (n > 1) {
-            double[][] resultData = result.getDataRef();
             double c = 1.0 / (n * (isBiasCorrected ? (n - 1) : n));
             int k = 0;
             for (int i = 0; i < dimension; ++i) {
                 for (int j = 0; j <= i; ++j) {
                     double e = c * (n * productsSums[k++] - sums[i] * sums[j]);
-                    resultData[i][j] = e;
-                    resultData[j][i] = e;
+                    result.setEntry(i, j, e);
+                    result.setEntry(j, i, e);
                 }
             }
         }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Fri Dec 19 16:03:13 2008
@@ -16,8 +16,10 @@
  */
 package org.apache.commons.math.stat.regression;
 
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
+import org.apache.commons.math.linear.RealVector;
+import org.apache.commons.math.linear.RealVectorImpl;
 
 /**
  * Abstract base class for implementations of MultipleLinearRegression.
@@ -31,7 +33,7 @@
     protected RealMatrix X;
 
     /** Y sample data. */
-    protected RealMatrix Y;
+    protected RealVector Y;
 
     /**
      * Loads model x and y sample data from a flat array of data, overriding any previous sample.
@@ -52,8 +54,8 @@
                 x[i][j] = data[pointer++];
             }
         }
-        this.X = new RealMatrixImpl(x);
-        this.Y = new RealMatrixImpl(y);
+        this.X = MatrixUtils.createRealMatrix(x);
+        this.Y = new RealVectorImpl(y);
     }
     
     /**
@@ -62,7 +64,7 @@
      * @param y the [n,1] array representing the y sample
      */
     protected void newYSampleData(double[] y) {
-        this.Y = new RealMatrixImpl(y);
+        this.Y = new RealVectorImpl(y);
     }
 
     /**
@@ -71,7 +73,7 @@
      * @param x the [n,k] array representing the x sample
      */
     protected void newXSampleData(double[][] x) {
-        this.X = new RealMatrixImpl(x);
+        this.X = MatrixUtils.createRealMatrix(x);
     }
 
     /**
@@ -120,17 +122,14 @@
      * {@inheritDoc}
      */
     public double[] estimateRegressionParameters() {
-        RealMatrix b = calculateBeta();
-        return b.getColumn(0);
+        return calculateBeta().getData();
     }
 
     /**
      * {@inheritDoc}
      */
     public double[] estimateResiduals() {
-        RealMatrix b = calculateBeta();
-        RealMatrix e = Y.subtract(X.multiply(b));
-        return e.getColumn(0);
+        return Y.subtract(X.operate(calculateBeta())).getData();
     }
 
     /**
@@ -152,7 +151,7 @@
      * 
      * @return beta
      */
-    protected abstract RealMatrix calculateBeta();
+    protected abstract RealVector calculateBeta();
 
     /**
      * Calculates the beta variance of multiple linear regression in matrix
@@ -179,9 +178,8 @@
      * 
      * @return The residuals [n,1] matrix
      */
-    protected RealMatrix calculateResiduals() {
-        RealMatrix b = calculateBeta();
-        return Y.subtract(X.multiply(b));
+    protected RealVector calculateResiduals() {
+        return Y.subtract(X.operate(calculateBeta()));
     }
 
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java Fri Dec 19 16:03:13 2008
@@ -18,8 +18,9 @@
 
 import org.apache.commons.math.linear.LUDecompositionImpl;
 import org.apache.commons.math.linear.LUSolver;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
+import org.apache.commons.math.linear.RealVector;
 
 
 /**
@@ -68,7 +69,7 @@
      * @param omega the [n,n] array representing the covariance
      */
     protected void newCovarianceData(double[][] omega){
-        this.Omega = new RealMatrixImpl(omega);
+        this.Omega = MatrixUtils.createRealMatrix(omega);
         this.OmegaInverse = null;
     }
 
@@ -91,12 +92,12 @@
      * </pre>
      * @return beta
      */
-    protected RealMatrix calculateBeta() {
+    protected RealVector calculateBeta() {
         RealMatrix OI = getOmegaInverse();
         RealMatrix XT = X.transpose();
         RealMatrix XTOIX = XT.multiply(OI).multiply(X);
         RealMatrix inverse = new LUSolver(new LUDecompositionImpl(XTOIX)).getInverse();
-        return inverse.multiply(XT).multiply(OI).multiply(Y);
+        return inverse.multiply(XT).multiply(OI).operate(Y);
     }
 
     /**
@@ -120,9 +121,9 @@
      * @return The Y variance
      */
     protected double calculateYVariance() {
-        RealMatrix u = calculateResiduals();
-        RealMatrix sse =  u.transpose().multiply(getOmegaInverse()).multiply(u);
-        return sse.getTrace()/(X.getRowDimension()-X.getColumnDimension());
+        final RealVector u = calculateResiduals();
+        final double sse =  u.dotProduct(getOmegaInverse().operate(u));
+        return sse / (X.getRowDimension() - X.getColumnDimension());
     }
     
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java Fri Dec 19 16:03:13 2008
@@ -16,12 +16,14 @@
  */
 package org.apache.commons.math.stat.regression;
 
+import org.apache.commons.math.linear.DenseRealMatrix;
 import org.apache.commons.math.linear.LUDecompositionImpl;
 import org.apache.commons.math.linear.LUSolver;
 import org.apache.commons.math.linear.QRDecomposition;
 import org.apache.commons.math.linear.QRDecompositionImpl;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
+import org.apache.commons.math.linear.RealVector;
+import org.apache.commons.math.linear.RealVectorImpl;
 
 /**
  * <p>Implements ordinary least squares (OLS) to estimate the parameters of a 
@@ -86,7 +88,7 @@
      * @param x the [n,k] array representing the x sample
      */
     protected void newXSampleData(double[][] x) {
-        this.X = new RealMatrixImpl(x);
+        this.X = new DenseRealMatrix(x);
         qr = new QRDecompositionImpl(X);
     }
     
@@ -95,9 +97,8 @@
      * 
      * @return beta
      */
-    protected RealMatrix calculateBeta() {
-        return solveUpperTriangular((RealMatrixImpl) qr.getR(),
-                (RealMatrixImpl) qr.getQ().transpose().multiply(Y));
+    protected RealVector calculateBeta() {
+        return solveUpperTriangular(qr.getR(), qr.getQ().transpose().operate(Y));
     }
 
     /**
@@ -121,9 +122,9 @@
      * @return The Y variance
      */
     protected double calculateYVariance() {
-        RealMatrix u = calculateResiduals();
-        RealMatrix sse = u.transpose().multiply(u);
-        return sse.getTrace()/(X.getRowDimension()-X.getColumnDimension());
+        final RealVector u = calculateResiduals();
+        final double sse = u.dotProduct(u);
+        return sse / (X.getRowDimension() - X.getColumnDimension());
     }
     
     /** TODO:  Find a home for the following methods in the linear package */   
@@ -143,32 +144,25 @@
      * 
      * @param coefficients upper-triangular coefficients matrix
      * @param constants column RHS constants matrix
-     * @return solution matrix as a column matrix
+     * @return solution matrix as a vector
      * 
      */
-    private static RealMatrix solveUpperTriangular(RealMatrixImpl coefficients,
-            RealMatrixImpl constants) {
+    private static RealVector solveUpperTriangular(RealMatrix coefficients, RealVector constants) {
         if (!isUpperTriangular(coefficients, 1E-12)) {
             throw new IllegalArgumentException(
                    "Coefficients is not upper-triangular");
         }
-        if (constants.getColumnDimension() != 1) {
-            throw new IllegalArgumentException(
-                    "Constants not a column matrix.");
-        }
         int length = coefficients.getColumnDimension();
-        double[][] cons = constants.getDataRef();
-        double[][] coef = coefficients.getDataRef();
         double x[] = new double[length];
         for (int i = 0; i < length; i++) {
             int index = length - 1 - i;
             double sum = 0;
             for (int j = index + 1; j < length; j++) {
-                sum += coef[index][j] * x[j];
+                sum += coefficients.getEntry(index, j) * x[j];
             }
-            x[index] = (cons[index][0] - sum) / coef[index][index];
+            x[index] = (constants.getEntry(index) - sum) / coefficients.getEntry(index, index);
         } 
-        return new RealMatrixImpl(x);
+        return new RealVectorImpl(x);
     }
     
     /**
@@ -183,14 +177,13 @@
      * @return true if m is upper-triangular; false otherwise
      * @throws NullPointerException if m is null
      */
-    private static boolean isUpperTriangular(RealMatrixImpl m, double epsilon) {
-        double[][] data = m.getDataRef();
+    private static boolean isUpperTriangular(RealMatrix m, double epsilon) {
         int nCols = m.getColumnDimension();
         int nRows = m.getRowDimension();
         for (int r = 0; r < nRows; r++) {
             int bound = Math.min(r, nCols);
             for (int c = 0; c < bound; c++) {
-                if (Math.abs(data[r][c]) > epsilon) {
+                if (Math.abs(m.getEntry(r, c)) > epsilon) {
                     return false;
                 }
             }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/BiDiagonalTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/BiDiagonalTransformerTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/BiDiagonalTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/BiDiagonalTransformerTest.java Fri Dec 19 16:03:13 2008
@@ -40,9 +40,9 @@
     }
 
     public void testDimensions() {
-        checkdimensions(new RealMatrixImpl(testSquare, false));
-        checkdimensions(new RealMatrixImpl(testNonSquare, false));
-        checkdimensions(new RealMatrixImpl(testNonSquare, false).transpose());
+        checkdimensions(MatrixUtils.createRealMatrix(testSquare));
+        checkdimensions(MatrixUtils.createRealMatrix(testNonSquare));
+        checkdimensions(MatrixUtils.createRealMatrix(testNonSquare).transpose());
     }
 
     private void checkdimensions(RealMatrix matrix) {
@@ -59,9 +59,9 @@
     }
 
     public void testAEqualUSVt() {
-        checkAEqualUSVt(new RealMatrixImpl(testSquare, false));
-        checkAEqualUSVt(new RealMatrixImpl(testNonSquare, false));
-        checkAEqualUSVt(new RealMatrixImpl(testNonSquare, false).transpose());
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testSquare));
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testNonSquare));
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testNonSquare).transpose());
     }
 
     private void checkAEqualUSVt(RealMatrix matrix) {
@@ -74,15 +74,15 @@
     }
 
     public void testUOrthogonal() {
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testSquare, false)).getU());
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false)).getU());
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false).transpose()).getU());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare)).getU());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare)).getU());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare).transpose()).getU());
     }
 
     public void testVOrthogonal() {
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testSquare, false)).getV());
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false)).getV());
-        checkOrthogonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false).transpose()).getV());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare)).getV());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare)).getV());
+        checkOrthogonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare).transpose()).getV());
     }
 
     private void checkOrthogonal(RealMatrix m) {
@@ -92,9 +92,9 @@
     }
 
     public void testBBiDiagonal() {
-        checkBiDiagonal(new BiDiagonalTransformer(new RealMatrixImpl(testSquare, false)).getB());
-        checkBiDiagonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false)).getB());
-        checkBiDiagonal(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false).transpose()).getB());
+        checkBiDiagonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare)).getB());
+        checkBiDiagonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare)).getB());
+        checkBiDiagonal(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare).transpose()).getB());
     }
 
     private void checkBiDiagonal(RealMatrix m) {
@@ -117,17 +117,17 @@
 
     public void testMatricesValues() {
        BiDiagonalTransformer transformer =
-            new BiDiagonalTransformer(new RealMatrixImpl(testSquare, false));
+            new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare));
        final double s17 = Math.sqrt(17.0);
-        RealMatrix uRef = new RealMatrixImpl(new double[][] {
+        RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
                 {  -8 / (5 * s17), 19 / (5 * s17) },
                 { -19 / (5 * s17), -8 / (5 * s17) }
         });
-        RealMatrix bRef = new RealMatrixImpl(new double[][] {
+        RealMatrix bRef = MatrixUtils.createRealMatrix(new double[][] {
                 { -3 * s17 / 5, 32 * s17 / 85 },
                 {      0.0,     -5 * s17 / 17 }
         });
-        RealMatrix vRef = new RealMatrixImpl(new double[][] {
+        RealMatrix vRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 1.0,  0.0 },
                 { 0.0, -1.0 }
         });
@@ -148,9 +148,9 @@
     }
 
     public void testUpperOrLower() {
-        assertTrue(new BiDiagonalTransformer(new RealMatrixImpl(testSquare, false)).isUpperBiDiagonal());
-        assertTrue(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false)).isUpperBiDiagonal());
-        assertFalse(new BiDiagonalTransformer(new RealMatrixImpl(testNonSquare, false).transpose()).isUpperBiDiagonal());
+        assertTrue(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare)).isUpperBiDiagonal());
+        assertTrue(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare)).isUpperBiDiagonal());
+        assertFalse(new BiDiagonalTransformer(MatrixUtils.createRealMatrix(testNonSquare).transpose()).isUpperBiDiagonal());
     }
 
     public static Test suite() {

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java Fri Dec 19 16:03:13 2008
@@ -43,19 +43,17 @@
 
     public void testDimension1() {
         RealMatrix matrix =
-            new RealMatrixImpl(new double[][] {
-                                   { 1.5 }
-                               }, false);
+            MatrixUtils.createRealMatrix(new double[][] { { 1.5 } });
         EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         assertEquals(1.5, ed.getEigenvalue(0), 1.0e-15);
     }
 
     public void testDimension2() {
         RealMatrix matrix =
-            new RealMatrixImpl(new double[][] {
-                                   {       59.0, 12.0 },
-                                   { Double.NaN, 66.0 }
-                               }, false);
+            MatrixUtils.createRealMatrix(new double[][] {
+                    {       59.0, 12.0 },
+                    { Double.NaN, 66.0 }
+            });
         EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         assertEquals(75.0, ed.getEigenvalue(0), 1.0e-15);
         assertEquals(50.0, ed.getEigenvalue(1), 1.0e-15);
@@ -63,11 +61,11 @@
 
     public void testDimension3() {
         RealMatrix matrix =
-            new RealMatrixImpl(new double[][] {
+            MatrixUtils.createRealMatrix(new double[][] {
                                    {    39632.0,    -4824.0, -16560.0 },
                                    { Double.NaN,     8693.0,   7920.0 },
                                    { Double.NaN, Double.NaN,  17300.0 }
-                               }, false);
+                               });
         EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         assertEquals(50000.0, ed.getEigenvalue(0), 3.0e-11);
         assertEquals(12500.0, ed.getEigenvalue(1), 3.0e-11);
@@ -76,12 +74,12 @@
 
     public void testDimension4WithSplit() {
         RealMatrix matrix =
-            new RealMatrixImpl(new double[][] {
+            MatrixUtils.createRealMatrix(new double[][] {
                                    {      0.784,     -0.288,       0.000,  0.000 },
                                    { Double.NaN,      0.616,       0.000,  0.000 },
                                    { Double.NaN, Double.NaN,       0.164, -0.048 },
                                    { Double.NaN, Double.NaN,  Double.NaN,  0.136 }
-                               }, false);
+                               });
         EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         assertEquals(1.0, ed.getEigenvalue(0), 1.0e-15);
         assertEquals(0.4, ed.getEigenvalue(1), 1.0e-15);
@@ -91,12 +89,12 @@
 
     public void testDimension4WithoutSplit() {
         RealMatrix matrix =
-            new RealMatrixImpl(new double[][] {
+            MatrixUtils.createRealMatrix(new double[][] {
                                    {  0.5608, -0.2016,  0.1152, -0.2976 },
                                    { -0.2016,  0.4432, -0.2304,  0.1152 },
                                    {  0.1152, -0.2304,  0.3088, -0.1344 },
                                    { -0.2976,  0.1152, -0.1344,  0.3872 }
-                               }, false);
+                               });
         EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         assertEquals(1.0, ed.getEigenvalue(0), 1.0e-15);
         assertEquals(0.4, ed.getEigenvalue(1), 1.0e-15);
@@ -213,7 +211,7 @@
      * Matrix with eigenvalues {8, -1, -1}
      */
     public void testRepeatedEigenvalue() {
-        RealMatrix repeated = new RealMatrixImpl(new double[][] {
+        RealMatrix repeated = MatrixUtils.createRealMatrix(new double[][] {
                 {3,  2,  4},
                 {2,  0,  2},
                 {4,  2,  3}
@@ -227,7 +225,7 @@
      * Matrix with eigenvalues {2, 0, 12}
      */
     public void testDistinctEigenvalues() {
-        RealMatrix distinct = new RealMatrixImpl(new double[][] {
+        RealMatrix distinct = MatrixUtils.createRealMatrix(new double[][] {
                 {3, 1, -4},  
                 {1, 3, -4}, 
                 {-4, -4, 8}
@@ -368,7 +366,7 @@
             } while (norm2 * size < 0.01);
         }
 
-        return new RealMatrixImpl(data, false);
+        return MatrixUtils.createRealMatrix(data);
 
     }
 
@@ -378,7 +376,7 @@
         for (int i = 0; i < Math.min(rows, columns); ++i) {
             dData[i][i] = diagonal[i];
         }
-        return new RealMatrixImpl(dData, false);
+        return MatrixUtils.createRealMatrix(dData);
     }
 
 }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenSolverTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/EigenSolverTest.java Fri Dec 19 16:03:13 2008
@@ -73,7 +73,7 @@
     /** test solve dimension errors */
     public void testSolveDimensionErrors() {
         EigenSolver es = new EigenSolver(new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN));
-        RealMatrix b = new RealMatrixImpl(new double[2][2]);
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
         try {
             es.solve(b);
             fail("an exception should have been thrown");
@@ -102,7 +102,7 @@
 
     /** test solve */
     public void testSolve() {
-        RealMatrix m = new RealMatrixImpl(new double[][] {
+        RealMatrix m = MatrixUtils.createRealMatrix(new double[][] {
                 { 91,  5, 29, 32, 40, 14 },
                 {  5, 34, -1,  0,  2, -1 },
                 { 29, -1, 12,  9, 21,  8 },
@@ -112,7 +112,7 @@
         });
         EigenSolver  es = new EigenSolver(new EigenDecompositionImpl(m, MathUtils.SAFE_MIN));
         assertEquals(184041, es.getDeterminant(), 2.0e-8);
-        RealMatrix b = new RealMatrixImpl(new double[][] {
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
                 { 1561, 269, 188 },
                 {   69, -21,  70 },
                 {  739, 108,  63 },
@@ -120,7 +120,7 @@
                 { 1624, 194, 107 },
                 {  796,  69,  36 }
         });
-        RealMatrix xRef = new RealMatrixImpl(new double[][] {
+        RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 1,   2, 1 },
                 { 2,  -1, 2 },
                 { 4,   2, 3 },

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUDecompositionImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUDecompositionImplTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUDecompositionImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUDecompositionImplTest.java Fri Dec 19 16:03:13 2008
@@ -66,7 +66,7 @@
 
     /** test dimensions */
     public void testDimensions() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
         LUDecomposition LU = new LUDecompositionImpl(matrix);
         assertEquals(testData.length, LU.getL().getRowDimension());
         assertEquals(testData.length, LU.getL().getColumnDimension());
@@ -80,7 +80,7 @@
     /** test non-square matrix */
     public void testNonSquare() {
         try {
-            new LUDecompositionImpl(new RealMatrixImpl(new double[3][2], false));
+            new LUDecompositionImpl(MatrixUtils.createRealMatrix(new double[3][2]));
         } catch (InvalidMatrixException ime) {
             // expected behavior
         } catch (Exception e) {
@@ -90,7 +90,7 @@
 
     /** test PA = LU */
     public void testPAEqualLU() {
-        RealMatrix matrix = new RealMatrixImpl(testData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
         LUDecomposition lu = new LUDecompositionImpl(matrix);
         RealMatrix l = lu.getL();
         RealMatrix u = lu.getU();
@@ -98,7 +98,7 @@
         double norm = l.multiply(u).subtract(p.multiply(matrix)).getNorm();
         assertEquals(0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testDataMinus, false);
+        matrix = MatrixUtils.createRealMatrix(testDataMinus);
         lu = new LUDecompositionImpl(matrix);
         l = lu.getL();
         u = lu.getU();
@@ -114,14 +114,14 @@
         norm = l.multiply(u).subtract(p.multiply(matrix)).getNorm();
         assertEquals(0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(singular, false);
+        matrix = MatrixUtils.createRealMatrix(singular);
         lu = new LUDecompositionImpl(matrix);
         assertTrue(lu.isSingular());
         assertNull(lu.getL());
         assertNull(lu.getU());
         assertNull(lu.getP());
 
-        matrix = new RealMatrixImpl(bigSingular, false);
+        matrix = MatrixUtils.createRealMatrix(bigSingular);
         lu = new LUDecompositionImpl(matrix);
         assertTrue(lu.isSingular());
         assertNull(lu.getL());
@@ -132,7 +132,7 @@
 
     /** test that L is lower triangular with unit diagonal */
     public void testLLowerTriangular() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
         RealMatrix l = new LUDecompositionImpl(matrix).getL();
         for (int i = 0; i < l.getRowDimension(); i++) {
             assertEquals(l.getEntry(i, i), 1, entryTolerance);
@@ -144,7 +144,7 @@
 
     /** test that U is upper triangular */
     public void testUUpperTriangular() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
         RealMatrix u = new LUDecompositionImpl(matrix).getU();
         for (int i = 0; i < u.getRowDimension(); i++) {
             for (int j = 0; j < i; j++) {
@@ -155,7 +155,7 @@
 
     /** test that P is a permutation matrix */
     public void testPPermutation() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
         RealMatrix p   = new LUDecompositionImpl(matrix).getP();
 
         RealMatrix ppT = p.multiply(p.transpose());
@@ -206,29 +206,29 @@
     /** test singular */
     public void testSingular() {
         LUDecomposition lu =
-            new LUDecompositionImpl(new RealMatrixImpl(testData, false));
+            new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData));
         assertFalse(lu.isSingular());
-        lu = new LUDecompositionImpl(new RealMatrixImpl(singular, false));
+        lu = new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular));
         assertTrue(lu.isSingular());
-        lu = new LUDecompositionImpl(new RealMatrixImpl(bigSingular, false));
+        lu = new LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular));
         assertTrue(lu.isSingular());
     }
 
     /** test matrices values */
     public void testMatricesValues1() {
        LUDecomposition lu =
-            new LUDecompositionImpl(new RealMatrixImpl(testData, false));
-        RealMatrix lRef = new RealMatrixImpl(new double[][] {
+            new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData));
+        RealMatrix lRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 1.0, 0.0, 0.0 },
                 { 0.5, 1.0, 0.0 },
                 { 0.5, 0.2, 1.0 }
         });
-        RealMatrix uRef = new RealMatrixImpl(new double[][] {
+        RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 2.0,  5.0, 3.0 },
                 { 0.0, -2.5, 6.5 },
                 { 0.0,  0.0, 0.2 }
         });
-        RealMatrix pRef = new RealMatrixImpl(new double[][] {
+        RealMatrix pRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 0.0, 1.0, 0.0 },
                 { 0.0, 0.0, 1.0 },
                 { 1.0, 0.0, 0.0 }
@@ -257,18 +257,18 @@
     /** test matrices values */
     public void testMatricesValues2() {
        LUDecomposition lu =
-            new LUDecompositionImpl(new RealMatrixImpl(luData, false));
-        RealMatrix lRef = new RealMatrixImpl(new double[][] {
+            new LUDecompositionImpl(MatrixUtils.createRealMatrix(luData));
+        RealMatrix lRef = MatrixUtils.createRealMatrix(new double[][] {
                 {    1.0,    0.0, 0.0 },
                 {    0.0,    1.0, 0.0 },
                 { 1.0 / 3.0, 0.0, 1.0 }
         });
-        RealMatrix uRef = new RealMatrixImpl(new double[][] {
+        RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 6.0, 9.0,    8.0    },
                 { 0.0, 5.0,    7.0    },
                 { 0.0, 0.0, 1.0 / 3.0 }
         });
-        RealMatrix pRef = new RealMatrixImpl(new double[][] {
+        RealMatrix pRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 0.0, 0.0, 1.0 },
                 { 0.0, 1.0, 0.0 },
                 { 1.0, 0.0, 0.0 }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUSolverTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/LUSolverTest.java Fri Dec 19 16:03:13 2008
@@ -57,11 +57,11 @@
 
     /** test threshold impact */
     public void testThreshold() {
-        final RealMatrix matrix = new RealMatrixImpl(new double[][] {
+        final RealMatrix matrix = MatrixUtils.createRealMatrix(new double[][] {
                                                        { 1.0, 2.0, 3.0},
                                                        { 2.0, 5.0, 3.0},
                                                        { 4.000001, 9.0, 9.0}
-                                                     }, false);
+                                                     });
         assertFalse(new LUSolver(new LUDecompositionImpl(matrix, 1.0e-5)).isNonSingular());
         assertTrue(new LUSolver(new LUDecompositionImpl(matrix, 1.0e-10)).isNonSingular());
     }
@@ -69,19 +69,19 @@
     /** test singular */
     public void testSingular() {
         LUSolver lu =
-            new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(testData, false)));
+            new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
         assertTrue(lu.isNonSingular());
-        lu = new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(singular, false)));
+        lu = new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)));
         assertFalse(lu.isNonSingular());
-        lu = new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(bigSingular, false)));
+        lu = new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular)));
         assertFalse(lu.isNonSingular());
     }
 
     /** test solve dimension errors */
     public void testSolveDimensionErrors() {
         LUSolver solver =
-            new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(testData, false)));
-        RealMatrix b = new RealMatrixImpl(new double[2][2]);
+            new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -111,8 +111,8 @@
     /** test solve singularity errors */
     public void testSolveSingularityErrors() {
         LUSolver solver =
-            new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(singular, false)));
-        RealMatrix b = new RealMatrixImpl(new double[2][2]);
+            new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -150,11 +150,11 @@
     /** test solve */
     public void testSolve() {
         LUSolver solver =
-            new LUSolver(new LUDecompositionImpl(new RealMatrixImpl(testData, false)));
-        RealMatrix b = new RealMatrixImpl(new double[][] {
+            new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
                 { 1, 0 }, { 2, -5 }, { 3, 1 }
         });
-        RealMatrix xRef = new RealMatrixImpl(new double[][] {
+        RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 19, -71 }, { -6, 22 }, { -2, 9 }
         });
 
@@ -188,10 +188,10 @@
 
     /** test determinant */
     public void testDeterminant() {
-        assertEquals( -1, getDeterminant(new RealMatrixImpl(testData, false)), 1.0e-15);
-        assertEquals(-10, getDeterminant(new RealMatrixImpl(luData, false)), 1.0e-14);
-        assertEquals(  0, getDeterminant(new RealMatrixImpl(singular, false)), 1.0e-17);
-        assertEquals(  0, getDeterminant(new RealMatrixImpl(bigSingular, false)), 1.0e-10);
+        assertEquals( -1, getDeterminant(MatrixUtils.createRealMatrix(testData)), 1.0e-15);
+        assertEquals(-10, getDeterminant(MatrixUtils.createRealMatrix(luData)), 1.0e-14);
+        assertEquals(  0, getDeterminant(MatrixUtils.createRealMatrix(singular)), 1.0e-17);
+        assertEquals(  0, getDeterminant(MatrixUtils.createRealMatrix(bigSingular)), 1.0e-10);
     }
 
     private double getDeterminant(RealMatrix m) {

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java Fri Dec 19 16:03:13 2008
@@ -59,21 +59,21 @@
 
     /** test dimensions */
     public void testDimensions() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData3x3NonSingular, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData3x3NonSingular);
         QRDecomposition qr = new QRDecompositionImpl(matrix);
         assertEquals("3x3 Q size", qr.getQ().getRowDimension(), 3);
         assertEquals("3x3 Q size", qr.getQ().getColumnDimension(), 3);
         assertEquals("3x3 R size", qr.getR().getRowDimension(), 3);
         assertEquals("3x3 R size", qr.getR().getColumnDimension(), 3);
 
-        matrix = new RealMatrixImpl(testData4x3, false);
+        matrix = MatrixUtils.createRealMatrix(testData4x3);
         qr = new QRDecompositionImpl(matrix);
         assertEquals("4x3 Q size", qr.getQ().getRowDimension(), 4);
         assertEquals("4x3 Q size", qr.getQ().getColumnDimension(), 4);
         assertEquals("4x3 R size", qr.getR().getRowDimension(), 4);
         assertEquals("4x3 R size", qr.getR().getColumnDimension(), 3);
 
-        matrix = new RealMatrixImpl(testData3x4, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x4);
         qr = new QRDecompositionImpl(matrix);
         assertEquals("3x4 Q size", qr.getQ().getRowDimension(), 3);
         assertEquals("3x4 Q size", qr.getQ().getColumnDimension(), 3);
@@ -83,24 +83,24 @@
 
     /** test A = QR */
     public void testAEqualQR() {
-        RealMatrix A = new RealMatrixImpl(testData3x3NonSingular, false);
+        RealMatrix A = MatrixUtils.createRealMatrix(testData3x3NonSingular);
         QRDecomposition qr = new QRDecompositionImpl(A);
         RealMatrix Q = qr.getQ();
         RealMatrix R = qr.getR();
         double norm = Q.multiply(R).subtract(A).getNorm();
         assertEquals("3x3 nonsingular A = QR", 0, norm, normTolerance);
 
-        RealMatrix matrix = new RealMatrixImpl(testData3x3Singular, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData3x3Singular);
         qr = new QRDecompositionImpl(matrix);
         norm = qr.getQ().multiply(qr.getR()).subtract(matrix).getNorm();
         assertEquals("3x3 singular A = QR", 0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testData3x4, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x4);
         qr = new QRDecompositionImpl(matrix);
         norm = qr.getQ().multiply(qr.getR()).subtract(matrix).getNorm();
         assertEquals("3x4 A = QR", 0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testData4x3, false);
+        matrix = MatrixUtils.createRealMatrix(testData4x3);
         qr = new QRDecompositionImpl(matrix);
         norm = qr.getQ().multiply(qr.getR()).subtract(matrix).getNorm();
         assertEquals("4x3 A = QR", 0, norm, normTolerance);
@@ -108,28 +108,28 @@
 
     /** test the orthogonality of Q */
     public void testQOrthogonal() {
-        RealMatrix matrix = new RealMatrixImpl(testData3x3NonSingular, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData3x3NonSingular);
         RealMatrix q  = new QRDecompositionImpl(matrix).getQ();
         RealMatrix qT = new QRDecompositionImpl(matrix).getQT();
         RealMatrix eye = MatrixUtils.createRealIdentityMatrix(3);
         double norm = qT.multiply(q).subtract(eye).getNorm();
         assertEquals("3x3 nonsingular Q'Q = I", 0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testData3x3Singular, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x3Singular);
         q  = new QRDecompositionImpl(matrix).getQ();
         qT = new QRDecompositionImpl(matrix).getQT();
         eye = MatrixUtils.createRealIdentityMatrix(3);
         norm = qT.multiply(q).subtract(eye).getNorm();
         assertEquals("3x3 singular Q'Q = I", 0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testData3x4, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x4);
         q  = new QRDecompositionImpl(matrix).getQ();
         qT = new QRDecompositionImpl(matrix).getQT();
         eye = MatrixUtils.createRealIdentityMatrix(3);
         norm = qT.multiply(q).subtract(eye).getNorm();
         assertEquals("3x4 Q'Q = I", 0, norm, normTolerance);
 
-        matrix = new RealMatrixImpl(testData4x3, false);
+        matrix = MatrixUtils.createRealMatrix(testData4x3);
         q  = new QRDecompositionImpl(matrix).getQ();
         qT = new QRDecompositionImpl(matrix).getQT();
         eye = MatrixUtils.createRealIdentityMatrix(4);
@@ -139,28 +139,28 @@
 
     /** test that R is upper triangular */
     public void testRUpperTriangular() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData3x3NonSingular, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData3x3NonSingular);
         RealMatrix R = new QRDecompositionImpl(matrix).getR();
         for (int i = 0; i < R.getRowDimension(); i++)
             for (int j = 0; j < i; j++)
                 assertEquals("R lower triangle", R.getEntry(i, j), 0,
                         entryTolerance);
 
-        matrix = new RealMatrixImpl(testData3x3Singular, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x3Singular);
         R = new QRDecompositionImpl(matrix).getR();
         for (int i = 0; i < R.getRowDimension(); i++)
             for (int j = 0; j < i; j++)
                 assertEquals("R lower triangle", R.getEntry(i, j), 0,
                         entryTolerance);
 
-        matrix = new RealMatrixImpl(testData3x4, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x4);
         R = new QRDecompositionImpl(matrix).getR();
         for (int i = 0; i < R.getRowDimension(); i++)
             for (int j = 0; j < i; j++)
                 assertEquals("R lower triangle", R.getEntry(i, j), 0,
                         entryTolerance);
 
-        matrix = new RealMatrixImpl(testData4x3, false);
+        matrix = MatrixUtils.createRealMatrix(testData4x3);
         R = new QRDecompositionImpl(matrix).getR();
         for (int i = 0; i < R.getRowDimension(); i++)
             for (int j = 0; j < i; j++)
@@ -170,25 +170,25 @@
 
     /** test that H is trapezoidal */
     public void testHTrapezoidal() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testData3x3NonSingular, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testData3x3NonSingular);
         RealMatrix H = new QRDecompositionImpl(matrix).getH();
         for (int i = 0; i < H.getRowDimension(); i++)
             for (int j = i + 1; j < H.getColumnDimension(); j++)
                 assertEquals(H.getEntry(i, j), 0, entryTolerance);
 
-        matrix = new RealMatrixImpl(testData3x3Singular, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x3Singular);
         H = new QRDecompositionImpl(matrix).getH();
         for (int i = 0; i < H.getRowDimension(); i++)
             for (int j = i + 1; j < H.getColumnDimension(); j++)
                 assertEquals(H.getEntry(i, j), 0, entryTolerance);
 
-        matrix = new RealMatrixImpl(testData3x4, false);
+        matrix = MatrixUtils.createRealMatrix(testData3x4);
         H = new QRDecompositionImpl(matrix).getH();
         for (int i = 0; i < H.getRowDimension(); i++)
             for (int j = i + 1; j < H.getColumnDimension(); j++)
                 assertEquals(H.getEntry(i, j), 0, entryTolerance);
 
-        matrix = new RealMatrixImpl(testData4x3, false);
+        matrix = MatrixUtils.createRealMatrix(testData4x3);
         H = new QRDecompositionImpl(matrix).getH();
         for (int i = 0; i < H.getRowDimension(); i++)
             for (int j = i + 1; j < H.getColumnDimension(); j++)
@@ -199,18 +199,18 @@
     /** test matrices values */
     public void testMatricesValues() {
         QRDecomposition qr =
-            new QRDecompositionImpl(new RealMatrixImpl(testData3x3NonSingular, false));
-        RealMatrix qRef = new RealMatrixImpl(new double[][] {
+            new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3NonSingular));
+        RealMatrix qRef = MatrixUtils.createRealMatrix(new double[][] {
                 { -12.0 / 14.0,   69.0 / 175.0,  -58.0 / 175.0 },
                 {  -6.0 / 14.0, -158.0 / 175.0,    6.0 / 175.0 },
                 {   4.0 / 14.0,  -30.0 / 175.0, -165.0 / 175.0 }
         });
-        RealMatrix rRef = new RealMatrixImpl(new double[][] {
+        RealMatrix rRef = MatrixUtils.createRealMatrix(new double[][] {
                 { -14.0,  -21.0, 14.0 },
                 {   0.0, -175.0, 70.0 },
                 {   0.0,    0.0, 35.0 }
         });
-        RealMatrix hRef = new RealMatrixImpl(new double[][] {
+        RealMatrix hRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 26.0 / 14.0, 0.0, 0.0 },
                 {  6.0 / 14.0, 648.0 / 325.0, 0.0 },
                 { -4.0 / 14.0,  36.0 / 325.0, 2.0 }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRSolverTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/QRSolverTest.java Fri Dec 19 16:03:13 2008
@@ -56,16 +56,16 @@
     /** test rank */
     public void testRank() {
         QRSolver solver =
-            new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x3NonSingular, false)));
+            new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3NonSingular)));
         assertTrue(solver.isNonSingular());
 
-        solver = new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x3Singular, false)));
+        solver = new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3Singular)));
         assertFalse(solver.isNonSingular());
 
-        solver = new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x4, false)));
+        solver = new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x4)));
         assertTrue(solver.isNonSingular());
 
-        solver = new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData4x3, false)));
+        solver = new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData4x3)));
         assertTrue(solver.isNonSingular());
 
     }
@@ -73,8 +73,8 @@
     /** test solve dimension errors */
     public void testSolveDimensionErrors() {
         QRSolver solver =
-            new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x3NonSingular, false)));
-        RealMatrix b = new RealMatrixImpl(new double[2][2]);
+            new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3NonSingular)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -104,8 +104,8 @@
     /** test solve rank errors */
     public void testSolveRankErrors() {
         QRSolver solver =
-            new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x3Singular, false)));
-        RealMatrix b = new RealMatrixImpl(new double[3][2]);
+            new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3Singular)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[3][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -135,11 +135,11 @@
     /** test solve */
     public void testSolve() {
         QRSolver solver =
-            new QRSolver(new QRDecompositionImpl(new RealMatrixImpl(testData3x3NonSingular, false)));
-        RealMatrix b = new RealMatrixImpl(new double[][] {
+            new QRSolver(new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3NonSingular)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
                 { -102, 12250 }, { 544, 24500 }, { 167, -36750 }
         });
-        RealMatrix xRef = new RealMatrixImpl(new double[][] {
+        RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 1, 2515 }, { 2, 422 }, { -3, 898 }
         });
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java Fri Dec 19 16:03:13 2008
@@ -1060,7 +1060,7 @@
         double dot_2 =  v1.dotProduct(v2_t);
         assertEquals("compare val ",32d, dot_2);
 
-        RealMatrixImpl m_outerProduct = v1.outerProduct(v2);
+        RealMatrix m_outerProduct = v1.outerProduct(v2);
         assertEquals("compare val ",4d, m_outerProduct.getEntry(0,0));
 
         RealMatrix m_outerProduct_2 = v1.outerProduct(v2_t);



Mime
View raw message