mathjs 9.3.2 → 9.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +22 -0
- package/README.md +1 -0
- package/bin/cli.js +11 -11
- package/docs/expressions/parsing.md +21 -4
- package/docs/reference/functions/complex.md +5 -49
- package/docs/reference/functions/eigs.md +12 -12
- package/docs/reference/functions/flatten.md +1 -0
- package/docs/reference/functions/matrixFromColumns.md +1 -1
- package/docs/reference/functions/matrixFromFunction.md +12 -0
- package/docs/reference/functions/matrixFromRows.md +1 -1
- package/docs/reference/functions.md +4 -1
- package/examples/advanced/custom_scope_objects.js +115 -0
- package/lib/browser/math.js +10 -10
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +8 -7
- package/lib/cjs/core/function/import.js +9 -7
- package/lib/cjs/core/function/typed.js +6 -1
- package/lib/cjs/defaultInstance.js +3 -3
- package/lib/cjs/entry/allFactoriesAny.js +3 -3
- package/lib/cjs/entry/allFactoriesNumber.js +3 -3
- package/lib/cjs/entry/configReadonly.js +5 -4
- package/lib/cjs/entry/dependenciesAny/dependenciesEigs.generated.js +51 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +29 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +26 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +29 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +24 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +22 -17
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +11 -9
- package/lib/cjs/entry/pureFunctionsAny.generated.js +78 -41
- package/lib/cjs/expression/Parser.js +22 -15
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +9 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/column.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromColumns.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromFunction.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromRows.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/row.js +1 -1
- package/lib/cjs/expression/function/evaluate.js +6 -4
- package/lib/cjs/expression/keywords.js +1 -3
- package/lib/cjs/expression/node/AccessorNode.js +1 -0
- package/lib/cjs/expression/node/AssignmentNode.js +6 -3
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +2 -4
- package/lib/cjs/expression/node/FunctionNode.js +76 -46
- package/lib/cjs/expression/node/IndexNode.js +5 -13
- package/lib/cjs/expression/node/Node.js +15 -9
- package/lib/cjs/expression/node/ObjectNode.js +5 -3
- package/lib/cjs/expression/node/SymbolNode.js +2 -2
- package/lib/cjs/expression/node/utils/access.js +5 -3
- package/lib/cjs/expression/node/utils/assign.js +5 -3
- package/lib/cjs/expression/parse.js +10 -14
- package/lib/cjs/expression/transform/utils/compileInlineExpression.js +5 -3
- package/lib/cjs/factoriesAny.js +24 -0
- package/lib/cjs/function/algebra/decomposition/qr.js +5 -3
- package/lib/cjs/function/algebra/simplify/resolve.js +7 -1
- package/lib/cjs/function/algebra/simplify.js +20 -14
- package/lib/cjs/function/algebra/solver/lsolveAll.js +6 -16
- package/lib/cjs/function/algebra/solver/usolveAll.js +6 -16
- package/lib/cjs/function/arithmetic/ceil.js +6 -16
- package/lib/cjs/function/arithmetic/floor.js +6 -16
- package/lib/cjs/function/arithmetic/norm.js +2 -2
- package/lib/cjs/function/arithmetic/pow.js +9 -7
- package/lib/cjs/function/arithmetic/round.js +7 -5
- package/lib/cjs/function/complex/im.js +3 -0
- package/lib/cjs/function/complex/re.js +3 -0
- package/lib/cjs/function/matrix/eigs/complexEigs.js +631 -0
- package/lib/cjs/function/matrix/eigs/realSymetric.js +341 -0
- package/lib/cjs/function/matrix/eigs.js +188 -334
- package/lib/cjs/function/matrix/flatten.js +1 -0
- package/lib/cjs/function/matrix/matrixFromColumns.js +118 -0
- package/lib/cjs/function/matrix/matrixFromFunction.js +85 -0
- package/lib/cjs/function/matrix/matrixFromRows.js +108 -0
- package/lib/cjs/function/probability/pickRandom.js +1 -1
- package/lib/cjs/function/probability/util/seededRNG.js +2 -2
- package/lib/cjs/function/relational/compareNatural.js +2 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/bignumber/index.js +2 -2
- package/lib/cjs/type/bignumber/BigNumber.js +2 -2
- package/lib/cjs/type/complex/Complex.js +5 -5
- package/lib/cjs/type/fraction/Fraction.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +138 -0
- package/lib/cjs/type/matrix/Matrix.js +10 -0
- package/lib/cjs/type/matrix/SparseMatrix.js +77 -3
- package/lib/cjs/type/matrix/function/matrix.js +2 -1
- package/lib/cjs/type/unit/Unit.js +15 -13
- package/lib/cjs/utils/array.js +1 -1
- package/lib/cjs/utils/customs.js +18 -4
- package/lib/cjs/utils/emitter.js +2 -2
- package/lib/cjs/utils/function.js +6 -2
- package/lib/cjs/utils/is.js +7 -5
- package/lib/cjs/utils/latex.js +2 -2
- package/lib/cjs/utils/map.js +197 -0
- package/lib/cjs/utils/object.js +6 -5
- package/lib/cjs/utils/scope.js +33 -0
- package/lib/cjs/utils/snapshot.js +17 -16
- package/lib/cjs/utils/string.js +6 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/constants.js +15 -15
- package/lib/esm/core/create.js +1 -2
- package/lib/esm/core/function/typed.js +5 -1
- package/lib/esm/entry/configReadonly.js +1 -2
- package/lib/esm/entry/dependenciesAny/dependenciesEigs.generated.js +34 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +16 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +14 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +16 -0
- package/lib/esm/entry/dependenciesAny.generated.js +3 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +13 -10
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/entry/pureFunctionsAny.generated.js +66 -32
- package/lib/esm/expression/Help.js +1 -1
- package/lib/esm/expression/Parser.js +23 -15
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/column.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromColumns.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromFunction.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromRows.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/row.js +1 -1
- package/lib/esm/expression/function/compile.js +1 -1
- package/lib/esm/expression/function/evaluate.js +6 -5
- package/lib/esm/expression/function/help.js +1 -1
- package/lib/esm/expression/function/parser.js +1 -1
- package/lib/esm/expression/keywords.js +1 -3
- package/lib/esm/expression/node/AccessorNode.js +2 -1
- package/lib/esm/expression/node/ArrayNode.js +1 -1
- package/lib/esm/expression/node/AssignmentNode.js +7 -4
- package/lib/esm/expression/node/BlockNode.js +1 -1
- package/lib/esm/expression/node/ConditionalNode.js +1 -1
- package/lib/esm/expression/node/ConstantNode.js +1 -1
- package/lib/esm/expression/node/FunctionAssignmentNode.js +3 -4
- package/lib/esm/expression/node/FunctionNode.js +57 -39
- package/lib/esm/expression/node/IndexNode.js +1 -1
- package/lib/esm/expression/node/Node.js +7 -8
- package/lib/esm/expression/node/ObjectNode.js +1 -1
- package/lib/esm/expression/node/OperatorNode.js +1 -1
- package/lib/esm/expression/node/ParenthesisNode.js +1 -1
- package/lib/esm/expression/node/RangeNode.js +1 -1
- package/lib/esm/expression/node/RelationalNode.js +1 -1
- package/lib/esm/expression/node/SymbolNode.js +3 -3
- package/lib/esm/expression/parse.js +2 -3
- package/lib/esm/expression/transform/apply.transform.js +1 -1
- package/lib/esm/expression/transform/column.transform.js +1 -1
- package/lib/esm/expression/transform/concat.transform.js +1 -1
- package/lib/esm/expression/transform/diff.transform.js +1 -1
- package/lib/esm/expression/transform/filter.transform.js +1 -1
- package/lib/esm/expression/transform/forEach.transform.js +1 -1
- package/lib/esm/expression/transform/index.transform.js +1 -1
- package/lib/esm/expression/transform/map.transform.js +1 -1
- package/lib/esm/expression/transform/max.transform.js +1 -1
- package/lib/esm/expression/transform/mean.transform.js +1 -1
- package/lib/esm/expression/transform/min.transform.js +1 -1
- package/lib/esm/expression/transform/range.transform.js +1 -1
- package/lib/esm/expression/transform/row.transform.js +1 -1
- package/lib/esm/expression/transform/std.transform.js +1 -1
- package/lib/esm/expression/transform/subset.transform.js +1 -1
- package/lib/esm/expression/transform/sum.transform.js +1 -1
- package/lib/esm/expression/transform/utils/compileInlineExpression.js +4 -3
- package/lib/esm/expression/transform/variance.transform.js +1 -1
- package/lib/esm/factoriesAny.js +3 -0
- package/lib/esm/factoriesNumber.js +1 -1
- package/lib/esm/function/algebra/decomposition/lup.js +1 -1
- package/lib/esm/function/algebra/decomposition/qr.js +2 -3
- package/lib/esm/function/algebra/decomposition/slu.js +1 -1
- package/lib/esm/function/algebra/derivative.js +1 -1
- package/lib/esm/function/algebra/rationalize.js +1 -1
- package/lib/esm/function/algebra/simplify/resolve.js +7 -2
- package/lib/esm/function/algebra/simplify/simplifyConstant.js +1 -1
- package/lib/esm/function/algebra/simplify/simplifyCore.js +1 -1
- package/lib/esm/function/algebra/simplify/util.js +1 -1
- package/lib/esm/function/algebra/simplify.js +16 -12
- package/lib/esm/function/algebra/solver/lsolve.js +1 -1
- package/lib/esm/function/algebra/solver/lsolveAll.js +1 -1
- package/lib/esm/function/algebra/solver/lusolve.js +1 -1
- package/lib/esm/function/algebra/solver/usolve.js +1 -1
- package/lib/esm/function/algebra/solver/usolveAll.js +1 -1
- package/lib/esm/function/algebra/sparse/csAmd.js +1 -1
- package/lib/esm/function/algebra/sparse/csChol.js +1 -1
- package/lib/esm/function/algebra/sparse/csCounts.js +1 -1
- package/lib/esm/function/algebra/sparse/csLu.js +1 -1
- package/lib/esm/function/algebra/sparse/csSpsolve.js +1 -1
- package/lib/esm/function/algebra/sparse/csSqr.js +1 -1
- package/lib/esm/function/algebra/sparse/csSymperm.js +1 -1
- package/lib/esm/function/arithmetic/abs.js +1 -1
- package/lib/esm/function/arithmetic/add.js +1 -1
- package/lib/esm/function/arithmetic/addScalar.js +1 -1
- package/lib/esm/function/arithmetic/cbrt.js +1 -1
- package/lib/esm/function/arithmetic/ceil.js +1 -1
- package/lib/esm/function/arithmetic/cube.js +1 -1
- package/lib/esm/function/arithmetic/divide.js +1 -1
- package/lib/esm/function/arithmetic/divideScalar.js +1 -1
- package/lib/esm/function/arithmetic/dotDivide.js +1 -1
- package/lib/esm/function/arithmetic/dotMultiply.js +1 -1
- package/lib/esm/function/arithmetic/dotPow.js +1 -1
- package/lib/esm/function/arithmetic/exp.js +1 -1
- package/lib/esm/function/arithmetic/expm1.js +1 -1
- package/lib/esm/function/arithmetic/fix.js +1 -1
- package/lib/esm/function/arithmetic/floor.js +1 -1
- package/lib/esm/function/arithmetic/gcd.js +1 -1
- package/lib/esm/function/arithmetic/hypot.js +1 -1
- package/lib/esm/function/arithmetic/lcm.js +1 -1
- package/lib/esm/function/arithmetic/log.js +1 -1
- package/lib/esm/function/arithmetic/log10.js +1 -1
- package/lib/esm/function/arithmetic/log1p.js +1 -1
- package/lib/esm/function/arithmetic/log2.js +1 -1
- package/lib/esm/function/arithmetic/mod.js +1 -1
- package/lib/esm/function/arithmetic/multiply.js +1 -1
- package/lib/esm/function/arithmetic/multiplyScalar.js +1 -1
- package/lib/esm/function/arithmetic/norm.js +3 -3
- package/lib/esm/function/arithmetic/nthRoot.js +2 -2
- package/lib/esm/function/arithmetic/nthRoots.js +1 -1
- package/lib/esm/function/arithmetic/pow.js +10 -8
- package/lib/esm/function/arithmetic/round.js +6 -6
- package/lib/esm/function/arithmetic/sign.js +1 -1
- package/lib/esm/function/arithmetic/sqrt.js +1 -1
- package/lib/esm/function/arithmetic/square.js +1 -1
- package/lib/esm/function/arithmetic/subtract.js +1 -1
- package/lib/esm/function/arithmetic/unaryMinus.js +1 -1
- package/lib/esm/function/arithmetic/unaryPlus.js +1 -1
- package/lib/esm/function/arithmetic/xgcd.js +1 -1
- package/lib/esm/function/bitwise/bitAnd.js +1 -1
- package/lib/esm/function/bitwise/bitNot.js +1 -1
- package/lib/esm/function/bitwise/bitOr.js +1 -1
- package/lib/esm/function/bitwise/bitXor.js +1 -1
- package/lib/esm/function/bitwise/leftShift.js +1 -1
- package/lib/esm/function/bitwise/rightArithShift.js +1 -1
- package/lib/esm/function/bitwise/rightLogShift.js +1 -1
- package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
- package/lib/esm/function/combinatorics/catalan.js +1 -1
- package/lib/esm/function/combinatorics/composition.js +1 -1
- package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
- package/lib/esm/function/complex/arg.js +1 -1
- package/lib/esm/function/complex/conj.js +1 -1
- package/lib/esm/function/complex/im.js +4 -1
- package/lib/esm/function/complex/re.js +4 -1
- package/lib/esm/function/geometry/distance.js +1 -1
- package/lib/esm/function/geometry/intersect.js +1 -1
- package/lib/esm/function/logical/and.js +1 -1
- package/lib/esm/function/logical/not.js +1 -1
- package/lib/esm/function/logical/or.js +1 -1
- package/lib/esm/function/logical/xor.js +1 -1
- package/lib/esm/function/matrix/apply.js +1 -1
- package/lib/esm/function/matrix/column.js +1 -1
- package/lib/esm/function/matrix/concat.js +1 -1
- package/lib/esm/function/matrix/count.js +1 -1
- package/lib/esm/function/matrix/cross.js +1 -1
- package/lib/esm/function/matrix/ctranspose.js +1 -1
- package/lib/esm/function/matrix/det.js +1 -1
- package/lib/esm/function/matrix/diag.js +1 -1
- package/lib/esm/function/matrix/diff.js +1 -1
- package/lib/esm/function/matrix/dot.js +1 -1
- package/lib/esm/function/matrix/eigs/complexEigs.js +586 -0
- package/lib/esm/function/matrix/eigs/realSymetric.js +335 -0
- package/lib/esm/function/matrix/eigs.js +187 -335
- package/lib/esm/function/matrix/expm.js +1 -1
- package/lib/esm/function/matrix/filter.js +1 -1
- package/lib/esm/function/matrix/flatten.js +2 -1
- package/lib/esm/function/matrix/forEach.js +1 -1
- package/lib/esm/function/matrix/getMatrixDataType.js +1 -1
- package/lib/esm/function/matrix/identity.js +1 -1
- package/lib/esm/function/matrix/inv.js +1 -1
- package/lib/esm/function/matrix/kron.js +1 -1
- package/lib/esm/function/matrix/map.js +1 -1
- package/lib/esm/function/matrix/matrixFromColumns.js +93 -0
- package/lib/esm/function/matrix/matrixFromFunction.js +78 -0
- package/lib/esm/function/matrix/matrixFromRows.js +83 -0
- package/lib/esm/function/matrix/ones.js +1 -1
- package/lib/esm/function/matrix/partitionSelect.js +1 -1
- package/lib/esm/function/matrix/range.js +1 -1
- package/lib/esm/function/matrix/reshape.js +1 -1
- package/lib/esm/function/matrix/resize.js +1 -1
- package/lib/esm/function/matrix/rotate.js +1 -1
- package/lib/esm/function/matrix/rotationMatrix.js +1 -1
- package/lib/esm/function/matrix/row.js +1 -1
- package/lib/esm/function/matrix/size.js +1 -1
- package/lib/esm/function/matrix/sort.js +1 -1
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/function/matrix/squeeze.js +1 -1
- package/lib/esm/function/matrix/subset.js +1 -1
- package/lib/esm/function/matrix/trace.js +1 -1
- package/lib/esm/function/matrix/transpose.js +1 -1
- package/lib/esm/function/matrix/zeros.js +1 -1
- package/lib/esm/function/probability/combinations.js +1 -1
- package/lib/esm/function/probability/combinationsWithRep.js +1 -1
- package/lib/esm/function/probability/factorial.js +1 -1
- package/lib/esm/function/probability/gamma.js +1 -1
- package/lib/esm/function/probability/kldivergence.js +1 -1
- package/lib/esm/function/probability/multinomial.js +1 -1
- package/lib/esm/function/probability/permutations.js +1 -1
- package/lib/esm/function/probability/pickRandom.js +2 -2
- package/lib/esm/function/probability/random.js +2 -2
- package/lib/esm/function/probability/randomInt.js +1 -1
- package/lib/esm/function/relational/compare.js +2 -2
- package/lib/esm/function/relational/compareNatural.js +1 -1
- package/lib/esm/function/relational/compareText.js +2 -2
- package/lib/esm/function/relational/deepEqual.js +1 -1
- package/lib/esm/function/relational/equal.js +2 -2
- package/lib/esm/function/relational/equalScalar.js +2 -2
- package/lib/esm/function/relational/equalText.js +1 -1
- package/lib/esm/function/relational/larger.js +2 -2
- package/lib/esm/function/relational/largerEq.js +2 -2
- package/lib/esm/function/relational/smaller.js +2 -2
- package/lib/esm/function/relational/smallerEq.js +2 -2
- package/lib/esm/function/relational/unequal.js +2 -2
- package/lib/esm/function/set/setCartesian.js +1 -1
- package/lib/esm/function/set/setDifference.js +1 -1
- package/lib/esm/function/set/setDistinct.js +1 -1
- package/lib/esm/function/set/setIntersect.js +1 -1
- package/lib/esm/function/set/setIsSubset.js +1 -1
- package/lib/esm/function/set/setMultiplicity.js +1 -1
- package/lib/esm/function/set/setPowerset.js +1 -1
- package/lib/esm/function/set/setSize.js +1 -1
- package/lib/esm/function/set/setSymDifference.js +1 -1
- package/lib/esm/function/set/setUnion.js +1 -1
- package/lib/esm/function/special/erf.js +1 -1
- package/lib/esm/function/statistics/mad.js +1 -1
- package/lib/esm/function/statistics/max.js +1 -1
- package/lib/esm/function/statistics/mean.js +1 -1
- package/lib/esm/function/statistics/median.js +1 -1
- package/lib/esm/function/statistics/min.js +1 -1
- package/lib/esm/function/statistics/mode.js +1 -1
- package/lib/esm/function/statistics/prod.js +1 -1
- package/lib/esm/function/statistics/quantileSeq.js +1 -1
- package/lib/esm/function/statistics/std.js +1 -1
- package/lib/esm/function/statistics/sum.js +1 -1
- package/lib/esm/function/statistics/variance.js +1 -1
- package/lib/esm/function/string/bin.js +1 -1
- package/lib/esm/function/string/format.js +1 -1
- package/lib/esm/function/string/hex.js +1 -1
- package/lib/esm/function/string/oct.js +1 -1
- package/lib/esm/function/string/print.js +1 -1
- package/lib/esm/function/trigonometry/acos.js +1 -1
- package/lib/esm/function/trigonometry/acosh.js +1 -1
- package/lib/esm/function/trigonometry/acot.js +1 -1
- package/lib/esm/function/trigonometry/acoth.js +1 -1
- package/lib/esm/function/trigonometry/acsc.js +1 -1
- package/lib/esm/function/trigonometry/acsch.js +1 -1
- package/lib/esm/function/trigonometry/asec.js +1 -1
- package/lib/esm/function/trigonometry/asech.js +1 -1
- package/lib/esm/function/trigonometry/asin.js +1 -1
- package/lib/esm/function/trigonometry/asinh.js +1 -1
- package/lib/esm/function/trigonometry/atan.js +1 -1
- package/lib/esm/function/trigonometry/atan2.js +1 -1
- package/lib/esm/function/trigonometry/atanh.js +1 -1
- package/lib/esm/function/trigonometry/cos.js +1 -1
- package/lib/esm/function/trigonometry/cosh.js +1 -1
- package/lib/esm/function/trigonometry/cot.js +1 -1
- package/lib/esm/function/trigonometry/coth.js +1 -1
- package/lib/esm/function/trigonometry/csc.js +1 -1
- package/lib/esm/function/trigonometry/csch.js +1 -1
- package/lib/esm/function/trigonometry/sec.js +1 -1
- package/lib/esm/function/trigonometry/sech.js +1 -1
- package/lib/esm/function/trigonometry/sin.js +1 -1
- package/lib/esm/function/trigonometry/sinh.js +1 -1
- package/lib/esm/function/trigonometry/tan.js +1 -1
- package/lib/esm/function/trigonometry/tanh.js +1 -1
- package/lib/esm/function/unit/to.js +1 -1
- package/lib/esm/function/utils/clone.js +1 -1
- package/lib/esm/function/utils/hasNumericValue.js +1 -1
- package/lib/esm/function/utils/isInteger.js +1 -1
- package/lib/esm/function/utils/isNaN.js +1 -1
- package/lib/esm/function/utils/isNegative.js +1 -1
- package/lib/esm/function/utils/isNumeric.js +1 -1
- package/lib/esm/function/utils/isPositive.js +1 -1
- package/lib/esm/function/utils/isPrime.js +1 -1
- package/lib/esm/function/utils/isZero.js +1 -1
- package/lib/esm/function/utils/numeric.js +1 -1
- package/lib/esm/function/utils/typeOf.js +1 -1
- package/lib/esm/json/reviver.js +1 -1
- package/lib/esm/type/bignumber/BigNumber.js +1 -1
- package/lib/esm/type/bignumber/function/bignumber.js +1 -1
- package/lib/esm/type/boolean.js +1 -1
- package/lib/esm/type/chain/Chain.js +1 -1
- package/lib/esm/type/chain/function/chain.js +1 -1
- package/lib/esm/type/complex/function/complex.js +1 -1
- package/lib/esm/type/fraction/function/fraction.js +1 -1
- package/lib/esm/type/matrix/DenseMatrix.js +75 -1
- package/lib/esm/type/matrix/FibonacciHeap.js +1 -1
- package/lib/esm/type/matrix/ImmutableDenseMatrix.js +1 -1
- package/lib/esm/type/matrix/Matrix.js +10 -0
- package/lib/esm/type/matrix/MatrixIndex.js +1 -1
- package/lib/esm/type/matrix/Spa.js +1 -1
- package/lib/esm/type/matrix/SparseMatrix.js +37 -3
- package/lib/esm/type/matrix/function/index.js +1 -1
- package/lib/esm/type/matrix/function/matrix.js +3 -2
- package/lib/esm/type/matrix/function/sparse.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm01.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm02.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm03.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm04.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm05.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm06.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm07.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm08.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm09.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm10.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm11.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm12.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm13.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm14.js +1 -1
- package/lib/esm/type/number.js +1 -1
- package/lib/esm/type/string.js +1 -1
- package/lib/esm/type/unit/Unit.js +4 -5
- package/lib/esm/type/unit/function/createUnit.js +1 -1
- package/lib/esm/type/unit/function/splitUnit.js +1 -1
- package/lib/esm/type/unit/function/unit.js +1 -1
- package/lib/esm/type/unit/physicalConstants.js +2 -2
- package/lib/esm/utils/array.js +1 -1
- package/lib/esm/utils/customs.js +10 -0
- package/lib/esm/utils/map.js +135 -0
- package/lib/esm/utils/scope.js +26 -0
- package/lib/esm/utils/snapshot.js +3 -4
- package/lib/esm/version.js +1 -1
- package/package.json +18 -9
@@ -1,9 +1,12 @@
|
|
1
|
-
import { clone } from '../../utils/object.js';
|
2
1
|
import { factory } from '../../utils/factory.js';
|
3
2
|
import { format } from '../../utils/string.js';
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
import { createComplexEigs } from './eigs/complexEigs.js';
|
4
|
+
import { createRealSymmetric } from './eigs/realSymetric.js';
|
5
|
+
import { typeOf, isNumber, isBigNumber, isComplex, isFraction } from '../../utils/is.js';
|
6
|
+
var name = 'eigs'; // The absolute state of math.js's dependency system:
|
7
|
+
|
8
|
+
var dependencies = ['config', 'typed', 'matrix', 'addScalar', 'equal', 'subtract', 'abs', 'atan', 'cos', 'sin', 'multiplyScalar', 'divideScalar', 'inv', 'bignumber', 'multiply', 'add', 'larger', 'column', 'flatten', 'number', 'complex', 'sqrt', 'diag', 'qr', 'usolveAll', 'im', 're', 'smaller', 'round', 'log10', 'transpose', 'matrixFromColumns'];
|
9
|
+
export var createEigs = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
10
|
var {
|
8
11
|
config,
|
9
12
|
typed,
|
@@ -16,415 +19,264 @@ export var createEigs = /* #__PURE__ */factory(name, dependencies, (_ref) => {
|
|
16
19
|
cos,
|
17
20
|
sin,
|
18
21
|
multiplyScalar,
|
22
|
+
divideScalar,
|
19
23
|
inv,
|
20
24
|
bignumber,
|
21
25
|
multiply,
|
22
|
-
add
|
26
|
+
add,
|
27
|
+
larger,
|
28
|
+
column,
|
29
|
+
flatten,
|
30
|
+
number,
|
31
|
+
complex,
|
32
|
+
sqrt,
|
33
|
+
diag,
|
34
|
+
qr,
|
35
|
+
usolveAll,
|
36
|
+
im,
|
37
|
+
re,
|
38
|
+
smaller,
|
39
|
+
round,
|
40
|
+
log10,
|
41
|
+
transpose,
|
42
|
+
matrixFromColumns
|
23
43
|
} = _ref;
|
24
|
-
|
44
|
+
var doRealSymetric = createRealSymmetric({
|
45
|
+
config,
|
46
|
+
addScalar,
|
47
|
+
subtract,
|
48
|
+
column,
|
49
|
+
flatten,
|
50
|
+
equal,
|
51
|
+
abs,
|
52
|
+
atan,
|
53
|
+
cos,
|
54
|
+
sin,
|
55
|
+
multiplyScalar,
|
56
|
+
inv,
|
57
|
+
bignumber,
|
58
|
+
complex,
|
59
|
+
multiply,
|
60
|
+
add
|
61
|
+
});
|
62
|
+
var doComplexEigs = createComplexEigs({
|
63
|
+
config,
|
64
|
+
addScalar,
|
65
|
+
subtract,
|
66
|
+
multiply,
|
67
|
+
multiplyScalar,
|
68
|
+
flatten,
|
69
|
+
divideScalar,
|
70
|
+
sqrt,
|
71
|
+
abs,
|
72
|
+
bignumber,
|
73
|
+
diag,
|
74
|
+
qr,
|
75
|
+
inv,
|
76
|
+
usolveAll,
|
77
|
+
equal,
|
78
|
+
complex,
|
79
|
+
larger,
|
80
|
+
smaller,
|
81
|
+
round,
|
82
|
+
log10,
|
83
|
+
transpose,
|
84
|
+
matrixFromColumns
|
85
|
+
});
|
25
86
|
/**
|
26
|
-
* Compute
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
31
|
-
* eigenvalues are of 'number' type. For 'bignumber' the eigenvalues are of ''bignumber' type.
|
32
|
-
* Eigenvectors are always of 'number' type.
|
87
|
+
* Compute eigenvalues and eigenvectors of a matrix. The eigenvalues are sorted by their absolute value, ascending.
|
88
|
+
* An eigenvalue with multiplicity k will be listed k times. The eigenvectors are returned as columns of a matrix –
|
89
|
+
* the eigenvector that belongs to the j-th eigenvalue in the list (eg. `values[j]`) is the j-th column (eg. `column(vectors, j)`).
|
90
|
+
* If the algorithm fails to converge, it will throw an error – in that case, however, you may still find useful information
|
91
|
+
* in `err.values` and `err.vectors`.
|
33
92
|
*
|
34
93
|
* Syntax:
|
35
94
|
*
|
36
|
-
* math.eigs(x)
|
95
|
+
* math.eigs(x, [prec])
|
37
96
|
*
|
38
97
|
* Examples:
|
39
98
|
*
|
99
|
+
* const { eigs, multiply, column, transpose } = math
|
40
100
|
* const H = [[5, 2.3], [2.3, 1]]
|
41
|
-
* const ans =
|
101
|
+
* const ans = eigs(H) // returns {values: [E1,E2...sorted], vectors: [v1,v2.... corresponding vectors as columns]}
|
42
102
|
* const E = ans.values
|
43
103
|
* const U = ans.vectors
|
44
|
-
*
|
45
|
-
* const UTxHxU =
|
104
|
+
* multiply(H, column(U, 0)) // returns multiply(E[0], column(U, 0))
|
105
|
+
* const UTxHxU = multiply(transpose(U), H, U) // diagonalizes H
|
46
106
|
* E[0] == UTxHxU[0][0] // returns true
|
107
|
+
*
|
47
108
|
* See also:
|
48
109
|
*
|
49
110
|
* inv
|
50
111
|
*
|
51
112
|
* @param {Array | Matrix} x Matrix to be diagonalized
|
52
|
-
*
|
113
|
+
*
|
114
|
+
* @param {number | BigNumber} [prec] Precision, default value: 1e-15
|
115
|
+
* @return {{values: Array|Matrix, vectors: Array|Matrix}} Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
|
116
|
+
*
|
53
117
|
*/
|
118
|
+
|
54
119
|
return typed('eigs', {
|
55
120
|
Array: function Array(x) {
|
56
|
-
// check array size
|
57
121
|
var mat = matrix(x);
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
var
|
122
|
+
return computeValuesAndVectors(mat);
|
123
|
+
},
|
124
|
+
'Array, number|BigNumber': function ArrayNumberBigNumber(x, prec) {
|
125
|
+
var mat = matrix(x);
|
126
|
+
return computeValuesAndVectors(mat, prec);
|
127
|
+
},
|
128
|
+
Matrix: function Matrix(mat) {
|
129
|
+
var {
|
130
|
+
values,
|
131
|
+
vectors
|
132
|
+
} = computeValuesAndVectors(mat);
|
66
133
|
return {
|
67
|
-
values:
|
68
|
-
vectors:
|
134
|
+
values: matrix(values),
|
135
|
+
vectors: matrix(vectors)
|
69
136
|
};
|
70
137
|
},
|
71
|
-
Matrix: function
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if (size.length !== 2 || size[0] !== size[1]) {
|
77
|
-
throw new RangeError('Matrix must be square ' + '(size: ' + format(size) + ')');
|
78
|
-
}
|
79
|
-
|
80
|
-
var ans = checkAndSubmit(x, size[0]);
|
138
|
+
'Matrix, number|BigNumber': function MatrixNumberBigNumber(mat, prec) {
|
139
|
+
var {
|
140
|
+
values,
|
141
|
+
vectors
|
142
|
+
} = computeValuesAndVectors(mat, prec);
|
81
143
|
return {
|
82
|
-
values: matrix(
|
83
|
-
vectors: matrix(
|
144
|
+
values: matrix(values),
|
145
|
+
vectors: matrix(vectors)
|
84
146
|
};
|
85
147
|
}
|
86
|
-
});
|
87
|
-
// symmetric ?
|
148
|
+
});
|
88
149
|
|
89
|
-
function
|
90
|
-
|
91
|
-
|
92
|
-
// not symmtric
|
93
|
-
if (!equal(x[i][j], x[j][i])) {
|
94
|
-
throw new TypeError('Input matrix is not symmetric');
|
95
|
-
}
|
96
|
-
}
|
150
|
+
function computeValuesAndVectors(mat, prec) {
|
151
|
+
if (prec === undefined) {
|
152
|
+
prec = config.epsilon;
|
97
153
|
}
|
98
|
-
} // check input for possible problems
|
99
|
-
// and perform diagonalization efficiently for
|
100
|
-
// specific type of number
|
101
154
|
|
155
|
+
var size = mat.size();
|
102
156
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
if (type === undefined) {
|
107
|
-
type = x.getDataType();
|
157
|
+
if (size.length !== 2 || size[0] !== size[1]) {
|
158
|
+
throw new RangeError('Matrix must be square (size: ' + format(size) + ')');
|
108
159
|
}
|
109
160
|
|
110
|
-
|
111
|
-
|
112
|
-
throw new TypeError('Mixed matrix element type is not supported');
|
113
|
-
} else {
|
114
|
-
throw new TypeError('Matrix element type not supported (' + type + ')');
|
115
|
-
}
|
116
|
-
} else {
|
117
|
-
isSymmetric(x.toArray(), n);
|
118
|
-
} // perform efficient calculation for 'numbers'
|
161
|
+
var arr = mat.toArray();
|
162
|
+
var N = size[0];
|
119
163
|
|
164
|
+
if (isReal(arr, N, prec)) {
|
165
|
+
coerceReal(arr, N);
|
120
166
|
|
121
|
-
|
122
|
-
|
123
|
-
} else if (type === 'Fraction') {
|
124
|
-
var xArr = x.toArray(); // convert fraction to numbers
|
167
|
+
if (isSymmetric(arr, N, prec)) {
|
168
|
+
var _type = coerceTypes(mat, arr, N);
|
125
169
|
|
126
|
-
|
127
|
-
for (var j = i; j < n; j++) {
|
128
|
-
xArr[i][j] = xArr[i][j].valueOf();
|
129
|
-
xArr[j][i] = xArr[i][j];
|
130
|
-
}
|
170
|
+
return doRealSymetric(arr, N, prec, _type);
|
131
171
|
}
|
132
|
-
|
133
|
-
return diag(x.toArray());
|
134
|
-
} else if (type === 'BigNumber') {
|
135
|
-
return diagBig(x.toArray());
|
136
172
|
}
|
137
|
-
} // diagonalization implementation for number (efficient)
|
138
173
|
|
174
|
+
var type = coerceTypes(mat, arr, N);
|
175
|
+
return doComplexEigs(arr, N, prec, type);
|
176
|
+
}
|
177
|
+
/** @return {boolean} */
|
139
178
|
|
140
|
-
function diag(x) {
|
141
|
-
var N = x.length;
|
142
|
-
var e0 = Math.abs(config.epsilon / N);
|
143
|
-
var psi;
|
144
|
-
var Sij = new Array(N); // Sij is Identity Matrix
|
145
179
|
|
180
|
+
function isSymmetric(arr, N, prec) {
|
146
181
|
for (var i = 0; i < N; i++) {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
while (Math.abs(Vab[1]) >= Math.abs(e0)) {
|
155
|
-
var _i = Vab[0][0];
|
156
|
-
var j = Vab[0][1];
|
157
|
-
psi = getTheta(x[_i][_i], x[j][j], x[_i][j]);
|
158
|
-
x = x1(x, psi, _i, j);
|
159
|
-
Sij = Sij1(Sij, psi, _i, j);
|
160
|
-
Vab = getAij(x);
|
161
|
-
}
|
162
|
-
|
163
|
-
var Ei = createArray(N, 0); // eigenvalues
|
164
|
-
|
165
|
-
for (var _i2 = 0; _i2 < N; _i2++) {
|
166
|
-
Ei[_i2] = x[_i2][_i2];
|
182
|
+
for (var j = i; j < N; j++) {
|
183
|
+
// TODO proper comparison of bignum and frac
|
184
|
+
if (larger(bignumber(abs(subtract(arr[i][j], arr[j][i]))), prec)) {
|
185
|
+
return false;
|
186
|
+
}
|
187
|
+
}
|
167
188
|
}
|
168
189
|
|
169
|
-
return
|
170
|
-
}
|
171
|
-
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
/** @return {boolean} */
|
172
193
|
|
173
|
-
function diagBig(x) {
|
174
|
-
var N = x.length;
|
175
|
-
var e0 = abs(config.epsilon / N);
|
176
|
-
var psi;
|
177
|
-
var Sij = new Array(N); // Sij is Identity Matrix
|
178
194
|
|
195
|
+
function isReal(arr, N, prec) {
|
179
196
|
for (var i = 0; i < N; i++) {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
while (abs(Vab[1]) >= abs(e0)) {
|
188
|
-
var _i3 = Vab[0][0];
|
189
|
-
var j = Vab[0][1];
|
190
|
-
psi = getThetaBig(x[_i3][_i3], x[j][j], x[_i3][j]);
|
191
|
-
x = x1Big(x, psi, _i3, j);
|
192
|
-
Sij = Sij1Big(Sij, psi, _i3, j);
|
193
|
-
Vab = getAijBig(x);
|
194
|
-
}
|
195
|
-
|
196
|
-
var Ei = createArray(N, 0); // eigenvalues
|
197
|
-
|
198
|
-
for (var _i4 = 0; _i4 < N; _i4++) {
|
199
|
-
Ei[_i4] = x[_i4][_i4];
|
200
|
-
} // return [clone(Ei), clone(Sij)]
|
201
|
-
|
202
|
-
|
203
|
-
return sorting(clone(Ei), clone(Sij));
|
204
|
-
} // get angle
|
205
|
-
|
206
|
-
|
207
|
-
function getTheta(aii, ajj, aij) {
|
208
|
-
var denom = ajj - aii;
|
209
|
-
|
210
|
-
if (Math.abs(denom) <= config.epsilon) {
|
211
|
-
return Math.PI / 4;
|
212
|
-
} else {
|
213
|
-
return 0.5 * Math.atan(2 * aij / (ajj - aii));
|
214
|
-
}
|
215
|
-
} // get angle
|
216
|
-
|
217
|
-
|
218
|
-
function getThetaBig(aii, ajj, aij) {
|
219
|
-
var denom = subtract(ajj, aii);
|
220
|
-
|
221
|
-
if (abs(denom) <= config.epsilon) {
|
222
|
-
return bignumber(-1).acos().div(4);
|
223
|
-
} else {
|
224
|
-
return multiplyScalar(0.5, atan(multiply(2, aij, inv(denom))));
|
225
|
-
}
|
226
|
-
} // update eigvec
|
227
|
-
|
228
|
-
|
229
|
-
function Sij1(Sij, theta, i, j) {
|
230
|
-
var N = Sij.length;
|
231
|
-
var c = Math.cos(theta);
|
232
|
-
var s = Math.sin(theta);
|
233
|
-
var Ski = createArray(N, 0);
|
234
|
-
var Skj = createArray(N, 0);
|
235
|
-
|
236
|
-
for (var k = 0; k < N; k++) {
|
237
|
-
Ski[k] = c * Sij[k][i] - s * Sij[k][j];
|
238
|
-
Skj[k] = s * Sij[k][i] + c * Sij[k][j];
|
239
|
-
}
|
240
|
-
|
241
|
-
for (var _k = 0; _k < N; _k++) {
|
242
|
-
Sij[_k][i] = Ski[_k];
|
243
|
-
Sij[_k][j] = Skj[_k];
|
244
|
-
}
|
245
|
-
|
246
|
-
return Sij;
|
247
|
-
} // update eigvec for overlap
|
248
|
-
|
249
|
-
|
250
|
-
function Sij1Big(Sij, theta, i, j) {
|
251
|
-
var N = Sij.length;
|
252
|
-
var c = cos(theta);
|
253
|
-
var s = sin(theta);
|
254
|
-
var Ski = createArray(N, bignumber(0));
|
255
|
-
var Skj = createArray(N, bignumber(0));
|
256
|
-
|
257
|
-
for (var k = 0; k < N; k++) {
|
258
|
-
Ski[k] = subtract(multiplyScalar(c, Sij[k][i]), multiplyScalar(s, Sij[k][j]));
|
259
|
-
Skj[k] = addScalar(multiplyScalar(s, Sij[k][i]), multiplyScalar(c, Sij[k][j]));
|
260
|
-
}
|
261
|
-
|
262
|
-
for (var _k2 = 0; _k2 < N; _k2++) {
|
263
|
-
Sij[_k2][i] = Ski[_k2];
|
264
|
-
Sij[_k2][j] = Skj[_k2];
|
197
|
+
for (var j = 0; j < N; j++) {
|
198
|
+
// TODO proper comparison of bignum and frac
|
199
|
+
if (larger(bignumber(abs(im(arr[i][j]))), prec)) {
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
}
|
265
203
|
}
|
266
204
|
|
267
|
-
return
|
268
|
-
}
|
269
|
-
|
270
|
-
|
271
|
-
function x1Big(Hij, theta, i, j) {
|
272
|
-
var N = Hij.length;
|
273
|
-
var c = bignumber(cos(theta));
|
274
|
-
var s = bignumber(sin(theta));
|
275
|
-
var c2 = multiplyScalar(c, c);
|
276
|
-
var s2 = multiplyScalar(s, s);
|
277
|
-
var Aki = createArray(N, bignumber(0));
|
278
|
-
var Akj = createArray(N, bignumber(0)); // 2cs Hij
|
279
|
-
|
280
|
-
var csHij = multiply(bignumber(2), c, s, Hij[i][j]); // Aii
|
281
|
-
|
282
|
-
var Aii = addScalar(subtract(multiplyScalar(c2, Hij[i][i]), csHij), multiplyScalar(s2, Hij[j][j]));
|
283
|
-
var Ajj = add(multiplyScalar(s2, Hij[i][i]), csHij, multiplyScalar(c2, Hij[j][j])); // 0 to i
|
284
|
-
|
285
|
-
for (var k = 0; k < N; k++) {
|
286
|
-
Aki[k] = subtract(multiplyScalar(c, Hij[i][k]), multiplyScalar(s, Hij[j][k]));
|
287
|
-
Akj[k] = addScalar(multiplyScalar(s, Hij[i][k]), multiplyScalar(c, Hij[j][k]));
|
288
|
-
} // Modify Hij
|
289
|
-
|
290
|
-
|
291
|
-
Hij[i][i] = Aii;
|
292
|
-
Hij[j][j] = Ajj;
|
293
|
-
Hij[i][j] = bignumber(0);
|
294
|
-
Hij[j][i] = bignumber(0); // 0 to i
|
205
|
+
return true;
|
206
|
+
}
|
295
207
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
Hij[j][_k3] = Akj[_k3];
|
301
|
-
Hij[_k3][j] = Akj[_k3];
|
208
|
+
function coerceReal(arr, N) {
|
209
|
+
for (var i = 0; i < N; i++) {
|
210
|
+
for (var j = 0; j < N; j++) {
|
211
|
+
arr[i][j] = re(arr[i][j]);
|
302
212
|
}
|
303
213
|
}
|
304
|
-
|
305
|
-
|
306
|
-
} // update matrix
|
307
|
-
|
308
|
-
|
309
|
-
function x1(Hij, theta, i, j) {
|
310
|
-
var N = Hij.length;
|
311
|
-
var c = Math.cos(theta);
|
312
|
-
var s = Math.sin(theta);
|
313
|
-
var c2 = c * c;
|
314
|
-
var s2 = s * s;
|
315
|
-
var Aki = createArray(N, 0);
|
316
|
-
var Akj = createArray(N, 0); // Aii
|
317
|
-
|
318
|
-
var Aii = c2 * Hij[i][i] - 2 * c * s * Hij[i][j] + s2 * Hij[j][j];
|
319
|
-
var Ajj = s2 * Hij[i][i] + 2 * c * s * Hij[i][j] + c2 * Hij[j][j]; // 0 to i
|
320
|
-
|
321
|
-
for (var k = 0; k < N; k++) {
|
322
|
-
Aki[k] = c * Hij[i][k] - s * Hij[j][k];
|
323
|
-
Akj[k] = s * Hij[i][k] + c * Hij[j][k];
|
324
|
-
} // Modify Hij
|
214
|
+
}
|
215
|
+
/** @return {'number' | 'BigNumber' | 'Complex'} */
|
325
216
|
|
326
217
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
Hij[j][i] = 0; // 0 to i
|
218
|
+
function coerceTypes(mat, arr, N) {
|
219
|
+
/** @type {string} */
|
220
|
+
var type = mat.datatype();
|
331
221
|
|
332
|
-
|
333
|
-
|
334
|
-
Hij[i][_k4] = Aki[_k4];
|
335
|
-
Hij[_k4][i] = Aki[_k4];
|
336
|
-
Hij[j][_k4] = Akj[_k4];
|
337
|
-
Hij[_k4][j] = Akj[_k4];
|
338
|
-
}
|
222
|
+
if (type === 'number' || type === 'BigNumber' || type === 'Complex') {
|
223
|
+
return type;
|
339
224
|
}
|
340
225
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
function getAij(Mij) {
|
346
|
-
var N = Mij.length;
|
347
|
-
var maxMij = 0;
|
348
|
-
var maxIJ = [0, 1];
|
226
|
+
var hasNumber = false;
|
227
|
+
var hasBig = false;
|
228
|
+
var hasComplex = false;
|
349
229
|
|
350
230
|
for (var i = 0; i < N; i++) {
|
351
|
-
for (var j =
|
352
|
-
|
353
|
-
|
354
|
-
|
231
|
+
for (var j = 0; j < N; j++) {
|
232
|
+
var el = arr[i][j];
|
233
|
+
|
234
|
+
if (isNumber(el) || isFraction(el)) {
|
235
|
+
hasNumber = true;
|
236
|
+
} else if (isBigNumber(el)) {
|
237
|
+
hasBig = true;
|
238
|
+
} else if (isComplex(el)) {
|
239
|
+
hasComplex = true;
|
240
|
+
} else {
|
241
|
+
throw TypeError('Unsupported type in Matrix: ' + typeOf(el));
|
355
242
|
}
|
356
243
|
}
|
357
244
|
}
|
358
245
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
function getAijBig(Mij) {
|
364
|
-
var N = Mij.length;
|
365
|
-
var maxMij = 0;
|
366
|
-
var maxIJ = [0, 1];
|
246
|
+
if (hasBig && hasComplex) {
|
247
|
+
console.warn('Complex BigNumbers not supported, this operation will lose precission.');
|
248
|
+
}
|
367
249
|
|
368
|
-
|
369
|
-
for (var
|
370
|
-
|
371
|
-
|
372
|
-
maxIJ = [i, j];
|
250
|
+
if (hasComplex) {
|
251
|
+
for (var _i = 0; _i < N; _i++) {
|
252
|
+
for (var _j = 0; _j < N; _j++) {
|
253
|
+
arr[_i][_j] = complex(arr[_i][_j]);
|
373
254
|
}
|
374
255
|
}
|
375
|
-
}
|
376
|
-
|
377
|
-
return [maxIJ, maxMij];
|
378
|
-
} // sort results
|
379
256
|
|
380
|
-
|
381
|
-
function sorting(E, S) {
|
382
|
-
var N = E.length;
|
383
|
-
var Ef = Array(N);
|
384
|
-
var Sf = Array(N);
|
385
|
-
|
386
|
-
for (var k = 0; k < N; k++) {
|
387
|
-
Sf[k] = Array(N);
|
257
|
+
return 'Complex';
|
388
258
|
}
|
389
259
|
|
390
|
-
|
391
|
-
var
|
392
|
-
|
393
|
-
|
394
|
-
for (var j = 0; j < E.length; j++) {
|
395
|
-
if (E[j] < minE) {
|
396
|
-
minID = j;
|
397
|
-
minE = E[minID];
|
260
|
+
if (hasBig) {
|
261
|
+
for (var _i2 = 0; _i2 < N; _i2++) {
|
262
|
+
for (var _j2 = 0; _j2 < N; _j2++) {
|
263
|
+
arr[_i2][_j2] = bignumber(arr[_i2][_j2]);
|
398
264
|
}
|
399
265
|
}
|
400
266
|
|
401
|
-
|
402
|
-
|
403
|
-
for (var _k5 = 0; _k5 < N; _k5++) {
|
404
|
-
Sf[_k5][i] = S[_k5][minID];
|
405
|
-
|
406
|
-
S[_k5].splice(minID, 1);
|
407
|
-
}
|
267
|
+
return 'BigNumber';
|
408
268
|
}
|
409
269
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
* @return {number[]}
|
417
|
-
*/
|
418
|
-
|
419
|
-
|
420
|
-
function createArray(size, value) {
|
421
|
-
// TODO: as soon as all browsers support Array.fill, use that instead (IE doesn't support it)
|
422
|
-
var array = new Array(size);
|
270
|
+
if (hasNumber) {
|
271
|
+
for (var _i3 = 0; _i3 < N; _i3++) {
|
272
|
+
for (var _j3 = 0; _j3 < N; _j3++) {
|
273
|
+
arr[_i3][_j3] = number(arr[_i3][_j3]);
|
274
|
+
}
|
275
|
+
}
|
423
276
|
|
424
|
-
|
425
|
-
|
277
|
+
return 'number';
|
278
|
+
} else {
|
279
|
+
throw TypeError('Matrix contains unsupported types only.');
|
426
280
|
}
|
427
|
-
|
428
|
-
return array;
|
429
281
|
}
|
430
282
|
});
|
@@ -3,7 +3,7 @@ import { format } from '../../utils/string.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
4
|
var name = 'expm';
|
5
5
|
var dependencies = ['typed', 'abs', 'add', 'identity', 'inv', 'multiply'];
|
6
|
-
export var createExpm = /* #__PURE__ */factory(name, dependencies,
|
6
|
+
export var createExpm = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
7
|
var {
|
8
8
|
typed,
|
9
9
|
abs,
|
@@ -3,7 +3,7 @@ import { maxArgumentCount } from '../../utils/function.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
4
|
var name = 'filter';
|
5
5
|
var dependencies = ['typed'];
|
6
|
-
export var createFilter = /* #__PURE__ */factory(name, dependencies,
|
6
|
+
export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
7
|
var {
|
8
8
|
typed
|
9
9
|
} = _ref;
|
@@ -3,7 +3,7 @@ import { flatten as flattenArray } from '../../utils/array.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
4
|
var name = 'flatten';
|
5
5
|
var dependencies = ['typed', 'matrix'];
|
6
|
-
export var createFlatten = /* #__PURE__ */factory(name, dependencies,
|
6
|
+
export var createFlatten = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
7
|
var {
|
8
8
|
typed,
|
9
9
|
matrix
|
@@ -11,6 +11,7 @@ export var createFlatten = /* #__PURE__ */factory(name, dependencies, (_ref) =>
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Flatten a multi dimensional matrix into a single dimensional matrix.
|
14
|
+
* It is guaranteed to always return a clone of the argument.
|
14
15
|
*
|
15
16
|
* Syntax:
|
16
17
|
*
|
@@ -3,7 +3,7 @@ import { forEach as forEachArray } from '../../utils/array.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
4
|
var name = 'forEach';
|
5
5
|
var dependencies = ['typed'];
|
6
|
-
export var createForEach = /* #__PURE__ */factory(name, dependencies,
|
6
|
+
export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
7
|
var {
|
8
8
|
typed
|
9
9
|
} = _ref;
|
@@ -3,7 +3,7 @@ import { getArrayDataType } from '../../utils/array.js';
|
|
3
3
|
import { typeOf } from '../../utils/is.js';
|
4
4
|
var name = 'getMatrixDataType';
|
5
5
|
var dependencies = ['typed'];
|
6
|
-
export var createGetMatrixDataType = /* #__PURE__ */factory(name, dependencies,
|
6
|
+
export var createGetMatrixDataType = /* #__PURE__ */factory(name, dependencies, _ref => {
|
7
7
|
var {
|
8
8
|
typed
|
9
9
|
} = _ref;
|
@@ -4,7 +4,7 @@ import { isInteger } from '../../utils/number.js';
|
|
4
4
|
import { factory } from '../../utils/factory.js';
|
5
5
|
var name = 'identity';
|
6
6
|
var dependencies = ['typed', 'config', 'matrix', 'BigNumber', 'DenseMatrix', 'SparseMatrix'];
|
7
|
-
export var createIdentity = /* #__PURE__ */factory(name, dependencies,
|
7
|
+
export var createIdentity = /* #__PURE__ */factory(name, dependencies, _ref => {
|
8
8
|
var {
|
9
9
|
typed,
|
10
10
|
config,
|