mathjs 13.0.3 → 13.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +17 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +12 -9
- package/lib/cjs/core/function/typed.js +3 -4
- package/lib/cjs/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
- package/lib/cjs/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +2 -2
- package/lib/cjs/entry/pureFunctionsAny.generated.js +6 -8
- package/lib/cjs/entry/typeChecks.js +18 -0
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/diff.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/kron.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/map.js +3 -3
- package/lib/cjs/expression/embeddedDocs/function/special/zeta.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/utils/clone.js +1 -1
- package/lib/cjs/expression/function/evaluate.js +5 -0
- package/lib/cjs/expression/node/FunctionNode.js +1 -1
- package/lib/cjs/expression/transform/filter.transform.js +2 -2
- package/lib/cjs/expression/transform/map.transform.js +104 -37
- package/lib/cjs/expression/transform/utils/dimToZeroBase.js +23 -0
- package/lib/cjs/expression/transform/utils/lastDimToZeroBase.js +3 -4
- package/lib/cjs/function/arithmetic/hypot.js +3 -3
- package/lib/cjs/function/matrix/apply.js +1 -1
- package/lib/cjs/function/matrix/fft.js +3 -3
- package/lib/cjs/function/matrix/filter.js +2 -2
- package/lib/cjs/function/matrix/flatten.js +5 -6
- package/lib/cjs/function/matrix/ifft.js +2 -2
- package/lib/cjs/function/matrix/kron.js +4 -4
- package/lib/cjs/function/matrix/map.js +109 -18
- package/lib/cjs/function/matrix/size.js +7 -7
- package/lib/cjs/function/matrix/squeeze.js +3 -4
- package/lib/cjs/function/probability/random.js +1 -1
- package/lib/cjs/function/probability/randomInt.js +1 -1
- package/lib/cjs/function/statistics/cumsum.js +2 -2
- package/lib/cjs/function/trigonometry/acoth.js +2 -2
- package/lib/cjs/function/trigonometry/acsch.js +2 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +3 -28
- package/lib/cjs/type/matrix/SparseMatrix.js +5 -8
- package/lib/cjs/utils/array.js +27 -0
- package/lib/cjs/utils/collection.js +1 -1
- package/lib/cjs/utils/function.js +0 -14
- package/lib/cjs/utils/is.js +27 -0
- package/lib/cjs/utils/map.js +2 -20
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/create.js +9 -6
- package/lib/esm/core/function/typed.js +2 -3
- package/lib/esm/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
- package/lib/esm/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +3 -3
- package/lib/esm/entry/pureFunctionsAny.generated.js +7 -9
- package/lib/esm/entry/typeChecks.js +1 -1
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/diff.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/kron.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/map.js +3 -3
- package/lib/esm/expression/embeddedDocs/function/special/zeta.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/utils/clone.js +1 -1
- package/lib/esm/expression/function/compile.js +1 -1
- package/lib/esm/expression/function/evaluate.js +8 -3
- package/lib/esm/expression/node/FunctionNode.js +1 -1
- package/lib/esm/expression/parse.js +2 -2
- package/lib/esm/expression/transform/filter.transform.js +4 -4
- package/lib/esm/expression/transform/forEach.transform.js +4 -4
- package/lib/esm/expression/transform/map.transform.js +104 -37
- package/lib/esm/expression/transform/print.transform.js +2 -2
- package/lib/esm/expression/transform/utils/dimToZeroBase.js +16 -0
- package/lib/esm/expression/transform/utils/lastDimToZeroBase.js +4 -6
- package/lib/esm/function/algebra/decomposition/slu.js +1 -1
- package/lib/esm/function/algebra/derivative.js +15 -15
- package/lib/esm/function/algebra/lyap.js +4 -4
- package/lib/esm/function/algebra/simplify/util.js +3 -3
- package/lib/esm/function/algebra/simplifyConstant.js +9 -9
- package/lib/esm/function/algebra/solver/lsolve.js +3 -3
- package/lib/esm/function/algebra/solver/lsolveAll.js +3 -3
- package/lib/esm/function/algebra/solver/lusolve.js +5 -5
- package/lib/esm/function/algebra/solver/usolve.js +3 -3
- package/lib/esm/function/algebra/solver/usolveAll.js +3 -3
- package/lib/esm/function/algebra/sylvester.js +7 -7
- package/lib/esm/function/arithmetic/addScalar.js +4 -4
- package/lib/esm/function/arithmetic/ceil.js +6 -6
- package/lib/esm/function/arithmetic/divide.js +5 -5
- package/lib/esm/function/arithmetic/divideScalar.js +5 -5
- package/lib/esm/function/arithmetic/fix.js +5 -5
- package/lib/esm/function/arithmetic/floor.js +6 -6
- package/lib/esm/function/arithmetic/hypot.js +3 -3
- package/lib/esm/function/arithmetic/mod.js +3 -3
- package/lib/esm/function/arithmetic/multiply.js +7 -7
- package/lib/esm/function/arithmetic/multiplyScalar.js +4 -4
- package/lib/esm/function/arithmetic/norm.js +2 -2
- package/lib/esm/function/arithmetic/pow.js +6 -6
- package/lib/esm/function/arithmetic/round.js +7 -7
- package/lib/esm/function/arithmetic/subtractScalar.js +4 -4
- package/lib/esm/function/arithmetic/xgcd.js +1 -1
- package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
- package/lib/esm/function/combinatorics/catalan.js +1 -1
- package/lib/esm/function/combinatorics/composition.js +1 -1
- package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
- package/lib/esm/function/geometry/distance.js +4 -4
- package/lib/esm/function/geometry/intersect.js +2 -2
- package/lib/esm/function/logical/and.js +2 -2
- package/lib/esm/function/logical/or.js +2 -2
- package/lib/esm/function/logical/xor.js +2 -2
- package/lib/esm/function/matrix/apply.js +2 -2
- package/lib/esm/function/matrix/column.js +1 -1
- package/lib/esm/function/matrix/concat.js +1 -1
- package/lib/esm/function/matrix/count.js +1 -1
- package/lib/esm/function/matrix/cross.js +3 -3
- package/lib/esm/function/matrix/diag.js +10 -10
- package/lib/esm/function/matrix/diff.js +2 -2
- package/lib/esm/function/matrix/eigs.js +3 -3
- package/lib/esm/function/matrix/fft.js +3 -3
- package/lib/esm/function/matrix/filter.js +4 -4
- package/lib/esm/function/matrix/flatten.js +5 -6
- package/lib/esm/function/matrix/forEach.js +4 -4
- package/lib/esm/function/matrix/identity.js +6 -6
- package/lib/esm/function/matrix/ifft.js +3 -3
- package/lib/esm/function/matrix/inv.js +1 -1
- package/lib/esm/function/matrix/kron.js +7 -7
- package/lib/esm/function/matrix/map.js +110 -19
- package/lib/esm/function/matrix/matrixFromFunction.js +6 -6
- package/lib/esm/function/matrix/ones.js +2 -2
- package/lib/esm/function/matrix/partitionSelect.js +2 -2
- package/lib/esm/function/matrix/pinv.js +1 -1
- package/lib/esm/function/matrix/range.js +10 -10
- package/lib/esm/function/matrix/reshape.js +2 -2
- package/lib/esm/function/matrix/rotate.js +4 -4
- package/lib/esm/function/matrix/rotationMatrix.js +6 -6
- package/lib/esm/function/matrix/row.js +1 -1
- package/lib/esm/function/matrix/size.js +8 -8
- package/lib/esm/function/matrix/sort.js +4 -4
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/function/matrix/squeeze.js +3 -4
- package/lib/esm/function/matrix/subset.js +2 -2
- package/lib/esm/function/matrix/zeros.js +2 -2
- package/lib/esm/function/probability/combinations.js +1 -1
- package/lib/esm/function/probability/combinationsWithRep.js +2 -2
- package/lib/esm/function/probability/kldivergence.js +4 -4
- package/lib/esm/function/probability/multinomial.js +1 -1
- package/lib/esm/function/probability/permutations.js +2 -2
- package/lib/esm/function/probability/pickRandom.js +6 -6
- package/lib/esm/function/probability/random.js +1 -1
- package/lib/esm/function/probability/randomInt.js +1 -1
- package/lib/esm/function/relational/compare.js +6 -6
- package/lib/esm/function/relational/deepEqual.js +1 -1
- package/lib/esm/function/relational/equal.js +1 -1
- package/lib/esm/function/relational/equalScalar.js +7 -7
- package/lib/esm/function/relational/equalText.js +1 -1
- package/lib/esm/function/relational/larger.js +3 -3
- package/lib/esm/function/relational/largerEq.js +4 -4
- package/lib/esm/function/relational/smaller.js +3 -3
- package/lib/esm/function/relational/smallerEq.js +3 -3
- package/lib/esm/function/relational/unequal.js +1 -1
- package/lib/esm/function/set/setCartesian.js +1 -1
- package/lib/esm/function/set/setDifference.js +1 -1
- package/lib/esm/function/set/setDistinct.js +1 -1
- package/lib/esm/function/set/setIntersect.js +1 -1
- package/lib/esm/function/set/setIsSubset.js +1 -1
- package/lib/esm/function/set/setMultiplicity.js +1 -1
- package/lib/esm/function/set/setPowerset.js +1 -1
- package/lib/esm/function/set/setSize.js +2 -2
- package/lib/esm/function/set/setSymDifference.js +1 -1
- package/lib/esm/function/set/setUnion.js +1 -1
- package/lib/esm/function/signal/freqz.js +6 -6
- package/lib/esm/function/statistics/corr.js +2 -2
- package/lib/esm/function/statistics/cumsum.js +3 -3
- package/lib/esm/function/statistics/max.js +1 -1
- package/lib/esm/function/statistics/median.js +3 -3
- package/lib/esm/function/statistics/min.js +1 -1
- package/lib/esm/function/statistics/prod.js +1 -1
- package/lib/esm/function/statistics/variance.js +2 -2
- package/lib/esm/function/string/bin.js +2 -2
- package/lib/esm/function/string/hex.js +2 -2
- package/lib/esm/function/string/oct.js +2 -2
- package/lib/esm/function/trigonometry/acoth.js +2 -2
- package/lib/esm/function/trigonometry/acsch.js +2 -2
- package/lib/esm/type/bigint.js +1 -1
- package/lib/esm/type/complex/function/complex.js +2 -2
- package/lib/esm/type/fraction/function/fraction.js +1 -1
- package/lib/esm/type/matrix/DenseMatrix.js +13 -38
- package/lib/esm/type/matrix/SparseMatrix.js +5 -8
- package/lib/esm/type/matrix/function/index.js +1 -1
- package/lib/esm/type/matrix/function/matrix.js +1 -1
- package/lib/esm/type/matrix/function/sparse.js +2 -2
- package/lib/esm/type/number.js +1 -1
- package/lib/esm/type/unit/function/createUnit.js +3 -3
- package/lib/esm/type/unit/function/splitUnit.js +1 -1
- package/lib/esm/type/unit/function/unit.js +2 -2
- package/lib/esm/utils/array.js +26 -0
- package/lib/esm/utils/collection.js +1 -1
- package/lib/esm/utils/function.js +0 -13
- package/lib/esm/utils/is.js +24 -0
- package/lib/esm/utils/map.js +2 -19
- package/lib/esm/version.js +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +57 -18
@@ -54,37 +54,37 @@ export var createDiag = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
54
54
|
Array: function Array(x) {
|
55
55
|
return _diag(x, 0, arraySize(x), null);
|
56
56
|
},
|
57
|
-
'Array, number': function
|
57
|
+
'Array, number': function Array_number(x, k) {
|
58
58
|
return _diag(x, k, arraySize(x), null);
|
59
59
|
},
|
60
|
-
'Array, BigNumber': function
|
60
|
+
'Array, BigNumber': function Array_BigNumber(x, k) {
|
61
61
|
return _diag(x, k.toNumber(), arraySize(x), null);
|
62
62
|
},
|
63
|
-
'Array, string': function
|
63
|
+
'Array, string': function Array_string(x, format) {
|
64
64
|
return _diag(x, 0, arraySize(x), format);
|
65
65
|
},
|
66
|
-
'Array, number, string': function
|
66
|
+
'Array, number, string': function Array_number_string(x, k, format) {
|
67
67
|
return _diag(x, k, arraySize(x), format);
|
68
68
|
},
|
69
|
-
'Array, BigNumber, string': function
|
69
|
+
'Array, BigNumber, string': function Array_BigNumber_string(x, k, format) {
|
70
70
|
return _diag(x, k.toNumber(), arraySize(x), format);
|
71
71
|
},
|
72
72
|
Matrix: function Matrix(x) {
|
73
73
|
return _diag(x, 0, x.size(), x.storage());
|
74
74
|
},
|
75
|
-
'Matrix, number': function
|
75
|
+
'Matrix, number': function Matrix_number(x, k) {
|
76
76
|
return _diag(x, k, x.size(), x.storage());
|
77
77
|
},
|
78
|
-
'Matrix, BigNumber': function
|
78
|
+
'Matrix, BigNumber': function Matrix_BigNumber(x, k) {
|
79
79
|
return _diag(x, k.toNumber(), x.size(), x.storage());
|
80
80
|
},
|
81
|
-
'Matrix, string': function
|
81
|
+
'Matrix, string': function Matrix_string(x, format) {
|
82
82
|
return _diag(x, 0, x.size(), format);
|
83
83
|
},
|
84
|
-
'Matrix, number, string': function
|
84
|
+
'Matrix, number, string': function Matrix_number_string(x, k, format) {
|
85
85
|
return _diag(x, k, x.size(), format);
|
86
86
|
},
|
87
|
-
'Matrix, BigNumber, string': function
|
87
|
+
'Matrix, BigNumber, string': function Matrix_BigNumber_string(x, k, format) {
|
88
88
|
return _diag(x, k.toNumber(), x.size(), format);
|
89
89
|
}
|
90
90
|
});
|
@@ -57,7 +57,7 @@ export var createDiff = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
57
57
|
* @return {Array | Matrix} Difference between array elements in given dimension
|
58
58
|
*/
|
59
59
|
return typed(name, {
|
60
|
-
'Array | Matrix': function
|
60
|
+
'Array | Matrix': function Array__Matrix(arr) {
|
61
61
|
// No dimension specified => assume dimension 0
|
62
62
|
if (isMatrix(arr)) {
|
63
63
|
return matrix(_diff(arr.toArray()));
|
@@ -65,7 +65,7 @@ export var createDiff = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
65
65
|
return _diff(arr);
|
66
66
|
}
|
67
67
|
},
|
68
|
-
'Array | Matrix, number': function
|
68
|
+
'Array | Matrix, number': function Array__Matrix_number(arr, dim) {
|
69
69
|
if (!isInteger(dim)) throw new RangeError('Dimension must be a whole number');
|
70
70
|
if (isMatrix(arr)) {
|
71
71
|
return matrix(_recursive(arr.toArray(), dim));
|
@@ -158,7 +158,7 @@ export var createEigs = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
158
158
|
Array: function Array(x) {
|
159
159
|
return doEigs(matrix(x));
|
160
160
|
},
|
161
|
-
'Array, number|BigNumber': function
|
161
|
+
'Array, number|BigNumber': function Array_numberBigNumber(x, prec) {
|
162
162
|
return doEigs(matrix(x), {
|
163
163
|
precision: prec
|
164
164
|
});
|
@@ -171,13 +171,13 @@ export var createEigs = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
171
171
|
matricize: true
|
172
172
|
});
|
173
173
|
},
|
174
|
-
'Matrix, number|BigNumber': function
|
174
|
+
'Matrix, number|BigNumber': function Matrix_numberBigNumber(mat, prec) {
|
175
175
|
return doEigs(mat, {
|
176
176
|
precision: prec,
|
177
177
|
matricize: true
|
178
178
|
});
|
179
179
|
},
|
180
|
-
'Matrix, Object': function
|
180
|
+
'Matrix, Object': function Matrix_Object(mat, opts) {
|
181
181
|
var useOpts = {
|
182
182
|
matricize: true
|
183
183
|
};
|
@@ -19,7 +19,7 @@ export var createFft = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
19
19
|
log2
|
20
20
|
} = _ref;
|
21
21
|
/**
|
22
|
-
* Calculate N-dimensional
|
22
|
+
* Calculate N-dimensional Fourier transform
|
23
23
|
*
|
24
24
|
* Syntax:
|
25
25
|
*
|
@@ -35,12 +35,12 @@ export var createFft = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
35
35
|
* ifft
|
36
36
|
*
|
37
37
|
* @param {Array | Matrix} arr An array or matrix
|
38
|
-
* @return {Array | Matrix} N-dimensional
|
38
|
+
* @return {Array | Matrix} N-dimensional Fourier transformation of the array
|
39
39
|
*/
|
40
40
|
return typed(name, {
|
41
41
|
Array: _ndFft,
|
42
42
|
Matrix: function Matrix(matrix) {
|
43
|
-
return matrix.create(_ndFft(matrix.
|
43
|
+
return matrix.create(_ndFft(matrix.valueOf()), matrix.datatype());
|
44
44
|
}
|
45
45
|
});
|
46
46
|
|
@@ -38,12 +38,12 @@ export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
38
38
|
*/
|
39
39
|
return typed('filter', {
|
40
40
|
'Array, function': _filterCallback,
|
41
|
-
'Matrix, function': function
|
42
|
-
return x.create(_filterCallback(x.
|
41
|
+
'Matrix, function': function Matrix_function(x, test) {
|
42
|
+
return x.create(_filterCallback(x.valueOf(), test), x.datatype());
|
43
43
|
},
|
44
44
|
'Array, RegExp': filterRegExp,
|
45
|
-
'Matrix, RegExp': function
|
46
|
-
return x.create(filterRegExp(x.
|
45
|
+
'Matrix, RegExp': function Matrix_RegExp(x, test) {
|
46
|
+
return x.create(filterRegExp(x.valueOf(), test), x.datatype());
|
47
47
|
}
|
48
48
|
});
|
49
49
|
});
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { flatten as flattenArray } from '../../utils/array.js';
|
2
2
|
import { factory } from '../../utils/factory.js';
|
3
3
|
var name = 'flatten';
|
4
|
-
var dependencies = ['typed'
|
4
|
+
var dependencies = ['typed'];
|
5
5
|
export var createFlatten = /* #__PURE__ */factory(name, dependencies, _ref => {
|
6
6
|
var {
|
7
|
-
typed
|
8
|
-
matrix
|
7
|
+
typed
|
9
8
|
} = _ref;
|
10
9
|
/**
|
11
10
|
* Flatten a multidimensional matrix into a single dimensional matrix.
|
@@ -31,9 +30,9 @@ export var createFlatten = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
31
30
|
return flattenArray(x);
|
32
31
|
},
|
33
32
|
Matrix: function Matrix(x) {
|
34
|
-
|
35
|
-
//
|
36
|
-
return
|
33
|
+
// Return the same matrix type as x (Dense or Sparse Matrix)
|
34
|
+
// Return the same data type as x
|
35
|
+
return x.create(flattenArray(x.toArray()), x.datatype());
|
37
36
|
}
|
38
37
|
});
|
39
38
|
});
|
@@ -32,7 +32,7 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
32
32
|
*/
|
33
33
|
return typed(name, {
|
34
34
|
'Array, function': _forEach,
|
35
|
-
'Matrix, function': function
|
35
|
+
'Matrix, function': function Matrix_function(x, callback) {
|
36
36
|
x.forEach(callback);
|
37
37
|
}
|
38
38
|
});
|
@@ -45,16 +45,16 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
45
45
|
* @private
|
46
46
|
*/
|
47
47
|
function _forEach(array, callback) {
|
48
|
-
var
|
48
|
+
var _recurse = function recurse(value, index) {
|
49
49
|
if (Array.isArray(value)) {
|
50
50
|
forEachArray(value, function (child, i) {
|
51
51
|
// we create a copy of the index array and append the new index value
|
52
|
-
|
52
|
+
_recurse(child, index.concat(i));
|
53
53
|
});
|
54
54
|
} else {
|
55
55
|
// invoke the callback function with the right number of arguments
|
56
56
|
return applyCallback(callback, value, index, array, 'forEach');
|
57
57
|
}
|
58
58
|
};
|
59
|
-
|
59
|
+
_recurse(array, []);
|
60
60
|
}
|
@@ -50,28 +50,28 @@ export var createIdentity = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
50
50
|
string: function string(format) {
|
51
51
|
return matrix(format);
|
52
52
|
},
|
53
|
-
'number | BigNumber': function
|
53
|
+
'number | BigNumber': function number__BigNumber(rows) {
|
54
54
|
return _identity(rows, rows, config.matrix === 'Matrix' ? 'dense' : undefined);
|
55
55
|
},
|
56
|
-
'number | BigNumber, string': function
|
56
|
+
'number | BigNumber, string': function number__BigNumber_string(rows, format) {
|
57
57
|
return _identity(rows, rows, format);
|
58
58
|
},
|
59
|
-
'number | BigNumber, number | BigNumber': function
|
59
|
+
'number | BigNumber, number | BigNumber': function number__BigNumber_number__BigNumber(rows, cols) {
|
60
60
|
return _identity(rows, cols, config.matrix === 'Matrix' ? 'dense' : undefined);
|
61
61
|
},
|
62
|
-
'number | BigNumber, number | BigNumber, string': function
|
62
|
+
'number | BigNumber, number | BigNumber, string': function number__BigNumber_number__BigNumber_string(rows, cols, format) {
|
63
63
|
return _identity(rows, cols, format);
|
64
64
|
},
|
65
65
|
Array: function Array(size) {
|
66
66
|
return _identityVector(size);
|
67
67
|
},
|
68
|
-
'Array, string': function
|
68
|
+
'Array, string': function Array_string(size, format) {
|
69
69
|
return _identityVector(size, format);
|
70
70
|
},
|
71
71
|
Matrix: function Matrix(size) {
|
72
72
|
return _identityVector(size.valueOf(), size.storage());
|
73
73
|
},
|
74
|
-
'Matrix, string': function
|
74
|
+
'Matrix, string': function Matrix_string(size, format) {
|
75
75
|
return _identityVector(size.valueOf(), format);
|
76
76
|
}
|
77
77
|
});
|
@@ -11,7 +11,7 @@ export var createIfft = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
11
11
|
conj
|
12
12
|
} = _ref;
|
13
13
|
/**
|
14
|
-
* Calculate N-dimensional inverse
|
14
|
+
* Calculate N-dimensional inverse Fourier transform
|
15
15
|
*
|
16
16
|
* Syntax:
|
17
17
|
*
|
@@ -26,10 +26,10 @@ export var createIfft = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
26
26
|
* fft
|
27
27
|
*
|
28
28
|
* @param {Array | Matrix} arr An array or matrix
|
29
|
-
* @return {Array | Matrix} N-dimensional
|
29
|
+
* @return {Array | Matrix} N-dimensional Fourier transformation of the array
|
30
30
|
*/
|
31
31
|
return typed(name, {
|
32
|
-
'Array | Matrix': function
|
32
|
+
'Array | Matrix': function Array__Matrix(arr) {
|
33
33
|
var size = isMatrix(arr) ? arr.size() : arraySize(arr);
|
34
34
|
return dotDivide(conj(fft(conj(arr))), size.reduce((acc, curr) => acc * curr, 1));
|
35
35
|
}
|
@@ -37,7 +37,7 @@ export var createInv = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
37
37
|
* @return {number | Complex | Array | Matrix} The inverse of `x`.
|
38
38
|
*/
|
39
39
|
return typed(name, {
|
40
|
-
'Array | Matrix': function
|
40
|
+
'Array | Matrix': function Array__Matrix(x) {
|
41
41
|
var size = isMatrix(x) ? x.size() : arraySize(x);
|
42
42
|
switch (size.length) {
|
43
43
|
case 1:
|
@@ -9,7 +9,7 @@ export var createKron = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
9
9
|
multiplyScalar
|
10
10
|
} = _ref;
|
11
11
|
/**
|
12
|
-
* Calculates the
|
12
|
+
* Calculates the Kronecker product of 2 matrices or vectors.
|
13
13
|
*
|
14
14
|
* NOTE: If a one dimensional vector / matrix is given, it will be
|
15
15
|
* wrapped so its two dimensions.
|
@@ -33,26 +33,26 @@ export var createKron = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
33
33
|
*
|
34
34
|
* @param {Array | Matrix} x First vector
|
35
35
|
* @param {Array | Matrix} y Second vector
|
36
|
-
* @return {Array | Matrix} Returns the
|
36
|
+
* @return {Array | Matrix} Returns the Kronecker product of `x` and `y`
|
37
37
|
*/
|
38
38
|
return typed(name, {
|
39
|
-
'Matrix, Matrix': function
|
39
|
+
'Matrix, Matrix': function Matrix_Matrix(x, y) {
|
40
40
|
return matrix(_kron(x.toArray(), y.toArray()));
|
41
41
|
},
|
42
|
-
'Matrix, Array': function
|
42
|
+
'Matrix, Array': function Matrix_Array(x, y) {
|
43
43
|
return matrix(_kron(x.toArray(), y));
|
44
44
|
},
|
45
|
-
'Array, Matrix': function
|
45
|
+
'Array, Matrix': function Array_Matrix(x, y) {
|
46
46
|
return matrix(_kron(x, y.toArray()));
|
47
47
|
},
|
48
48
|
'Array, Array': _kron
|
49
49
|
});
|
50
50
|
|
51
51
|
/**
|
52
|
-
* Calculate the
|
52
|
+
* Calculate the Kronecker product of two matrices / vectors
|
53
53
|
* @param {Array} a First vector
|
54
54
|
* @param {Array} b Second vector
|
55
|
-
* @returns {Array} Returns the
|
55
|
+
* @returns {Array} Returns the Kronecker product of x and y
|
56
56
|
* @private
|
57
57
|
*/
|
58
58
|
function _kron(a, b) {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { applyCallback } from '../../utils/applyCallback.js';
|
2
|
+
import { arraySize, broadcastSizes, broadcastTo, get } from '../../utils/array.js';
|
2
3
|
import { factory } from '../../utils/factory.js';
|
3
4
|
var name = 'map';
|
4
5
|
var dependencies = ['typed'];
|
@@ -10,9 +11,12 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
10
11
|
* Create a new matrix or array with the results of a callback function executed on
|
11
12
|
* each entry of a given matrix/array.
|
12
13
|
*
|
13
|
-
* For each entry of the input,
|
14
|
-
*
|
15
|
-
*
|
14
|
+
* For each entry of the input,
|
15
|
+
*
|
16
|
+
* the callback is invoked with 2N + 1 arguments:
|
17
|
+
* the N values of the entry, the index at which that entry occurs, and the N full
|
18
|
+
* broadcasted matrix/array being traversed where N is the number of matrices being traversed.
|
19
|
+
* Note that because the matrix/array might be
|
16
20
|
* multidimensional, the "index" argument is always an array of numbers giving
|
17
21
|
* the index in each dimension. This is true even for vectors: the "index"
|
18
22
|
* argument is an array of length 1, rather than simply a number.
|
@@ -20,17 +24,23 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
20
24
|
* Syntax:
|
21
25
|
*
|
22
26
|
* math.map(x, callback)
|
27
|
+
* math.map(x, y, ..., callback)
|
23
28
|
*
|
24
29
|
* Examples:
|
25
30
|
*
|
26
31
|
* math.map([1, 2, 3], function(value) {
|
27
32
|
* return value * value
|
28
33
|
* }) // returns [1, 4, 9]
|
34
|
+
* math.map([1, 2], [3, 4], function(a, b) {
|
35
|
+
* return a + b
|
36
|
+
* }) // returns [4, 6]
|
29
37
|
*
|
30
38
|
* // The callback is normally called with three arguments:
|
31
39
|
* // callback(value, index, Array)
|
32
40
|
* // If you want to call with only one argument, use:
|
33
41
|
* math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
|
42
|
+
* // It can also be called with 2N + 1 arguments: for N arrays
|
43
|
+
* // callback(value1, value2, index, BroadcastedArray1, BroadcastedArray2)
|
34
44
|
*
|
35
45
|
* See also:
|
36
46
|
*
|
@@ -43,11 +53,82 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
43
53
|
* Transformed map of x; always has the same type and shape as x
|
44
54
|
*/
|
45
55
|
return typed(name, {
|
46
|
-
'Array, function':
|
47
|
-
'Matrix, function': function
|
56
|
+
'Array, function': _mapArray,
|
57
|
+
'Matrix, function': function Matrix_function(x, callback) {
|
48
58
|
return x.map(callback);
|
49
|
-
}
|
59
|
+
},
|
60
|
+
'Array|Matrix, Array|Matrix, ...Array|Matrix|function': (A, B, rest) => _mapMultiple([A, B, ...rest.slice(0, rest.length - 1)], rest[rest.length - 1])
|
50
61
|
});
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Maps over multiple arrays or matrices.
|
65
|
+
*
|
66
|
+
* @param {Array<Array|Matrix>} Arrays - An array of arrays or matrices to map over.
|
67
|
+
* @param {function} multiCallback - The callback function to apply to each element.
|
68
|
+
* @throws {Error} If the last argument is not a callback function.
|
69
|
+
* @returns {Array|Matrix} A new array or matrix with each element being the result of the callback function.
|
70
|
+
*
|
71
|
+
* @example
|
72
|
+
* _mapMultiple([[1, 2, 3], [4, 5, 6]], (a, b) => a + b); // Returns [5, 7, 9]
|
73
|
+
*/
|
74
|
+
function _mapMultiple(Arrays, multiCallback) {
|
75
|
+
if (typeof multiCallback !== 'function') {
|
76
|
+
throw new Error('Last argument must be a callback function');
|
77
|
+
}
|
78
|
+
var firstArrayIsMatrix = Arrays[0].isMatrix;
|
79
|
+
var newSize = broadcastSizes(...Arrays.map(M => M.isMatrix ? M.size() : arraySize(M)));
|
80
|
+
var _get = firstArrayIsMatrix ? (matrix, idx) => matrix.get(idx) : get;
|
81
|
+
var broadcastedArrays = firstArrayIsMatrix ? Arrays.map(M => M.isMatrix ? M.create(broadcastTo(M.toArray(), newSize), M.datatype()) : Arrays[0].create(broadcastTo(M.valueOf(), newSize))) : Arrays.map(M => M.isMatrix ? broadcastTo(M.toArray(), newSize) : broadcastTo(M, newSize));
|
82
|
+
var callback;
|
83
|
+
if (typed.isTypedFunction(multiCallback)) {
|
84
|
+
var firstIndex = newSize.map(() => 0);
|
85
|
+
var firstValues = broadcastedArrays.map(array => _get(array, firstIndex));
|
86
|
+
var callbackCase = _getTypedCallbackCase(multiCallback, firstValues, firstIndex, broadcastedArrays);
|
87
|
+
callback = _getLimitedCallback(callbackCase);
|
88
|
+
} else {
|
89
|
+
var numberOfArrays = Arrays.length;
|
90
|
+
var _callbackCase = _getCallbackCase(multiCallback, numberOfArrays);
|
91
|
+
callback = _getLimitedCallback(_callbackCase);
|
92
|
+
}
|
93
|
+
var broadcastedArraysCallback = (x, idx) => callback([x, ...broadcastedArrays.slice(1).map(Array => _get(Array, idx))], idx);
|
94
|
+
if (firstArrayIsMatrix) {
|
95
|
+
return broadcastedArrays[0].map(broadcastedArraysCallback);
|
96
|
+
} else {
|
97
|
+
return _mapArray(broadcastedArrays[0], broadcastedArraysCallback);
|
98
|
+
}
|
99
|
+
function _getLimitedCallback(callbackCase) {
|
100
|
+
switch (callbackCase) {
|
101
|
+
case 0:
|
102
|
+
return x => multiCallback(...x);
|
103
|
+
case 1:
|
104
|
+
return (x, idx) => multiCallback(...x, idx);
|
105
|
+
case 2:
|
106
|
+
return (x, idx) => multiCallback(...x, idx, ...broadcastedArrays);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
function _getCallbackCase(callback, numberOfArrays) {
|
110
|
+
if (callback.length > numberOfArrays + 1) {
|
111
|
+
return 2;
|
112
|
+
}
|
113
|
+
if (callback.length === numberOfArrays + 1) {
|
114
|
+
return 1;
|
115
|
+
}
|
116
|
+
return 0;
|
117
|
+
}
|
118
|
+
function _getTypedCallbackCase(callback, values, idx, arrays) {
|
119
|
+
if (typed.resolve(callback, [...values, idx, ...arrays]) !== null) {
|
120
|
+
return 2;
|
121
|
+
}
|
122
|
+
if (typed.resolve(callback, [...values, idx]) !== null) {
|
123
|
+
return 1;
|
124
|
+
}
|
125
|
+
if (typed.resolve(callback, values) !== null) {
|
126
|
+
return 0;
|
127
|
+
}
|
128
|
+
// this should never happen
|
129
|
+
return 0;
|
130
|
+
}
|
131
|
+
}
|
51
132
|
});
|
52
133
|
|
53
134
|
/**
|
@@ -57,17 +138,27 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
57
138
|
* @return {Array}
|
58
139
|
* @private
|
59
140
|
*/
|
60
|
-
function
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
141
|
+
function _mapArray(array, callback) {
|
142
|
+
return _recurse(array, [], array, callback);
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Recursive function to map a multi-dimensional array.
|
147
|
+
*
|
148
|
+
* @param {*} value - The current value being processed in the array.
|
149
|
+
* @param {Array} index - The index of the current value being processed in the array.
|
150
|
+
* @param {Array} array - The array being processed.
|
151
|
+
* @param {Function} callback - Function that produces the element of the new Array, taking three arguments: the value of the element, the index of the element, and the Array being processed.
|
152
|
+
* @returns {*} The new array with each element being the result of the callback function.
|
153
|
+
*/
|
154
|
+
function _recurse(value, index, array, callback) {
|
155
|
+
if (Array.isArray(value)) {
|
156
|
+
return value.map(function (child, i) {
|
157
|
+
// we create a copy of the index array and append the new index value
|
158
|
+
return _recurse(child, index.concat(i), array, callback);
|
159
|
+
});
|
160
|
+
} else {
|
161
|
+
// invoke the callback function with the right number of arguments
|
162
|
+
return applyCallback(callback, value, index, array, 'map');
|
163
|
+
}
|
73
164
|
}
|
@@ -37,22 +37,22 @@ export var createMatrixFromFunction = /* #__PURE__ */factory(name, dependencies,
|
|
37
37
|
* @return {Array | Matrix} Returns the created matrix
|
38
38
|
*/
|
39
39
|
return typed(name, {
|
40
|
-
'Array | Matrix, function, string, string': function
|
40
|
+
'Array | Matrix, function, string, string': function Array__Matrix_function_string_string(size, fn, format, datatype) {
|
41
41
|
return _create(size, fn, format, datatype);
|
42
42
|
},
|
43
|
-
'Array | Matrix, function, string': function
|
43
|
+
'Array | Matrix, function, string': function Array__Matrix_function_string(size, fn, format) {
|
44
44
|
return _create(size, fn, format);
|
45
45
|
},
|
46
|
-
'Matrix, function': function
|
46
|
+
'Matrix, function': function Matrix_function(size, fn) {
|
47
47
|
return _create(size, fn, 'dense');
|
48
48
|
},
|
49
|
-
'Array, function': function
|
49
|
+
'Array, function': function Array_function(size, fn) {
|
50
50
|
return _create(size, fn, 'dense').toArray();
|
51
51
|
},
|
52
|
-
'Array | Matrix, string, function': function
|
52
|
+
'Array | Matrix, string, function': function Array__Matrix_string_function(size, format, fn) {
|
53
53
|
return _create(size, fn, format);
|
54
54
|
},
|
55
|
-
'Array | Matrix, string, string, function': function
|
55
|
+
'Array | Matrix, string, string, function': function Array__Matrix_string_string_function(size, format, datatype, fn) {
|
56
56
|
return _create(size, fn, format, datatype);
|
57
57
|
}
|
58
58
|
});
|
@@ -51,7 +51,7 @@ export var createOnes = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
51
51
|
},
|
52
52
|
// math.ones(m, n, p, ..., format)
|
53
53
|
// TODO: more accurate signature '...number | BigNumber, string' as soon as typed-function supports this
|
54
|
-
'...number | BigNumber | string': function
|
54
|
+
'...number | BigNumber | string': function number__BigNumber__string(size) {
|
55
55
|
var last = size[size.length - 1];
|
56
56
|
if (typeof last === 'string') {
|
57
57
|
var format = size.pop();
|
@@ -67,7 +67,7 @@ export var createOnes = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
67
67
|
var format = size.storage();
|
68
68
|
return _ones(size.valueOf(), format);
|
69
69
|
},
|
70
|
-
'Array | Matrix, string': function
|
70
|
+
'Array | Matrix, string': function Array__Matrix_string(size, format) {
|
71
71
|
return _ones(size.valueOf(), format);
|
72
72
|
}
|
73
73
|
});
|
@@ -51,10 +51,10 @@ export var createPartitionSelect = /* #__PURE__ */factory(name, dependencies, _r
|
|
51
51
|
* @return {*} Returns the kth lowest value.
|
52
52
|
*/
|
53
53
|
return typed(name, {
|
54
|
-
'Array | Matrix, number': function
|
54
|
+
'Array | Matrix, number': function Array__Matrix_number(x, k) {
|
55
55
|
return _partitionSelect(x, k, asc);
|
56
56
|
},
|
57
|
-
'Array | Matrix, number, string': function
|
57
|
+
'Array | Matrix, number, string': function Array__Matrix_number_string(x, k, compare) {
|
58
58
|
if (compare === 'asc') {
|
59
59
|
return _partitionSelect(x, k, asc);
|
60
60
|
} else if (compare === 'desc') {
|
@@ -41,7 +41,7 @@ export var createPinv = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
41
41
|
* @return {number | Complex | Array | Matrix} The inverse of `x`.
|
42
42
|
*/
|
43
43
|
return typed(name, {
|
44
|
-
'Array | Matrix': function
|
44
|
+
'Array | Matrix': function Array__Matrix(x) {
|
45
45
|
var size = isMatrix(x) ? x.size() : arraySize(x);
|
46
46
|
switch (size.length) {
|
47
47
|
case 1:
|
@@ -65,36 +65,36 @@ export var createRange = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
65
65
|
// TODO: a number or boolean should not be converted to string here
|
66
66
|
string: _strRange,
|
67
67
|
'string, boolean': _strRange,
|
68
|
-
'number, number': function
|
68
|
+
'number, number': function number_number(start, end) {
|
69
69
|
return _out(_range(start, end, 1, false));
|
70
70
|
},
|
71
|
-
'number, number, number': function
|
71
|
+
'number, number, number': function number_number_number(start, end, step) {
|
72
72
|
return _out(_range(start, end, step, false));
|
73
73
|
},
|
74
|
-
'number, number, boolean': function
|
74
|
+
'number, number, boolean': function number_number_boolean(start, end, includeEnd) {
|
75
75
|
return _out(_range(start, end, 1, includeEnd));
|
76
76
|
},
|
77
|
-
'number, number, number, boolean': function
|
77
|
+
'number, number, number, boolean': function number_number_number_boolean(start, end, step, includeEnd) {
|
78
78
|
return _out(_range(start, end, step, includeEnd));
|
79
79
|
},
|
80
|
-
'BigNumber, BigNumber': function
|
80
|
+
'BigNumber, BigNumber': function BigNumber_BigNumber(start, end) {
|
81
81
|
var BigNumber = start.constructor;
|
82
82
|
return _out(_range(start, end, new BigNumber(1), false));
|
83
83
|
},
|
84
|
-
'BigNumber, BigNumber, BigNumber': function
|
84
|
+
'BigNumber, BigNumber, BigNumber': function BigNumber_BigNumber_BigNumber(start, end, step) {
|
85
85
|
return _out(_range(start, end, step, false));
|
86
86
|
},
|
87
|
-
'BigNumber, BigNumber, boolean': function
|
87
|
+
'BigNumber, BigNumber, boolean': function BigNumber_BigNumber_boolean(start, end, includeEnd) {
|
88
88
|
var BigNumber = start.constructor;
|
89
89
|
return _out(_range(start, end, new BigNumber(1), includeEnd));
|
90
90
|
},
|
91
|
-
'BigNumber, BigNumber, BigNumber, boolean': function
|
91
|
+
'BigNumber, BigNumber, BigNumber, boolean': function BigNumber_BigNumber_BigNumber_boolean(start, end, step, includeEnd) {
|
92
92
|
return _out(_range(start, end, step, includeEnd));
|
93
93
|
},
|
94
|
-
'Unit, Unit, Unit': function
|
94
|
+
'Unit, Unit, Unit': function Unit_Unit_Unit(start, end, step) {
|
95
95
|
return _out(_range(start, end, step, false));
|
96
96
|
},
|
97
|
-
'Unit, Unit, Unit, boolean': function
|
97
|
+
'Unit, Unit, Unit, boolean': function Unit_Unit_Unit_boolean(start, end, step, includeEnd) {
|
98
98
|
return _out(_range(start, end, step, includeEnd));
|
99
99
|
}
|
100
100
|
});
|
@@ -48,10 +48,10 @@ export var createReshape = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
48
48
|
* not equal that of the old ones
|
49
49
|
*/
|
50
50
|
return typed(name, {
|
51
|
-
'Matrix, Array': function
|
51
|
+
'Matrix, Array': function Matrix_Array(x, sizes) {
|
52
52
|
return x.reshape(sizes, true);
|
53
53
|
},
|
54
|
-
'Array, Array': function
|
54
|
+
'Array, Array': function Array_Array(x, sizes) {
|
55
55
|
sizes.forEach(function (size) {
|
56
56
|
if (!isInteger(size)) {
|
57
57
|
throw new TypeError('Invalid size for dimension: ' + size);
|
@@ -37,21 +37,21 @@ export var createRotate = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
37
37
|
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
38
38
|
*/
|
39
39
|
return typed(name, {
|
40
|
-
'Array , number | BigNumber | Complex | Unit': function
|
40
|
+
'Array , number | BigNumber | Complex | Unit': function Array__number__BigNumber__Complex__Unit(w, theta) {
|
41
41
|
_validateSize(w, 2);
|
42
42
|
var matrixRes = multiply(rotationMatrix(theta), w);
|
43
43
|
return matrixRes.toArray();
|
44
44
|
},
|
45
|
-
'Matrix , number | BigNumber | Complex | Unit': function
|
45
|
+
'Matrix , number | BigNumber | Complex | Unit': function Matrix__number__BigNumber__Complex__Unit(w, theta) {
|
46
46
|
_validateSize(w, 2);
|
47
47
|
return multiply(rotationMatrix(theta), w);
|
48
48
|
},
|
49
|
-
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function
|
49
|
+
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function Array_number__BigNumber__Complex__Unit_Array__Matrix(w, theta, v) {
|
50
50
|
_validateSize(w, 3);
|
51
51
|
var matrixRes = multiply(rotationMatrix(theta, v), w);
|
52
52
|
return matrixRes;
|
53
53
|
},
|
54
|
-
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function
|
54
|
+
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function Matrix_number__BigNumber__Complex__Unit_Array__Matrix(w, theta, v) {
|
55
55
|
_validateSize(w, 3);
|
56
56
|
return multiply(rotationMatrix(theta, v), w);
|
57
57
|
}
|