/** * Compute the dot product. * * @param v vector with which dot product should be computed * @return the scalar dot product between instance and v * @exception IllegalArgumentException if v is not the same size as this */ public T dotProduct(ArrayFieldVector<T> v) { checkVectorDimensions(v.data.length); T dot = field.getZero(); for (int i = 0; i < data.length; i++) { dot = dot.add(data[i].multiply(v.data[i])); } return dot; }
/** * Element-by-element division. * * @param v vector by which instance elements must be divided * @return a vector containing this[i] / v[i] for all i * @throws IllegalArgumentException if v is not the same size as this */ public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v) { checkVectorDimensions(v.data.length); T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].divide(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public T dotProduct(FieldVector<T> v) { try { return dotProduct((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T dot = field.getZero(); for (int i = 0; i < data.length; i++) { dot = dot.add(data[i].multiply(v.getEntry(i))); } return dot; } }
/** {@inheritDoc} */ public FieldVector<T> ebeDivide(FieldVector<T> v) { try { return ebeDivide((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].divide(v.getEntry(i)); } return new ArrayFieldVector<T>(field, out, false); } }
/** * Check if instance and specified vectors have the same dimension. * * @param v vector to compare instance with * @exception IllegalArgumentException if the vectors do not have the same dimension */ protected void checkVectorDimensions(FieldVector<T> v) { checkVectorDimensions(v.getDimension()); }