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

Arne Plöse commented on MATH-623:
---------------------------------

Sorry, I just point out where I think things should go ...
So at first let look at ArrayRealVector.add and then to 
(OpenMap|Array)(Real|Field)(Vector|Matrix).(add|subtract|...).
After that wee will see...

{code}
    @Override
    public RealVector add(RealVector v) {
        if (v instanceof ArrayRealVector) {
            return add(((ArrayRealVector)v).data);
        } else if (v instanceof SparseRealVector){
            checkVectorDimensions(v);
            double[] out = data.clone();
            Iterator<Entry> it = ((SparseRealVector)v).sparseIterator();
            Entry e;
            while (it.hasNext() && (e = it.next()) != null) {
                out[e.getIndex()] += e.getValue();
            }
            return new ArrayRealVector(out, false);
        } else {
            final int dim = v.getDimension();
            checkVectorDimensions(dim);
            ArrayRealVector result = new ArrayRealVector(dim);
            double[] resultData = result.data;
            for (int i = 0; i < dim; i++) {
                resultData[i] = data[i] + v.getEntry(i);
            }
            return result;
        }
    }

    RealVector addOld(double[] v) {
        final int dim = v.length;
        checkVectorDimensions(dim);
        double[] out = data.clone();
        for (int i = 0; i < dim; i++) {
            out[i] += v[i];
        }
        return new ArrayRealVector(out, false);
    }

    @Override
    public RealVector add(double[] v) {
        final int dim = v.length;
        checkVectorDimensions(dim);
        ArrayRealVector result = new ArrayRealVector(dim);
        double[] resultData = result.data;
        for (int i = 0; i < dim; i++) {
            resultData[i] = data[i] + v[i];
        }
        return result;
    }
{code}

> Use implementation of JAMA for ArrayRealVector operators
> --------------------------------------------------------
>
>                 Key: MATH-623
>                 URL: https://issues.apache.org/jira/browse/MATH-623
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.0
>            Reporter: Arne Plöse
>            Priority: Minor
>         Attachments: ArrayRealVector.diff
>
>
> For instance the add(double[] v) fist clones the array, and then adds all 
> entries of this.data to the result.
> JAMA uses the following approach create a empty result[] the assign the sum 
> of each entry to the result. this is approximately 10 -20 % faster.
> I will provide a patch with some more enhancements/cleanups for this.
> in the test look for XXX: 
> the first number is the jama time the second the current algorithm.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to