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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations