/** {@inheritDoc} */ public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { checkVectorDimensions(v.getDimension()); return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
@SuppressWarnings("unchecked") // May fail, but we ignore ClassCastException FieldVector<T> rhs = (FieldVector<T>) other; if (data.length != rhs.getDimension()) { return false; if (!data[i].equals(rhs.getEntry(i))) { return false;
/** * 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(FieldVector<T> v) throws NullArgumentException { MathUtils.checkNotNull(v); field = v.getField(); data = MathArrays.buildArray(field, v.getDimension()); for (int i = 0; i < data.length; ++i) { data[i] = v.getEntry(i); } }
/** {@inheritDoc} */ public FieldVector<T> append(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return append((SparseFieldVector<T>) v); } else { final int n = v.getDimension(); FieldVector<T> res = new SparseFieldVector<T>(this, n); for (int i = 0; i < n; i++) { res.setEntry(i + virtualSize, v.getEntry(i)); } return res; } }
/** * 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}. * @since 3.2 */ public ArrayFieldVector(FieldVector<T> v1, FieldVector<T> v2) throws NullArgumentException { MathUtils.checkNotNull(v1); MathUtils.checkNotNull(v2); field = v1.getField(); final T[] v1Data = (v1 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v1).data : v1.toArray(); final T[] v2Data = (v2 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v2).data : v2.toArray(); data = MathArrays.buildArray(field, v1Data.length + v2Data.length); System.arraycopy(v1Data, 0, data, 0, v1Data.length); System.arraycopy(v2Data, 0, data, v1Data.length, v2Data.length); }
/** {@inheritDoc} */ public FieldVector<T> add(FieldVector<T> v) throws DimensionMismatchException { try { return add((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(v.getEntry(i)); } return new ArrayFieldVector<T>(field, out, false); } }
/** {@inheritDoc} */ public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
list = (IAST) o1; matrix1 = Convert.list2Matrix(list); FieldElement<ExprFieldElement>[] av = vector0.getData(); BlockFieldMatrix<ExprFieldElement> m = new BlockFieldMatrix<ExprFieldElement>(ExprField.CONST,1,av.length); m.setRow(0, vector0.getData()); return Convert.matrix2List(m.multiply( matrix1)); list = (IAST) o1; vector1 = Convert.list2Vector(list); return vector0.dotProduct(vector1).getExpr();
/** * Check if instance and specified vectors have the same dimension. * @param v vector to compare instance with * @exception DimensionMismatchException if the vectors do not * have the same dimensions */ protected void checkVectorDimensions(FieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); }
/** {@inheritDoc} */ public FieldVector<T> mapDivide(T d) throws NullArgumentException, MathArithmeticException { return copy().mapDivideToSelf(d); }
/** {@inheritDoc} */ public FieldVector<T> mapSubtract(T d) throws NullArgumentException { return copy().mapSubtractToSelf(d); }
/** {@inheritDoc} */ public FieldVector<T> mapInv() throws MathArithmeticException { return copy().mapInvToSelf(); }
/** {@inheritDoc} */ public FieldVector<T> mapMultiply(T d) throws NullArgumentException { return copy().mapMultiplyToSelf(d); }
/** {@inheritDoc} */ public FieldVector<T> mapAdd(T d) throws NullArgumentException { return copy().mapAddToSelf(d); }
/** {@inheritDoc} */ public FieldVector<T> append(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return append((SparseFieldVector<T>) v); } else { final int n = v.getDimension(); FieldVector<T> res = new SparseFieldVector<T>(this, n); for (int i = 0; i < n; i++) { res.setEntry(i + virtualSize, v.getEntry(i)); } return res; } }
/** * 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}. * @since 3.2 */ public ArrayFieldVector(T[] v1, FieldVector<T> v2) throws NullArgumentException { MathUtils.checkNotNull(v1); MathUtils.checkNotNull(v2); field = v2.getField(); final T[] v2Data = (v2 instanceof ArrayFieldVector) ? ((ArrayFieldVector<T>) v2).data : v2.toArray(); data = MathArrays.buildArray(field, v1.length + v2Data.length); System.arraycopy(v1, 0, data, 0, v1.length); System.arraycopy(v2Data, 0, data, v1.length, v2Data.length); }
/** {@inheritDoc} */ public FieldVector<T> subtract(FieldVector<T> v) throws DimensionMismatchException { try { return subtract((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(v.getEntry(i)); } return new ArrayFieldVector<T>(field, out, false); } }
/** {@inheritDoc} */ public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
/** * Check if instance and specified vectors have the same dimension. * @param v vector to compare instance with * @exception DimensionMismatchException if the vectors do not * have the same dimensions */ protected void checkVectorDimensions(FieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); }
/** {@inheritDoc} */ public FieldVector<T> mapDivide(T d) throws NullArgumentException, MathArithmeticException { return copy().mapDivideToSelf(d); }