/** * Construct a vector from another vector. * * @param v Vector to copy. * @param deep If {@code true} perform a deep copy, otherwise perform a shallow copy * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep) { if (v == null) { throw new NullArgumentException(); } field = v.getField(); data = deep ? v.data.clone() : v.data; }
/** * Construct a vector from another vector, using a deep copy. * * @param v Vector to copy. * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector<T> v) { if (v == null) { throw new NullArgumentException(); } field = v.getField(); data = v.data.clone(); }
/** * 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(T[] v1, ArrayFieldVector<T> v2) { if (v1 == null || v2 == null) { throw new NullArgumentException(); } field = v2.getField(); data = buildArray(v1.length + v2.data.length); System.arraycopy(v1, 0, data, 0, v1.length); System.arraycopy(v2.data, 0, data, v1.length, v2.data.length); }
/** * Find the orthogonal projection of this vector onto another vector. * * @param v vector onto which instance must be projected * @return projection of the instance onto v * @throws IllegalArgumentException if v is not the same size as this */ public ArrayFieldVector<T> projection(ArrayFieldVector<T> v) { return (ArrayFieldVector<T>) v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }