Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2A6519E38 for ; Fri, 22 Jun 2012 06:06:46 +0000 (UTC) Received: (qmail 70631 invoked by uid 500); 22 Jun 2012 06:06:45 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 70534 invoked by uid 500); 22 Jun 2012 06:06:45 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 69859 invoked by uid 99); 22 Jun 2012 06:06:43 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 06:06:43 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id A58501427F2 for ; Fri, 22 Jun 2012 06:06:43 +0000 (UTC) Date: Fri, 22 Jun 2012 06:06:43 +0000 (UTC) From: =?utf-8?Q?S=C3=A9bastien_Brisard_=28JIRA=29?= To: issues@commons.apache.org Message-ID: <220713578.42945.1340345203682.JavaMail.jiratomcat@issues-vm> In-Reply-To: <665728963.588.1339267902813.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Updated] (MATH-803) Bugs in RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MATH-803?page=3Dcom.atlassian.= jira.plugin.system.issuetabpanels:all-tabpanel ] S=C3=A9bastien Brisard updated MATH-803: ----------------------------------- Summary: Bugs in RealVector.ebeMultiply(RealVector) and ebeDivide(RealV= ector) (was: Bugs in OpenMapRealVector.ebeMultiply(RealVector) and ebeDivi= de(RealVector)) Changed the title of the ticket, since the scope of this bug is much broade= r. Indeed, it affects {{RealVector.ebeMultiply(RealVector)}} and {{RealVect= or.ebeDivide(RealVector)}} as soon as the {{RealVector}} passed as a parame= ter is sparse, see examples below # for {{ebeMultiply()}} {code:java} final RealVector v1 =3D new ArrayRealVector(new double[] { 1d }); final RealVector v2 =3D new OpenMapRealVector(new double[] { -0d }); final RealVector w =3D v1.ebeMultiply(v2); System.out.println(1d / w.getEntry(0)); {code} prints {{Infinity}}, instead of {{-Infinity}} (because the sign is lost in = {{v2}}). This means that {{w}} holds {{+0d}} instead of {{-0d}}. # for {{ebeDivide()}} {code:java} final RealVector v1 =3D new ArrayRealVector(new double[] { 1d }); final RealVector v2 =3D new OpenMapRealVector(new double[] { -0d }); final RealVector w =3D v1.ebeDivide(v2); System.out.println(w.getEntry(0)); {code} prints {{Infinity}}, instead of {{-Infinity}}. =20 > Bugs in RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector) > -------------------------------------------------------------------- > > Key: MATH-803 > URL: https://issues.apache.org/jira/browse/MATH-803 > Project: Commons Math > Issue Type: Bug > Affects Versions: 3.0 > Reporter: S=C3=A9bastien Brisard > Assignee: S=C3=A9bastien Brisard > > {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebe= Divide(RealVector)}} return wrong values when one entry of the specified {{= RealVector}} is nan or infinity. The bug is easy to understand. Here is the= current implementation of {{ebeMultiply}} > {code:java} > public OpenMapRealVector ebeMultiply(RealVector v) { > checkVectorDimensions(v.getDimension()); > OpenMapRealVector res =3D new OpenMapRealVector(this); > Iterator iter =3D entries.iterator(); > while (iter.hasNext()) { > iter.advance(); > res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()= )); > } > return res; > } > {code} > The assumption is that for any double {{x}}, {{x * 0d =3D=3D 0d}} holds, = which is not true. The bug is easy enough to identify, but more complex to = solve. The only solution I can come up with is to loop through *all* entrie= s of v (instead of those entries which correspond to non-zero entries of th= is). I'm afraid about performance losses. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira