mathjs 14.1.0 → 14.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +11 -0
- 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/core/function/import.js +14 -4
- 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/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/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 +13 -13
- package/lib/cjs/entry/pureFunctionsAny.generated.js +328 -326
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +13 -11
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
- 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/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/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/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/header.js +2 -2
- package/lib/cjs/type/matrix/MatrixIndex.js +6 -3
- package/lib/cjs/type/matrix/Range.js +15 -8
- package/lib/cjs/utils/factory.js +5 -2
- 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/{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/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/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 +15 -15
- package/lib/esm/entry/pureFunctionsAny.generated.js +326 -324
- package/lib/esm/entry/pureFunctionsNumber.generated.js +12 -10
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
- 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/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/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/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/type/matrix/MatrixIndex.js +6 -3
- package/lib/esm/type/matrix/Range.js +16 -9
- package/lib/esm/utils/factory.js +5 -2
- package/lib/esm/utils/snapshot.js +8 -1
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +75 -12
- package/lib/esm/expression/transform/apply.transform.js +0 -44
@@ -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
|
},
|
@@ -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
|
}
|
@@ -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
|
*
|
@@ -26,7 +26,7 @@ const createAsin = exports.createAsin = /* #__PURE__ */(0, _factory.factory)(nam
|
|
26
26
|
* Examples:
|
27
27
|
*
|
28
28
|
* math.asin(0.5) // returns number 0.5235987755982989
|
29
|
-
* math.asin(math.sin(1.5)) // returns number
|
29
|
+
* math.asin(math.sin(1.5)) // returns number 1.5
|
30
30
|
*
|
31
31
|
* math.asin(2) // returns Complex 1.5707963267948966 -1.3169578969248166i
|
32
32
|
*
|
@@ -62,9 +62,10 @@ const createAtan2 = exports.createAtan2 = /* #__PURE__ */(0, _factory.factory)(n
|
|
62
62
|
*
|
63
63
|
* math.atan2(2, 2) / math.pi // returns number 0.25
|
64
64
|
*
|
65
|
-
* const angle = math.unit(60, 'deg')
|
65
|
+
* const angle = math.unit(60, 'deg')
|
66
66
|
* const x = math.cos(angle)
|
67
67
|
* const y = math.sin(angle)
|
68
|
+
* math.atan2(y, x) * 180 / math.pi // returns 60
|
68
69
|
*
|
69
70
|
* math.atan(2) // returns number 1.1071487177940904
|
70
71
|
*
|
@@ -34,7 +34,7 @@ const createCos = exports.createCos = /* #__PURE__ */(0, _factory.factory)(name,
|
|
34
34
|
* math.cos(math.unit(60, 'deg')) // returns number 0.5
|
35
35
|
*
|
36
36
|
* const angle = 0.2
|
37
|
-
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number
|
37
|
+
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number 1
|
38
38
|
*
|
39
39
|
* See also:
|
40
40
|
*
|
@@ -34,7 +34,7 @@ const createSin = exports.createSin = /* #__PURE__ */(0, _factory.factory)(name,
|
|
34
34
|
* math.sin(math.unit(30, 'deg')) // returns number 0.5
|
35
35
|
*
|
36
36
|
* const angle = 0.2
|
37
|
-
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number
|
37
|
+
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number 1
|
38
38
|
*
|
39
39
|
* See also:
|
40
40
|
*
|
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-01-
|
9
|
+
* @version 14.2.0
|
10
|
+
* @date 2025-01-30
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2025 Jos de Jong <wjosdejong@gmail.com>
|
@@ -48,6 +48,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
|
|
48
48
|
const arg = arguments[i];
|
49
49
|
const argIsArray = (0, _is.isArray)(arg);
|
50
50
|
const argIsMatrix = (0, _is.isMatrix)(arg);
|
51
|
+
const argType = typeof arg;
|
51
52
|
let sourceSize = null;
|
52
53
|
if ((0, _is.isRange)(arg)) {
|
53
54
|
this._dimensions.push(arg);
|
@@ -69,13 +70,15 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
|
|
69
70
|
if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
|
70
71
|
this._isScalar = false;
|
71
72
|
}
|
72
|
-
} else if (
|
73
|
+
} else if (argType === 'number') {
|
73
74
|
this._dimensions.push(_createImmutableMatrix([arg]));
|
74
|
-
} else if (
|
75
|
+
} else if (argType === 'bigint') {
|
76
|
+
this._dimensions.push(_createImmutableMatrix([Number(arg)]));
|
77
|
+
} else if (argType === 'string') {
|
75
78
|
// object property (arguments.count should be 1)
|
76
79
|
this._dimensions.push(arg);
|
77
80
|
} else {
|
78
|
-
throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
|
81
|
+
throw new TypeError('Dimension must be an Array, Matrix, number, bigint, string, or Range');
|
79
82
|
}
|
80
83
|
this._sourceSize.push(sourceSize);
|
81
84
|
// TODO: implement support for wildcard '*'
|
@@ -11,14 +11,21 @@ const name = 'Range';
|
|
11
11
|
const dependencies = [];
|
12
12
|
const createRangeClass = exports.createRangeClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, () => {
|
13
13
|
/**
|
14
|
-
* Create a range. A range has a start, step, and end,
|
15
|
-
* to iterate over the range.
|
14
|
+
* Create a range of numbers. A range has a start, step, and end,
|
15
|
+
* and contains functions to iterate over the range.
|
16
16
|
*
|
17
17
|
* A range can be constructed as:
|
18
18
|
*
|
19
19
|
* const range = new Range(start, end)
|
20
20
|
* const range = new Range(start, end, step)
|
21
21
|
*
|
22
|
+
* Note that the endpoints and step may be specified with other numeric
|
23
|
+
* types such as bigint or BigNumber, but they will be demoted to the
|
24
|
+
* built-in `number` type and the Range will only contain numbers. The
|
25
|
+
* rationale for this demotion is that Range objects are primarily used
|
26
|
+
* for indexing Matrix objects, and Matrix objects may only be indexed
|
27
|
+
* with `number`s.
|
28
|
+
*
|
22
29
|
* To get the result of the range:
|
23
30
|
* range.forEach(function (x) {
|
24
31
|
* console.log(x)
|
@@ -51,22 +58,22 @@ const createRangeClass = exports.createRangeClass = /* #__PURE__ */(0, _factory.
|
|
51
58
|
if (hasStart) {
|
52
59
|
if ((0, _is.isBigNumber)(start)) {
|
53
60
|
start = start.toNumber();
|
54
|
-
} else if (typeof start !== 'number') {
|
55
|
-
throw new TypeError('Parameter start must be a number');
|
61
|
+
} else if (typeof start !== 'number' && !(0, _is.isBigInt)(start)) {
|
62
|
+
throw new TypeError('Parameter start must be a number or bigint');
|
56
63
|
}
|
57
64
|
}
|
58
65
|
if (hasEnd) {
|
59
66
|
if ((0, _is.isBigNumber)(end)) {
|
60
67
|
end = end.toNumber();
|
61
|
-
} else if (typeof end !== 'number') {
|
62
|
-
throw new TypeError('Parameter end must be a number');
|
68
|
+
} else if (typeof end !== 'number' && !(0, _is.isBigInt)(end)) {
|
69
|
+
throw new TypeError('Parameter end must be a number or bigint');
|
63
70
|
}
|
64
71
|
}
|
65
72
|
if (hasStep) {
|
66
73
|
if ((0, _is.isBigNumber)(step)) {
|
67
74
|
step = step.toNumber();
|
68
|
-
} else if (typeof step !== 'number') {
|
69
|
-
throw new TypeError('Parameter step must be a number');
|
75
|
+
} else if (typeof step !== 'number' && !(0, _is.isBigInt)(step)) {
|
76
|
+
throw new TypeError('Parameter step must be a number or bigint');
|
70
77
|
}
|
71
78
|
}
|
72
79
|
this.start = hasStart ? parseFloat(start) : 0;
|
package/lib/cjs/utils/factory.js
CHANGED
@@ -31,8 +31,11 @@ var _object = require("./object.js");
|
|
31
31
|
* @param {string} name Name of the function to be created
|
32
32
|
* @param {string[]} dependencies The names of all required dependencies
|
33
33
|
* @param {function} create Callback function called with an object with all dependencies
|
34
|
-
* @param {Object} [meta]
|
35
|
-
*
|
34
|
+
* @param {Object} [meta]
|
35
|
+
* Optional object with meta information that will be attached
|
36
|
+
* to the created factory function as property `meta`. For explanation
|
37
|
+
* of what meta properties can be specified and what they mean, see
|
38
|
+
* docs/core/extension.md.
|
36
39
|
* @returns {function}
|
37
40
|
*/
|
38
41
|
function factory(name, dependencies, create, meta) {
|
@@ -110,16 +110,22 @@ function createSnapshotFromFactories(factories) {
|
|
110
110
|
const allClasses = {};
|
111
111
|
const allNodeClasses = {};
|
112
112
|
Object.keys(factories).forEach(factoryName => {
|
113
|
+
var _factory$meta$formerl, _factory$meta;
|
113
114
|
const factory = factories[factoryName];
|
114
115
|
const name = factory.fn;
|
115
116
|
const isTransformFunction = factory.meta && factory.meta.isTransformFunction;
|
116
117
|
const isClass = !isLowerCase(name[0]) && validateTypeOf(math[name]) === 'function';
|
117
118
|
const dependenciesName = factory.fn + (isTransformFunction ? 'Transform' : '') + 'Dependencies';
|
119
|
+
const former = (_factory$meta$formerl = (_factory$meta = factory.meta) === null || _factory$meta === void 0 ? void 0 : _factory$meta.formerly) !== null && _factory$meta$formerl !== void 0 ? _factory$meta$formerl : '';
|
118
120
|
allFactoryFunctions[factoryName] = 'function';
|
119
121
|
allFunctionsConstantsClasses[name] = validateTypeOf(math[name]);
|
122
|
+
if (former) {
|
123
|
+
allFunctionsConstantsClasses[former] = allFunctionsConstantsClasses[name];
|
124
|
+
}
|
120
125
|
allDependencyCollections[dependenciesName] = 'Object';
|
121
126
|
if (isTransformFunction) {
|
122
127
|
allTransformFunctions[name] = 'function';
|
128
|
+
if (former) allTransformFunctions[former] = 'function';
|
123
129
|
}
|
124
130
|
if (isClass) {
|
125
131
|
if ((0, _string.endsWith)(name, 'Node')) {
|
@@ -129,6 +135,7 @@ function createSnapshotFromFactories(factories) {
|
|
129
135
|
}
|
130
136
|
} else {
|
131
137
|
allFunctionsConstants[name] = validateTypeOf(math[name]);
|
138
|
+
if (former) allFunctionsConstants[former] = allFunctionsConstants[name];
|
132
139
|
}
|
133
140
|
});
|
134
141
|
let embeddedDocs = {};
|
@@ -140,7 +147,7 @@ function createSnapshotFromFactories(factories) {
|
|
140
147
|
embeddedDocs[name] = 'Object';
|
141
148
|
}
|
142
149
|
});
|
143
|
-
embeddedDocs = exclude(embeddedDocs, ['equalScalar', '
|
150
|
+
embeddedDocs = exclude(embeddedDocs, ['equalScalar', 'addScalar', 'subtractScalar', 'multiplyScalar', 'print', 'divideScalar', 'parse', 'compile', 'parser', 'chain', 'reviver', 'replacer']);
|
144
151
|
const allTypeChecks = {};
|
145
152
|
Object.keys(allIsFunctions).forEach(name => {
|
146
153
|
if (name.indexOf('is') === 0) {
|
package/lib/cjs/version.js
CHANGED
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
const version = exports.version = '14.
|
7
|
+
const version = exports.version = '14.2.0';
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
9
9
|
// Changes made in this file will be overwritten.
|
@@ -217,6 +217,7 @@ export function importFactory(typed, load, math, importedFactories) {
|
|
217
217
|
* @private
|
218
218
|
*/
|
219
219
|
function _importFactory(factory, options) {
|
220
|
+
var _factory$meta$formerl, _factory$meta;
|
220
221
|
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : factory.fn;
|
221
222
|
if (name.includes('.')) {
|
222
223
|
throw new Error('Factory name should not contain a nested path. ' + 'Name: ' + JSON.stringify(name));
|
@@ -260,28 +261,37 @@ export function importFactory(typed, load, math, importedFactories) {
|
|
260
261
|
throw new Error('Cannot import "' + name + '": already exists');
|
261
262
|
}
|
262
263
|
};
|
264
|
+
var former = (_factory$meta$formerl = (_factory$meta = factory.meta) === null || _factory$meta === void 0 ? void 0 : _factory$meta.formerly) !== null && _factory$meta$formerl !== void 0 ? _factory$meta$formerl : '';
|
265
|
+
var needsTransform = isTransformFunctionFactory(factory) || factoryAllowedInExpressions(factory);
|
266
|
+
var withTransform = math.expression.mathWithTransform;
|
263
267
|
|
264
268
|
// TODO: add unit test with non-lazy factory
|
265
269
|
if (!factory.meta || factory.meta.lazy !== false) {
|
266
270
|
lazy(namespace, name, resolver);
|
271
|
+
if (former) lazy(namespace, former, resolver);
|
267
272
|
|
268
273
|
// FIXME: remove the `if (existing &&` condition again. Can we make sure subset is loaded before subset.transform? (Name collision, and no dependencies between the two)
|
269
274
|
if (existing && existingTransform) {
|
270
275
|
_deleteTransform(name);
|
276
|
+
if (former) _deleteTransform(former);
|
271
277
|
} else {
|
272
|
-
if (
|
273
|
-
lazy(
|
278
|
+
if (needsTransform) {
|
279
|
+
lazy(withTransform, name, () => namespace[name]);
|
280
|
+
if (former) lazy(withTransform, former, () => namespace[name]);
|
274
281
|
}
|
275
282
|
}
|
276
283
|
} else {
|
277
284
|
namespace[name] = resolver();
|
285
|
+
if (former) namespace[former] = namespace[name];
|
278
286
|
|
279
287
|
// FIXME: remove the `if (existing &&` condition again. Can we make sure subset is loaded before subset.transform? (Name collision, and no dependencies between the two)
|
280
288
|
if (existing && existingTransform) {
|
281
289
|
_deleteTransform(name);
|
290
|
+
if (former) _deleteTransform(former);
|
282
291
|
} else {
|
283
|
-
if (
|
284
|
-
lazy(
|
292
|
+
if (needsTransform) {
|
293
|
+
lazy(withTransform, name, () => namespace[name]);
|
294
|
+
if (former) lazy(withTransform, former, () => namespace[name]);
|
285
295
|
}
|
286
296
|
}
|
287
297
|
}
|
@@ -4,9 +4,9 @@
|
|
4
4
|
*/
|
5
5
|
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
6
6
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
7
|
-
import {
|
8
|
-
export var
|
7
|
+
import { createMapSlices } from '../../factoriesAny.js';
|
8
|
+
export var mapSlicesDependencies = {
|
9
9
|
isIntegerDependencies,
|
10
10
|
typedDependencies,
|
11
|
-
|
11
|
+
createMapSlices
|
12
12
|
};
|
@@ -4,9 +4,9 @@
|
|
4
4
|
*/
|
5
5
|
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
6
6
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
7
|
-
import {
|
8
|
-
export var
|
7
|
+
import { createMapSlicesTransform } from '../../factoriesAny.js';
|
8
|
+
export var mapSlicesTransformDependencies = {
|
9
9
|
isIntegerDependencies,
|
10
10
|
typedDependencies,
|
11
|
-
|
11
|
+
createMapSlicesTransform
|
12
12
|
};
|
@@ -8,6 +8,7 @@ import { compareDependencies } from './dependenciesCompare.generated.js';
|
|
8
8
|
import { divideDependencies } from './dependenciesDivide.generated.js';
|
9
9
|
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
10
10
|
import { largerDependencies } from './dependenciesLarger.generated.js';
|
11
|
+
import { mapSlicesDependencies } from './dependenciesMapSlices.generated.js';
|
11
12
|
import { multiplyDependencies } from './dependenciesMultiply.generated.js';
|
12
13
|
import { partitionSelectDependencies } from './dependenciesPartitionSelect.generated.js';
|
13
14
|
import { smallerDependencies } from './dependenciesSmaller.generated.js';
|
@@ -22,6 +23,7 @@ export var quantileSeqDependencies = {
|
|
22
23
|
divideDependencies,
|
23
24
|
isIntegerDependencies,
|
24
25
|
largerDependencies,
|
26
|
+
mapSlicesDependencies,
|
25
27
|
multiplyDependencies,
|
26
28
|
partitionSelectDependencies,
|
27
29
|
smallerDependencies,
|