Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#INDEX

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#INDEX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RealVector.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the indices of a subvector are valid.
 *
 * @param start the index of the first entry of the subvector
 * @param end the index of the last entry of the subvector (inclusive)
 * @throws OutOfRangeException if {@code start} of {@code end} are not valid
 * @throws NumberIsTooSmallException if {@code end < start}
 */
protected void checkIndices(final int start, final int end)
    throws NumberIsTooSmallException, OutOfRangeException {
    final int dim = getDimension();
    if ((start < 0) || (start >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0,
                                      dim - 1);
    }
    if ((end < 0) || (end >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0,
                                      dim - 1);
    }
    if (end < start) {
        // TODO Use more specific error message
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
                                            end, start, false);
    }
}
 
Example 2
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@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);
    }
}
 
Example 3
Source File: RealVector.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the indices of a subvector are valid.
 *
 * @param start the index of the first entry of the subvector
 * @param end the index of the last entry of the subvector (inclusive)
 * @throws OutOfRangeException if {@code start} of {@code end} are not valid
 * @throws NumberIsTooSmallException if {@code end < start}
 * @since 3.1
 */
protected void checkIndices(final int start, final int end)
    throws NumberIsTooSmallException, OutOfRangeException {
    final int dim = getDimension();
    if ((start < 0) || (start >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0,
                                      dim - 1);
    }
    if ((end < 0) || (end >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0,
                                      dim - 1);
    }
    if (end < start) {
        // TODO Use more specific error message
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
                                            end, start, false);
    }
}
 
Example 4
Source File: RealVector.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the indices of a subvector are valid.
 *
 * @param start the index of the first entry of the subvector
 * @param end the index of the last entry of the subvector (inclusive)
 * @throws OutOfRangeException if {@code start} of {@code end} are not valid
 * @throws NumberIsTooSmallException if {@code end < start}
 * @since 3.1
 */
protected void checkIndices(final int start, final int end)
    throws NumberIsTooSmallException, OutOfRangeException {
    final int dim = getDimension();
    if ((start < 0) || (start >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0,
                                      dim - 1);
    }
    if ((end < 0) || (end >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0,
                                      dim - 1);
    }
    if (end < start) {
        // TODO Use more specific error message
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
                                            end, start, false);
    }
}
 
Example 5
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addToEntry(int index, double increment) {
    try {
    data[index] += increment;
    } catch(IndexOutOfBoundsException e){
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, data.length - 1);
    }
}
 
Example 6
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@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);
}
 
Example 7
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getEntry(int index) throws OutOfRangeException {
    try {
        return data[index];
    } catch (IndexOutOfBoundsException e) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, index, 0,
            getDimension() - 1);
    }
}
 
Example 9
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FieldVector<T> mapInvToSelf() throws MathArithmeticException {
    final T one = field.getOne();
    for (int i = 0; i < data.length; i++) {
        try {
            data[i] = one.divide(data[i]);
        } catch (final MathArithmeticException e) {
            throw new MathArithmeticException(LocalizedFormats.INDEX, i);
        }
    }
    return this;
}
 
Example 10
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@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);
}
 
Example 11
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FieldVector<T> mapInvToSelf() throws MathArithmeticException {
    final T one = field.getOne();
    for (int i = 0; i < data.length; i++) {
        try {
            data[i] = one.divide(data[i]);
        } catch (final MathArithmeticException e) {
            throw new MathArithmeticException(LocalizedFormats.INDEX, i);
        }
    }
    return this;
}
 
Example 12
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getEntry(int index) {
    try {
        return data[index];
    } catch (IndexOutOfBoundsException e) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, index, 0,
            getDimension() - 1);
    }
}
 
Example 13
Source File: RealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if an index is valid.
 *
 * @param index Index to check.
 * @exception OutOfRangeException if {@code index} is not valid.
 */
protected void checkIndex(final int index) throws OutOfRangeException {
    if (index < 0 ||
        index >= getDimension()) {
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, getDimension() - 1);
    }
}
 
Example 14
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addToEntry(int index, double increment)
    throws OutOfRangeException {
    try {
    data[index] += increment;
    } catch(IndexOutOfBoundsException e){
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, data.length - 1);
    }
}
 
Example 15
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if an index is valid.
 *
 * @param index Index to check.
 * @exception OutOfRangeException if the index is not valid.
 */
private void checkIndex(final int index) {
    if (index < 0 || index >= getDimension()) {
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, getDimension() - 1);
    }
}
 
Example 16
Source File: RealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if an index is valid.
 *
 * @param index Index to check.
 * @exception OutOfRangeException if {@code index} is not valid.
 */
protected void checkIndex(final int index) throws OutOfRangeException {
    if (index < 0 ||
        index >= getDimension()) {
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, getDimension() - 1);
    }
}
 
Example 17
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if an index is valid.
 *
 * @param index Index to check.
 * @exception OutOfRangeException if the index is not valid.
 */
private void checkIndex(final int index) throws OutOfRangeException {
    if (index < 0 || index >= getDimension()) {
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, getDimension() - 1);
    }
}
 
Example 18
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if an index is valid.
 *
 * @param index Index to check.
 * @exception OutOfRangeException if the index is not valid.
 */
private void checkIndex(final int index) throws OutOfRangeException {
    if (index < 0 || index >= getDimension()) {
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, getDimension() - 1);
    }
}
 
Example 20
Source File: ArrayRealVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addToEntry(int index, double increment)
    throws OutOfRangeException {
    try {
    data[index] += increment;
    } catch(IndexOutOfBoundsException e){
        throw new OutOfRangeException(LocalizedFormats.INDEX,
                                      index, 0, data.length - 1);
    }
}