diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java index 559b7e1d2f..1b3bfc175b 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Algebra.java @@ -4745,8 +4745,8 @@ private static IExpr powerExpandLogRational(IRational rationalNumber) { for (int i = startPosition; i < factors.size(); i++) { pair = (IAST) factors.get(i); - IExpr exponent = pair.exponent(); - IExpr base = pair.base(); + IExpr base = pair.arg1(); + IExpr exponent = pair.arg2(); if (exponent.isOne()) { logIntExpanded.append(F.Log(base)); } else { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java index 0d203c6fa3..e042471f77 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java @@ -5382,30 +5382,36 @@ private static final class PrincipalComponents extends AbstractFunctionOptionEva public IExpr evaluate(final IAST ast, final int argSize, final IExpr[] option, final EvalEngine engine, IAST originalAST) { int[] dimension = ast.arg1().isMatrix(); - RealMatrix matrix = ast.arg1().toRealMatrix(); - if (dimension != null) { - if (dimension[0] == 1) { - if (dimension[1] == 0) { - return F.CEmptyList; - } else { - return F.List(F.constantArray(F.CD0, dimension[1])); - } - } - if (dimension[0] > 1 && dimension[1] > 0) { - PCA pca = null; - String method = option[0].toString(); - if (method.equals("Covariance")) { - pca = new PCA(dimension[1]); - } else if (method.equals("Correlation")) { - pca = new PCA(dimension[1], true, true); - } else { - pca = new PCA(dimension[1]); - } - double[][] data = pca.fitAndTransform(matrix.getData()); - return Convert.matrix2List(new Array2DRowRealMatrix(data)); + if (dimension == null) { + return F.NIL; + } + if (dimension[0] == 1) { + if (dimension[1] == 0) { + return F.CEmptyList; } + return F.List(F.constantArray(F.CD0, dimension[1])); } - return F.NIL; + + if (dimension[0] < 1 || dimension[1] <= 0) { + return F.NIL; + } + + RealMatrix matrix = ast.arg1().toRealMatrix(); + if (matrix == null) { + return F.NIL; + } + + PCA pca = null; + String method = option[0].toString(); + if (method.equals("Covariance")) { + pca = new PCA(dimension[1]); + } else if (method.equals("Correlation")) { + pca = new PCA(dimension[1], true, true); + } else { + pca = new PCA(dimension[1]); + } + double[][] data = pca.fitAndTransform(matrix.getData()); + return Convert.matrix2List(new Array2DRowRealMatrix(data)); } @Override @@ -6248,8 +6254,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { if (vector.exists(x -> x.isReal() && !((IReal) x).isRange(F.C0, F.C1))) { // The Quantile specification `1` should be a number or a list of numbers between // `2` and `3`. - return Errors.printMessage(ast.topHead(), "nquan", F.list(q, F.C0, F.C1), - engine); + return Errors.printMessage(ast.topHead(), "nquan", F.list(q, F.C0, F.C1), engine); } return vector.mapThread(ast, 2); } else { @@ -7005,8 +7010,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { // numbers with length greater than the dimension of the array or two such arrays // with // of equal dimension. - return Errors.printMessage(ast.topHead(), "rctndm1", F.list(arg1, F.C1), - engine); + return Errors.printMessage(ast.topHead(), "rctndm1", F.list(arg1, F.C1), engine); } org.hipparchus.stat.inference.TTest tTest = new org.hipparchus.stat.inference.TTest(); diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java index c48a70ba9c..0316d076cc 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/Errors.java @@ -190,6 +190,7 @@ public static void initGeneralMessages() { "memlimit", "This computation has exceeded the memeory limit settings of this evaluation engines instance.", // "meprec", "Internal precision limit `1` reached while evaluating `2`.", // + "mindet", "Input matrix contains an indeterminate entry.", // "minv", "The `1` arguments to `2` must be ordinary integers.", // or gaussian "mseqs", "Sequence specification or a list of sequence specifications expected at position `1` in `2`.", // @@ -422,8 +423,7 @@ public static IExpr printMessage(ISymbol symbol, final MathException mex, EvalEn * @param engine * @return */ - public static IExpr printMessage(ISymbol symbol, final Throwable exception, - EvalEngine engine) { + public static IExpr printMessage(ISymbol symbol, final Throwable exception, EvalEngine engine) { if (Config.SHOW_STACKTRACE) { exception.printStackTrace(); } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java index cd5e134c5e..7d78ac8c29 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java @@ -2041,6 +2041,7 @@ public FieldVector toFieldVector(boolean copyArray) { @Override public RealMatrix toRealMatrix() { if (fDimension.length == 2 && fDimension[0] > 0 && fDimension[1] > 0) { + IExpr value = null; try { OpenMapRealMatrix result = new OpenMapRealMatrix(fDimension[0], fDimension[1]); if (!fDefaultValue.isZero()) { @@ -2053,12 +2054,16 @@ public RealMatrix toRealMatrix() { } for (TrieNode entry : fData.nodeSet()) { int[] key = entry.getKey(); - IExpr value = entry.getValue(); + value = entry.getValue(); result.setEntry(key[0] - 1, key[1] - 1, value.evalf()); } return result; } catch (ArgumentTypeException rex) { - + if (value != null && value.isIndeterminate()) { + // Input matrix contains an indeterminate entry. + Errors.printMessage(S.SparseArray, "mindet", F.List()); + return null; + } } } return null; diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java index 31318a80c3..e7eaa2e834 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java @@ -19129,6 +19129,10 @@ public void testPrimePi() { } public void testPrincipleComponents() { + // message SparseArray: Input matrix contains an indeterminate entry. + check( + "PrincipalComponents(SparseArray({{0,0},{0,0}},0) ^ (I*1/3*Pi))", // + "PrincipalComponents(SparseArray(Number of elements: 4 Dimensions: {2,2} Default value: 0))"); check("PrincipalComponents({{0.25,0.33,0.45,0.01}},Method->\"Correlation\")", // "{{0.0,0.0,0.0,0.0}}"); check("PrincipalComponents({{0.25,0.33,0.01}} )", //