Search in sources :

Example 31 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class SparseArrayExpr method toDoubleVector.

/**
 * {@inheritDoc}
 */
@Override
public double[] toDoubleVector() {
    if (fDimension.length == 1 && fDimension[0] > 0) {
        try {
            double[] result = new double[fDimension[0]];
            if (!fDefaultValue.isZero()) {
                double d = fDefaultValue.evalDouble();
                for (int i = 0; i < result.length; i++) {
                    result[i] = d;
                }
            }
            for (TrieNode<int[], IExpr> entry : fData.nodeSet()) {
                int[] key = entry.getKey();
                IExpr value = entry.getValue();
                result[key[0] - 1] = value.evalDouble();
            }
            return result;
        } catch (ArgumentTypeException rex) {
        }
    }
    return null;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 32 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class SparseArrayExpr method toDoubleMatrix.

/**
 * {@inheritDoc}
 */
@Override
public double[][] toDoubleMatrix() {
    if (fDimension.length == 2 && fDimension[0] > 0 && fDimension[1] > 0) {
        try {
            double[][] result = new double[fDimension[0]][fDimension[1]];
            if (!fDefaultValue.isZero()) {
                double d = fDefaultValue.evalDouble();
                for (int i = 0; i < fDimension[0]; i++) {
                    for (int j = 0; j < fDimension[1]; j++) {
                        result[i][j] = d;
                    }
                }
            }
            for (TrieNode<int[], IExpr> entry : fData.nodeSet()) {
                int[] key = entry.getKey();
                IExpr value = entry.getValue();
                result[key[0] - 1][key[1] - 1] = value.evalDouble();
            }
            return result;
        } catch (ArgumentTypeException rex) {
        }
    }
    return null;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 33 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class SparseArrayExpr method toRealMatrix.

/**
 * {@inheritDoc}
 */
@Override
public RealMatrix toRealMatrix() {
    if (fDimension.length == 2 && fDimension[0] > 0 && fDimension[1] > 0) {
        try {
            OpenMapRealMatrix result = new OpenMapRealMatrix(fDimension[0], fDimension[1]);
            if (!fDefaultValue.isZero()) {
                double d = fDefaultValue.evalDouble();
                for (int i = 0; i < fDimension[0]; i++) {
                    for (int j = 0; j < fDimension[1]; j++) {
                        result.setEntry(i, j, d);
                    }
                }
            }
            for (TrieNode<int[], IExpr> entry : fData.nodeSet()) {
                int[] key = entry.getKey();
                IExpr value = entry.getValue();
                result.setEntry(key[0] - 1, key[1] - 1, value.evalDouble());
            }
            return result;
        } catch (ArgumentTypeException rex) {
        }
    }
    return null;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) OpenMapRealMatrix(org.hipparchus.linear.OpenMapRealMatrix) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 34 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class Functors method rulesFromNestedList.

private static Function<IExpr, IExpr> rulesFromNestedList(IAST astRules, EvalEngine engine, List<PatternMatcherAndEvaluator> matchers) {
    final Map<IExpr, IExpr> equalRules;
    IAST rule;
    if (astRules.size() > 1) {
        // assuming multiple rules in a list
        int argsSize = astRules.argSize();
        if (argsSize <= 5) {
            equalRules = new OpenFixedSizeMap<IExpr, IExpr>(argsSize * 3 - 1);
        } else {
            equalRules = new HashMap<IExpr, IExpr>();
        }
        for (final IExpr expr : astRules) {
            if (expr.isRuleAST()) {
                rule = (IAST) expr;
                addRuleToCollection(equalRules, matchers, rule);
            } else {
                if (astRules.isList()) {
                    return rulesFromNestedList((IAST) expr, engine, matchers);
                } else {
                    throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + expr.toString());
                }
            }
        }
        if (matchers.size() > 0) {
            return new RulesPatternFunctor(equalRules, matchers, engine);
        }
        if (argsSize == 1) {
            return equalRule((IAST) astRules.arg1());
        }
        return rules(equalRules);
    }
    equalRules = new HashMap<IExpr, IExpr>();
    return rules(equalRules);
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 35 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class Functors method listRules.

public static Function<IExpr, IExpr> listRules(IAST astRules, IASTAppendable result, EvalEngine engine) {
    final Map<IExpr, IExpr> equalRules;
    List<PatternMatcherList> matchers = new ArrayList<PatternMatcherList>();
    if (astRules.isList()) {
        if (astRules.size() > 1) {
            // assuming multiple rules in a list
            IAST rule;
            int argsSize = astRules.argSize();
            if (argsSize <= 5) {
                equalRules = new OpenFixedSizeMap<IExpr, IExpr>(argsSize * 3 - 1);
            } else {
                equalRules = new HashMap<IExpr, IExpr>();
            }
            for (final IExpr expr : astRules) {
                if (expr.isRuleAST()) {
                    rule = (IAST) expr;
                    createPatternMatcherList(equalRules, matchers, rule);
                } else {
                    throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + expr.toString());
                }
            }
        } else {
            equalRules = new HashMap<IExpr, IExpr>();
        }
    } else {
        if (astRules.isRuleAST()) {
            equalRules = new OpenFixedSizeMap<IExpr, IExpr>(3);
            createPatternMatcherList(equalRules, matchers, astRules);
        } else {
            throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + astRules.toString());
        }
    }
    if (matchers.size() > 0) {
        return new ListRulesPatternFunctor(equalRules, matchers, result, engine);
    }
    return listRules(equalRules, result);
}
Also used : PatternMatcherList(org.matheclipse.core.patternmatching.PatternMatcherList) ArrayList(java.util.ArrayList) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Aggregations

ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)44 IExpr (org.matheclipse.core.interfaces.IExpr)24 IAST (org.matheclipse.core.interfaces.IAST)16 Complex (org.hipparchus.complex.Complex)11 ISymbol (org.matheclipse.core.interfaces.ISymbol)10 EvalEngine (org.matheclipse.core.eval.EvalEngine)6 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)6 UnivariateDifferentiableFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction)5 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)5 ArrayList (java.util.ArrayList)4 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)4 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)3 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)3 Config (org.matheclipse.core.basic.Config)3 F (org.matheclipse.core.expression.F)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 INum (org.matheclipse.core.interfaces.INum)3 BisectionSolver (org.hipparchus.analysis.solvers.BisectionSolver)2 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)2 Gamma (org.hipparchus.special.Gamma)2