Search in sources :

Example 11 with MathIllegalArgumentException

use of org.hipparchus.exception.MathIllegalArgumentException in project symja_android_library by axkr.

the class InterpolatingPolynomial method checkPartialRealOrder.

/**
 * Check that the given array is sorted for real numbers. If symbolic expressions occur we don't
 * compare.
 *
 * @param val Values.
 * @param dir Ordering direction.
 * @param strict Whether the order should be strict.
 * @param abort Whether to throw an exception if the check fails.
 * @return {@code true} if the array is sorted.
 * @throws MathIllegalArgumentException if the array is not sorted and {@code abort} is {@code
 *     true}.
 */
public static boolean checkPartialRealOrder(IExpr[] val, OrderDirection dir, boolean strict, boolean abort) throws MathIllegalArgumentException {
    ISignedNumber previous = F.C0;
    final int max = val.length;
    int start = max;
    for (int i = 0; i < val.length; i++) {
        if (val[i] instanceof ISignedNumber) {
            previous = (ISignedNumber) val[i];
            start = i + 1;
            break;
        }
    }
    int index;
    ITEM: for (index = start; index < max; index++) {
        if (val[index] instanceof ISignedNumber) {
            switch(dir) {
                case INCREASING:
                    if (strict) {
                        if (((ISignedNumber) val[index]).isLE(previous)) {
                            break ITEM;
                        }
                    } else {
                        if (((ISignedNumber) val[index]).isLT(previous)) {
                            break ITEM;
                        }
                    }
                    break;
                case DECREASING:
                    if (strict) {
                        if (((ISignedNumber) val[index]).isGE(previous)) {
                            break ITEM;
                        }
                    } else {
                        if (((ISignedNumber) val[index]).isGT(previous)) {
                            break ITEM;
                        }
                    }
                    break;
                default:
                    // Should never happen.
                    throw MathRuntimeException.createInternalError();
            }
            previous = (ISignedNumber) val[index];
        }
    }
    if (index == max) {
        // Loop completed.
        return true;
    }
    // Loop early exit means wrong ordering.
    if (abort) {
        throw new MathIllegalArgumentException(dir == MathArrays.OrderDirection.INCREASING ? (strict ? LocalizedCoreFormats.NOT_STRICTLY_INCREASING_SEQUENCE : LocalizedCoreFormats.NOT_INCREASING_SEQUENCE) : (strict ? LocalizedCoreFormats.NOT_STRICTLY_DECREASING_SEQUENCE : LocalizedCoreFormats.NOT_DECREASING_SEQUENCE), val[index], previous, index, index - 1);
    } else {
        return false;
    }
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) MathIllegalArgumentException(org.hipparchus.exception.MathIllegalArgumentException)

Aggregations

MathIllegalArgumentException (org.hipparchus.exception.MathIllegalArgumentException)11 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 MathRuntimeException (org.hipparchus.exception.MathRuntimeException)2 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)2 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)2 RealMatrix (org.hipparchus.linear.RealMatrix)2 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)2 IAST (org.matheclipse.core.interfaces.IAST)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 OrekitException (org.orekit.errors.OrekitException)2 BigInteger (java.math.BigInteger)1 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)1 RombergIntegrator (org.hipparchus.analysis.integration.RombergIntegrator)1 SimpsonIntegrator (org.hipparchus.analysis.integration.SimpsonIntegrator)1 TrapezoidIntegrator (org.hipparchus.analysis.integration.TrapezoidIntegrator)1 UnivariateIntegrator (org.hipparchus.analysis.integration.UnivariateIntegrator)1 GaussIntegrator (org.hipparchus.analysis.integration.gauss.GaussIntegrator)1