commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Brisard (JIRA) <>
Subject [jira] [Created] (MATH-802) RealVector.subtract(RealVector) returns wrong answer.
Date Sat, 09 Jun 2012 13:06:42 GMT
Sébastien Brisard created MATH-802:

             Summary: RealVector.subtract(RealVector) returns wrong answer.
                 Key: MATH-802
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.0
            Reporter: Sébastien Brisard
            Assignee: Sébastien Brisard
             Fix For: 3.1

The following piece of code
import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.OpenMapRealVector;
import org.apache.commons.math3.linear.RealVectorFormat;

public class DemoMath {

    public static void main(String[] args) {
        final double[] data1 = {
            0d, 1d, 0d, 0d, 2d
        final double[] data2 = {
            3d, 0d, 4d, 0d, 5d
        final RealVectorFormat format = new RealVectorFormat();
        System.out.println(format.format(new ArrayRealVector(data1)
            .subtract(new ArrayRealVector(data2))));
        System.out.println(format.format(new OpenMapRealVector(data1)
            .subtract(new ArrayRealVector(data2))));

{-3; 1; -4; 0; -3}
{3; 1; 4; 0; -3}

the second line being wrong. In fact, when subtracting mixed types, {{OpenMapRealVector}}
delegates to the default implementation in {{RealVector}} which is buggy.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message