commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-316) Perf improvement: ArrayRealVector makes superfluous copies and often doesn't optimally operate on array values
Date Mon, 28 Dec 2009 15:33:29 GMT

    [ https://issues.apache.org/jira/browse/MATH-316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794827#action_12794827
] 

Luc Maisonobe commented on MATH-316:
------------------------------------

The last few forgotten copies should have been fixed now I hope.
I have also added a few more constructors using RealVectors and improved test coverage which
lies now somewhere between 99% and 100% for this class.

> Perf improvement: ArrayRealVector makes superfluous copies and often doesn't optimally
operate on array values
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-316
>                 URL: https://issues.apache.org/jira/browse/MATH-316
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>         Environment: all
>            Reporter: Jake Mannix
>            Priority: Minor
>             Fix For: 2.1
>
>         Attachments: MATH-316.patch
>
>
> As discussed in the mailing list, things like ArrayRealVector#add:
> {code}
>             double[] out = new double[data.length];
>             for (int i = 0; i < data.length; i++) {
>                 out[i] = data[i] + v.getEntry(i);
>             }
>             return new ArrayRealVector(out);
> {code}
> can be improved in the inner loop by simply
> {code}
>             double[] out = out.clone();
>             for (int i = 0; i < data.length; i++) {
>                 out[i] += v.getEntry(i);
>             }
>             return new ArrayRealVector(out);
> {code}
> Which cuts down on array accesses.
> Even more importantly, the last return line should pass in the boolean false, for "shallow
copy", or else this whole temporary array is being copied again and then the original discarded.
> {code}
>   return new ArrayRealVector(out, false);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message