mathjs 13.0.2 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +26 -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/import.js +1 -1
- 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/type/unit/Unit.js +57 -114
- 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/import.js +1 -1
- 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/Unit.js +57 -114
- 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 +19 -19
- package/types/index.d.ts +108 -25
|
@@ -21,11 +21,11 @@ const createHypot = exports.createHypot = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
21
21
|
isPositive
|
|
22
22
|
} = _ref;
|
|
23
23
|
/**
|
|
24
|
-
* Calculate the
|
|
24
|
+
* Calculate the hypotenuse of a list with values. The hypotenuse is defined as:
|
|
25
25
|
*
|
|
26
26
|
* hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...)
|
|
27
27
|
*
|
|
28
|
-
* For matrix input, the
|
|
28
|
+
* For matrix input, the hypotenuse is calculated for all values in the matrix.
|
|
29
29
|
*
|
|
30
30
|
* Syntax:
|
|
31
31
|
*
|
|
@@ -55,7 +55,7 @@ const createHypot = exports.createHypot = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Calculate the
|
|
58
|
+
* Calculate the hypotenuse for an Array with values
|
|
59
59
|
* @param {Array.<number | BigNumber>} args
|
|
60
60
|
* @return {number | BigNumber} Returns the result
|
|
61
61
|
* @private
|
|
@@ -57,7 +57,7 @@ const createApply = exports.createApply = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
57
57
|
throw new _IndexError.IndexError(dim, size.length);
|
|
58
58
|
}
|
|
59
59
|
if ((0, _is.isMatrix)(mat)) {
|
|
60
|
-
return mat.create(_apply(mat.valueOf(), dim, callback));
|
|
60
|
+
return mat.create(_apply(mat.valueOf(), dim, callback), mat.datatype());
|
|
61
61
|
} else {
|
|
62
62
|
return _apply(mat, dim, callback);
|
|
63
63
|
}
|
|
@@ -25,7 +25,7 @@ const createFft = exports.createFft = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
25
25
|
log2
|
|
26
26
|
} = _ref;
|
|
27
27
|
/**
|
|
28
|
-
* Calculate N-dimensional
|
|
28
|
+
* Calculate N-dimensional Fourier transform
|
|
29
29
|
*
|
|
30
30
|
* Syntax:
|
|
31
31
|
*
|
|
@@ -41,12 +41,12 @@ const createFft = exports.createFft = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
41
41
|
* ifft
|
|
42
42
|
*
|
|
43
43
|
* @param {Array | Matrix} arr An array or matrix
|
|
44
|
-
* @return {Array | Matrix} N-dimensional
|
|
44
|
+
* @return {Array | Matrix} N-dimensional Fourier transformation of the array
|
|
45
45
|
*/
|
|
46
46
|
return typed(name, {
|
|
47
47
|
Array: _ndFft,
|
|
48
48
|
Matrix: function (matrix) {
|
|
49
|
-
return matrix.create(_ndFft(matrix.
|
|
49
|
+
return matrix.create(_ndFft(matrix.valueOf()), matrix.datatype());
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -45,11 +45,11 @@ const createFilter = exports.createFilter = /* #__PURE__ */(0, _factory.factory)
|
|
|
45
45
|
return typed('filter', {
|
|
46
46
|
'Array, function': _filterCallback,
|
|
47
47
|
'Matrix, function': function (x, test) {
|
|
48
|
-
return x.create(_filterCallback(x.
|
|
48
|
+
return x.create(_filterCallback(x.valueOf(), test), x.datatype());
|
|
49
49
|
},
|
|
50
50
|
'Array, RegExp': _array.filterRegExp,
|
|
51
51
|
'Matrix, RegExp': function (x, test) {
|
|
52
|
-
return x.create((0, _array.filterRegExp)(x.
|
|
52
|
+
return x.create((0, _array.filterRegExp)(x.valueOf(), test), x.datatype());
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
});
|
|
@@ -7,11 +7,10 @@ exports.createFlatten = void 0;
|
|
|
7
7
|
var _array = require("../../utils/array.js");
|
|
8
8
|
var _factory = require("../../utils/factory.js");
|
|
9
9
|
const name = 'flatten';
|
|
10
|
-
const dependencies = ['typed'
|
|
10
|
+
const dependencies = ['typed'];
|
|
11
11
|
const createFlatten = exports.createFlatten = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
12
12
|
let {
|
|
13
|
-
typed
|
|
14
|
-
matrix
|
|
13
|
+
typed
|
|
15
14
|
} = _ref;
|
|
16
15
|
/**
|
|
17
16
|
* Flatten a multidimensional matrix into a single dimensional matrix.
|
|
@@ -37,9 +36,9 @@ const createFlatten = exports.createFlatten = /* #__PURE__ */(0, _factory.factor
|
|
|
37
36
|
return (0, _array.flatten)(x);
|
|
38
37
|
},
|
|
39
38
|
Matrix: function (x) {
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
return
|
|
39
|
+
// Return the same matrix type as x (Dense or Sparse Matrix)
|
|
40
|
+
// Return the same data type as x
|
|
41
|
+
return x.create((0, _array.flatten)(x.toArray()), x.datatype());
|
|
43
42
|
}
|
|
44
43
|
});
|
|
45
44
|
});
|
|
@@ -17,7 +17,7 @@ const createIfft = exports.createIfft = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
17
17
|
conj
|
|
18
18
|
} = _ref;
|
|
19
19
|
/**
|
|
20
|
-
* Calculate N-dimensional inverse
|
|
20
|
+
* Calculate N-dimensional inverse Fourier transform
|
|
21
21
|
*
|
|
22
22
|
* Syntax:
|
|
23
23
|
*
|
|
@@ -32,7 +32,7 @@ const createIfft = exports.createIfft = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
32
32
|
* fft
|
|
33
33
|
*
|
|
34
34
|
* @param {Array | Matrix} arr An array or matrix
|
|
35
|
-
* @return {Array | Matrix} N-dimensional
|
|
35
|
+
* @return {Array | Matrix} N-dimensional Fourier transformation of the array
|
|
36
36
|
*/
|
|
37
37
|
return typed(name, {
|
|
38
38
|
'Array | Matrix': function (arr) {
|
|
@@ -15,7 +15,7 @@ const createKron = exports.createKron = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
15
15
|
multiplyScalar
|
|
16
16
|
} = _ref;
|
|
17
17
|
/**
|
|
18
|
-
* Calculates the
|
|
18
|
+
* Calculates the Kronecker product of 2 matrices or vectors.
|
|
19
19
|
*
|
|
20
20
|
* NOTE: If a one dimensional vector / matrix is given, it will be
|
|
21
21
|
* wrapped so its two dimensions.
|
|
@@ -39,7 +39,7 @@ const createKron = exports.createKron = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
39
39
|
*
|
|
40
40
|
* @param {Array | Matrix} x First vector
|
|
41
41
|
* @param {Array | Matrix} y Second vector
|
|
42
|
-
* @return {Array | Matrix} Returns the
|
|
42
|
+
* @return {Array | Matrix} Returns the Kronecker product of `x` and `y`
|
|
43
43
|
*/
|
|
44
44
|
return typed(name, {
|
|
45
45
|
'Matrix, Matrix': function (x, y) {
|
|
@@ -55,10 +55,10 @@ const createKron = exports.createKron = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Calculate the
|
|
58
|
+
* Calculate the Kronecker product of two matrices / vectors
|
|
59
59
|
* @param {Array} a First vector
|
|
60
60
|
* @param {Array} b Second vector
|
|
61
|
-
* @returns {Array} Returns the
|
|
61
|
+
* @returns {Array} Returns the Kronecker product of x and y
|
|
62
62
|
* @private
|
|
63
63
|
*/
|
|
64
64
|
function _kron(a, b) {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createMap = void 0;
|
|
7
7
|
var _applyCallback = require("../../utils/applyCallback.js");
|
|
8
|
+
var _array = require("../../utils/array.js");
|
|
8
9
|
var _factory = require("../../utils/factory.js");
|
|
9
10
|
const name = 'map';
|
|
10
11
|
const dependencies = ['typed'];
|
|
@@ -16,9 +17,12 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
16
17
|
* Create a new matrix or array with the results of a callback function executed on
|
|
17
18
|
* each entry of a given matrix/array.
|
|
18
19
|
*
|
|
19
|
-
* For each entry of the input,
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* For each entry of the input,
|
|
21
|
+
*
|
|
22
|
+
* the callback is invoked with 2N + 1 arguments:
|
|
23
|
+
* the N values of the entry, the index at which that entry occurs, and the N full
|
|
24
|
+
* broadcasted matrix/array being traversed where N is the number of matrices being traversed.
|
|
25
|
+
* Note that because the matrix/array might be
|
|
22
26
|
* multidimensional, the "index" argument is always an array of numbers giving
|
|
23
27
|
* the index in each dimension. This is true even for vectors: the "index"
|
|
24
28
|
* argument is an array of length 1, rather than simply a number.
|
|
@@ -26,17 +30,23 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
26
30
|
* Syntax:
|
|
27
31
|
*
|
|
28
32
|
* math.map(x, callback)
|
|
33
|
+
* math.map(x, y, ..., callback)
|
|
29
34
|
*
|
|
30
35
|
* Examples:
|
|
31
36
|
*
|
|
32
37
|
* math.map([1, 2, 3], function(value) {
|
|
33
38
|
* return value * value
|
|
34
39
|
* }) // returns [1, 4, 9]
|
|
40
|
+
* math.map([1, 2], [3, 4], function(a, b) {
|
|
41
|
+
* return a + b
|
|
42
|
+
* }) // returns [4, 6]
|
|
35
43
|
*
|
|
36
44
|
* // The callback is normally called with three arguments:
|
|
37
45
|
* // callback(value, index, Array)
|
|
38
46
|
* // If you want to call with only one argument, use:
|
|
39
47
|
* math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
|
|
48
|
+
* // It can also be called with 2N + 1 arguments: for N arrays
|
|
49
|
+
* // callback(value1, value2, index, BroadcastedArray1, BroadcastedArray2)
|
|
40
50
|
*
|
|
41
51
|
* See also:
|
|
42
52
|
*
|
|
@@ -49,11 +59,82 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
49
59
|
* Transformed map of x; always has the same type and shape as x
|
|
50
60
|
*/
|
|
51
61
|
return typed(name, {
|
|
52
|
-
'Array, function':
|
|
62
|
+
'Array, function': _mapArray,
|
|
53
63
|
'Matrix, function': function (x, callback) {
|
|
54
64
|
return x.map(callback);
|
|
55
|
-
}
|
|
65
|
+
},
|
|
66
|
+
'Array|Matrix, Array|Matrix, ...Array|Matrix|function': (A, B, rest) => _mapMultiple([A, B, ...rest.slice(0, rest.length - 1)], rest[rest.length - 1])
|
|
56
67
|
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Maps over multiple arrays or matrices.
|
|
71
|
+
*
|
|
72
|
+
* @param {Array<Array|Matrix>} Arrays - An array of arrays or matrices to map over.
|
|
73
|
+
* @param {function} multiCallback - The callback function to apply to each element.
|
|
74
|
+
* @throws {Error} If the last argument is not a callback function.
|
|
75
|
+
* @returns {Array|Matrix} A new array or matrix with each element being the result of the callback function.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* _mapMultiple([[1, 2, 3], [4, 5, 6]], (a, b) => a + b); // Returns [5, 7, 9]
|
|
79
|
+
*/
|
|
80
|
+
function _mapMultiple(Arrays, multiCallback) {
|
|
81
|
+
if (typeof multiCallback !== 'function') {
|
|
82
|
+
throw new Error('Last argument must be a callback function');
|
|
83
|
+
}
|
|
84
|
+
const firstArrayIsMatrix = Arrays[0].isMatrix;
|
|
85
|
+
const newSize = (0, _array.broadcastSizes)(...Arrays.map(M => M.isMatrix ? M.size() : (0, _array.arraySize)(M)));
|
|
86
|
+
const _get = firstArrayIsMatrix ? (matrix, idx) => matrix.get(idx) : _array.get;
|
|
87
|
+
const broadcastedArrays = firstArrayIsMatrix ? Arrays.map(M => M.isMatrix ? M.create((0, _array.broadcastTo)(M.toArray(), newSize), M.datatype()) : Arrays[0].create((0, _array.broadcastTo)(M.valueOf(), newSize))) : Arrays.map(M => M.isMatrix ? (0, _array.broadcastTo)(M.toArray(), newSize) : (0, _array.broadcastTo)(M, newSize));
|
|
88
|
+
let callback;
|
|
89
|
+
if (typed.isTypedFunction(multiCallback)) {
|
|
90
|
+
const firstIndex = newSize.map(() => 0);
|
|
91
|
+
const firstValues = broadcastedArrays.map(array => _get(array, firstIndex));
|
|
92
|
+
const callbackCase = _getTypedCallbackCase(multiCallback, firstValues, firstIndex, broadcastedArrays);
|
|
93
|
+
callback = _getLimitedCallback(callbackCase);
|
|
94
|
+
} else {
|
|
95
|
+
const numberOfArrays = Arrays.length;
|
|
96
|
+
const callbackCase = _getCallbackCase(multiCallback, numberOfArrays);
|
|
97
|
+
callback = _getLimitedCallback(callbackCase);
|
|
98
|
+
}
|
|
99
|
+
const broadcastedArraysCallback = (x, idx) => callback([x, ...broadcastedArrays.slice(1).map(Array => _get(Array, idx))], idx);
|
|
100
|
+
if (firstArrayIsMatrix) {
|
|
101
|
+
return broadcastedArrays[0].map(broadcastedArraysCallback);
|
|
102
|
+
} else {
|
|
103
|
+
return _mapArray(broadcastedArrays[0], broadcastedArraysCallback);
|
|
104
|
+
}
|
|
105
|
+
function _getLimitedCallback(callbackCase) {
|
|
106
|
+
switch (callbackCase) {
|
|
107
|
+
case 0:
|
|
108
|
+
return x => multiCallback(...x);
|
|
109
|
+
case 1:
|
|
110
|
+
return (x, idx) => multiCallback(...x, idx);
|
|
111
|
+
case 2:
|
|
112
|
+
return (x, idx) => multiCallback(...x, idx, ...broadcastedArrays);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function _getCallbackCase(callback, numberOfArrays) {
|
|
116
|
+
if (callback.length > numberOfArrays + 1) {
|
|
117
|
+
return 2;
|
|
118
|
+
}
|
|
119
|
+
if (callback.length === numberOfArrays + 1) {
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
function _getTypedCallbackCase(callback, values, idx, arrays) {
|
|
125
|
+
if (typed.resolve(callback, [...values, idx, ...arrays]) !== null) {
|
|
126
|
+
return 2;
|
|
127
|
+
}
|
|
128
|
+
if (typed.resolve(callback, [...values, idx]) !== null) {
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
if (typed.resolve(callback, values) !== null) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
// this should never happen
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
57
138
|
});
|
|
58
139
|
|
|
59
140
|
/**
|
|
@@ -63,17 +144,27 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
63
144
|
* @return {Array}
|
|
64
145
|
* @private
|
|
65
146
|
*/
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
147
|
+
function _mapArray(array, callback) {
|
|
148
|
+
return _recurse(array, [], array, callback);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Recursive function to map a multi-dimensional array.
|
|
153
|
+
*
|
|
154
|
+
* @param {*} value - The current value being processed in the array.
|
|
155
|
+
* @param {Array} index - The index of the current value being processed in the array.
|
|
156
|
+
* @param {Array} array - The array being processed.
|
|
157
|
+
* @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.
|
|
158
|
+
* @returns {*} The new array with each element being the result of the callback function.
|
|
159
|
+
*/
|
|
160
|
+
function _recurse(value, index, array, callback) {
|
|
161
|
+
if (Array.isArray(value)) {
|
|
162
|
+
return value.map(function (child, i) {
|
|
163
|
+
// we create a copy of the index array and append the new index value
|
|
164
|
+
return _recurse(child, index.concat(i), array, callback);
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
// invoke the callback function with the right number of arguments
|
|
168
|
+
return (0, _applyCallback.applyCallback)(callback, value, index, array, 'map');
|
|
169
|
+
}
|
|
79
170
|
}
|
|
@@ -24,12 +24,12 @@ const createSize = exports.createSize = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
24
24
|
*
|
|
25
25
|
* Examples:
|
|
26
26
|
*
|
|
27
|
-
* math.size(2.3)
|
|
28
|
-
* math.size('hello world')
|
|
27
|
+
* math.size(2.3) // returns []
|
|
28
|
+
* math.size('hello world') // returns [11]
|
|
29
29
|
*
|
|
30
30
|
* const A = [[1, 2, 3], [4, 5, 6]]
|
|
31
|
-
* math.size(A)
|
|
32
|
-
* math.size(math.range(1,6))
|
|
31
|
+
* math.size(A) // returns [2, 3]
|
|
32
|
+
* math.size(math.range(1,6).toArray()) // returns [5]
|
|
33
33
|
*
|
|
34
34
|
* See also:
|
|
35
35
|
*
|
|
@@ -40,15 +40,15 @@ const createSize = exports.createSize = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
40
40
|
*/
|
|
41
41
|
return typed(name, {
|
|
42
42
|
Matrix: function (x) {
|
|
43
|
-
return x.create(x.size());
|
|
43
|
+
return x.create(x.size(), 'number');
|
|
44
44
|
},
|
|
45
45
|
Array: _array.arraySize,
|
|
46
46
|
string: function (x) {
|
|
47
|
-
return config.matrix === 'Array' ? [x.length] : matrix([x.length]);
|
|
47
|
+
return config.matrix === 'Array' ? [x.length] : matrix([x.length], 'dense', 'number');
|
|
48
48
|
},
|
|
49
49
|
'number | Complex | BigNumber | Unit | boolean | null': function (x) {
|
|
50
50
|
// scalar
|
|
51
|
-
return config.matrix === 'Array' ? [] : matrix ? matrix([]) : (0, _noop.noMatrix)();
|
|
51
|
+
return config.matrix === 'Array' ? [] : matrix ? matrix([], 'dense', 'number') : (0, _noop.noMatrix)();
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
});
|
|
@@ -8,11 +8,10 @@ var _object = require("../../utils/object.js");
|
|
|
8
8
|
var _array = require("../../utils/array.js");
|
|
9
9
|
var _factory = require("../../utils/factory.js");
|
|
10
10
|
const name = 'squeeze';
|
|
11
|
-
const dependencies = ['typed'
|
|
11
|
+
const dependencies = ['typed'];
|
|
12
12
|
const createSqueeze = exports.createSqueeze = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
13
13
|
let {
|
|
14
|
-
typed
|
|
15
|
-
matrix
|
|
14
|
+
typed
|
|
16
15
|
} = _ref;
|
|
17
16
|
/**
|
|
18
17
|
* Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
|
|
@@ -50,7 +49,7 @@ const createSqueeze = exports.createSqueeze = /* #__PURE__ */(0, _factory.factor
|
|
|
50
49
|
Matrix: function (x) {
|
|
51
50
|
const res = (0, _array.squeeze)(x.toArray());
|
|
52
51
|
// FIXME: return the same type of matrix as the input
|
|
53
|
-
return Array.isArray(res) ?
|
|
52
|
+
return Array.isArray(res) ? x.create(res, x.datatype()) : res;
|
|
54
53
|
},
|
|
55
54
|
any: function (x) {
|
|
56
55
|
// scalar
|
|
@@ -66,7 +66,7 @@ const createRandom = exports.createRandom = /* #__PURE__ */(0, _factory.factory)
|
|
|
66
66
|
});
|
|
67
67
|
function _randomMatrix(size, min, max) {
|
|
68
68
|
const res = (0, _randomMatrix2.randomMatrix)(size.valueOf(), () => _random(min, max));
|
|
69
|
-
return (0, _is.isMatrix)(size) ? size.create(res) : res;
|
|
69
|
+
return (0, _is.isMatrix)(size) ? size.create(res, 'number') : res;
|
|
70
70
|
}
|
|
71
71
|
function _random(min, max) {
|
|
72
72
|
return min + rng() * (max - min);
|
|
@@ -65,7 +65,7 @@ const createRandomInt = exports.createRandomInt = /* #__PURE__ */(0, _factory.fa
|
|
|
65
65
|
});
|
|
66
66
|
function _randomIntMatrix(size, min, max) {
|
|
67
67
|
const res = (0, _randomMatrix.randomMatrix)(size.valueOf(), () => _randomInt(min, max));
|
|
68
|
-
return (0, _is.isMatrix)(size) ? size.create(res) : res;
|
|
68
|
+
return (0, _is.isMatrix)(size) ? size.create(res, 'number') : res;
|
|
69
69
|
}
|
|
70
70
|
function _randomInt(min, max) {
|
|
71
71
|
return Math.floor(min + rng() * (max - min));
|
|
@@ -48,12 +48,12 @@ const createCumSum = exports.createCumSum = /* #__PURE__ */(0, _factory.factory)
|
|
|
48
48
|
// sum([a, b, c, d, ...])
|
|
49
49
|
Array: _cumsum,
|
|
50
50
|
Matrix: function (matrix) {
|
|
51
|
-
return matrix.create(_cumsum(matrix.valueOf()));
|
|
51
|
+
return matrix.create(_cumsum(matrix.valueOf(), matrix.datatype()));
|
|
52
52
|
},
|
|
53
53
|
// sum([a, b, c, d, ...], dim)
|
|
54
54
|
'Array, number | BigNumber': _ncumSumDim,
|
|
55
55
|
'Matrix, number | BigNumber': function (matrix, dim) {
|
|
56
|
-
return matrix.create(_ncumSumDim(matrix.valueOf(), dim));
|
|
56
|
+
return matrix.create(_ncumSumDim(matrix.valueOf(), dim), matrix.datatype());
|
|
57
57
|
},
|
|
58
58
|
// cumsum(a, b, c, d, ...)
|
|
59
59
|
'...': function (args) {
|
|
@@ -16,10 +16,10 @@ const createAcoth = exports.createAcoth = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
16
16
|
BigNumber
|
|
17
17
|
} = _ref;
|
|
18
18
|
/**
|
|
19
|
-
* Calculate the hyperbolic
|
|
19
|
+
* Calculate the inverse hyperbolic tangent of a value,
|
|
20
20
|
* defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
|
|
21
21
|
*
|
|
22
|
-
* To avoid confusion with the matrix hyperbolic
|
|
22
|
+
* To avoid confusion with the matrix inverse hyperbolic tangent, this
|
|
23
23
|
* function does not apply to matrices.
|
|
24
24
|
*
|
|
25
25
|
* Syntax:
|
|
@@ -14,10 +14,10 @@ const createAcsch = exports.createAcsch = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
14
14
|
BigNumber
|
|
15
15
|
} = _ref;
|
|
16
16
|
/**
|
|
17
|
-
* Calculate the hyperbolic
|
|
17
|
+
* Calculate the inverse hyperbolic cosecant of a value,
|
|
18
18
|
* defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
|
|
19
19
|
*
|
|
20
|
-
* To avoid confusion with the matrix hyperbolic
|
|
20
|
+
* To avoid confusion with the matrix inverse hyperbolic cosecant, this function
|
|
21
21
|
* does not apply to matrices.
|
|
22
22
|
*
|
|
23
23
|
* Syntax:
|
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 13.0
|
|
10
|
-
* @date 2024-
|
|
9
|
+
* @version 13.1.0
|
|
10
|
+
* @date 2024-08-26
|
|
11
11
|
*
|
|
12
12
|
* @license
|
|
13
13
|
* Copyright (C) 2013-2024 Jos de Jong <wjosdejong@gmail.com>
|
|
@@ -11,7 +11,7 @@ var _number = require("../../utils/number.js");
|
|
|
11
11
|
var _object = require("../../utils/object.js");
|
|
12
12
|
var _DimensionError = require("../../error/DimensionError.js");
|
|
13
13
|
var _factory = require("../../utils/factory.js");
|
|
14
|
-
var
|
|
14
|
+
var _applyCallback = require("../../utils/applyCallback.js");
|
|
15
15
|
const name = 'DenseMatrix';
|
|
16
16
|
const dependencies = ['Matrix'];
|
|
17
17
|
const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
@@ -172,24 +172,7 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
|
|
|
172
172
|
* @return {*} value
|
|
173
173
|
*/
|
|
174
174
|
DenseMatrix.prototype.get = function (index) {
|
|
175
|
-
|
|
176
|
-
throw new TypeError('Array expected');
|
|
177
|
-
}
|
|
178
|
-
if (index.length !== this._size.length) {
|
|
179
|
-
throw new _DimensionError.DimensionError(index.length, this._size.length);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// check index
|
|
183
|
-
for (let x = 0; x < index.length; x++) {
|
|
184
|
-
(0, _array.validateIndex)(index[x], this._size[x]);
|
|
185
|
-
}
|
|
186
|
-
let data = this._data;
|
|
187
|
-
for (let i = 0, ii = index.length; i < ii; i++) {
|
|
188
|
-
const indexI = index[i];
|
|
189
|
-
(0, _array.validateIndex)(indexI, data.length);
|
|
190
|
-
data = data[indexI];
|
|
191
|
-
}
|
|
192
|
-
return data;
|
|
175
|
+
return (0, _array.get)(this._data, index);
|
|
193
176
|
};
|
|
194
177
|
|
|
195
178
|
/**
|
|
@@ -552,7 +535,6 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
|
|
|
552
535
|
DenseMatrix.prototype.map = function (callback) {
|
|
553
536
|
// matrix instance
|
|
554
537
|
const me = this;
|
|
555
|
-
const args = (0, _function.maxArgumentCount)(callback);
|
|
556
538
|
const recurse = function (value, index) {
|
|
557
539
|
if ((0, _is.isArray)(value)) {
|
|
558
540
|
return value.map(function (child, i) {
|
|
@@ -560,14 +542,7 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
|
|
|
560
542
|
});
|
|
561
543
|
} else {
|
|
562
544
|
// invoke the callback function with the right number of arguments
|
|
563
|
-
|
|
564
|
-
return callback(value);
|
|
565
|
-
} else if (args === 2) {
|
|
566
|
-
return callback(value, index);
|
|
567
|
-
} else {
|
|
568
|
-
// 3 or -1
|
|
569
|
-
return callback(value, index, me);
|
|
570
|
-
}
|
|
545
|
+
return (0, _applyCallback.applyCallback)(callback, value, index, me, 'map');
|
|
571
546
|
}
|
|
572
547
|
};
|
|
573
548
|
|
|
@@ -11,7 +11,7 @@ var _object = require("../../utils/object.js");
|
|
|
11
11
|
var _array = require("../../utils/array.js");
|
|
12
12
|
var _factory = require("../../utils/factory.js");
|
|
13
13
|
var _DimensionError = require("../../error/DimensionError.js");
|
|
14
|
-
var
|
|
14
|
+
var _applyCallback = require("../../utils/applyCallback.js");
|
|
15
15
|
const name = 'SparseMatrix';
|
|
16
16
|
const dependencies = ['typed', 'equalScalar', 'Matrix'];
|
|
17
17
|
const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
@@ -879,12 +879,9 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
|
|
|
879
879
|
const rows = this._size[0];
|
|
880
880
|
const columns = this._size[1];
|
|
881
881
|
// invoke callback
|
|
882
|
-
const args = (0, _function.maxArgumentCount)(callback);
|
|
883
882
|
const invoke = function (v, i, j) {
|
|
884
883
|
// invoke callback
|
|
885
|
-
|
|
886
|
-
if (args === 2) return callback(v, [i, j]);
|
|
887
|
-
return callback(v, [i, j], me);
|
|
884
|
+
return (0, _applyCallback.applyCallback)(callback, v, [i, j], me, 'map');
|
|
888
885
|
};
|
|
889
886
|
// invoke _map
|
|
890
887
|
return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
|
|
@@ -914,11 +911,11 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
|
|
|
914
911
|
// invoke callback
|
|
915
912
|
const invoke = function (v, x, y) {
|
|
916
913
|
// invoke callback
|
|
917
|
-
|
|
914
|
+
const value = callback(v, x, y);
|
|
918
915
|
// check value != 0
|
|
919
|
-
if (!eq(
|
|
916
|
+
if (!eq(value, zero)) {
|
|
920
917
|
// store value
|
|
921
|
-
values.push(
|
|
918
|
+
values.push(value);
|
|
922
919
|
// index
|
|
923
920
|
index.push(x);
|
|
924
921
|
}
|