You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sébastien Brisard (JIRA)" <ji...@apache.org> on 2012/06/09 20:51:42 UTC
[jira] [Created] (MATH-803) Bugs in
OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Sébastien Brisard created MATH-803:
--------------------------------------
Summary: Bugs in OpenMapRealVector.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ébastien Brisard
Assignee: Sébastien Brisard
{{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-803) Bugs in
OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292525#comment-13292525 ]
Luc Maisonobe commented on MATH-803:
------------------------------------
Perhaps we should use a post-processing branch to handle infinite or spacial values:
{code}
// current implementation looping over non-zero instance elements goes here
if (v.isNaN() || v.isInfinite()) {
// post-processing loop, to handle 0 * infinity and 0 * NaN cases
for (int i = 0; i < v.getDimension(); ++v) {
if (Double.isInfinite(v.getElement(i)) || Double.isNaN(v.getElement(i)) {
res.setEntry(i, Double.NaN);
}
}
}
{code}
This could be fast only if isNaN() and isInfinite() results are cached and the same vector is reused, otherwise the outer if statement should be removed and the post-processing should be done in all cases.
> Bugs in OpenMapRealVector.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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-803) Bugs in
RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles updated MATH-803:
------------------------
Affects Version/s: (was: 4.0)
3.0
> 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ébastien Brisard
> Fix For: 4.0
>
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-803) Bugs in
RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles updated MATH-803:
------------------------
Fix Version/s: 4.0
> 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ébastien Brisard
> Fix For: 4.0
>
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-803) Bugs in
OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292648#comment-13292648 ]
Sébastien Brisard commented on MATH-803:
----------------------------------------
I think this does not work for {{ebeDivide(RealVector)}}. In this case, I suggest to revert to naive implementation (loop through all entries).
> Bugs in OpenMapRealVector.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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-803) Bugs in
OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292642#comment-13292642 ]
Sébastien Brisard commented on MATH-803:
----------------------------------------
I'm going to implement the suggested post-processing for the time being; this should solve the bug. Caching of isNaN() and isInfinite() is postponed.
> Bugs in OpenMapRealVector.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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-803) Bugs in
OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292413#comment-13292413 ]
Sébastien Brisard commented on MATH-803:
----------------------------------------
In {{r1348485}}, {{RealVectorAbstractTest}} include unit tests illustrating this bug.
> Bugs in OpenMapRealVector.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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (MATH-803) Bugs in
RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13399150#comment-13399150 ]
Sébastien Brisard commented on MATH-803:
----------------------------------------
According to this [thread|http://markmail.org/thread/4evd6dcyrh2yc2bs], {{ebeMultiply}} and {{ebeDivide}} are deprecated.
> 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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-803) Bugs in
RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sébastien Brisard updated MATH-803:
-----------------------------------
Affects Version/s: (was: 3.0)
4.0
Methods are deprecated in {{r1352782}}, and unit tests are skipped (they are kept for reference). Issue is to remain open until the methods are removed in version 4.0.
> 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: 4.0
> Reporter: Sébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-803) Bugs in
RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector)
Posted by "Sébastien Brisard (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sébastien Brisard updated MATH-803:
-----------------------------------
Summary: Bugs in RealVector.ebeMultiply(RealVector) and ebeDivide(RealVector) (was: Bugs in OpenMapRealVector.ebeMultiply(RealVector) and ebeDivide(RealVector))
Changed the title of the ticket, since the scope of this bug is much broader. Indeed, it affects {{RealVector.ebeMultiply(RealVector)}} and {{RealVector.ebeDivide(RealVector)}} as soon as the {{RealVector}} passed as a parameter is sparse, see examples below
# for {{ebeMultiply()}}
{code:java}
final RealVector v1 = new ArrayRealVector(new double[] { 1d });
final RealVector v2 = new OpenMapRealVector(new double[] { -0d });
final RealVector w = 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 = new ArrayRealVector(new double[] { 1d });
final RealVector v2 = new OpenMapRealVector(new double[] { -0d });
final RealVector w = v1.ebeDivide(v2);
System.out.println(w.getEntry(0));
{code}
prints {{Infinity}}, instead of {{-Infinity}}.
> 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ébastien Brisard
> Assignee: Sébastien Brisard
>
> {{OpenMapRealVector.ebeMultiply(RealVector)}} and {{OpenMapRealVector.ebeDivide(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 = new OpenMapRealVector(this);
> Iterator iter = 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 == 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* entries of v (instead of those entries which correspond to non-zero entries of this). I'm afraid about performance losses.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira