commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arne Plöse (JIRA) <j...@apache.org>
Subject [jira] [Commented] (MATH-570) Change some constructors of ArrayFieldVector to accept FieldVector
Date Tue, 10 May 2011 20:34:47 GMT

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

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

What agbout this (without generics)

    public ArrayFieldVector(FieldVector<T, ?, ?> v1, FieldVector<T, ?, ?> v2)
{
        if (v1 == null
                || v2 == null) {
            throw new NullArgumentException();
        }
        field = v1.getField();
        T[] v1Data;
        T[] v2Data;
        if (v1 instanceof ArrayFieldVector) {
            v1Data = ((ArrayFieldVector<T, ?, ?>) v1).data;
        } else {
            v1Data = v1.getData();
        }
        if (v2 instanceof ArrayFieldVector) {
            v2Data = ((ArrayFieldVector<T, ?, ?>) v2).data;
        } else {
            v2Data = v2.getData();
        }
        data = buildArray(v1Data, v2Data);
    }

    private T[] buildArray(T[] v1, T[] v2) {
        T[] result = buildArray(v1.length + v2.length);
        System.arraycopy(v1, 0, data, 0, v1.length);
        System.arraycopy(v2, 0, data, v1.length, v2.length);
        return result;
    }

    /**
     * Construct a vector by appending one vector to another vector.
     *
     * @param v1 First vector (will be put in front of the new vector).
     * @param v2 Second vector (will be put at back of the new vector).
     * @throws NullArgumentException if {@code v1} or {@code v2} is
     * {@code null}.
     */
    public ArrayFieldVector(FieldVector<T, ?, ?> v1, T[] v2) {
        if (v1 == null
                || v2 == null) {
            throw new NullArgumentException();
        }
        field = v1.getField();
        T[] v1Data;
        if (v1 instanceof ArrayFieldVector) {
            v1Data = ((ArrayFieldVector<T, ?, ?>) v1).data;
        } else {
            v1Data = v1.getData();
        }
        data = buildArray(v1Data, v2);
    }


> Change some constructors of ArrayFieldVector to accept FieldVector
> ------------------------------------------------------------------
>
>                 Key: MATH-570
>                 URL: https://issues.apache.org/jira/browse/MATH-570
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.0
>            Reporter: Arne Plöse
>            Priority: Minor
>
> the constructor     public ArrayFieldVector(T[] v1, ArrayFieldVector<T> v2) {
>  ... 
> }
> takes an ArrayFieldVector.
> but the same can be easier archieved with this 
>     public ArrayFieldVector(T[] v1, FieldVector<T> v2) {
>         this(v1, v2 == null ? null : v2.getData());
>     }
> this goes for all other constructors...
> P.S. I donk know if copying the data in getData is an issue ... for this the named constructor
may make sense...

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

Mime
View raw message