/** * Construct a vector by appending a vector to this vector. * @param v vector to append to this one. * @return a new vector */ public ArrayFieldVector<T> append(ArrayFieldVector<T> v) { return new ArrayFieldVector<T>(this, v); }
/** {@inheritDoc} */ public FieldVector<T> copy() { return new ArrayFieldVector<T>(this, true); }
/** {@inheritDoc} */ public FieldVector<T> append(FieldVector<T> v) { try { return append((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { return new ArrayFieldVector<T>(this,new ArrayFieldVector<T>(v)); } }
/** {@inheritDoc} */ public FieldVector<T> getRowVector(final int row) throws OutOfRangeException { return new ArrayFieldVector<T>(field, getRow(row), false); }
/** {@inheritDoc} */ public FieldVector<T> getColumnVector(final int column) throws OutOfRangeException { return new ArrayFieldVector<T>(field, getColumn(column), false); }
/** {@inheritDoc} */ public FieldVector<T> append(T in) { final T[] out = MathArrays.buildArray(field, data.length + 1); System.arraycopy(data, 0, out, 0, data.length); out[data.length] = in; return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public FieldVector<T> mapAdd(T d) throws NullArgumentException { T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(d); } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public FieldVector<T> mapMultiply(T d) throws NullArgumentException { T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].multiply(d); } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public FieldVector<T> mapSubtract(T d) throws NullArgumentException { T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(d); } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ public FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); } ArrayFieldVector<T> out = new ArrayFieldVector<T>(field, n); try { System.arraycopy(data, index, out.data, 0, n); } catch (IndexOutOfBoundsException e) { checkIndex(index); checkIndex(index + n - 1); } return out; }
/** {@inheritDoc} */ public FieldVector<T> mapDivide(T d) throws NullArgumentException, MathArithmeticException { MathUtils.checkNotNull(d); T[] out = MathArrays.buildArray(field, data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].divide(d); } 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 {@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); }
/** {@inheritDoc} */ public FieldVector<T> mapInv() throws MathArithmeticException { T[] out = MathArrays.buildArray(field, data.length); final T one = field.getOne(); for (int i = 0; i < data.length; i++) { try { out[i] = one.divide(data[i]); } catch (final MathArithmeticException e) { throw new MathArithmeticException(LocalizedFormats.INDEX, i); } } return new ArrayFieldVector<T>(field, out, false); }
/** {@inheritDoc} */ @Override public FieldVector<T> getRowVector(final int row) throws OutOfRangeException { checkRowIndex(row); final T[] outData = MathArrays.buildArray(getField(), columns); // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(block, iRow * jWidth, outData, outIndex, jWidth); outIndex += jWidth; } return new ArrayFieldVector<T>(getField(), outData, 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 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> 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); } }