/** * 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 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); } }
/** 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); } }
/** 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); }
/** {@inheritDoc} */ @Override protected void sanityChecks(final FieldODEState<T> eqn, final T t) throws DimensionMismatchException, NumberIsTooSmallException { super.sanityChecks(eqn, t); mainSetDimension = eqn.getStateDimension(); if (vecAbsoluteTolerance != null && vecAbsoluteTolerance.length != mainSetDimension) { throw new DimensionMismatchException(mainSetDimension, vecAbsoluteTolerance.length); } if (vecRelativeTolerance != null && vecRelativeTolerance.length != mainSetDimension) { throw new DimensionMismatchException(mainSetDimension, vecRelativeTolerance.length); } }
/** * 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 != means.length) { throw new DimensionMismatchException(v.length, means.length); } for (int i = 0; i < v.length; ++i) { means[i].increment(v[i]); } }
/** {@inheritDoc} */ @Override protected void sanityChecks(final ExpandableStatefulODE equations, final double t) throws DimensionMismatchException, NumberIsTooSmallException { super.sanityChecks(equations, t); mainSetDimension = equations.getPrimaryMapper().getDimension(); if ((vecAbsoluteTolerance != null) && (vecAbsoluteTolerance.length != mainSetDimension)) { throw new DimensionMismatchException(mainSetDimension, vecAbsoluteTolerance.length); } if ((vecRelativeTolerance != null) && (vecRelativeTolerance.length != mainSetDimension)) { throw new DimensionMismatchException(mainSetDimension, vecRelativeTolerance.length); } }
/** * Check parameters consistency. * * @throws DimensionMismatchException if {@link #target} and * {@link #weightMatrix} have inconsistent dimensions. */ private void checkParameters() { if (target.length != weightMatrix.getColumnDimension()) { throw new DimensionMismatchException(target.length, weightMatrix.getColumnDimension()); } } }
/** * Check parameters consistency. * * @throws DimensionMismatchException if {@link #target} and * {@link #weightMatrix} have inconsistent dimensions. */ private void checkParameters() { if (target.length != weightMatrix.getColumnDimension()) { throw new DimensionMismatchException(target.length, weightMatrix.getColumnDimension()); } } }
/** * Check if instance dimension is equal to some expected value. * * @param n Expected dimension. * @throws DimensionMismatchException if the dimensions do not match. */ protected void checkVectorDimensions(int n) throws DimensionMismatchException { if (getDimension() != n) { throw new DimensionMismatchException(getDimension(), n); } }
/** {@inheritDoc} * @since 3.2 */ public Dfp linearCombination(final double[] a, final Dfp[] b) throws DimensionMismatchException { if (a.length != b.length) { throw new DimensionMismatchException(a.length, b.length); } Dfp r = getZero(); for (int i = 0; i < a.length; ++i) { r = r.add(b[i].multiply(a[i])); } return r; }
/** {@inheritDoc} */ public double density(final double[] vals) throws DimensionMismatchException { final int dim = getDimension(); if (vals.length != dim) { throw new DimensionMismatchException(vals.length, dim); } return FastMath.pow(2 * FastMath.PI, -0.5 * dim) * FastMath.pow(covarianceMatrixDeterminant, -0.5) * getExponentTerm(vals); }
/** * Check if a matrix is multiplication compatible with the instance. * * @param m Matrix to check. * @throws DimensionMismatchException if the matrix is not * multiplication-compatible with instance. */ protected void checkMultiplicationCompatible(final FieldMatrix<T> m) throws DimensionMismatchException { if (getColumnDimension() != m.getRowDimension()) { throw new DimensionMismatchException(m.getRowDimension(), getColumnDimension()); } } }