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
@@ -9,8 +9,10 @@ export var createMatrixFromFunction = /* #__PURE__ */factory(name, dependencies,
|
|
9
9
|
} = _ref;
|
10
10
|
/**
|
11
11
|
* Create a matrix by evaluating a generating function at each index.
|
12
|
-
* The simplest overload returns a multi-dimensional array as long as `size`
|
13
|
-
*
|
12
|
+
* The simplest overload returns a multi-dimensional array as long as `size`
|
13
|
+
* is an array.
|
14
|
+
* Passing `size` as a Matrix or specifying a `format` will result in
|
15
|
+
* returning a Matrix.
|
14
16
|
*
|
15
17
|
* Syntax:
|
16
18
|
*
|
@@ -20,6 +22,37 @@ export var createMatrixFromFunction = /* #__PURE__ */factory(name, dependencies,
|
|
20
22
|
* math.matrixFromFunction(size, format, fn)
|
21
23
|
* math.matrixFromFunction(size, format, datatype, fn)
|
22
24
|
*
|
25
|
+
* Where:
|
26
|
+
*
|
27
|
+
* - `size: (number[] | Matrix)`
|
28
|
+
* A vector giving the extent of the array to be created in each
|
29
|
+
* dimension. If size has one entry, a vector is created; if it
|
30
|
+
* has two, a rectangular array/Matrix is created; if three, a
|
31
|
+
* three-dimensional array/Matrix is created; and so on.
|
32
|
+
* - `fn: (index: number[]) => MathType`
|
33
|
+
* The callback function that will generate the entries of the
|
34
|
+
* matrix. It is called in turn with the index of each entry of
|
35
|
+
* the matrix. The index is always an ordinary array of numbers
|
36
|
+
* with the same length as _size_. So for vectors, you will get
|
37
|
+
* indices like `[0]` or `[1]`, whereas for matrices, you will
|
38
|
+
* get indices like `[2, 0]` or `[1,3]`. The return value may
|
39
|
+
* be any type that can go in an array or Matrix entry, although
|
40
|
+
* if you supply the _datatype_ argument, you must yourself ensure
|
41
|
+
* the type of the return value matches. Note that currently,
|
42
|
+
* your callback _fn_ will receive 0-based indices for the matrix
|
43
|
+
* entries, regardless of whether matrixFromFunction is invoked
|
44
|
+
* directly from JavaScript or via the mathjs expression language.
|
45
|
+
* - `format: 'dense'|'sparse'`
|
46
|
+
* Specifies the storage format for the resulting Matrix. Note that
|
47
|
+
* if this argument is given, the return value will always be a
|
48
|
+
* Matrix (rather than possibly an Array).
|
49
|
+
* - `datatype: string`
|
50
|
+
* Specifies the data type of entries of the new matrix. If given,
|
51
|
+
* it should be the name of a data type that mathjs supports, as
|
52
|
+
* returned by the math.typeOf function. It is up to the caller
|
53
|
+
* to make certain that all values returned by _fn_ are consistent
|
54
|
+
* with this datatype if specified.
|
55
|
+
*
|
23
56
|
* Examples:
|
24
57
|
*
|
25
58
|
* math.matrixFromFunction([3,3], i => i[0] - i[1]) // an antisymmetric matrix
|
@@ -28,7 +61,7 @@ export var createMatrixFromFunction = /* #__PURE__ */factory(name, dependencies,
|
|
28
61
|
*
|
29
62
|
* See also:
|
30
63
|
*
|
31
|
-
* matrix, zeros
|
64
|
+
* matrix, typeOf, zeros
|
32
65
|
*
|
33
66
|
* @param {Array | Matrix} size The size of the matrix to be created
|
34
67
|
* @param {function} fn Callback function invoked for every entry in the matrix
|
@@ -35,36 +35,48 @@ export var createRange = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
35
35
|
*
|
36
36
|
* - `str: string`
|
37
37
|
* A string 'start:end' or 'start:step:end'
|
38
|
-
* - `start: {number | BigNumber | Unit}`
|
38
|
+
* - `start: {number | bigint | BigNumber | Fraction | Unit}`
|
39
39
|
* Start of the range
|
40
|
-
* - `end: number | BigNumber | Unit`
|
40
|
+
* - `end: number | bigint | BigNumber | Fraction | Unit`
|
41
41
|
* End of the range, excluded by default, included when parameter includeEnd=true
|
42
|
-
* - `step: number | BigNumber | Unit`
|
42
|
+
* - `step: number | bigint | BigNumber | Fraction | Unit`
|
43
43
|
* Step size. Default value is 1.
|
44
44
|
* - `includeEnd: boolean`
|
45
45
|
* Option to specify whether to include the end or not. False by default.
|
46
46
|
*
|
47
|
+
* Note that the return type of the range is taken from the type of
|
48
|
+
* the start/end. If only one these is a built-in `number` type, it will
|
49
|
+
* be promoted to the type of the other endpoint. However, in the case of
|
50
|
+
* Unit values, both endpoints must have compatible units, and the return
|
51
|
+
* value will have compatible units as well.
|
52
|
+
*
|
47
53
|
* Examples:
|
48
54
|
*
|
49
55
|
* math.range(2, 6) // [2, 3, 4, 5]
|
50
56
|
* math.range(2, -3, -1) // [2, 1, 0, -1, -2]
|
51
57
|
* math.range('2:1:6') // [2, 3, 4, 5]
|
52
58
|
* math.range(2, 6, true) // [2, 3, 4, 5, 6]
|
59
|
+
* math.range(2, math.fraction(8,3), math.fraction(1,3)) // [fraction(2), fraction(7,3)]
|
53
60
|
* math.range(math.unit(2, 'm'), math.unit(-3, 'm'), math.unit(-1, 'm')) // [2 m, 1 m, 0 m , -1 m, -2 m]
|
54
61
|
*
|
55
62
|
* See also:
|
56
63
|
*
|
57
64
|
* ones, zeros, size, subset
|
58
65
|
*
|
59
|
-
* @param {*} args Parameters describing the
|
66
|
+
* @param {*} args Parameters describing the range's `start`, `end`, and optional `step`.
|
60
67
|
* @return {Array | Matrix} range
|
61
68
|
*/
|
62
69
|
return typed(name, {
|
63
70
|
// TODO: simplify signatures when typed-function supports default values and optional arguments
|
64
71
|
|
65
|
-
// TODO: a number or boolean should not be converted to string here
|
66
72
|
string: _strRange,
|
67
73
|
'string, boolean': _strRange,
|
74
|
+
number: function number(oops) {
|
75
|
+
throw new TypeError("Too few arguments to function range(): ".concat(oops));
|
76
|
+
},
|
77
|
+
boolean: function boolean(oops) {
|
78
|
+
throw new TypeError("Unexpected type of argument 1 to function range(): ".concat(oops, ", number|bigint|BigNumber|Fraction"));
|
79
|
+
},
|
68
80
|
'number, number': function number_number(start, end) {
|
69
81
|
return _out(_range(start, end, 1, false));
|
70
82
|
},
|
@@ -77,6 +89,31 @@ export var createRange = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
77
89
|
'number, number, number, boolean': function number_number_number_boolean(start, end, step, includeEnd) {
|
78
90
|
return _out(_range(start, end, step, includeEnd));
|
79
91
|
},
|
92
|
+
// Handle bigints; if either limit is bigint, range should be too
|
93
|
+
'bigint, bigint|number': function bigint_bigintNumber(start, end) {
|
94
|
+
return _out(_range(start, end, 1n, false));
|
95
|
+
},
|
96
|
+
'number, bigint': function number_bigint(start, end) {
|
97
|
+
return _out(_range(BigInt(start), end, 1n, false));
|
98
|
+
},
|
99
|
+
'bigint, bigint|number, bigint|number': function bigint_bigintNumber_bigintNumber(start, end, step) {
|
100
|
+
return _out(_range(start, end, BigInt(step), false));
|
101
|
+
},
|
102
|
+
'number, bigint, bigint|number': function number_bigint_bigintNumber(start, end, step) {
|
103
|
+
return _out(_range(BigInt(start), end, BigInt(step), false));
|
104
|
+
},
|
105
|
+
'bigint, bigint|number, boolean': function bigint_bigintNumber_boolean(start, end, includeEnd) {
|
106
|
+
return _out(_range(start, end, 1n, includeEnd));
|
107
|
+
},
|
108
|
+
'number, bigint, boolean': function number_bigint_boolean(start, end, includeEnd) {
|
109
|
+
return _out(_range(BigInt(start), end, 1n, includeEnd));
|
110
|
+
},
|
111
|
+
'bigint, bigint|number, bigint|number, boolean': function bigint_bigintNumber_bigintNumber_boolean(start, end, step, includeEnd) {
|
112
|
+
return _out(_range(start, end, BigInt(step), includeEnd));
|
113
|
+
},
|
114
|
+
'number, bigint, bigint|number, boolean': function number_bigint_bigintNumber_boolean(start, end, step, includeEnd) {
|
115
|
+
return _out(_range(BigInt(start), end, BigInt(step), includeEnd));
|
116
|
+
},
|
80
117
|
'BigNumber, BigNumber': function BigNumber_BigNumber(start, end) {
|
81
118
|
var BigNumber = start.constructor;
|
82
119
|
return _out(_range(start, end, new BigNumber(1), false));
|
@@ -91,6 +128,18 @@ export var createRange = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
91
128
|
'BigNumber, BigNumber, BigNumber, boolean': function BigNumber_BigNumber_BigNumber_boolean(start, end, step, includeEnd) {
|
92
129
|
return _out(_range(start, end, step, includeEnd));
|
93
130
|
},
|
131
|
+
'Fraction, Fraction': function Fraction_Fraction(start, end) {
|
132
|
+
return _out(_range(start, end, 1, false));
|
133
|
+
},
|
134
|
+
'Fraction, Fraction, Fraction': function Fraction_Fraction_Fraction(start, end, step) {
|
135
|
+
return _out(_range(start, end, step, false));
|
136
|
+
},
|
137
|
+
'Fraction, Fraction, boolean': function Fraction_Fraction_boolean(start, end, includeEnd) {
|
138
|
+
return _out(_range(start, end, 1, includeEnd));
|
139
|
+
},
|
140
|
+
'Fraction, Fraction, Fraction, boolean': function Fraction_Fraction_Fraction_boolean(start, end, step, includeEnd) {
|
141
|
+
return _out(_range(start, end, step, includeEnd));
|
142
|
+
},
|
94
143
|
'Unit, Unit, Unit': function Unit_Unit_Unit(start, end, step) {
|
95
144
|
return _out(_range(start, end, step, false));
|
96
145
|
},
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { isNumber } from '../../utils/is.js';
|
2
2
|
import { flatten } from '../../utils/array.js';
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
|
-
import { createApply } from '../matrix/apply.js';
|
5
4
|
var name = 'quantileSeq';
|
6
|
-
var dependencies = ['typed', '?bignumber', 'add', 'subtract', 'divide', 'multiply', 'partitionSelect', 'compare', 'isInteger', 'smaller', 'smallerEq', 'larger'];
|
5
|
+
var dependencies = ['typed', '?bignumber', 'add', 'subtract', 'divide', 'multiply', 'partitionSelect', 'compare', 'isInteger', 'smaller', 'smallerEq', 'larger', 'mapSlices'];
|
7
6
|
export var createQuantileSeq = /* #__PURE__ */factory(name, dependencies, _ref => {
|
8
7
|
var {
|
9
8
|
typed,
|
@@ -17,13 +16,9 @@ export var createQuantileSeq = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
17
16
|
isInteger,
|
18
17
|
smaller,
|
19
18
|
smallerEq,
|
20
|
-
larger
|
19
|
+
larger,
|
20
|
+
mapSlices
|
21
21
|
} = _ref;
|
22
|
-
var apply = createApply({
|
23
|
-
typed,
|
24
|
-
isInteger
|
25
|
-
});
|
26
|
-
|
27
22
|
/**
|
28
23
|
* Compute the prob order quantile of a matrix or a list with values.
|
29
24
|
* The sequence is sorted and the middle value is returned.
|
@@ -69,7 +64,7 @@ export var createQuantileSeq = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
69
64
|
'Array | Matrix, Array | Matrix, boolean, number': (data, prob, sorted, dim) => _quantileSeqDim(data, prob, sorted, dim, _quantileSeqProbCollection)
|
70
65
|
});
|
71
66
|
function _quantileSeqDim(data, prob, sorted, dim, fn) {
|
72
|
-
return
|
67
|
+
return mapSlices(data, dim, x => fn(x, prob, sorted));
|
73
68
|
}
|
74
69
|
function _quantileSeqProbNumber(data, probOrN, sorted) {
|
75
70
|
var probArr;
|
@@ -4,7 +4,7 @@ import { factory } from '../../utils/factory.js';
|
|
4
4
|
import { improveErrorMessage } from './utils/improveErrorMessage.js';
|
5
5
|
var DEFAULT_NORMALIZATION = 'unbiased';
|
6
6
|
var name = 'variance';
|
7
|
-
var dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', '
|
7
|
+
var dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'mapSlices', 'isNaN'];
|
8
8
|
export var createVariance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
9
9
|
var {
|
10
10
|
typed,
|
@@ -12,7 +12,7 @@ export var createVariance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
12
12
|
subtract,
|
13
13
|
multiply,
|
14
14
|
divide,
|
15
|
-
|
15
|
+
mapSlices,
|
16
16
|
isNaN
|
17
17
|
} = _ref;
|
18
18
|
/**
|
@@ -145,7 +145,7 @@ export var createVariance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
145
145
|
if (array.length === 0) {
|
146
146
|
throw new SyntaxError('Function variance requires one or more parameters (0 provided)');
|
147
147
|
}
|
148
|
-
return
|
148
|
+
return mapSlices(array, dim, x => _var(x, normalization));
|
149
149
|
} catch (err) {
|
150
150
|
throw improveErrorMessage(err, 'variance');
|
151
151
|
}
|
@@ -23,7 +23,7 @@ export var createAcsc = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
23
23
|
*
|
24
24
|
* math.acsc(2) // returns 0.5235987755982989
|
25
25
|
* math.acsc(0.5) // returns Complex 1.5707963267948966 -1.3169578969248166i
|
26
|
-
* math.acsc(math.csc(1.5)) // returns number
|
26
|
+
* math.acsc(math.csc(1.5)) // returns number 1.5
|
27
27
|
*
|
28
28
|
* See also:
|
29
29
|
*
|
@@ -20,7 +20,7 @@ export var createAsin = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
20
20
|
* Examples:
|
21
21
|
*
|
22
22
|
* math.asin(0.5) // returns number 0.5235987755982989
|
23
|
-
* math.asin(math.sin(1.5)) // returns number
|
23
|
+
* math.asin(math.sin(1.5)) // returns number 1.5
|
24
24
|
*
|
25
25
|
* math.asin(2) // returns Complex 1.5707963267948966 -1.3169578969248166i
|
26
26
|
*
|
@@ -56,9 +56,10 @@ export var createAtan2 = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
56
56
|
*
|
57
57
|
* math.atan2(2, 2) / math.pi // returns number 0.25
|
58
58
|
*
|
59
|
-
* const angle = math.unit(60, 'deg')
|
59
|
+
* const angle = math.unit(60, 'deg')
|
60
60
|
* const x = math.cos(angle)
|
61
61
|
* const y = math.sin(angle)
|
62
|
+
* math.atan2(y, x) * 180 / math.pi // returns 60
|
62
63
|
*
|
63
64
|
* math.atan(2) // returns number 1.1071487177940904
|
64
65
|
*
|
@@ -28,7 +28,7 @@ export var createCos = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
28
28
|
* math.cos(math.unit(60, 'deg')) // returns number 0.5
|
29
29
|
*
|
30
30
|
* const angle = 0.2
|
31
|
-
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number
|
31
|
+
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number 1
|
32
32
|
*
|
33
33
|
* See also:
|
34
34
|
*
|
@@ -28,7 +28,7 @@ export var createSin = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
28
28
|
* math.sin(math.unit(30, 'deg')) // returns number 0.5
|
29
29
|
*
|
30
30
|
* const angle = 0.2
|
31
|
-
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number
|
31
|
+
* math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number 1
|
32
32
|
*
|
33
33
|
* See also:
|
34
34
|
*
|
@@ -42,6 +42,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
42
42
|
var arg = arguments[i];
|
43
43
|
var argIsArray = isArray(arg);
|
44
44
|
var argIsMatrix = isMatrix(arg);
|
45
|
+
var argType = typeof arg;
|
45
46
|
var sourceSize = null;
|
46
47
|
if (isRange(arg)) {
|
47
48
|
this._dimensions.push(arg);
|
@@ -63,13 +64,15 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
63
64
|
if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
|
64
65
|
this._isScalar = false;
|
65
66
|
}
|
66
|
-
} else if (
|
67
|
+
} else if (argType === 'number') {
|
67
68
|
this._dimensions.push(_createImmutableMatrix([arg]));
|
68
|
-
} else if (
|
69
|
+
} else if (argType === 'bigint') {
|
70
|
+
this._dimensions.push(_createImmutableMatrix([Number(arg)]));
|
71
|
+
} else if (argType === 'string') {
|
69
72
|
// object property (arguments.count should be 1)
|
70
73
|
this._dimensions.push(arg);
|
71
74
|
} else {
|
72
|
-
throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
|
75
|
+
throw new TypeError('Dimension must be an Array, Matrix, number, bigint, string, or Range');
|
73
76
|
}
|
74
77
|
this._sourceSize.push(sourceSize);
|
75
78
|
// TODO: implement support for wildcard '*'
|
@@ -1,18 +1,25 @@
|
|
1
|
-
import { isBigNumber } from '../../utils/is.js';
|
1
|
+
import { isBigInt, isBigNumber } from '../../utils/is.js';
|
2
2
|
import { format, sign } from '../../utils/number.js';
|
3
3
|
import { factory } from '../../utils/factory.js';
|
4
4
|
var name = 'Range';
|
5
5
|
var dependencies = [];
|
6
6
|
export var createRangeClass = /* #__PURE__ */factory(name, dependencies, () => {
|
7
7
|
/**
|
8
|
-
* Create a range. A range has a start, step, and end,
|
9
|
-
* to iterate over the range.
|
8
|
+
* Create a range of numbers. A range has a start, step, and end,
|
9
|
+
* and contains functions to iterate over the range.
|
10
10
|
*
|
11
11
|
* A range can be constructed as:
|
12
12
|
*
|
13
13
|
* const range = new Range(start, end)
|
14
14
|
* const range = new Range(start, end, step)
|
15
15
|
*
|
16
|
+
* Note that the endpoints and step may be specified with other numeric
|
17
|
+
* types such as bigint or BigNumber, but they will be demoted to the
|
18
|
+
* built-in `number` type and the Range will only contain numbers. The
|
19
|
+
* rationale for this demotion is that Range objects are primarily used
|
20
|
+
* for indexing Matrix objects, and Matrix objects may only be indexed
|
21
|
+
* with `number`s.
|
22
|
+
*
|
16
23
|
* To get the result of the range:
|
17
24
|
* range.forEach(function (x) {
|
18
25
|
* console.log(x)
|
@@ -45,22 +52,22 @@ export var createRangeClass = /* #__PURE__ */factory(name, dependencies, () => {
|
|
45
52
|
if (hasStart) {
|
46
53
|
if (isBigNumber(start)) {
|
47
54
|
start = start.toNumber();
|
48
|
-
} else if (typeof start !== 'number') {
|
49
|
-
throw new TypeError('Parameter start must be a number');
|
55
|
+
} else if (typeof start !== 'number' && !isBigInt(start)) {
|
56
|
+
throw new TypeError('Parameter start must be a number or bigint');
|
50
57
|
}
|
51
58
|
}
|
52
59
|
if (hasEnd) {
|
53
60
|
if (isBigNumber(end)) {
|
54
61
|
end = end.toNumber();
|
55
|
-
} else if (typeof end !== 'number') {
|
56
|
-
throw new TypeError('Parameter end must be a number');
|
62
|
+
} else if (typeof end !== 'number' && !isBigInt(end)) {
|
63
|
+
throw new TypeError('Parameter end must be a number or bigint');
|
57
64
|
}
|
58
65
|
}
|
59
66
|
if (hasStep) {
|
60
67
|
if (isBigNumber(step)) {
|
61
68
|
step = step.toNumber();
|
62
|
-
} else if (typeof step !== 'number') {
|
63
|
-
throw new TypeError('Parameter step must be a number');
|
69
|
+
} else if (typeof step !== 'number' && !isBigInt(step)) {
|
70
|
+
throw new TypeError('Parameter step must be a number or bigint');
|
64
71
|
}
|
65
72
|
}
|
66
73
|
this.start = hasStart ? parseFloat(start) : 0;
|
package/lib/esm/utils/factory.js
CHANGED
@@ -20,8 +20,11 @@ import { pickShallow } from './object.js';
|
|
20
20
|
* @param {string} name Name of the function to be created
|
21
21
|
* @param {string[]} dependencies The names of all required dependencies
|
22
22
|
* @param {function} create Callback function called with an object with all dependencies
|
23
|
-
* @param {Object} [meta]
|
24
|
-
*
|
23
|
+
* @param {Object} [meta]
|
24
|
+
* Optional object with meta information that will be attached
|
25
|
+
* to the created factory function as property `meta`. For explanation
|
26
|
+
* of what meta properties can be specified and what they mean, see
|
27
|
+
* docs/core/extension.md.
|
25
28
|
* @returns {function}
|
26
29
|
*/
|
27
30
|
export function factory(name, dependencies, create, meta) {
|
@@ -101,16 +101,22 @@ export function createSnapshotFromFactories(factories) {
|
|
101
101
|
var allClasses = {};
|
102
102
|
var allNodeClasses = {};
|
103
103
|
Object.keys(factories).forEach(factoryName => {
|
104
|
+
var _factory$meta$formerl, _factory$meta;
|
104
105
|
var factory = factories[factoryName];
|
105
106
|
var name = factory.fn;
|
106
107
|
var isTransformFunction = factory.meta && factory.meta.isTransformFunction;
|
107
108
|
var isClass = !isLowerCase(name[0]) && validateTypeOf(math[name]) === 'function';
|
108
109
|
var dependenciesName = factory.fn + (isTransformFunction ? 'Transform' : '') + 'Dependencies';
|
110
|
+
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 : '';
|
109
111
|
allFactoryFunctions[factoryName] = 'function';
|
110
112
|
allFunctionsConstantsClasses[name] = validateTypeOf(math[name]);
|
113
|
+
if (former) {
|
114
|
+
allFunctionsConstantsClasses[former] = allFunctionsConstantsClasses[name];
|
115
|
+
}
|
111
116
|
allDependencyCollections[dependenciesName] = 'Object';
|
112
117
|
if (isTransformFunction) {
|
113
118
|
allTransformFunctions[name] = 'function';
|
119
|
+
if (former) allTransformFunctions[former] = 'function';
|
114
120
|
}
|
115
121
|
if (isClass) {
|
116
122
|
if (endsWith(name, 'Node')) {
|
@@ -120,6 +126,7 @@ export function createSnapshotFromFactories(factories) {
|
|
120
126
|
}
|
121
127
|
} else {
|
122
128
|
allFunctionsConstants[name] = validateTypeOf(math[name]);
|
129
|
+
if (former) allFunctionsConstants[former] = allFunctionsConstants[name];
|
123
130
|
}
|
124
131
|
});
|
125
132
|
var embeddedDocs = {};
|
@@ -131,7 +138,7 @@ export function createSnapshotFromFactories(factories) {
|
|
131
138
|
embeddedDocs[name] = 'Object';
|
132
139
|
}
|
133
140
|
});
|
134
|
-
embeddedDocs = exclude(embeddedDocs, ['equalScalar', '
|
141
|
+
embeddedDocs = exclude(embeddedDocs, ['equalScalar', 'addScalar', 'subtractScalar', 'multiplyScalar', 'print', 'divideScalar', 'parse', 'compile', 'parser', 'chain', 'reviver', 'replacer']);
|
135
142
|
var allTypeChecks = {};
|
136
143
|
Object.keys(allIsFunctions).forEach(name => {
|
137
144
|
if (name.indexOf('is') === 0) {
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "14.
|
3
|
+
"version": "14.2.0",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
package/types/index.d.ts
CHANGED
@@ -21,6 +21,12 @@ export type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>
|
|
21
21
|
export type MathType = MathScalarType | MathCollection
|
22
22
|
export type MathExpression = string | string[] | MathCollection
|
23
23
|
|
24
|
+
// add type for Matrix Callback Function and Matrix Storage Format
|
25
|
+
export type MatrixStorageFormat = 'dense' | 'sparse'
|
26
|
+
export type MatrixFromFunctionCallback<T extends MathScalarType> = (
|
27
|
+
index: number[]
|
28
|
+
) => T
|
29
|
+
|
24
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
25
31
|
export type FactoryFunction<T> = (scope: any) => T
|
26
32
|
|
@@ -743,7 +749,7 @@ export interface MathJsInstance extends MathJsFactory {
|
|
743
749
|
* @param format The Matrix storage format
|
744
750
|
* @returns The created Matrix
|
745
751
|
*/
|
746
|
-
matrix(format?:
|
752
|
+
matrix(format?: MatrixStorageFormat): Matrix
|
747
753
|
/**
|
748
754
|
* @param data A multi dimensional array
|
749
755
|
* @param format The Matrix storage format
|
@@ -752,12 +758,12 @@ export interface MathJsInstance extends MathJsFactory {
|
|
752
758
|
*/
|
753
759
|
matrix(
|
754
760
|
data: MathCollection | string[],
|
755
|
-
format?:
|
761
|
+
format?: MatrixStorageFormat,
|
756
762
|
dataType?: string
|
757
763
|
): Matrix
|
758
764
|
matrix<T extends MathScalarType>(
|
759
765
|
data: MathCollection<T>,
|
760
|
-
format?:
|
766
|
+
format?: MatrixStorageFormat,
|
761
767
|
dataType?: string
|
762
768
|
): Matrix<T>
|
763
769
|
|
@@ -1322,6 +1328,58 @@ export interface MathJsInstance extends MathJsFactory {
|
|
1322
1328
|
hypot<T extends number | BigNumber>(...args: T[]): T
|
1323
1329
|
hypot<T extends number | BigNumber>(args: T[]): T
|
1324
1330
|
|
1331
|
+
/**
|
1332
|
+
* Create a dense matrix from vectors as individual rows. If you pass column vectors, they will be transposed (but not conjugated!)
|
1333
|
+
* @param rows - a multi-dimensional number array or matrix
|
1334
|
+
*/
|
1335
|
+
matrixFromRows(...rows: Matrix[]): Matrix
|
1336
|
+
matrixFromRows<T extends MathScalarType>(
|
1337
|
+
...rows: (T[] | [T][] | Matrix)[]
|
1338
|
+
): T[][]
|
1339
|
+
|
1340
|
+
/**
|
1341
|
+
* Create a dense matrix from vectors as individual columns. If you pass row vectors, they will be transposed (but not conjugated!)
|
1342
|
+
* @param cols - a multi-dimensional number array or matrix
|
1343
|
+
*/
|
1344
|
+
matrixFromColumns(...cols: Matrix[]): Matrix
|
1345
|
+
matrixFromColumns<T extends MathScalarType>(
|
1346
|
+
...cols: (T[] | [T][] | Matrix)[]
|
1347
|
+
): T[][]
|
1348
|
+
/**
|
1349
|
+
* Create a matrix by evaluating a generating function at each index. The simplest overload returns a multi-dimensional array as long as size is an array. Passing size as a Matrix or specifying a format will result in returning a Matrix.
|
1350
|
+
* @param size - the size of the matrix to be created
|
1351
|
+
* @param fn - Callback function invoked for every entry in the matrix
|
1352
|
+
* @param format - The Matrix storage format, either 'dense' or 'sparse'
|
1353
|
+
* @param datatype - Type of the values
|
1354
|
+
*/
|
1355
|
+
matrixFromFunction<T extends MathScalarType>(
|
1356
|
+
size: [number],
|
1357
|
+
fn: MatrixFromFunctionCallback<T>
|
1358
|
+
): T[]
|
1359
|
+
matrixFromFunction<T extends MathScalarType>(
|
1360
|
+
size: [number, number],
|
1361
|
+
fn: MatrixFromFunctionCallback<T>
|
1362
|
+
): T[][]
|
1363
|
+
matrixFromFunction<T extends MathScalarType>(
|
1364
|
+
size: number[],
|
1365
|
+
fn: MatrixFromFunctionCallback<T>
|
1366
|
+
): MathArray<T>
|
1367
|
+
matrixFromFunction(
|
1368
|
+
size: Matrix<number>,
|
1369
|
+
fn: MatrixFromFunctionCallback<MathScalarType>
|
1370
|
+
): Matrix
|
1371
|
+
matrixFromFunction(
|
1372
|
+
size: number[] | Matrix<number>,
|
1373
|
+
fn: MatrixFromFunctionCallback<MathScalarType>,
|
1374
|
+
format: MatrixStorageFormat,
|
1375
|
+
datatype?: string
|
1376
|
+
): Matrix
|
1377
|
+
matrixFromFunction(
|
1378
|
+
size: number[] | Matrix<number>,
|
1379
|
+
format: MatrixStorageFormat,
|
1380
|
+
fn: MatrixFromFunctionCallback<MathScalarType>,
|
1381
|
+
datatype?: string
|
1382
|
+
): Matrix
|
1325
1383
|
/**
|
1326
1384
|
* Calculate the least common multiple for two or more values or arrays.
|
1327
1385
|
* lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
|
@@ -1805,11 +1863,15 @@ export interface MathJsInstance extends MathJsFactory {
|
|
1805
1863
|
* array or 1-d matrix as an input and return a number.
|
1806
1864
|
* @returns The residual matrix with the function applied over some dimension.
|
1807
1865
|
*/
|
1808
|
-
|
1866
|
+
mapSlices<T extends MathCollection>(
|
1809
1867
|
array: T,
|
1810
1868
|
dim: number,
|
1811
1869
|
callback: (array: MathCollection) => number
|
1812
1870
|
): T
|
1871
|
+
/**
|
1872
|
+
* @deprecated backwards-compatibility old name of mapSlices
|
1873
|
+
*/
|
1874
|
+
apply: MathJsInstance['mapSlices']
|
1813
1875
|
|
1814
1876
|
/**
|
1815
1877
|
* Concatenate two or more matrices. dim: number is a zero-based
|
@@ -3705,7 +3767,7 @@ export const {
|
|
3705
3767
|
unaryMinusDependencies,
|
3706
3768
|
unaryPlusDependencies,
|
3707
3769
|
absDependencies,
|
3708
|
-
|
3770
|
+
mapSlicesDependencies,
|
3709
3771
|
addScalarDependencies,
|
3710
3772
|
cbrtDependencies,
|
3711
3773
|
ceilDependencies,
|
@@ -3984,7 +4046,7 @@ export const {
|
|
3984
4046
|
vacuumImpedanceDependencies,
|
3985
4047
|
weakMixingAngleDependencies,
|
3986
4048
|
wienDisplacementDependencies,
|
3987
|
-
|
4049
|
+
mapSlicesTransformDependencies,
|
3988
4050
|
columnTransformDependencies,
|
3989
4051
|
filterTransformDependencies,
|
3990
4052
|
forEachTransformDependencies,
|
@@ -4010,10 +4072,6 @@ export interface Matrix<T = MathGeneric> {
|
|
4010
4072
|
density(): number
|
4011
4073
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
4012
4074
|
subset(index: Index, replacement?: any, defaultValue?: any): Matrix
|
4013
|
-
apply(
|
4014
|
-
dim: number,
|
4015
|
-
callback: (array: MathCollection) => number
|
4016
|
-
): MathCollection
|
4017
4075
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
4018
4076
|
get(index: number[]): any
|
4019
4077
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -4996,11 +5054,15 @@ export interface MathJsChain<TValue> {
|
|
4996
5054
|
* array or 1-d matrix as an input and return a number.
|
4997
5055
|
* @returns The residual matrix with the function applied over some dimension.
|
4998
5056
|
*/
|
4999
|
-
|
5057
|
+
mapSlices<T extends MathCollection>(
|
5000
5058
|
this: MathJsChain<T>,
|
5001
5059
|
dim: number,
|
5002
5060
|
callback: (array: Array<MathType> | Matrix) => number
|
5003
5061
|
): MathJsChain<T>
|
5062
|
+
/**
|
5063
|
+
* @deprecated backwards-compatibility old name of mapSlices
|
5064
|
+
**/
|
5065
|
+
apply: MathJsChain<TValue>['mapSlices']
|
5004
5066
|
|
5005
5067
|
/**
|
5006
5068
|
* Calculate the cubic root of a value. For matrices, the function is
|
@@ -7162,7 +7224,8 @@ export const {
|
|
7162
7224
|
xor,
|
7163
7225
|
|
7164
7226
|
// matrix functions
|
7165
|
-
|
7227
|
+
mapSlices,
|
7228
|
+
apply, // @deprecated prior name of mapSlices
|
7166
7229
|
concat,
|
7167
7230
|
cross,
|
7168
7231
|
det,
|