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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT . 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: MatrixUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link FieldVector} using the data from the input array.
 *
 * @param <T> the type of the field elements
 * @param data the input data
 * @return a data.length FieldVector
 * @throws NoDataException if {@code data} is empty.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws ZeroException if {@code data} has 0 elements
 */
public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data)
    throws NoDataException, NullArgumentException, ZeroException {
    if (data == null) {
        throw new NullArgumentException();
    }
    if (data.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    return new ArrayFieldVector<T>(data[0].getField(), data, true);
}
 
Example 2
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d)
        throws NullArgumentException, ZeroException {
    if (d == null) {
        throw new NullArgumentException();
    }
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 3
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link FieldVector} using the data from the input array.
 *
 * @param <T> the type of the field elements
 * @param data the input data
 * @return a data.length FieldVector
 * @throws NoDataException if {@code data} is empty.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws ZeroException if {@code data} has 0 elements
 */
public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data)
    throws NoDataException, NullArgumentException, ZeroException {
    if (data == null) {
        throw new NullArgumentException();
    }
    if (data.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    return new ArrayFieldVector<T>(data[0].getField(), data, true);
}
 
Example 4
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link FieldVector} using the data from the input array.
 *
 * @param <T> the type of the field elements
 * @param data the input data
 * @return a data.length FieldVector
 * @throws NoDataException if {@code data} is empty.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws ZeroException if {@code data} has 0 elements
 */
public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data)
    throws NoDataException, NullArgumentException, ZeroException {
    if (data == null) {
        throw new NullArgumentException();
    }
    if (data.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    return new ArrayFieldVector<T>(data[0].getField(), data, true);
}
 
Example 5
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d) {
    if (d == null) {
        throw new NullArgumentException();
    }
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 6
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 7
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d) {
    if (d == null) {
        throw new NullArgumentException();
    }
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 8
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector by appending one vector to another vector.
 * This constructor needs at least one non-empty array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])}
 * constructor.
 *
 * @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}.
 * @throws ZeroException if both arrays are empty.
 * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
 */
public ArrayFieldVector(T[] v1, T[] v2)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(v1);
    MathUtils.checkNotNull(v2);
    if (v1.length + v2.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    data = MathArrays.buildArray(v1[0].getField(), v1.length + v2.length);
    System.arraycopy(v1, 0, data, 0, v1.length);
    System.arraycopy(v2, 0, data, v1.length, v2.length);
    field = data[0].getField();
}
 
Example 9
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ArrayFieldVector using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * ArrayFieldVector and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
 * constructor.
 *
 * @param d Data for the new vector.
 * @param copyArray If {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(FieldElement[])
 * @see #ArrayFieldVector(Field, FieldElement[], boolean)
 */
public ArrayFieldVector(T[] d, boolean copyArray)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    if (d.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    field = d[0].getField();
    data = copyArray ? d.clone() : d;
}
 
Example 10
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ArrayFieldVector using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * ArrayFieldVector and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
 * constructor.
 *
 * @param d Data for the new vector.
 * @param copyArray If {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(FieldElement[])
 * @see #ArrayFieldVector(Field, FieldElement[], boolean)
 */
public ArrayFieldVector(T[] d, boolean copyArray)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    if (d.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    field = d[0].getField();
    data = copyArray ? d.clone() : d;
}
 
Example 11
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a {@link FieldVector} using the data from the input array.
 *
 * @param <T> the type of the field elements
 * @param data the input data
 * @return a data.length FieldVector
 * @throws NoDataException if {@code data} is empty.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws ZeroException if {@code data} has 0 elements
 */
public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data) {
    if (data == null) {
        throw new NullArgumentException();
    }
    if (data.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    return new ArrayFieldVector<T>(data[0].getField(), data, true);
}
 
Example 12
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector by appending one vector to another vector.
 * This constructor needs at least one non-empty array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])}
 * constructor.
 *
 * @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}.
 * @throws ZeroException if both arrays are empty.
 * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
 */
public ArrayFieldVector(T[] v1, T[] v2)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(v1);
    MathUtils.checkNotNull(v2);
    if (v1.length + v2.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    data = MathArrays.buildArray(v1[0].getField(), v1.length + v2.length);
    System.arraycopy(v1, 0, data, 0, v1.length);
    System.arraycopy(v2, 0, data, v1.length, v2.length);
    field = data[0].getField();
}
 
Example 13
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector by appending one vector to another vector.
 * This constructor needs at least one non-empty array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])}
 * constructor.
 *
 * @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}.
 * @throws ZeroException if both arrays are empty.
 * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
 */
public ArrayFieldVector(T[] v1, T[] v2)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(v1);
    MathUtils.checkNotNull(v2);
    if (v1.length + v2.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    data = MathArrays.buildArray(v1[0].getField(), v1.length + v2.length);
    System.arraycopy(v1, 0, data, 0, v1.length);
    System.arraycopy(v2, 0, data, v1.length, v2.length);
    field = data[0].getField();
}
 
Example 14
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 15
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 16
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector by appending one vector to another vector.
 * This constructor needs at least one non-empty array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])}
 * constructor.
 *
 * @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}.
 * @throws ZeroException if both arrays are empty.
 * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
 */
public ArrayFieldVector(T[] v1, T[] v2)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(v1);
    MathUtils.checkNotNull(v2);
    if (v1.length + v2.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    data = MathArrays.buildArray(v1[0].getField(), v1.length + v2.length);
    System.arraycopy(v1, 0, data, 0, v1.length);
    System.arraycopy(v2, 0, data, v1.length, v2.length);
    field = data[0].getField();
}
 
Example 17
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ArrayFieldVector using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * ArrayFieldVector and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
 * constructor.
 *
 * @param d Data for the new vector.
 * @param copyArray If {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(FieldElement[])
 * @see #ArrayFieldVector(Field, FieldElement[], boolean)
 */
public ArrayFieldVector(T[] d, boolean copyArray)
        throws NullArgumentException, ZeroException {
    if (d == null) {
        throw new NullArgumentException();
    }
    if (d.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    field = d[0].getField();
    data = copyArray ? d.clone() : d;
}
 
Example 18
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct a vector from an array, copying the input array.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
 *
 * @param d Array.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(Field, FieldElement[])
 */
public ArrayFieldVector(T[] d)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    try {
        field = d[0].getField();
        data = d.clone();
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
}
 
Example 19
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ArrayFieldVector using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * ArrayFieldVector and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
 * constructor.
 *
 * @param d Data for the new vector.
 * @param copyArray If {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(FieldElement[])
 * @see #ArrayFieldVector(Field, FieldElement[], boolean)
 */
public ArrayFieldVector(T[] d, boolean copyArray)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    if (d.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    field = d[0].getField();
    data = copyArray ? d.clone() : d;
}
 
Example 20
Source File: ArrayFieldVector.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ArrayFieldVector using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * ArrayFieldVector and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 * This constructor needs a non-empty {@code d} array to retrieve
 * the field from its first element. This implies it cannot build
 * 0 length vectors. To build vectors from any size, one should
 * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
 * constructor.
 *
 * @param d Data for the new vector.
 * @param copyArray If {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @throws ZeroException if {@code d} is empty.
 * @see #ArrayFieldVector(FieldElement[])
 * @see #ArrayFieldVector(Field, FieldElement[], boolean)
 */
public ArrayFieldVector(T[] d, boolean copyArray)
        throws NullArgumentException, ZeroException {
    MathUtils.checkNotNull(d);
    if (d.length == 0) {
        throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
    }
    field = d[0].getField();
    data = copyArray ? d.clone() : d;
}