/** * 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()); }
/** * Compute the sum of {@code this} and {@code v}. * @param v vector to be added * @return {@code this + v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> add(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Compute {@code this} minus {@code v}. * @param v vector to be subtracted * @return {@code this - v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Element-by-element multiplication. * @param v vector by which instance elements must be multiplied * @return a vector containing {@code this[i] * v[i]} for all {@code i} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].multiply(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Compute the dot product. * @param v vector with which dot product should be computed * @return the scalar dot product of {@code this} and {@code v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public T dotProduct(ArrayFieldVector<T> v) throws DimensionMismatchException { 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 {@code this[i] / v[i]} for all {@code i} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} * @throws MathArithmeticException if one entry of {@code v} is zero. */ public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { try { out[i] = data[i].divide(v.data[i]); } catch (final MathArithmeticException e) { throw new MathArithmeticException(LocalizedFormats.INDEX, i); } } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public FieldVector<T> ebeMultiply(FieldVector<T> v) throws DimensionMismatchException { try { return ebeMultiply((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].multiply(v.getEntry(i)); } return new ArrayFieldVector<T>(field, out, false); } }
/** {@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> 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 T dotProduct(FieldVector<T> v) throws DimensionMismatchException { 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) throws DimensionMismatchException, MathArithmeticException { try { return ebeDivide((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { try { out[i] = data[i].divide(v.getEntry(i)); } catch (final MathArithmeticException e) { throw new MathArithmeticException(LocalizedFormats.INDEX, 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 DimensionMismatchException if the vectors do not * have the same dimensions */ protected void checkVectorDimensions(FieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); }
/** * Compute {@code this} minus {@code v}. * @param v vector to be subtracted * @return {@code this - v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Element-by-element multiplication. * @param v vector by which instance elements must be multiplied * @return a vector containing {@code this[i] * v[i]} for all {@code i} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].multiply(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Compute the sum of {@code this} and {@code v}. * @param v vector to be added * @return {@code this + v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public ArrayFieldVector<T> add(ArrayFieldVector<T> v) throws DimensionMismatchException { checkVectorDimensions(v.data.length); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(v.data[i]); } return new ArrayFieldVector<T>(field, out, false); }
/** * Compute the dot product. * @param v vector with which dot product should be computed * @return the scalar dot product of {@code this} and {@code v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} */ public T dotProduct(ArrayFieldVector<T> v) throws DimensionMismatchException { 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; }
/** {@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> 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> ebeMultiply(FieldVector<T> v) throws DimensionMismatchException { try { return ebeMultiply((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].multiply(v.getEntry(i)); } return new ArrayFieldVector<T>(field, out, false); } }
/** {@inheritDoc} */ public T dotProduct(FieldVector<T> v) throws DimensionMismatchException { 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; } }