mathjs 14.3.1 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +28 -6
- package/README.md +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/constants.js +12 -12
- package/lib/cjs/core/create.js +1 -2
- package/lib/cjs/defaultInstance.js +1 -2
- package/lib/cjs/entry/allFactoriesAny.js +1 -2
- package/lib/cjs/entry/allFactoriesNumber.js +1 -2
- package/lib/cjs/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/cjs/expression/embeddedDocs/function/expression/compile.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/expression/evaluate.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/expression/parse.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/expression/parser.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/statistics/sum.js +1 -1
- package/lib/cjs/expression/function/parser.js +1 -1
- package/lib/cjs/expression/parse.js +4 -3
- package/lib/cjs/function/arithmetic/add.js +33 -33
- package/lib/cjs/function/arithmetic/hypot.js +1 -1
- package/lib/cjs/function/matrix/filter.js +4 -1
- package/lib/cjs/function/matrix/flatten.js +1 -1
- package/lib/cjs/function/matrix/forEach.js +2 -1
- package/lib/cjs/function/matrix/map.js +2 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +144 -81
- package/lib/cjs/type/matrix/SparseMatrix.js +4 -3
- package/lib/cjs/type/unit/Unit.js +19 -4
- package/lib/cjs/utils/array.js +31 -7
- package/lib/cjs/utils/collection.js +3 -3
- package/lib/cjs/utils/latex.js +4 -1
- package/lib/cjs/utils/optimizeCallback.js +61 -13
- package/lib/cjs/utils/snapshot.js +1 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/constants.js +12 -12
- package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/esm/expression/embeddedDocs/function/expression/compile.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/expression/evaluate.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/expression/parse.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/expression/parser.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/statistics/sum.js +1 -1
- package/lib/esm/expression/function/parser.js +1 -1
- package/lib/esm/expression/parse.js +4 -3
- package/lib/esm/function/arithmetic/add.js +33 -33
- package/lib/esm/function/arithmetic/hypot.js +1 -1
- package/lib/esm/function/matrix/filter.js +4 -1
- package/lib/esm/function/matrix/flatten.js +1 -1
- package/lib/esm/function/matrix/forEach.js +2 -1
- package/lib/esm/function/matrix/map.js +2 -1
- package/lib/esm/type/matrix/DenseMatrix.js +150 -87
- package/lib/esm/type/matrix/SparseMatrix.js +4 -3
- package/lib/esm/type/unit/Unit.js +19 -4
- package/lib/esm/utils/array.js +33 -9
- package/lib/esm/utils/collection.js +3 -3
- package/lib/esm/utils/latex.js +4 -1
- package/lib/esm/utils/optimizeCallback.js +61 -13
- package/lib/esm/version.js +1 -1
- package/package.json +20 -20
package/lib/cjs/constants.js
CHANGED
@@ -76,47 +76,47 @@ const createLOG2E = exports.createLOG2E = /* #__PURE__ */recreateFactory('LOG2E'
|
|
76
76
|
} = _ref9;
|
77
77
|
return config.number === 'BigNumber' ? new BigNumber(1).div(new BigNumber(2).ln()) : Math.LOG2E;
|
78
78
|
});
|
79
|
-
const createLOG10E = exports.createLOG10E = /* #__PURE__ */recreateFactory('LOG10E', ['config', '?BigNumber'],
|
79
|
+
const createLOG10E = exports.createLOG10E = /* #__PURE__ */recreateFactory('LOG10E', ['config', '?BigNumber'], _ref0 => {
|
80
80
|
let {
|
81
81
|
config,
|
82
82
|
BigNumber
|
83
|
-
} =
|
83
|
+
} = _ref0;
|
84
84
|
return config.number === 'BigNumber' ? new BigNumber(1).div(new BigNumber(10).ln()) : Math.LOG10E;
|
85
85
|
});
|
86
86
|
const createSQRT1_2 = exports.createSQRT1_2 = /* #__PURE__ */recreateFactory(
|
87
87
|
// eslint-disable-line camelcase
|
88
|
-
'SQRT1_2', ['config', '?BigNumber'],
|
88
|
+
'SQRT1_2', ['config', '?BigNumber'], _ref1 => {
|
89
89
|
let {
|
90
90
|
config,
|
91
91
|
BigNumber
|
92
|
-
} =
|
92
|
+
} = _ref1;
|
93
93
|
return config.number === 'BigNumber' ? new BigNumber('0.5').sqrt() : Math.SQRT1_2;
|
94
94
|
});
|
95
|
-
const createSQRT2 = exports.createSQRT2 = /* #__PURE__ */recreateFactory('SQRT2', ['config', '?BigNumber'],
|
95
|
+
const createSQRT2 = exports.createSQRT2 = /* #__PURE__ */recreateFactory('SQRT2', ['config', '?BigNumber'], _ref10 => {
|
96
96
|
let {
|
97
97
|
config,
|
98
98
|
BigNumber
|
99
|
-
} =
|
99
|
+
} = _ref10;
|
100
100
|
return config.number === 'BigNumber' ? new BigNumber(2).sqrt() : Math.SQRT2;
|
101
101
|
});
|
102
|
-
const createI = exports.createI = /* #__PURE__ */recreateFactory('i', ['Complex'],
|
102
|
+
const createI = exports.createI = /* #__PURE__ */recreateFactory('i', ['Complex'], _ref11 => {
|
103
103
|
let {
|
104
104
|
Complex
|
105
|
-
} =
|
105
|
+
} = _ref11;
|
106
106
|
return Complex.I;
|
107
107
|
});
|
108
108
|
|
109
109
|
// for backward compatibility with v5
|
110
|
-
const createUppercasePi = exports.createUppercasePi = /* #__PURE__ */(0, _factory.factory)('PI', ['pi'],
|
110
|
+
const createUppercasePi = exports.createUppercasePi = /* #__PURE__ */(0, _factory.factory)('PI', ['pi'], _ref12 => {
|
111
111
|
let {
|
112
112
|
pi
|
113
|
-
} =
|
113
|
+
} = _ref12;
|
114
114
|
return pi;
|
115
115
|
});
|
116
|
-
const createUppercaseE = exports.createUppercaseE = /* #__PURE__ */(0, _factory.factory)('E', ['e'],
|
116
|
+
const createUppercaseE = exports.createUppercaseE = /* #__PURE__ */(0, _factory.factory)('E', ['e'], _ref13 => {
|
117
117
|
let {
|
118
118
|
e
|
119
|
-
} =
|
119
|
+
} = _ref13;
|
120
120
|
return e;
|
121
121
|
});
|
122
122
|
const createVersion = exports.createVersion = /* #__PURE__ */(0, _factory.factory)('version', [], () => _version.version);
|
package/lib/cjs/core/create.js
CHANGED
@@ -17,8 +17,7 @@ var emitter = _interopRequireWildcard(require("./../utils/emitter.js"));
|
|
17
17
|
var _config = require("./config.js");
|
18
18
|
var _config2 = require("./function/config.js");
|
19
19
|
var _import = require("./function/import.js");
|
20
|
-
function
|
21
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
20
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
22
21
|
/**
|
23
22
|
* Create a mathjs instance from given factory functions and optionally config
|
24
23
|
*
|
@@ -6,6 +6,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = void 0;
|
7
7
|
var all = _interopRequireWildcard(require("./factoriesAny.js"));
|
8
8
|
var _create = require("./core/create.js");
|
9
|
-
function
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
11
10
|
var _default = exports.default = (0, _create.create)(all);
|
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.all = void 0;
|
7
7
|
var allFactories = _interopRequireWildcard(require("../factoriesAny.js"));
|
8
|
-
function
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
10
9
|
// creating all factories here in a separate file is needed to get tree-shaking working
|
11
10
|
|
12
11
|
const all = exports.all = allFactories;
|
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.all = void 0;
|
7
7
|
var allFactories = _interopRequireWildcard(require("../factoriesNumber.js"));
|
8
|
-
function
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
10
9
|
// creating all factories here in a separate file is needed to get tree-shaking working
|
11
10
|
|
12
11
|
const all = exports.all = allFactories;
|
@@ -10,5 +10,5 @@ const indexDocs = exports.indexDocs = {
|
|
10
10
|
syntax: ['[start]', '[start:end]', '[start:step:end]', '[start1, start 2, ...]', '[start1:end1, start2:end2, ...]', '[start1:step1:end1, start2:step2:end2, ...]'],
|
11
11
|
description: 'Create an index to get or replace a subset of a matrix',
|
12
12
|
examples: ['A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[1:2, 1:2] = 1', 'B = [1, 2, 3]', 'B[B>1 and B<3]'],
|
13
|
-
seealso: ['bignumber', 'boolean', 'complex', 'matrix
|
13
|
+
seealso: ['bignumber', 'boolean', 'complex', 'matrix', 'number', 'range', 'string', 'unit']
|
14
14
|
};
|
@@ -110,6 +110,9 @@ var _conj = require("./function/complex/conj.js");
|
|
110
110
|
var _im = require("./function/complex/im.js");
|
111
111
|
var _re = require("./function/complex/re.js");
|
112
112
|
var _evaluate = require("./function/expression/evaluate.js");
|
113
|
+
var _parser = require("./function/expression/parser.js");
|
114
|
+
var _parse = require("./function/expression/parse.js");
|
115
|
+
var _compile = require("./function/expression/compile.js");
|
113
116
|
var _help = require("./function/expression/help.js");
|
114
117
|
var _distance = require("./function/geometry/distance.js");
|
115
118
|
var _intersect = require("./function/geometry/intersect.js");
|
@@ -570,6 +573,9 @@ const embeddedDocs = exports.embeddedDocs = {
|
|
570
573
|
// functions - expression
|
571
574
|
evaluate: _evaluate.evaluateDocs,
|
572
575
|
help: _help.helpDocs,
|
576
|
+
parse: _parse.parseDocs,
|
577
|
+
parser: _parser.parserDocs,
|
578
|
+
compile: _compile.compileDocs,
|
573
579
|
// functions - geometry
|
574
580
|
distance: _distance.distanceDocs,
|
575
581
|
intersect: _intersect.intersectDocs,
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.compileDocs = void 0;
|
7
|
+
const compileDocs = exports.compileDocs = {
|
8
|
+
name: 'compile',
|
9
|
+
category: 'Expression',
|
10
|
+
syntax: ['compile(expr) ', 'compile([expr1, expr2, expr3, ...])'],
|
11
|
+
description: 'Parse and compile an expression. Returns a an object with a function evaluate([scope]) to evaluate the compiled expression.',
|
12
|
+
examples: ['code1 = compile("sqrt(3^2 + 4^2)")', 'code1.evaluate() ', 'code2 = compile("a * b")', 'code2.evaluate({a: 3, b: 4})'],
|
13
|
+
seealso: ['parser', 'parse', 'evaluate']
|
14
|
+
};
|
@@ -10,5 +10,5 @@ const evaluateDocs = exports.evaluateDocs = {
|
|
10
10
|
syntax: ['evaluate(expression)', 'evaluate(expression, scope)', 'evaluate([expr1, expr2, expr3, ...])', 'evaluate([expr1, expr2, expr3, ...], scope)'],
|
11
11
|
description: 'Evaluate an expression or an array with expressions.',
|
12
12
|
examples: ['evaluate("2 + 3")', 'evaluate("sqrt(16)")', 'evaluate("2 inch to cm")', 'evaluate("sin(x * pi)", { "x": 1/2 })', 'evaluate(["width=2", "height=4","width*height"])'],
|
13
|
-
seealso: []
|
13
|
+
seealso: ['parser', 'parse', 'compile']
|
14
14
|
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.parseDocs = void 0;
|
7
|
+
const parseDocs = exports.parseDocs = {
|
8
|
+
name: 'parse',
|
9
|
+
category: 'Expression',
|
10
|
+
syntax: ['parse(expr)', 'parse(expr, options)', 'parse([expr1, expr2, expr3, ...])', 'parse([expr1, expr2, expr3, ...], options)'],
|
11
|
+
description: 'Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate() or transformed into a functional object via node.compile().',
|
12
|
+
examples: ['node1 = parse("sqrt(3^2 + 4^2)")', 'node1.evaluate()', 'code1 = node1.compile()', 'code1.evaluate()', 'scope = {a: 3, b: 4}', 'node2 = parse("a * b")', 'node2.evaluate(scope)', 'code2 = node2.compile()', 'code2.evaluate(scope)'],
|
13
|
+
seealso: ['parser', 'evaluate', 'compile']
|
14
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.parserDocs = void 0;
|
7
|
+
const parserDocs = exports.parserDocs = {
|
8
|
+
name: 'parser',
|
9
|
+
category: 'Expression',
|
10
|
+
syntax: ['parser()'],
|
11
|
+
description: 'Create a parser object that keeps a context of variables and their values, allowing the evaluation of expressions in that context.',
|
12
|
+
examples: ['myParser = parser()', 'myParser.evaluate("sqrt(3^2 + 4^2)")', 'myParser.set("x", 3)', 'myParser.evaluate("y = x + 3")', 'myParser.evaluate(["y = x + 3", "y = y + 1"])', 'myParser.get("y")'],
|
13
|
+
seealso: ['evaluate', 'parse', 'compile']
|
14
|
+
};
|
@@ -10,5 +10,5 @@ const sumDocs = exports.sumDocs = {
|
|
10
10
|
syntax: ['sum(a, b, c, ...)', 'sum(A)', 'sum(A, dimension)'],
|
11
11
|
description: 'Compute the sum of all values.',
|
12
12
|
examples: ['sum(2, 3, 4, 1)', 'sum([2, 3, 4, 1])', 'sum([2, 5; 4, 3])'],
|
13
|
-
seealso: ['max', 'mean', 'median', 'min', 'prod', 'std', '
|
13
|
+
seealso: ['max', 'mean', 'median', 'min', 'prod', 'std', 'variance']
|
14
14
|
};
|
@@ -13,7 +13,7 @@ const createParser = exports.createParser = /* #__PURE__ */(0, _factory.factory)
|
|
13
13
|
Parser
|
14
14
|
} = _ref;
|
15
15
|
/**
|
16
|
-
* Create a
|
16
|
+
* Create a `math.Parser` object that keeps a context of variables and their values, allowing the evaluation of expressions in that context.
|
17
17
|
*
|
18
18
|
* Syntax:
|
19
19
|
*
|
@@ -36,7 +36,7 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
36
36
|
} = _ref;
|
37
37
|
/**
|
38
38
|
* Parse an expression. Returns a node tree, which can be evaluated by
|
39
|
-
* invoking node.evaluate().
|
39
|
+
* invoking node.evaluate() or transformed into a functional object via node.compile().
|
40
40
|
*
|
41
41
|
* Note the evaluating arbitrary expressions may involve security risks,
|
42
42
|
* see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
|
@@ -55,6 +55,7 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
55
55
|
*
|
56
56
|
* let scope = {a:3, b:4}
|
57
57
|
* const node2 = math.parse('a * b') // 12
|
58
|
+
* node2.evaluate(scope) // 12
|
58
59
|
* const code2 = node2.compile()
|
59
60
|
* code2.evaluate(scope) // 12
|
60
61
|
* scope.a = 5
|
@@ -396,7 +397,7 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
396
397
|
if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
|
397
398
|
throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
|
398
399
|
}
|
399
|
-
} else if (nextCharacter(state)
|
400
|
+
} else if (parse.isDecimalMark(nextCharacter(state), state.expression.charAt(state.index + 2))) {
|
400
401
|
next(state);
|
401
402
|
throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
|
402
403
|
}
|
@@ -877,7 +878,7 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
877
878
|
name = state.token;
|
878
879
|
fn = operators[name];
|
879
880
|
getTokenSkipNewline(state);
|
880
|
-
if (name === 'in' && state.token
|
881
|
+
if (name === 'in' && '])},;'.includes(state.token)) {
|
881
882
|
// end of expression -> this is the unit 'in' ('inch')
|
882
883
|
node = new OperatorNode('*', 'multiply', [node, new SymbolNode('in')], true);
|
883
884
|
} else {
|
@@ -38,39 +38,39 @@ const createAdd = exports.createAdd = /* #__PURE__ */(0, _factory.factory)(name,
|
|
38
38
|
concat
|
39
39
|
});
|
40
40
|
/**
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
41
|
+
* Add two or more values, `x + y`.
|
42
|
+
* For matrices, the function is evaluated element wise.
|
43
|
+
*
|
44
|
+
* Syntax:
|
45
|
+
*
|
46
|
+
* math.add(x, y)
|
47
|
+
* math.add(x, y, z, ...)
|
48
|
+
*
|
49
|
+
* Examples:
|
50
|
+
*
|
51
|
+
* math.add(2, 3) // returns number 5
|
52
|
+
* math.add(2, 3, 4) // returns number 9
|
53
|
+
*
|
54
|
+
* const a = math.complex(2, 3)
|
55
|
+
* const b = math.complex(-4, 1)
|
56
|
+
* math.add(a, b) // returns Complex -2 + 4i
|
57
|
+
*
|
58
|
+
* math.add([1, 2, 3], 4) // returns Array [5, 6, 7]
|
59
|
+
*
|
60
|
+
* const c = math.unit('5 cm')
|
61
|
+
* const d = math.unit('2.1 mm')
|
62
|
+
* math.add(c, d) // returns Unit 52.1 mm
|
63
|
+
*
|
64
|
+
* math.add("2.3", "4") // returns number 6.3
|
65
|
+
*
|
66
|
+
* See also:
|
67
|
+
*
|
68
|
+
* subtract, sum
|
69
|
+
*
|
70
|
+
* @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x First value to add
|
71
|
+
* @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Second value to add
|
72
|
+
* @return {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} Sum of `x` and `y`
|
73
|
+
*/
|
74
74
|
return typed(name, {
|
75
75
|
'any, any': addScalar,
|
76
76
|
'any, any, ...any': typed.referToSelf(self => (x, y, rest) => {
|
@@ -51,7 +51,7 @@ const createHypot = exports.createHypot = /* #__PURE__ */(0, _factory.factory)(n
|
|
51
51
|
return typed(name, {
|
52
52
|
'... number | BigNumber': _hypot,
|
53
53
|
Array: _hypot,
|
54
|
-
Matrix: M => _hypot((0, _array.flatten)(M.toArray()))
|
54
|
+
Matrix: M => _hypot((0, _array.flatten)(M.toArray(), true))
|
55
55
|
});
|
56
56
|
|
57
57
|
/**
|
@@ -70,8 +70,11 @@ const createFilter = exports.createFilter = /* #__PURE__ */(0, _factory.factory)
|
|
70
70
|
*/
|
71
71
|
function _filterCallback(x, callback) {
|
72
72
|
const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, x, 'filter');
|
73
|
+
if (fastCallback.isUnary) {
|
74
|
+
return (0, _array.filter)(x, fastCallback.fn);
|
75
|
+
}
|
73
76
|
return (0, _array.filter)(x, function (value, index, array) {
|
74
77
|
// invoke the callback function with the right number of arguments
|
75
|
-
return fastCallback(value, [index], array);
|
78
|
+
return fastCallback.fn(value, [index], array);
|
76
79
|
});
|
77
80
|
}
|
@@ -38,7 +38,7 @@ const createFlatten = exports.createFlatten = /* #__PURE__ */(0, _factory.factor
|
|
38
38
|
Matrix: function (x) {
|
39
39
|
// Return the same matrix type as x (Dense or Sparse Matrix)
|
40
40
|
// Return the same data type as x
|
41
|
-
return x.create((0, _array.flatten)(x.valueOf()), x.datatype());
|
41
|
+
return x.create((0, _array.flatten)(x.valueOf(), true), x.datatype());
|
42
42
|
}
|
43
43
|
});
|
44
44
|
});
|
@@ -58,5 +58,6 @@ const createForEach = exports.createForEach = /* #__PURE__ */(0, _factory.factor
|
|
58
58
|
* @private
|
59
59
|
*/
|
60
60
|
function _forEach(array, callback) {
|
61
|
-
|
61
|
+
const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, array, name);
|
62
|
+
(0, _array.deepForEach)(array, fastCallback.fn, fastCallback.isUnary);
|
62
63
|
}
|
@@ -143,6 +143,7 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
143
143
|
* @private
|
144
144
|
*/
|
145
145
|
function _mapArray(array, callback) {
|
146
|
-
|
146
|
+
const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, array, name);
|
147
|
+
return (0, _array.deepMap)(array, fastCallback.fn, fastCallback.isUnary);
|
147
148
|
}
|
148
149
|
});
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version 14.
|
10
|
-
* @date 2025-
|
9
|
+
* @version 14.5.0
|
10
|
+
* @date 2025-05-21
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2025 Jos de Jong <wjosdejong@gmail.com>
|