You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/07/12 13:29:12 UTC

svn commit: r1502516 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/util/MathArrays.java test/java/org/apache/commons/math3/util/MathArraysTest.java

Author: erans
Date: Fri Jul 12 11:29:12 2013
New Revision: 1502516

URL: http://svn.apache.org/r1502516
Log:
MATH-1005
Array of length 1 must be handled as a special case.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1502516&r1=1502515&r2=1502516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Fri Jul 12 11:29:12 2013
@@ -51,6 +51,9 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="x.y" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-1005" due-to="Roman Werpachowski">
+        Fixed "MathArrays.linearCombination" when array length is 1.
+      </action>
       <action dev="erans" type="add" issue="MATH-997">
         Implemented Gauss-Hermite quadrature scheme (in package
         "o.a.c.m.analysis.integration.gauss").

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1502516&r1=1502515&r2=1502516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Fri Jul 12 11:29:12 2013
@@ -818,6 +818,11 @@ public class MathArrays {
             throw new DimensionMismatchException(len, b.length);
         }
 
+        if (len == 1) {
+            // Revert to scalar multiplication.
+            return a[0] * b[0];
+        }
+
         final double[] prodHigh = new double[len];
         double prodLowSum = 0;
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java?rev=1502516&r1=1502515&r2=1502516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java Fri Jul 12 11:29:12 2013
@@ -582,6 +582,15 @@ public class MathArraysTest {
         }
     }
 
+    // MATH-1005
+    @Test
+    public void testLinearCombinationWithSingleElementArray() {
+        final double[] a = { 1.23456789 };
+        final double[] b = { 98765432.1 };
+
+        Assert.assertEquals(a[0] * b[0], MathArrays.linearCombination(a, b), 0d);
+    }
+
     @Test
     public void testLinearCombination1() {
         final double[] a = new double[] {