commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1304216 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java test/java/org/apache/commons/math3/linear/SymmLQTest.java
Date Fri, 23 Mar 2012 07:50:51 GMT
Author: celestin
Date: Fri Mar 23 07:50:51 2012
New Revision: 1304216

URL: http://svn.apache.org/viewvc?rev=1304216&view=rev
Log:
In SymmLQTest, testPreconditionedNormOfResidual() now passes.
Previous failure was due to the test itself, not to the implementation of SymmLQ.
See MATH-770.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java?rev=1304216&r1=1304215&r2=1304216&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/JacobiPreconditioner.java
Fri Mar 23 07:50:51 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.linear;
 
+import org.apache.commons.math3.analysis.function.Sqrt;
+
 /**
  * This class implements the standard Jacobi (diagonal) preconditioner. For a
  * matrix A<sub>ij</sub>, this preconditioner is
@@ -98,4 +100,34 @@ public class JacobiPreconditioner extend
         // Dimension check is carried out by ebeMultiply
         return x.ebeDivide(diag);
     }
+
+    /**
+     * Returns the square root of {@code this} diagonal operator. More
+     * precisely, this method returns
+     * P = diag(1 / &radic;A<sub>11</sub>, 1 / &radic;A<sub>22</sub>,
&hellip;).
+     *
+     * @return the square root of {@code this} operator
+     */
+    public RealLinearOperator sqrt(){
+        final RealVector sqrtDiag = diag.map(new Sqrt());
+        return new RealLinearOperator() {
+            /** {@inheritDoc} */
+            @Override
+            public RealVector operate(final RealVector x) {
+                return x.ebeDivide(sqrtDiag);
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public int getRowDimension() {
+                return sqrtDiag.getDimension();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public int getColumnDimension() {
+                return sqrtDiag.getDimension();
+            }
+        };
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java?rev=1304216&r1=1304215&r2=1304216&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SymmLQTest.java
Fri Mar 23 07:50:51 2012
@@ -19,7 +19,6 @@ package org.apache.commons.math3.linear;
 import java.util.Arrays;
 
 import org.apache.commons.math3.exception.DimensionMismatchException;
-import org.apache.commons.math3.exception.MathUnsupportedOperationException;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.IterationEvent;
 import org.apache.commons.math3.util.IterationListener;
@@ -643,7 +642,8 @@ public class SymmLQTest {
         final int n = 5;
         final int maxIterations = 100;
         final RealLinearOperator a = new HilbertMatrix(n);
-        final RealLinearOperator m = JacobiPreconditioner.create(a);
+        final JacobiPreconditioner m = JacobiPreconditioner.create(a);
+        final RealLinearOperator p = m.sqrt();
         final PreconditionedIterativeLinearSolver solver;
         final IterationListener listener = new IterationListener() {
 
@@ -653,7 +653,7 @@ public class SymmLQTest {
                 final RealVector x = evt.getSolution();
                 final RealVector b = evt.getRightHandSideVector();
                 final RealVector r = b.subtract(a.operate(x));
-                final double rnorm = r.getNorm();
+                final double rnorm = p.operate(r).getNorm();
                 Assert.assertEquals("iteration performed (residual)",
                     rnorm, evt.getNormOfResidual(),
                     FastMath.max(1E-5 * rnorm, 1E-10));



Mime
View raw message