mathjs 14.0.1 → 14.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +20 -0
- package/NOTICE +1 -1
- package/README.md +7 -7
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +5 -5
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/import.js +14 -4
- package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/{dependenciesApply.generated.js → dependenciesMapSlices.generated.js} +3 -3
- package/lib/cjs/entry/dependenciesAny/{dependenciesApplyTransform.generated.js → dependenciesMapSlicesTransform.generated.js} +3 -3
- package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesVariance.generated.js +2 -2
- package/lib/cjs/entry/dependenciesAny/dependenciesVarianceTransform.generated.js +2 -2
- package/lib/cjs/entry/dependenciesAny.generated.js +14 -14
- package/lib/cjs/entry/dependenciesNumber/{dependenciesApply.generated.js → dependenciesMapSlices.generated.js} +3 -3
- package/lib/cjs/entry/dependenciesNumber/{dependenciesApplyTransform.generated.js → dependenciesMapSlicesTransform.generated.js} +3 -3
- package/lib/cjs/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesVariance.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber/dependenciesVarianceTransform.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber.generated.js +14 -14
- package/lib/cjs/entry/impureFunctionsAny.generated.js +86 -85
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +14 -14
- package/lib/cjs/entry/pureFunctionsAny.generated.js +330 -325
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +18 -15
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/mapSlices.js +17 -0
- package/lib/cjs/expression/transform/index.transform.js +2 -2
- package/lib/cjs/expression/transform/{apply.transform.js → mapSlices.transform.js} +11 -10
- package/lib/cjs/expression/transform/quantileSeq.transform.js +5 -3
- package/lib/cjs/expression/transform/variance.transform.js +3 -3
- package/lib/cjs/factoriesAny.js +14 -14
- package/lib/cjs/factoriesNumber.js +16 -15
- package/lib/cjs/function/arithmetic/ceil.js +34 -26
- package/lib/cjs/function/arithmetic/fix.js +3 -0
- package/lib/cjs/function/arithmetic/floor.js +41 -26
- package/lib/cjs/function/arithmetic/log.js +12 -5
- package/lib/cjs/function/arithmetic/log10.js +15 -7
- package/lib/cjs/function/arithmetic/log2.js +9 -4
- package/lib/cjs/function/arithmetic/round.js +4 -0
- package/lib/cjs/function/matrix/ctranspose.js +1 -1
- package/lib/cjs/function/matrix/{apply.js → mapSlices.js} +19 -12
- package/lib/cjs/function/matrix/matrixFromFunction.js +36 -3
- package/lib/cjs/function/matrix/range.js +54 -5
- package/lib/cjs/function/probability/randomInt.js +26 -3
- package/lib/cjs/function/relational/larger.js +12 -4
- package/lib/cjs/function/relational/smaller.js +12 -4
- package/lib/cjs/function/statistics/max.js +1 -1
- package/lib/cjs/function/statistics/min.js +1 -1
- package/lib/cjs/function/statistics/quantileSeq.js +4 -9
- package/lib/cjs/function/statistics/variance.js +3 -3
- package/lib/cjs/function/string/hex.js +1 -1
- package/lib/cjs/function/string/print.js +2 -2
- package/lib/cjs/function/trigonometry/acoth.js +1 -1
- package/lib/cjs/function/trigonometry/acsc.js +1 -1
- package/lib/cjs/function/trigonometry/asin.js +1 -1
- package/lib/cjs/function/trigonometry/atan2.js +2 -1
- package/lib/cjs/function/trigonometry/cos.js +1 -1
- package/lib/cjs/function/trigonometry/sin.js +1 -1
- package/lib/cjs/function/utils/isInteger.js +1 -1
- package/lib/cjs/header.js +3 -3
- package/lib/cjs/type/matrix/MatrixIndex.js +6 -3
- package/lib/cjs/type/matrix/Range.js +15 -8
- package/lib/cjs/utils/bigint.js +33 -0
- package/lib/cjs/utils/factory.js +5 -2
- package/lib/cjs/utils/number.js +7 -19
- package/lib/cjs/utils/snapshot.js +8 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +14 -4
- package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/esm/entry/{dependenciesNumber/dependenciesApply.generated.js → dependenciesAny/dependenciesMapSlices.generated.js} +3 -3
- package/lib/esm/entry/{dependenciesNumber/dependenciesApplyTransform.generated.js → dependenciesAny/dependenciesMapSlicesTransform.generated.js} +3 -3
- package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesVariance.generated.js +2 -2
- package/lib/esm/entry/dependenciesAny/dependenciesVarianceTransform.generated.js +2 -2
- package/lib/esm/entry/dependenciesAny.generated.js +2 -2
- package/lib/esm/entry/{dependenciesAny/dependenciesApply.generated.js → dependenciesNumber/dependenciesMapSlices.generated.js} +3 -3
- package/lib/esm/entry/{dependenciesAny/dependenciesApplyTransform.generated.js → dependenciesNumber/dependenciesMapSlicesTransform.generated.js} +3 -3
- package/lib/esm/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesVariance.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesVarianceTransform.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber.generated.js +2 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +88 -87
- package/lib/esm/entry/impureFunctionsNumber.generated.js +16 -16
- package/lib/esm/entry/pureFunctionsAny.generated.js +328 -323
- package/lib/esm/entry/pureFunctionsNumber.generated.js +17 -14
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/esm/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/mapSlices.js +11 -0
- package/lib/esm/expression/transform/index.transform.js +3 -3
- package/lib/esm/expression/transform/mapSlices.transform.js +47 -0
- package/lib/esm/expression/transform/quantileSeq.transform.js +5 -3
- package/lib/esm/expression/transform/variance.transform.js +3 -3
- package/lib/esm/factoriesAny.js +2 -2
- package/lib/esm/factoriesNumber.js +2 -2
- package/lib/esm/function/arithmetic/ceil.js +35 -27
- package/lib/esm/function/arithmetic/fix.js +3 -0
- package/lib/esm/function/arithmetic/floor.js +42 -27
- package/lib/esm/function/arithmetic/log.js +12 -5
- package/lib/esm/function/arithmetic/log10.js +16 -8
- package/lib/esm/function/arithmetic/log2.js +9 -4
- package/lib/esm/function/arithmetic/round.js +4 -0
- package/lib/esm/function/matrix/ctranspose.js +1 -1
- package/lib/esm/function/matrix/{apply.js → mapSlices.js} +18 -11
- package/lib/esm/function/matrix/matrixFromFunction.js +36 -3
- package/lib/esm/function/matrix/range.js +54 -5
- package/lib/esm/function/probability/randomInt.js +26 -3
- package/lib/esm/function/relational/larger.js +12 -4
- package/lib/esm/function/relational/smaller.js +12 -4
- package/lib/esm/function/statistics/max.js +1 -1
- package/lib/esm/function/statistics/min.js +1 -1
- package/lib/esm/function/statistics/quantileSeq.js +4 -9
- package/lib/esm/function/statistics/variance.js +3 -3
- package/lib/esm/function/string/hex.js +1 -1
- package/lib/esm/function/string/print.js +2 -2
- package/lib/esm/function/trigonometry/acoth.js +1 -1
- package/lib/esm/function/trigonometry/acsc.js +1 -1
- package/lib/esm/function/trigonometry/asin.js +1 -1
- package/lib/esm/function/trigonometry/atan2.js +2 -1
- package/lib/esm/function/trigonometry/cos.js +1 -1
- package/lib/esm/function/trigonometry/sin.js +1 -1
- package/lib/esm/function/utils/isInteger.js +1 -1
- package/lib/esm/header.js +1 -1
- package/lib/esm/type/matrix/MatrixIndex.js +6 -3
- package/lib/esm/type/matrix/Range.js +16 -9
- package/lib/esm/utils/bigint.js +27 -0
- package/lib/esm/utils/factory.js +5 -2
- package/lib/esm/utils/number.js +6 -17
- package/lib/esm/utils/snapshot.js +8 -1
- package/lib/esm/version.js +1 -1
- package/package.json +13 -11
- package/types/index.d.ts +75 -12
- package/lib/esm/expression/transform/apply.transform.js +0 -44
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createLog10 = void 0;
|
7
|
-
var _factory = require("../../utils/factory.js");
|
8
|
-
var _collection = require("../../utils/collection.js");
|
9
7
|
var _index = require("../../plain/number/index.js");
|
8
|
+
var _bigint = require("../../utils/bigint.js");
|
9
|
+
var _collection = require("../../utils/collection.js");
|
10
|
+
var _factory = require("../../utils/factory.js");
|
10
11
|
const name = 'log10';
|
11
12
|
const dependencies = ['typed', 'config', 'Complex'];
|
13
|
+
const log16 = (0, _index.log10Number)(16);
|
12
14
|
const createLog10 = exports.createLog10 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
13
15
|
let {
|
14
16
|
typed,
|
@@ -40,24 +42,30 @@ const createLog10 = exports.createLog10 = /* #__PURE__ */(0, _factory.factory)(n
|
|
40
42
|
* @return {number | BigNumber | Complex | Array | Matrix}
|
41
43
|
* Returns the 10-base logarithm of `x`
|
42
44
|
*/
|
45
|
+
|
46
|
+
function complexLog(c) {
|
47
|
+
return c.log().div(Math.LN10);
|
48
|
+
}
|
49
|
+
function complexLogNumber(x) {
|
50
|
+
return complexLog(new Complex(x, 0));
|
51
|
+
}
|
43
52
|
return typed(name, {
|
44
53
|
number: function (x) {
|
45
54
|
if (x >= 0 || config.predictable) {
|
46
55
|
return (0, _index.log10Number)(x);
|
47
56
|
} else {
|
48
57
|
// negative value -> complex value computation
|
49
|
-
return
|
58
|
+
return complexLogNumber(x);
|
50
59
|
}
|
51
60
|
},
|
52
|
-
|
53
|
-
|
54
|
-
},
|
61
|
+
bigint: (0, _bigint.promoteLogarithm)(log16, _index.log10Number, config, complexLogNumber),
|
62
|
+
Complex: complexLog,
|
55
63
|
BigNumber: function (x) {
|
56
64
|
if (!x.isNegative() || config.predictable) {
|
57
65
|
return x.log();
|
58
66
|
} else {
|
59
67
|
// downgrade to number, return Complex valued result
|
60
|
-
return
|
68
|
+
return complexLogNumber(x.toNumber());
|
61
69
|
}
|
62
70
|
},
|
63
71
|
'Array | Matrix': typed.referToSelf(self => x => (0, _collection.deepMap)(x, self))
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createLog2 = void 0;
|
7
|
-
var _factory = require("../../utils/factory.js");
|
8
|
-
var _collection = require("../../utils/collection.js");
|
9
7
|
var _index = require("../../plain/number/index.js");
|
8
|
+
var _bigint = require("../../utils/bigint.js");
|
9
|
+
var _collection = require("../../utils/collection.js");
|
10
|
+
var _factory = require("../../utils/factory.js");
|
10
11
|
const name = 'log2';
|
11
12
|
const dependencies = ['typed', 'config', 'Complex'];
|
12
13
|
const createLog2 = exports.createLog2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
@@ -40,22 +41,26 @@ const createLog2 = exports.createLog2 = /* #__PURE__ */(0, _factory.factory)(nam
|
|
40
41
|
* @return {number | BigNumber | Complex | Array | Matrix}
|
41
42
|
* Returns the 2-base logarithm of `x`
|
42
43
|
*/
|
44
|
+
function complexLog2Number(x) {
|
45
|
+
return _log2Complex(new Complex(x, 0));
|
46
|
+
}
|
43
47
|
return typed(name, {
|
44
48
|
number: function (x) {
|
45
49
|
if (x >= 0 || config.predictable) {
|
46
50
|
return (0, _index.log2Number)(x);
|
47
51
|
} else {
|
48
52
|
// negative value -> complex value computation
|
49
|
-
return
|
53
|
+
return complexLog2Number(x);
|
50
54
|
}
|
51
55
|
},
|
56
|
+
bigint: (0, _bigint.promoteLogarithm)(4, _index.log2Number, config, complexLog2Number),
|
52
57
|
Complex: _log2Complex,
|
53
58
|
BigNumber: function (x) {
|
54
59
|
if (!x.isNegative() || config.predictable) {
|
55
60
|
return x.log(2);
|
56
61
|
} else {
|
57
62
|
// downgrade to number, return Complex valued result
|
58
|
-
return
|
63
|
+
return complexLog2Number(x.toNumber());
|
59
64
|
}
|
60
65
|
},
|
61
66
|
'Array | Matrix': typed.referToSelf(self => x => (0, _collection.deepMap)(x, self))
|
@@ -143,6 +143,10 @@ const createRound = exports.createRound = /* #__PURE__ */(0, _factory.factory)(n
|
|
143
143
|
const xSelected = (0, _nearlyEqual.nearlyEqual)(x, xEpsilon, config.relTol, config.absTol) ? xEpsilon : x;
|
144
144
|
return xSelected.toDecimalPlaces(n.toNumber());
|
145
145
|
},
|
146
|
+
// bigints can't be rounded
|
147
|
+
bigint: b => b,
|
148
|
+
'bigint, number': (b, _dummy) => b,
|
149
|
+
'bigint, BigNumber': (b, _dummy) => b,
|
146
150
|
Fraction: function (x) {
|
147
151
|
return x.round();
|
148
152
|
},
|
@@ -26,7 +26,7 @@ const createCtranspose = exports.createCtranspose = /* #__PURE__ */(0, _factory.
|
|
26
26
|
* Examples:
|
27
27
|
*
|
28
28
|
* const A = [[1, 2, 3], [4, 5, math.complex(6,7)]]
|
29
|
-
* math.ctranspose(A)
|
29
|
+
* math.ctranspose(A) // returns [[1, 4], [2, 5], [3, {re:6,im:-7}]]
|
30
30
|
*
|
31
31
|
* See also:
|
32
32
|
*
|
@@ -3,14 +3,14 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.createMapSlices = void 0;
|
7
7
|
var _factory = require("../../utils/factory.js");
|
8
8
|
var _array = require("../../utils/array.js");
|
9
9
|
var _is = require("../../utils/is.js");
|
10
10
|
var _IndexError = require("../../error/IndexError.js");
|
11
|
-
const name = '
|
11
|
+
const name = 'mapSlices';
|
12
12
|
const dependencies = ['typed', 'isInteger'];
|
13
|
-
const
|
13
|
+
const createMapSlices = exports.createMapSlices = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
14
14
|
let {
|
15
15
|
typed,
|
16
16
|
isInteger
|
@@ -22,7 +22,7 @@ const createApply = exports.createApply = /* #__PURE__ */(0, _factory.factory)(n
|
|
22
22
|
*
|
23
23
|
* Syntax:
|
24
24
|
*
|
25
|
-
* math.
|
25
|
+
* math.mapSlices(A, dim, callback)
|
26
26
|
*
|
27
27
|
* Where:
|
28
28
|
*
|
@@ -33,19 +33,24 @@ const createApply = exports.createApply = /* #__PURE__ */(0, _factory.factory)(n
|
|
33
33
|
* const A = [[1, 2], [3, 4]]
|
34
34
|
* const sum = math.sum
|
35
35
|
*
|
36
|
-
* math.
|
37
|
-
* math.
|
36
|
+
* math.mapSlices(A, 0, sum) // returns [4, 6]
|
37
|
+
* math.mapSlices(A, 1, sum) // returns [3, 7]
|
38
38
|
*
|
39
39
|
* See also:
|
40
40
|
*
|
41
41
|
* map, filter, forEach
|
42
42
|
*
|
43
|
+
* Note:
|
44
|
+
*
|
45
|
+
* `mapSlices()` is also currently available via its deprecated
|
46
|
+
* synonym `apply()`.
|
47
|
+
*
|
43
48
|
* @param {Array | Matrix} array The input Matrix
|
44
49
|
* @param {number} dim The dimension along which the callback is applied
|
45
50
|
* @param {Function} callback The callback function that is applied. This Function
|
46
51
|
* should take an array or 1-d matrix as an input and
|
47
52
|
* return a number.
|
48
|
-
* @return {Array | Matrix} res The residual matrix with the function
|
53
|
+
* @return {Array | Matrix} res The residual matrix with the function mapped on the slices over some dimension.
|
49
54
|
*/
|
50
55
|
return typed(name, {
|
51
56
|
'Array | Matrix, number | BigNumber, function': function (mat, dim, callback) {
|
@@ -57,12 +62,14 @@ const createApply = exports.createApply = /* #__PURE__ */(0, _factory.factory)(n
|
|
57
62
|
throw new _IndexError.IndexError(dim, size.length);
|
58
63
|
}
|
59
64
|
if ((0, _is.isMatrix)(mat)) {
|
60
|
-
return mat.create(
|
65
|
+
return mat.create(_mapSlices(mat.valueOf(), dim, callback), mat.datatype());
|
61
66
|
} else {
|
62
|
-
return
|
67
|
+
return _mapSlices(mat, dim, callback);
|
63
68
|
}
|
64
69
|
}
|
65
70
|
});
|
71
|
+
}, {
|
72
|
+
formerly: 'apply'
|
66
73
|
});
|
67
74
|
|
68
75
|
/**
|
@@ -73,7 +80,7 @@ const createApply = exports.createApply = /* #__PURE__ */(0, _factory.factory)(n
|
|
73
80
|
* @returns {Array} ret
|
74
81
|
* @private
|
75
82
|
*/
|
76
|
-
function
|
83
|
+
function _mapSlices(mat, dim, callback) {
|
77
84
|
let i, ret, tran;
|
78
85
|
if (dim <= 0) {
|
79
86
|
if (!Array.isArray(mat[0])) {
|
@@ -82,14 +89,14 @@ function _apply(mat, dim, callback) {
|
|
82
89
|
tran = _switch(mat);
|
83
90
|
ret = [];
|
84
91
|
for (i = 0; i < tran.length; i++) {
|
85
|
-
ret[i] =
|
92
|
+
ret[i] = _mapSlices(tran[i], dim - 1, callback);
|
86
93
|
}
|
87
94
|
return ret;
|
88
95
|
}
|
89
96
|
} else {
|
90
97
|
ret = [];
|
91
98
|
for (i = 0; i < mat.length; i++) {
|
92
|
-
ret[i] =
|
99
|
+
ret[i] = _mapSlices(mat[i], dim - 1, callback);
|
93
100
|
}
|
94
101
|
return ret;
|
95
102
|
}
|
@@ -15,8 +15,10 @@ const createMatrixFromFunction = exports.createMatrixFromFunction = /* #__PURE__
|
|
15
15
|
} = _ref;
|
16
16
|
/**
|
17
17
|
* Create a matrix by evaluating a generating function at each index.
|
18
|
-
* The simplest overload returns a multi-dimensional array as long as `size`
|
19
|
-
*
|
18
|
+
* The simplest overload returns a multi-dimensional array as long as `size`
|
19
|
+
* is an array.
|
20
|
+
* Passing `size` as a Matrix or specifying a `format` will result in
|
21
|
+
* returning a Matrix.
|
20
22
|
*
|
21
23
|
* Syntax:
|
22
24
|
*
|
@@ -26,6 +28,37 @@ const createMatrixFromFunction = exports.createMatrixFromFunction = /* #__PURE__
|
|
26
28
|
* math.matrixFromFunction(size, format, fn)
|
27
29
|
* math.matrixFromFunction(size, format, datatype, fn)
|
28
30
|
*
|
31
|
+
* Where:
|
32
|
+
*
|
33
|
+
* - `size: (number[] | Matrix)`
|
34
|
+
* A vector giving the extent of the array to be created in each
|
35
|
+
* dimension. If size has one entry, a vector is created; if it
|
36
|
+
* has two, a rectangular array/Matrix is created; if three, a
|
37
|
+
* three-dimensional array/Matrix is created; and so on.
|
38
|
+
* - `fn: (index: number[]) => MathType`
|
39
|
+
* The callback function that will generate the entries of the
|
40
|
+
* matrix. It is called in turn with the index of each entry of
|
41
|
+
* the matrix. The index is always an ordinary array of numbers
|
42
|
+
* with the same length as _size_. So for vectors, you will get
|
43
|
+
* indices like `[0]` or `[1]`, whereas for matrices, you will
|
44
|
+
* get indices like `[2, 0]` or `[1,3]`. The return value may
|
45
|
+
* be any type that can go in an array or Matrix entry, although
|
46
|
+
* if you supply the _datatype_ argument, you must yourself ensure
|
47
|
+
* the type of the return value matches. Note that currently,
|
48
|
+
* your callback _fn_ will receive 0-based indices for the matrix
|
49
|
+
* entries, regardless of whether matrixFromFunction is invoked
|
50
|
+
* directly from JavaScript or via the mathjs expression language.
|
51
|
+
* - `format: 'dense'|'sparse'`
|
52
|
+
* Specifies the storage format for the resulting Matrix. Note that
|
53
|
+
* if this argument is given, the return value will always be a
|
54
|
+
* Matrix (rather than possibly an Array).
|
55
|
+
* - `datatype: string`
|
56
|
+
* Specifies the data type of entries of the new matrix. If given,
|
57
|
+
* it should be the name of a data type that mathjs supports, as
|
58
|
+
* returned by the math.typeOf function. It is up to the caller
|
59
|
+
* to make certain that all values returned by _fn_ are consistent
|
60
|
+
* with this datatype if specified.
|
61
|
+
*
|
29
62
|
* Examples:
|
30
63
|
*
|
31
64
|
* math.matrixFromFunction([3,3], i => i[0] - i[1]) // an antisymmetric matrix
|
@@ -34,7 +67,7 @@ const createMatrixFromFunction = exports.createMatrixFromFunction = /* #__PURE__
|
|
34
67
|
*
|
35
68
|
* See also:
|
36
69
|
*
|
37
|
-
* matrix, zeros
|
70
|
+
* matrix, typeOf, zeros
|
38
71
|
*
|
39
72
|
* @param {Array | Matrix} size The size of the matrix to be created
|
40
73
|
* @param {function} fn Callback function invoked for every entry in the matrix
|
@@ -41,36 +41,48 @@ const createRange = exports.createRange = /* #__PURE__ */(0, _factory.factory)(n
|
|
41
41
|
*
|
42
42
|
* - `str: string`
|
43
43
|
* A string 'start:end' or 'start:step:end'
|
44
|
-
* - `start: {number | BigNumber | Unit}`
|
44
|
+
* - `start: {number | bigint | BigNumber | Fraction | Unit}`
|
45
45
|
* Start of the range
|
46
|
-
* - `end: number | BigNumber | Unit`
|
46
|
+
* - `end: number | bigint | BigNumber | Fraction | Unit`
|
47
47
|
* End of the range, excluded by default, included when parameter includeEnd=true
|
48
|
-
* - `step: number | BigNumber | Unit`
|
48
|
+
* - `step: number | bigint | BigNumber | Fraction | Unit`
|
49
49
|
* Step size. Default value is 1.
|
50
50
|
* - `includeEnd: boolean`
|
51
51
|
* Option to specify whether to include the end or not. False by default.
|
52
52
|
*
|
53
|
+
* Note that the return type of the range is taken from the type of
|
54
|
+
* the start/end. If only one these is a built-in `number` type, it will
|
55
|
+
* be promoted to the type of the other endpoint. However, in the case of
|
56
|
+
* Unit values, both endpoints must have compatible units, and the return
|
57
|
+
* value will have compatible units as well.
|
58
|
+
*
|
53
59
|
* Examples:
|
54
60
|
*
|
55
61
|
* math.range(2, 6) // [2, 3, 4, 5]
|
56
62
|
* math.range(2, -3, -1) // [2, 1, 0, -1, -2]
|
57
63
|
* math.range('2:1:6') // [2, 3, 4, 5]
|
58
64
|
* math.range(2, 6, true) // [2, 3, 4, 5, 6]
|
65
|
+
* math.range(2, math.fraction(8,3), math.fraction(1,3)) // [fraction(2), fraction(7,3)]
|
59
66
|
* math.range(math.unit(2, 'm'), math.unit(-3, 'm'), math.unit(-1, 'm')) // [2 m, 1 m, 0 m , -1 m, -2 m]
|
60
67
|
*
|
61
68
|
* See also:
|
62
69
|
*
|
63
70
|
* ones, zeros, size, subset
|
64
71
|
*
|
65
|
-
* @param {*} args Parameters describing the
|
72
|
+
* @param {*} args Parameters describing the range's `start`, `end`, and optional `step`.
|
66
73
|
* @return {Array | Matrix} range
|
67
74
|
*/
|
68
75
|
return typed(name, {
|
69
76
|
// TODO: simplify signatures when typed-function supports default values and optional arguments
|
70
77
|
|
71
|
-
// TODO: a number or boolean should not be converted to string here
|
72
78
|
string: _strRange,
|
73
79
|
'string, boolean': _strRange,
|
80
|
+
number: function (oops) {
|
81
|
+
throw new TypeError(`Too few arguments to function range(): ${oops}`);
|
82
|
+
},
|
83
|
+
boolean: function (oops) {
|
84
|
+
throw new TypeError(`Unexpected type of argument 1 to function range(): ${oops}, number|bigint|BigNumber|Fraction`);
|
85
|
+
},
|
74
86
|
'number, number': function (start, end) {
|
75
87
|
return _out(_range(start, end, 1, false));
|
76
88
|
},
|
@@ -83,6 +95,31 @@ const createRange = exports.createRange = /* #__PURE__ */(0, _factory.factory)(n
|
|
83
95
|
'number, number, number, boolean': function (start, end, step, includeEnd) {
|
84
96
|
return _out(_range(start, end, step, includeEnd));
|
85
97
|
},
|
98
|
+
// Handle bigints; if either limit is bigint, range should be too
|
99
|
+
'bigint, bigint|number': function (start, end) {
|
100
|
+
return _out(_range(start, end, 1n, false));
|
101
|
+
},
|
102
|
+
'number, bigint': function (start, end) {
|
103
|
+
return _out(_range(BigInt(start), end, 1n, false));
|
104
|
+
},
|
105
|
+
'bigint, bigint|number, bigint|number': function (start, end, step) {
|
106
|
+
return _out(_range(start, end, BigInt(step), false));
|
107
|
+
},
|
108
|
+
'number, bigint, bigint|number': function (start, end, step) {
|
109
|
+
return _out(_range(BigInt(start), end, BigInt(step), false));
|
110
|
+
},
|
111
|
+
'bigint, bigint|number, boolean': function (start, end, includeEnd) {
|
112
|
+
return _out(_range(start, end, 1n, includeEnd));
|
113
|
+
},
|
114
|
+
'number, bigint, boolean': function (start, end, includeEnd) {
|
115
|
+
return _out(_range(BigInt(start), end, 1n, includeEnd));
|
116
|
+
},
|
117
|
+
'bigint, bigint|number, bigint|number, boolean': function (start, end, step, includeEnd) {
|
118
|
+
return _out(_range(start, end, BigInt(step), includeEnd));
|
119
|
+
},
|
120
|
+
'number, bigint, bigint|number, boolean': function (start, end, step, includeEnd) {
|
121
|
+
return _out(_range(BigInt(start), end, BigInt(step), includeEnd));
|
122
|
+
},
|
86
123
|
'BigNumber, BigNumber': function (start, end) {
|
87
124
|
const BigNumber = start.constructor;
|
88
125
|
return _out(_range(start, end, new BigNumber(1), false));
|
@@ -97,6 +134,18 @@ const createRange = exports.createRange = /* #__PURE__ */(0, _factory.factory)(n
|
|
97
134
|
'BigNumber, BigNumber, BigNumber, boolean': function (start, end, step, includeEnd) {
|
98
135
|
return _out(_range(start, end, step, includeEnd));
|
99
136
|
},
|
137
|
+
'Fraction, Fraction': function (start, end) {
|
138
|
+
return _out(_range(start, end, 1, false));
|
139
|
+
},
|
140
|
+
'Fraction, Fraction, Fraction': function (start, end, step) {
|
141
|
+
return _out(_range(start, end, step, false));
|
142
|
+
},
|
143
|
+
'Fraction, Fraction, boolean': function (start, end, includeEnd) {
|
144
|
+
return _out(_range(start, end, 1, includeEnd));
|
145
|
+
},
|
146
|
+
'Fraction, Fraction, Fraction, boolean': function (start, end, step, includeEnd) {
|
147
|
+
return _out(_range(start, end, step, includeEnd));
|
148
|
+
},
|
100
149
|
'Unit, Unit, Unit': function (start, end, step) {
|
101
150
|
return _out(_range(start, end, step, false));
|
102
151
|
},
|
@@ -9,11 +9,13 @@ var _randomMatrix = require("./util/randomMatrix.js");
|
|
9
9
|
var _seededRNG = require("./util/seededRNG.js");
|
10
10
|
var _is = require("../../utils/is.js");
|
11
11
|
const name = 'randomInt';
|
12
|
-
const dependencies = ['typed', 'config', '?on'];
|
12
|
+
const dependencies = ['typed', 'config', 'log2', '?on'];
|
13
|
+
const simpleCutoff = 2n ** 30n;
|
13
14
|
const createRandomInt = exports.createRandomInt = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
14
15
|
let {
|
15
16
|
typed,
|
16
17
|
config,
|
18
|
+
log2,
|
17
19
|
on
|
18
20
|
} = _ref;
|
19
21
|
// seeded pseudo random number generator
|
@@ -32,7 +34,7 @@ const createRandomInt = exports.createRandomInt = /* #__PURE__ */(0, _factory.fa
|
|
32
34
|
*
|
33
35
|
* Syntax:
|
34
36
|
*
|
35
|
-
* math.randomInt() // generate
|
37
|
+
* math.randomInt() // generate either 0 or 1, randomly
|
36
38
|
* math.randomInt(max) // generate a random integer between 0 and max
|
37
39
|
* math.randomInt(min, max) // generate a random integer between min and max
|
38
40
|
* math.randomInt(size) // generate a matrix with random integer between 0 and 1
|
@@ -56,9 +58,11 @@ const createRandomInt = exports.createRandomInt = /* #__PURE__ */(0, _factory.fa
|
|
56
58
|
* @return {number | Array | Matrix} A random integer value
|
57
59
|
*/
|
58
60
|
return typed(name, {
|
59
|
-
'': () => _randomInt(0,
|
61
|
+
'': () => _randomInt(0, 2),
|
60
62
|
number: max => _randomInt(0, max),
|
61
63
|
'number, number': (min, max) => _randomInt(min, max),
|
64
|
+
bigint: max => _randomBigint(0n, max),
|
65
|
+
'bigint, bigint': _randomBigint,
|
62
66
|
'Array | Matrix': size => _randomIntMatrix(size, 0, 1),
|
63
67
|
'Array | Matrix, number': (size, max) => _randomIntMatrix(size, 0, max),
|
64
68
|
'Array | Matrix, number, number': (size, min, max) => _randomIntMatrix(size, min, max)
|
@@ -70,4 +74,23 @@ const createRandomInt = exports.createRandomInt = /* #__PURE__ */(0, _factory.fa
|
|
70
74
|
function _randomInt(min, max) {
|
71
75
|
return Math.floor(min + rng() * (max - min));
|
72
76
|
}
|
77
|
+
function _randomBigint(min, max) {
|
78
|
+
const width = max - min; // number of choices
|
79
|
+
if (width <= simpleCutoff) {
|
80
|
+
// do it with number type
|
81
|
+
return min + BigInt(_randomInt(0, Number(width)));
|
82
|
+
}
|
83
|
+
// Too big to choose accurately that way. Instead, choose the correct
|
84
|
+
// number of random bits to cover the width, and repeat until the
|
85
|
+
// resulting number falls within the width
|
86
|
+
const bits = log2(width);
|
87
|
+
let picked = width;
|
88
|
+
while (picked >= width) {
|
89
|
+
picked = 0n;
|
90
|
+
for (let i = 0; i < bits; ++i) {
|
91
|
+
picked = 2n * picked + (rng() < 0.5 ? 0n : 1n);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return min + picked;
|
95
|
+
}
|
73
96
|
});
|
@@ -13,11 +13,12 @@ var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
|
|
13
13
|
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
|
14
14
|
var _compareUnits = require("./compareUnits.js");
|
15
15
|
const name = 'larger';
|
16
|
-
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
16
|
+
const dependencies = ['typed', 'config', 'bignumber', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
17
17
|
const createLarger = exports.createLarger = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
18
18
|
let {
|
19
19
|
typed,
|
20
20
|
config,
|
21
|
+
bignumber,
|
21
22
|
matrix,
|
22
23
|
DenseMatrix,
|
23
24
|
concat,
|
@@ -74,16 +75,23 @@ const createLarger = exports.createLarger = /* #__PURE__ */(0, _factory.factory)
|
|
74
75
|
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
|
75
76
|
* @return {boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
|
76
77
|
*/
|
78
|
+
function bignumLarger(x, y) {
|
79
|
+
return x.gt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
|
80
|
+
}
|
77
81
|
return typed(name, createLargerNumber({
|
78
82
|
typed,
|
79
83
|
config
|
80
84
|
}), {
|
81
85
|
'boolean, boolean': (x, y) => x > y,
|
82
|
-
'BigNumber, BigNumber':
|
83
|
-
return x.gt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
|
84
|
-
},
|
86
|
+
'BigNumber, BigNumber': bignumLarger,
|
85
87
|
'bigint, bigint': (x, y) => x > y,
|
86
88
|
'Fraction, Fraction': (x, y) => x.compare(y) === 1,
|
89
|
+
'Fraction, BigNumber': function (x, y) {
|
90
|
+
return bignumLarger(bignumber(x), y);
|
91
|
+
},
|
92
|
+
'BigNumber, Fraction': function (x, y) {
|
93
|
+
return bignumLarger(x, bignumber(y));
|
94
|
+
},
|
87
95
|
'Complex, Complex': function () {
|
88
96
|
throw new TypeError('No ordering relation is defined for complex numbers');
|
89
97
|
}
|
@@ -13,11 +13,12 @@ var _matAlgo12xSfs = require("../../type/matrix/utils/matAlgo12xSfs.js");
|
|
13
13
|
var _matrixAlgorithmSuite = require("../../type/matrix/utils/matrixAlgorithmSuite.js");
|
14
14
|
var _compareUnits = require("./compareUnits.js");
|
15
15
|
const name = 'smaller';
|
16
|
-
const dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
16
|
+
const dependencies = ['typed', 'config', 'bignumber', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
17
17
|
const createSmaller = exports.createSmaller = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
18
18
|
let {
|
19
19
|
typed,
|
20
20
|
config,
|
21
|
+
bignumber,
|
21
22
|
matrix,
|
22
23
|
DenseMatrix,
|
23
24
|
concat,
|
@@ -74,16 +75,23 @@ const createSmaller = exports.createSmaller = /* #__PURE__ */(0, _factory.factor
|
|
74
75
|
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
|
75
76
|
* @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
|
76
77
|
*/
|
78
|
+
function bignumSmaller(x, y) {
|
79
|
+
return x.lt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
|
80
|
+
}
|
77
81
|
return typed(name, createSmallerNumber({
|
78
82
|
typed,
|
79
83
|
config
|
80
84
|
}), {
|
81
85
|
'boolean, boolean': (x, y) => x < y,
|
82
|
-
'BigNumber, BigNumber':
|
83
|
-
return x.lt(y) && !(0, _nearlyEqual.nearlyEqual)(x, y, config.relTol, config.absTol);
|
84
|
-
},
|
86
|
+
'BigNumber, BigNumber': bignumSmaller,
|
85
87
|
'bigint, bigint': (x, y) => x < y,
|
86
88
|
'Fraction, Fraction': (x, y) => x.compare(y) === -1,
|
89
|
+
'Fraction, BigNumber': function (x, y) {
|
90
|
+
return bignumSmaller(bignumber(x), y);
|
91
|
+
},
|
92
|
+
'BigNumber, Fraction': function (x, y) {
|
93
|
+
return bignumSmaller(x, bignumber(y));
|
94
|
+
},
|
87
95
|
'Complex, Complex': function (x, y) {
|
88
96
|
throw new TypeError('No ordering relation is defined for complex numbers');
|
89
97
|
}
|
@@ -89,7 +89,7 @@ const createMax = exports.createMax = /* #__PURE__ */(0, _factory.factory)(name,
|
|
89
89
|
let res;
|
90
90
|
(0, _collection.deepForEach)(array, function (value) {
|
91
91
|
try {
|
92
|
-
if (
|
92
|
+
if (typeof value === 'number' && isNaN(value)) {
|
93
93
|
res = NaN;
|
94
94
|
} else if (res === undefined || larger(value, res)) {
|
95
95
|
res = value;
|
@@ -89,7 +89,7 @@ const createMin = exports.createMin = /* #__PURE__ */(0, _factory.factory)(name,
|
|
89
89
|
let min;
|
90
90
|
(0, _collection.deepForEach)(array, function (value) {
|
91
91
|
try {
|
92
|
-
if (
|
92
|
+
if (typeof value === 'number' && isNaN(value)) {
|
93
93
|
min = NaN;
|
94
94
|
} else if (min === undefined || smaller(value, min)) {
|
95
95
|
min = value;
|
@@ -7,9 +7,8 @@ exports.createQuantileSeq = void 0;
|
|
7
7
|
var _is = require("../../utils/is.js");
|
8
8
|
var _array = require("../../utils/array.js");
|
9
9
|
var _factory = require("../../utils/factory.js");
|
10
|
-
var _apply = require("../matrix/apply.js");
|
11
10
|
const name = 'quantileSeq';
|
12
|
-
const dependencies = ['typed', '?bignumber', 'add', 'subtract', 'divide', 'multiply', 'partitionSelect', 'compare', 'isInteger', 'smaller', 'smallerEq', 'larger'];
|
11
|
+
const dependencies = ['typed', '?bignumber', 'add', 'subtract', 'divide', 'multiply', 'partitionSelect', 'compare', 'isInteger', 'smaller', 'smallerEq', 'larger', 'mapSlices'];
|
13
12
|
const createQuantileSeq = exports.createQuantileSeq = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
14
13
|
let {
|
15
14
|
typed,
|
@@ -23,13 +22,9 @@ const createQuantileSeq = exports.createQuantileSeq = /* #__PURE__ */(0, _factor
|
|
23
22
|
isInteger,
|
24
23
|
smaller,
|
25
24
|
smallerEq,
|
26
|
-
larger
|
25
|
+
larger,
|
26
|
+
mapSlices
|
27
27
|
} = _ref;
|
28
|
-
const apply = (0, _apply.createApply)({
|
29
|
-
typed,
|
30
|
-
isInteger
|
31
|
-
});
|
32
|
-
|
33
28
|
/**
|
34
29
|
* Compute the prob order quantile of a matrix or a list with values.
|
35
30
|
* The sequence is sorted and the middle value is returned.
|
@@ -75,7 +70,7 @@ const createQuantileSeq = exports.createQuantileSeq = /* #__PURE__ */(0, _factor
|
|
75
70
|
'Array | Matrix, Array | Matrix, boolean, number': (data, prob, sorted, dim) => _quantileSeqDim(data, prob, sorted, dim, _quantileSeqProbCollection)
|
76
71
|
});
|
77
72
|
function _quantileSeqDim(data, prob, sorted, dim, fn) {
|
78
|
-
return
|
73
|
+
return mapSlices(data, dim, x => fn(x, prob, sorted));
|
79
74
|
}
|
80
75
|
function _quantileSeqProbNumber(data, probOrN, sorted) {
|
81
76
|
let probArr;
|
@@ -10,7 +10,7 @@ var _factory = require("../../utils/factory.js");
|
|
10
10
|
var _improveErrorMessage = require("./utils/improveErrorMessage.js");
|
11
11
|
const DEFAULT_NORMALIZATION = 'unbiased';
|
12
12
|
const name = 'variance';
|
13
|
-
const dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', '
|
13
|
+
const dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'mapSlices', 'isNaN'];
|
14
14
|
const createVariance = exports.createVariance = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
15
15
|
let {
|
16
16
|
typed,
|
@@ -18,7 +18,7 @@ const createVariance = exports.createVariance = /* #__PURE__ */(0, _factory.fact
|
|
18
18
|
subtract,
|
19
19
|
multiply,
|
20
20
|
divide,
|
21
|
-
|
21
|
+
mapSlices,
|
22
22
|
isNaN
|
23
23
|
} = _ref;
|
24
24
|
/**
|
@@ -151,7 +151,7 @@ const createVariance = exports.createVariance = /* #__PURE__ */(0, _factory.fact
|
|
151
151
|
if (array.length === 0) {
|
152
152
|
throw new SyntaxError('Function variance requires one or more parameters (0 provided)');
|
153
153
|
}
|
154
|
-
return
|
154
|
+
return mapSlices(array, dim, x => _var(x, normalization));
|
155
155
|
} catch (err) {
|
156
156
|
throw (0, _improveErrorMessage.improveErrorMessage)(err, 'variance');
|
157
157
|
}
|
@@ -31,12 +31,12 @@ const createPrint = exports.createPrint = /* #__PURE__ */(0, _factory.factory)(n
|
|
31
31
|
* // the following outputs: 'The value of pi is 3.141592654'
|
32
32
|
* math.print('The value of pi is $pi', {pi: math.pi}, 10)
|
33
33
|
*
|
34
|
-
* // the following outputs: '
|
34
|
+
* // the following outputs: 'Hello Mary! The date is 2013-03-23'
|
35
35
|
* math.print('Hello $user.name! The date is $date', {
|
36
36
|
* user: {
|
37
37
|
* name: 'Mary',
|
38
38
|
* },
|
39
|
-
* date:
|
39
|
+
* date: '2013-03-23'
|
40
40
|
* })
|
41
41
|
*
|
42
42
|
* // the following outputs: 'My favorite fruits are apples and bananas !'
|
@@ -29,7 +29,7 @@ const createAcsc = exports.createAcsc = /* #__PURE__ */(0, _factory.factory)(nam
|
|
29
29
|
*
|
30
30
|
* math.acsc(2) // returns 0.5235987755982989
|
31
31
|
* math.acsc(0.5) // returns Complex 1.5707963267948966 -1.3169578969248166i
|
32
|
-
* math.acsc(math.csc(1.5)) // returns number
|
32
|
+
* math.acsc(math.csc(1.5)) // returns number 1.5
|
33
33
|
*
|
34
34
|
* See also:
|
35
35
|
*
|