/** * Check two lengths are equal. * @param expectedLen expected length * @param actual actual length * @exception DimensionMismatchException if the two lengths are not equal */ private static void checkLen(int expectedLen, int actual) throws DimensionMismatchException { if (expectedLen != actual) { throw new DimensionMismatchException(actual, expectedLen); } }
/** * Throws DimensionMismatchException if dimension != k. * @param dimension dimension to check * @throws DimensionMismatchException if dimension != k */ private void checkDimension(int dimension) throws DimensionMismatchException { if (dimension != k) { throw new DimensionMismatchException(dimension, k); } } }
/** * Replace all points. * Note that no deep-copy of {@code points} is performed. * * @param points New Points. */ protected void setPoints(PointValuePair[] points) { if (points.length != simplex.length) { throw new DimensionMismatchException(points.length, simplex.length); } simplex = points; }
/** Check dimensions equality. * @param d1 first dimension * @param d2 second dimansion * @exception DimensionMismatchException if dimensions do not match */ private void checkDimensionsEquality(final int d1, final int d2) throws DimensionMismatchException { if (d1 != d2) { throw new DimensionMismatchException(d2, d1); } }
/** * Replace all points. * Note that no deep-copy of {@code points} is performed. * * @param points New Points. */ protected void setPoints(PointValuePair[] points) { if (points.length != simplex.length) { throw new DimensionMismatchException(points.length, simplex.length); } simplex = points; }
/** Simple constructor. * Build a vector from its coordinates * @param v coordinates array * @exception DimensionMismatchException if array does not have 2 elements * @see #toArray() */ public Vector2D(double[] v) throws DimensionMismatchException { if (v.length != 2) { throw new DimensionMismatchException(v.length, 2); } this.x = v[0]; this.y = v[1]; }
/** * Check if instance dimension is equal to some expected value. * * @param n Expected dimension. * @throws DimensionMismatchException if the dimension is * inconsistent with vector size. */ @Override protected void checkVectorDimensions(int n) throws DimensionMismatchException { if (data.length != n) { throw new DimensionMismatchException(data.length, n); } }
/** Check rules set compatibility. * @param compiler other compiler to check against instance * @exception DimensionMismatchException if number of free parameters or orders are inconsistent */ public void checkCompatibility(final DSCompiler compiler) throws DimensionMismatchException { if (parameters != compiler.parameters) { throw new DimensionMismatchException(parameters, compiler.parameters); } if (order != compiler.order) { throw new DimensionMismatchException(order, compiler.order); } }
/** * Check if instance dimension is equal to some expected value. * * @param n Expected dimension. * @throws DimensionMismatchException if the dimension is not equal to the * size of {@code this} vector. */ protected void checkVectorDimensions(int n) throws DimensionMismatchException { if (data.length != n) { throw new DimensionMismatchException(data.length, n); } }
/** Simple constructor. * Build a vector from its coordinates * @param v coordinates array * @exception DimensionMismatchException if array does not have 3 elements * @see #toArray() */ public Vector3D(double[] v) throws DimensionMismatchException { if (v.length != 3) { throw new DimensionMismatchException(v.length, 3); } this.x = v[0]; this.y = v[1]; this.z = v[2]; }
/** Simple constructor. * Build a vector from its coordinates * @param v coordinates array * @exception DimensionMismatchException if array does not have 3 elements * @see #toArray() */ public FieldVector3D(final T[] v) throws DimensionMismatchException { if (v.length != 3) { throw new DimensionMismatchException(v.length, 3); } this.x = v[0]; this.y = v[1]; this.z = v[2]; }
/** * Add a new vector to the sample. * @param v vector to add * @throws DimensionMismatchException if the vector does not have the right dimension */ public void increment(double[] v) throws DimensionMismatchException { if (v.length != sums.length) { throw new DimensionMismatchException(v.length, sums.length); } int k = 0; for (int i = 0; i < v.length; ++i) { sums[i] += v[i]; for (int j = 0; j <= i; ++j) { productsSums[k++] += v[i] * v[j]; } } n++; }
/** * Builds a quaternion from scalar and vector parts. * * @param scalar Scalar part of the quaternion. * @param v Components of the vector part of the quaternion. * * @throws DimensionMismatchException if the array length is not 3. */ public Quaternion(final double scalar, final double[] v) throws DimensionMismatchException { if (v.length != 3) { throw new DimensionMismatchException(v.length, 3); } this.q0 = scalar; this.q1 = v[0]; this.q2 = v[1]; this.q3 = v[2]; }
/** Check array dimensions. * @param expected expected dimension * @param array (may be null if expected is 0) * @throws DimensionMismatchException if the array dimension does not match the expected one */ private void checkDimension(final int expected, final Object array) throws DimensionMismatchException { int arrayDimension = (array == null) ? 0 : Array.getLength(array); if (arrayDimension != expected) { throw new DimensionMismatchException(arrayDimension, expected); } }
/** * Check that both arrays have the same length. * * @param a Array. * @param b Array. * @param abort Whether to throw an exception if the check fails. * @return {@code true} if the arrays have the same length. * @throws DimensionMismatchException if the lengths differ and * {@code abort} is {@code true}. * @since 3.6 */ public static boolean checkEqualLength(double[] a, double[] b, boolean abort) { if (a.length == b.length) { return true; } else { if (abort) { throw new DimensionMismatchException(a.length, b.length); } return false; } }
/** * Check that both arrays have the same length. * * @param a Array. * @param b Array. * @param abort Whether to throw an exception if the check fails. * @return {@code true} if the arrays have the same length. * @throws DimensionMismatchException if the lengths differ and * {@code abort} is {@code true}. * @since 3.6 */ public static boolean checkEqualLength(int[] a, int[] b, boolean abort) { if (a.length == b.length) { return true; } else { if (abort) { throw new DimensionMismatchException(a.length, b.length); } return false; } }
/** Extract equation data from a complete state or derivative array. * @param complete complete state or derivative array from which * equation data should be retrieved * @param equationData placeholder where to put equation data * @throws DimensionMismatchException if the dimension of the equation data does not * match the mapper dimension */ public void extractEquationData(double[] complete, double[] equationData) throws DimensionMismatchException { if (equationData.length != dimension) { throw new DimensionMismatchException(equationData.length, dimension); } System.arraycopy(complete, firstIndex, equationData, 0, dimension); }
/** Set primary part of the current state. * @param primaryState primary part of the current state * @throws DimensionMismatchException if the dimension of the array does not * match the primary set */ public void setPrimaryState(final double[] primaryState) throws DimensionMismatchException { // safety checks if (primaryState.length != this.primaryState.length) { throw new DimensionMismatchException(primaryState.length, this.primaryState.length); } // set the data System.arraycopy(primaryState, 0, this.primaryState, 0, primaryState.length); }
/** Insert equation data into a complete state or derivative array. * @param equationData equation data to be inserted into the complete array * @param complete placeholder where to put equation data (only the * part corresponding to the equation will be overwritten) * @throws DimensionMismatchException if the dimension of the equation data does not * match the mapper dimension */ public void insertEquationData(double[] equationData, double[] complete) throws DimensionMismatchException { if (equationData.length != dimension) { throw new DimensionMismatchException(equationData.length, dimension); } System.arraycopy(equationData, 0, complete, firstIndex, dimension); }
/** Build an instance from all its derivatives. * @param parameters number of free parameters * @param order derivation order * @param derivatives derivatives sorted according to * {@link DSCompiler#getPartialDerivativeIndex(int...)} * @exception DimensionMismatchException if derivatives array does not match the * {@link DSCompiler#getSize() size} expected by the compiler * @throws NumberIsTooLargeException if order is too large * @see #getAllDerivatives() */ public DerivativeStructure(final int parameters, final int order, final double ... derivatives) throws DimensionMismatchException, NumberIsTooLargeException { this(parameters, order); if (derivatives.length != data.length) { throw new DimensionMismatchException(derivatives.length, data.length); } System.arraycopy(derivatives, 0, data, 0, data.length); }