mathjs 13.0.3 → 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 +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
|
@@ -34,7 +34,7 @@ export var createSetUnion = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
34
34
|
* @return {Array | Matrix} The union of two (multi)sets
|
|
35
35
|
*/
|
|
36
36
|
return typed(name, {
|
|
37
|
-
'Array | Matrix, Array | Matrix': function
|
|
37
|
+
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
|
|
38
38
|
if (subset(size(a1), new Index(0)) === 0) {
|
|
39
39
|
// if any of them is empty, return the other one
|
|
40
40
|
return flatten(a2);
|
|
@@ -32,21 +32,21 @@ export var createFreqz = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
34
|
return typed(name, {
|
|
35
|
-
'Array, Array': function
|
|
35
|
+
'Array, Array': function Array_Array(b, a) {
|
|
36
36
|
var w = createBins(512);
|
|
37
37
|
return _freqz(b, a, w);
|
|
38
38
|
},
|
|
39
|
-
'Array, Array, Array': function
|
|
39
|
+
'Array, Array, Array': function Array_Array_Array(b, a, w) {
|
|
40
40
|
return _freqz(b, a, w);
|
|
41
41
|
},
|
|
42
|
-
'Array, Array, number': function
|
|
42
|
+
'Array, Array, number': function Array_Array_number(b, a, w) {
|
|
43
43
|
if (w < 0) {
|
|
44
44
|
throw new Error('w must be a positive number');
|
|
45
45
|
}
|
|
46
46
|
var w2 = createBins(w);
|
|
47
47
|
return _freqz(b, a, w2);
|
|
48
48
|
},
|
|
49
|
-
'Matrix, Matrix': function
|
|
49
|
+
'Matrix, Matrix': function Matrix_Matrix(b, a) {
|
|
50
50
|
// console.log('here')
|
|
51
51
|
var _w = createBins(512);
|
|
52
52
|
var {
|
|
@@ -58,7 +58,7 @@ export var createFreqz = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
58
58
|
h: matrix(h)
|
|
59
59
|
};
|
|
60
60
|
},
|
|
61
|
-
'Matrix, Matrix, Matrix': function
|
|
61
|
+
'Matrix, Matrix, Matrix': function Matrix_Matrix_Matrix(b, a, w) {
|
|
62
62
|
var {
|
|
63
63
|
h
|
|
64
64
|
} = _freqz(b.valueOf(), a.valueOf(), w.valueOf());
|
|
@@ -67,7 +67,7 @@ export var createFreqz = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
67
67
|
w: matrix(w)
|
|
68
68
|
};
|
|
69
69
|
},
|
|
70
|
-
'Matrix, Matrix, number': function
|
|
70
|
+
'Matrix, Matrix, number': function Matrix_Matrix_number(b, a, w) {
|
|
71
71
|
if (w < 0) {
|
|
72
72
|
throw new Error('w must be a positive number');
|
|
73
73
|
}
|
|
@@ -35,10 +35,10 @@ export var createCorr = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
35
35
|
* @return {*} The correlation coefficient
|
|
36
36
|
*/
|
|
37
37
|
return typed(name, {
|
|
38
|
-
'Array, Array': function
|
|
38
|
+
'Array, Array': function Array_Array(A, B) {
|
|
39
39
|
return _corr(A, B);
|
|
40
40
|
},
|
|
41
|
-
'Matrix, Matrix': function
|
|
41
|
+
'Matrix, Matrix': function Matrix_Matrix(A, B) {
|
|
42
42
|
var res = _corr(A.toArray(), B.toArray());
|
|
43
43
|
return Array.isArray(res) ? matrix(res) : res;
|
|
44
44
|
}
|
|
@@ -42,12 +42,12 @@ export var createCumSum = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
42
42
|
// sum([a, b, c, d, ...])
|
|
43
43
|
Array: _cumsum,
|
|
44
44
|
Matrix: function Matrix(matrix) {
|
|
45
|
-
return matrix.create(_cumsum(matrix.valueOf()));
|
|
45
|
+
return matrix.create(_cumsum(matrix.valueOf(), matrix.datatype()));
|
|
46
46
|
},
|
|
47
47
|
// sum([a, b, c, d, ...], dim)
|
|
48
48
|
'Array, number | BigNumber': _ncumSumDim,
|
|
49
|
-
'Matrix, number | BigNumber': function
|
|
50
|
-
return matrix.create(_ncumSumDim(matrix.valueOf(), dim));
|
|
49
|
+
'Matrix, number | BigNumber': function Matrix_number__BigNumber(matrix, dim) {
|
|
50
|
+
return matrix.create(_ncumSumDim(matrix.valueOf(), dim), matrix.datatype());
|
|
51
51
|
},
|
|
52
52
|
// cumsum(a, b, c, d, ...)
|
|
53
53
|
'...': function _(args) {
|
|
@@ -46,7 +46,7 @@ export var createMax = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
46
46
|
// max([a, b, c, d, ...])
|
|
47
47
|
'Array | Matrix': _max,
|
|
48
48
|
// max([a, b, c, d, ...], dim)
|
|
49
|
-
'Array | Matrix, number | BigNumber': function
|
|
49
|
+
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
|
|
50
50
|
return reduce(array, dim.valueOf(), _largest);
|
|
51
51
|
},
|
|
52
52
|
// max(a, b, c, d, ...)
|
|
@@ -50,14 +50,14 @@ export var createMedian = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
50
50
|
|
|
51
51
|
// helper function to type check the middle value of the array
|
|
52
52
|
var middle = typed({
|
|
53
|
-
'number | BigNumber | Complex | Unit': function
|
|
53
|
+
'number | BigNumber | Complex | Unit': function number__BigNumber__Complex__Unit(value) {
|
|
54
54
|
return value;
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
// helper function to type check the two middle value of the array
|
|
59
59
|
var middle2 = typed({
|
|
60
|
-
'number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit': function
|
|
60
|
+
'number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit': function number__BigNumber__Complex__Unit_number__BigNumber__Complex__Unit(left, right) {
|
|
61
61
|
return divide(add(left, right), 2);
|
|
62
62
|
}
|
|
63
63
|
});
|
|
@@ -92,7 +92,7 @@ export var createMedian = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
92
92
|
// median([a, b, c, d, ...])
|
|
93
93
|
'Array | Matrix': _median,
|
|
94
94
|
// median([a, b, c, d, ...], dim)
|
|
95
|
-
'Array | Matrix, number | BigNumber': function
|
|
95
|
+
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
|
|
96
96
|
// TODO: implement median(A, dim)
|
|
97
97
|
throw new Error('median(A, dim) is not yet supported');
|
|
98
98
|
// return reduce(arguments[0], arguments[1], ...)
|
|
@@ -46,7 +46,7 @@ export var createMin = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
46
46
|
// min([a, b, c, d, ...])
|
|
47
47
|
'Array | Matrix': _min,
|
|
48
48
|
// min([a, b, c, d, ...], dim)
|
|
49
|
-
'Array | Matrix, number | BigNumber': function
|
|
49
|
+
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
|
|
50
50
|
return reduce(array, dim.valueOf(), _smallest);
|
|
51
51
|
},
|
|
52
52
|
// min(a, b, c, d, ...)
|
|
@@ -40,7 +40,7 @@ export var createProd = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
40
40
|
// prod([a, b, c, d, ...])
|
|
41
41
|
'Array | Matrix': _prod,
|
|
42
42
|
// prod([a, b, c, d, ...], dim)
|
|
43
|
-
'Array | Matrix, number | BigNumber': function
|
|
43
|
+
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
|
|
44
44
|
// TODO: implement prod(A, dim)
|
|
45
45
|
throw new Error('prod(A, dim) is not yet supported');
|
|
46
46
|
// return reduce(arguments[0], arguments[1], math.prod)
|
|
@@ -70,13 +70,13 @@ export var createVariance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
70
70
|
*/
|
|
71
71
|
return typed(name, {
|
|
72
72
|
// variance([a, b, c, d, ...])
|
|
73
|
-
'Array | Matrix': function
|
|
73
|
+
'Array | Matrix': function Array__Matrix(array) {
|
|
74
74
|
return _var(array, DEFAULT_NORMALIZATION);
|
|
75
75
|
},
|
|
76
76
|
// variance([a, b, c, d, ...], normalization)
|
|
77
77
|
'Array | Matrix, string': _var,
|
|
78
78
|
// variance([a, b, c, c, ...], dim)
|
|
79
|
-
'Array | Matrix, number | BigNumber': function
|
|
79
|
+
'Array | Matrix, number | BigNumber': function Array__Matrix_number__BigNumber(array, dim) {
|
|
80
80
|
return _varDim(array, dim, DEFAULT_NORMALIZATION);
|
|
81
81
|
},
|
|
82
82
|
// variance([a, b, c, c, ...], dim, normalization)
|
|
@@ -29,12 +29,12 @@ export var createBin = factory(name, dependencies, _ref => {
|
|
|
29
29
|
format
|
|
30
30
|
} = _ref;
|
|
31
31
|
return typed(name, {
|
|
32
|
-
'number | BigNumber': function
|
|
32
|
+
'number | BigNumber': function number__BigNumber(n) {
|
|
33
33
|
return format(n, {
|
|
34
34
|
notation: 'bin'
|
|
35
35
|
});
|
|
36
36
|
},
|
|
37
|
-
'number | BigNumber, number | BigNumber': function
|
|
37
|
+
'number | BigNumber, number | BigNumber': function number__BigNumber_number__BigNumber(n, wordSize) {
|
|
38
38
|
return format(n, {
|
|
39
39
|
notation: 'bin',
|
|
40
40
|
wordSize
|
|
@@ -28,12 +28,12 @@ export var createHex = factory(name, dependencies, _ref => {
|
|
|
28
28
|
format
|
|
29
29
|
} = _ref;
|
|
30
30
|
return typed(name, {
|
|
31
|
-
'number | BigNumber': function
|
|
31
|
+
'number | BigNumber': function number__BigNumber(n) {
|
|
32
32
|
return format(n, {
|
|
33
33
|
notation: 'hex'
|
|
34
34
|
});
|
|
35
35
|
},
|
|
36
|
-
'number | BigNumber, number | BigNumber': function
|
|
36
|
+
'number | BigNumber, number | BigNumber': function number__BigNumber_number__BigNumber(n, wordSize) {
|
|
37
37
|
return format(n, {
|
|
38
38
|
notation: 'hex',
|
|
39
39
|
wordSize
|
|
@@ -30,12 +30,12 @@ export var createOct = factory(name, dependencies, _ref => {
|
|
|
30
30
|
format
|
|
31
31
|
} = _ref;
|
|
32
32
|
return typed(name, {
|
|
33
|
-
'number | BigNumber': function
|
|
33
|
+
'number | BigNumber': function number__BigNumber(n) {
|
|
34
34
|
return format(n, {
|
|
35
35
|
notation: 'oct'
|
|
36
36
|
});
|
|
37
37
|
},
|
|
38
|
-
'number | BigNumber, number | BigNumber': function
|
|
38
|
+
'number | BigNumber, number | BigNumber': function number__BigNumber_number__BigNumber(n, wordSize) {
|
|
39
39
|
return format(n, {
|
|
40
40
|
notation: 'oct',
|
|
41
41
|
wordSize
|
|
@@ -10,10 +10,10 @@ export var createAcoth = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
10
10
|
BigNumber: _BigNumber
|
|
11
11
|
} = _ref;
|
|
12
12
|
/**
|
|
13
|
-
* Calculate the hyperbolic
|
|
13
|
+
* Calculate the inverse hyperbolic tangent of a value,
|
|
14
14
|
* defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
|
|
15
15
|
*
|
|
16
|
-
* To avoid confusion with the matrix hyperbolic
|
|
16
|
+
* To avoid confusion with the matrix inverse hyperbolic tangent, this
|
|
17
17
|
* function does not apply to matrices.
|
|
18
18
|
*
|
|
19
19
|
* Syntax:
|
|
@@ -8,10 +8,10 @@ export var createAcsch = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
8
8
|
BigNumber: _BigNumber
|
|
9
9
|
} = _ref;
|
|
10
10
|
/**
|
|
11
|
-
* Calculate the hyperbolic
|
|
11
|
+
* Calculate the inverse hyperbolic cosecant of a value,
|
|
12
12
|
* defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
|
|
13
13
|
*
|
|
14
|
-
* To avoid confusion with the matrix hyperbolic
|
|
14
|
+
* To avoid confusion with the matrix inverse hyperbolic cosecant, this function
|
|
15
15
|
* does not apply to matrices.
|
|
16
16
|
*
|
|
17
17
|
* Syntax:
|
package/lib/esm/type/bigint.js
CHANGED
|
@@ -44,7 +44,7 @@ export var createBigint = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
44
44
|
Fraction: function Fraction(x) {
|
|
45
45
|
return BigInt(x.valueOf().toFixed());
|
|
46
46
|
},
|
|
47
|
-
'string | boolean': function
|
|
47
|
+
'string | boolean': function string__boolean(x) {
|
|
48
48
|
return BigInt(x);
|
|
49
49
|
},
|
|
50
50
|
null: function _null(x) {
|
|
@@ -52,11 +52,11 @@ export var createComplex = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
52
52
|
number: function number(x) {
|
|
53
53
|
return new Complex(x, 0);
|
|
54
54
|
},
|
|
55
|
-
'number, number': function
|
|
55
|
+
'number, number': function number_number(re, im) {
|
|
56
56
|
return new Complex(re, im);
|
|
57
57
|
},
|
|
58
58
|
// TODO: this signature should be redundant
|
|
59
|
-
'BigNumber, BigNumber': function
|
|
59
|
+
'BigNumber, BigNumber': function BigNumber_BigNumber(re, im) {
|
|
60
60
|
return new Complex(re.toNumber(), im.toNumber());
|
|
61
61
|
},
|
|
62
62
|
Fraction: function Fraction(x) {
|
|
@@ -54,7 +54,7 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
54
54
|
string: function string(x) {
|
|
55
55
|
return new Fraction(x);
|
|
56
56
|
},
|
|
57
|
-
'number, number': function
|
|
57
|
+
'number, number': function number_number(numerator, denominator) {
|
|
58
58
|
return new Fraction(numerator, denominator);
|
|
59
59
|
},
|
|
60
60
|
null: function _null(x) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isArray, isBigNumber, isCollection, isIndex, isMatrix, isNumber, isString, typeOf } from '../../utils/is.js';
|
|
2
|
-
import { arraySize, getArrayDataType, processSizesWildcard, reshape, resize, unsqueeze, validate, validateIndex, broadcastTo } from '../../utils/array.js';
|
|
2
|
+
import { arraySize, getArrayDataType, processSizesWildcard, reshape, resize, unsqueeze, validate, validateIndex, broadcastTo, get } from '../../utils/array.js';
|
|
3
3
|
import { format } from '../../utils/string.js';
|
|
4
4
|
import { isInteger } from '../../utils/number.js';
|
|
5
5
|
import { clone, deepStrictEqual } from '../../utils/object.js';
|
|
6
6
|
import { DimensionError } from '../../error/DimensionError.js';
|
|
7
7
|
import { factory } from '../../utils/factory.js';
|
|
8
|
-
import {
|
|
8
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
|
9
9
|
var name = 'DenseMatrix';
|
|
10
10
|
var dependencies = ['Matrix'];
|
|
11
11
|
export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
@@ -166,24 +166,7 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
|
166
166
|
* @return {*} value
|
|
167
167
|
*/
|
|
168
168
|
DenseMatrix.prototype.get = function (index) {
|
|
169
|
-
|
|
170
|
-
throw new TypeError('Array expected');
|
|
171
|
-
}
|
|
172
|
-
if (index.length !== this._size.length) {
|
|
173
|
-
throw new DimensionError(index.length, this._size.length);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// check index
|
|
177
|
-
for (var x = 0; x < index.length; x++) {
|
|
178
|
-
validateIndex(index[x], this._size[x]);
|
|
179
|
-
}
|
|
180
|
-
var data = this._data;
|
|
181
|
-
for (var i = 0, ii = index.length; i < ii; i++) {
|
|
182
|
-
var indexI = index[i];
|
|
183
|
-
validateIndex(indexI, data.length);
|
|
184
|
-
data = data[indexI];
|
|
185
|
-
}
|
|
186
|
-
return data;
|
|
169
|
+
return get(this._data, index);
|
|
187
170
|
};
|
|
188
171
|
|
|
189
172
|
/**
|
|
@@ -546,28 +529,20 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
|
546
529
|
DenseMatrix.prototype.map = function (callback) {
|
|
547
530
|
// matrix instance
|
|
548
531
|
var me = this;
|
|
549
|
-
var
|
|
550
|
-
var recurse = function recurse(value, index) {
|
|
532
|
+
var _recurse = function recurse(value, index) {
|
|
551
533
|
if (isArray(value)) {
|
|
552
534
|
return value.map(function (child, i) {
|
|
553
|
-
return
|
|
535
|
+
return _recurse(child, index.concat(i));
|
|
554
536
|
});
|
|
555
537
|
} else {
|
|
556
538
|
// invoke the callback function with the right number of arguments
|
|
557
|
-
|
|
558
|
-
return callback(value);
|
|
559
|
-
} else if (args === 2) {
|
|
560
|
-
return callback(value, index);
|
|
561
|
-
} else {
|
|
562
|
-
// 3 or -1
|
|
563
|
-
return callback(value, index, me);
|
|
564
|
-
}
|
|
539
|
+
return applyCallback(callback, value, index, me, 'map');
|
|
565
540
|
}
|
|
566
541
|
};
|
|
567
542
|
|
|
568
543
|
// determine the new datatype when the original matrix has datatype defined
|
|
569
544
|
// TODO: should be done in matrix constructor instead
|
|
570
|
-
var data =
|
|
545
|
+
var data = _recurse(this._data, []);
|
|
571
546
|
var datatype = this._datatype !== undefined ? getArrayDataType(data, typeOf) : undefined;
|
|
572
547
|
return new DenseMatrix(data, datatype);
|
|
573
548
|
};
|
|
@@ -582,16 +557,16 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
|
582
557
|
DenseMatrix.prototype.forEach = function (callback) {
|
|
583
558
|
// matrix instance
|
|
584
559
|
var me = this;
|
|
585
|
-
var
|
|
560
|
+
var _recurse2 = function recurse(value, index) {
|
|
586
561
|
if (isArray(value)) {
|
|
587
562
|
value.forEach(function (child, i) {
|
|
588
|
-
|
|
563
|
+
_recurse2(child, index.concat(i));
|
|
589
564
|
});
|
|
590
565
|
} else {
|
|
591
566
|
callback(value, index, me);
|
|
592
567
|
}
|
|
593
568
|
};
|
|
594
|
-
|
|
569
|
+
_recurse2(this._data, []);
|
|
595
570
|
};
|
|
596
571
|
|
|
597
572
|
/**
|
|
@@ -599,10 +574,10 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
|
599
574
|
* @return {Iterable<{ value, index: number[] }>}
|
|
600
575
|
*/
|
|
601
576
|
DenseMatrix.prototype[Symbol.iterator] = function* () {
|
|
602
|
-
var
|
|
577
|
+
var _recurse3 = function* recurse(value, index) {
|
|
603
578
|
if (isArray(value)) {
|
|
604
579
|
for (var i = 0; i < value.length; i++) {
|
|
605
|
-
yield*
|
|
580
|
+
yield* _recurse3(value[i], index.concat(i));
|
|
606
581
|
}
|
|
607
582
|
} else {
|
|
608
583
|
yield {
|
|
@@ -611,7 +586,7 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
|
611
586
|
};
|
|
612
587
|
}
|
|
613
588
|
};
|
|
614
|
-
yield*
|
|
589
|
+
yield* _recurse3(this._data, []);
|
|
615
590
|
};
|
|
616
591
|
|
|
617
592
|
/**
|
|
@@ -5,7 +5,7 @@ import { clone, deepStrictEqual } from '../../utils/object.js';
|
|
|
5
5
|
import { arraySize, getArrayDataType, processSizesWildcard, unsqueeze, validateIndex } from '../../utils/array.js';
|
|
6
6
|
import { factory } from '../../utils/factory.js';
|
|
7
7
|
import { DimensionError } from '../../error/DimensionError.js';
|
|
8
|
-
import {
|
|
8
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
|
9
9
|
var name = 'SparseMatrix';
|
|
10
10
|
var dependencies = ['typed', 'equalScalar', 'Matrix'];
|
|
11
11
|
export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
@@ -873,12 +873,9 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
|
|
|
873
873
|
var rows = this._size[0];
|
|
874
874
|
var columns = this._size[1];
|
|
875
875
|
// invoke callback
|
|
876
|
-
var args = maxArgumentCount(callback);
|
|
877
876
|
var invoke = function invoke(v, i, j) {
|
|
878
877
|
// invoke callback
|
|
879
|
-
|
|
880
|
-
if (args === 2) return callback(v, [i, j]);
|
|
881
|
-
return callback(v, [i, j], me);
|
|
878
|
+
return applyCallback(callback, v, [i, j], me, 'map');
|
|
882
879
|
};
|
|
883
880
|
// invoke _map
|
|
884
881
|
return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
|
|
@@ -908,11 +905,11 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
|
|
|
908
905
|
// invoke callback
|
|
909
906
|
var invoke = function invoke(v, x, y) {
|
|
910
907
|
// invoke callback
|
|
911
|
-
|
|
908
|
+
var value = callback(v, x, y);
|
|
912
909
|
// check value != 0
|
|
913
|
-
if (!eq(
|
|
910
|
+
if (!eq(value, zero)) {
|
|
914
911
|
// store value
|
|
915
|
-
values.push(
|
|
912
|
+
values.push(value);
|
|
916
913
|
// index
|
|
917
914
|
index.push(x);
|
|
918
915
|
}
|
|
@@ -43,7 +43,7 @@ export var createIndex = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
43
43
|
* @return {Index} Returns the created index
|
|
44
44
|
*/
|
|
45
45
|
return typed(name, {
|
|
46
|
-
'...number | string | BigNumber | Range | Array | Matrix': function
|
|
46
|
+
'...number | string | BigNumber | Range | Array | Matrix': function number__string__BigNumber__Range__Array__Matrix(args) {
|
|
47
47
|
var ranges = args.map(function (arg) {
|
|
48
48
|
if (isBigNumber(arg)) {
|
|
49
49
|
return arg.toNumber(); // convert BigNumber to Number
|
|
@@ -48,7 +48,7 @@ export var createMatrix = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
48
48
|
string: function string(format) {
|
|
49
49
|
return _create([], format);
|
|
50
50
|
},
|
|
51
|
-
'string, string': function
|
|
51
|
+
'string, string': function string_string(format, datatype) {
|
|
52
52
|
return _create([], format, datatype);
|
|
53
53
|
},
|
|
54
54
|
Array: function Array(data) {
|
|
@@ -46,10 +46,10 @@ export var createSparse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
46
46
|
string: function string(datatype) {
|
|
47
47
|
return new SparseMatrix([], datatype);
|
|
48
48
|
},
|
|
49
|
-
'Array | Matrix': function
|
|
49
|
+
'Array | Matrix': function Array__Matrix(data) {
|
|
50
50
|
return new SparseMatrix(data);
|
|
51
51
|
},
|
|
52
|
-
'Array | Matrix, string': function
|
|
52
|
+
'Array | Matrix, string': function Array__Matrix_string(data, datatype) {
|
|
53
53
|
return new SparseMatrix(data, datatype);
|
|
54
54
|
}
|
|
55
55
|
});
|
package/lib/esm/type/number.js
CHANGED
|
@@ -132,7 +132,7 @@ export var createNumber = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
132
132
|
null: function _null(x) {
|
|
133
133
|
return 0;
|
|
134
134
|
},
|
|
135
|
-
'Unit, string | Unit': function
|
|
135
|
+
'Unit, string | Unit': function Unit_string__Unit(unit, valuelessUnit) {
|
|
136
136
|
return unit.toNumber(valuelessUnit);
|
|
137
137
|
},
|
|
138
138
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
|
@@ -50,7 +50,7 @@ export var createCreateUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
50
50
|
*/
|
|
51
51
|
return typed(name, {
|
|
52
52
|
// General function signature. First parameter is an object where each property is the definition of a new unit. The object keys are the unit names and the values are the definitions. The values can be objects, strings, or Units. If a property is an empty object or an empty string, a new base unit is created. The second parameter is the options.
|
|
53
|
-
'Object, Object': function
|
|
53
|
+
'Object, Object': function Object_Object(obj, options) {
|
|
54
54
|
return Unit.createUnit(obj, options);
|
|
55
55
|
},
|
|
56
56
|
// Same as above but without the options.
|
|
@@ -58,13 +58,13 @@ export var createCreateUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
58
58
|
return Unit.createUnit(obj, {});
|
|
59
59
|
},
|
|
60
60
|
// Shortcut method for creating one unit.
|
|
61
|
-
'string, Unit | string | Object, Object': function
|
|
61
|
+
'string, Unit | string | Object, Object': function string_Unit__string__Object_Object(name, def, options) {
|
|
62
62
|
var obj = {};
|
|
63
63
|
obj[name] = def;
|
|
64
64
|
return Unit.createUnit(obj, options);
|
|
65
65
|
},
|
|
66
66
|
// Same as above but without the options.
|
|
67
|
-
'string, Unit | string | Object': function
|
|
67
|
+
'string, Unit | string | Object': function string_Unit__string__Object(name, def) {
|
|
68
68
|
var obj = {};
|
|
69
69
|
obj[name] = def;
|
|
70
70
|
return Unit.createUnit(obj, {});
|
|
@@ -25,7 +25,7 @@ export var createSplitUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
25
25
|
* @return {Array} An array of units.
|
|
26
26
|
*/
|
|
27
27
|
return typed(name, {
|
|
28
|
-
'Unit, Array': function
|
|
28
|
+
'Unit, Array': function Unit_Array(unit, parts) {
|
|
29
29
|
return unit.splitUnit(parts);
|
|
30
30
|
}
|
|
31
31
|
});
|
|
@@ -48,10 +48,10 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
48
48
|
allowNoUnits: true
|
|
49
49
|
}); // a unit with value, like '5cm'
|
|
50
50
|
},
|
|
51
|
-
'number | BigNumber | Fraction | Complex, string | Unit': function
|
|
51
|
+
'number | BigNumber | Fraction | Complex, string | Unit': function number__BigNumber__Fraction__Complex_string__Unit(value, unit) {
|
|
52
52
|
return new Unit(value, unit);
|
|
53
53
|
},
|
|
54
|
-
'number | BigNumber | Fraction': function
|
|
54
|
+
'number | BigNumber | Fraction': function number__BigNumber__Fraction(value) {
|
|
55
55
|
// dimensionless
|
|
56
56
|
return new Unit(value);
|
|
57
57
|
},
|
package/lib/esm/utils/array.js
CHANGED
|
@@ -780,6 +780,32 @@ export function stretch(arrayToStretch, sizeToStretch, dimToStretch) {
|
|
|
780
780
|
return concat(...Array(sizeToStretch).fill(arrayToStretch), dimToStretch);
|
|
781
781
|
}
|
|
782
782
|
|
|
783
|
+
/**
|
|
784
|
+
* Retrieves a single element from an array given an index.
|
|
785
|
+
*
|
|
786
|
+
* @param {Array} array - The array from which to retrieve the value.
|
|
787
|
+
* @param {Array<number>} idx - An array of indices specifying the position of the desired element in each dimension.
|
|
788
|
+
* @returns {*} - The value at the specified position in the array.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
|
|
792
|
+
* const index = [1, 0, 1];
|
|
793
|
+
* console.log(getValue(arr, index)); // 6
|
|
794
|
+
*/
|
|
795
|
+
export function get(array, index) {
|
|
796
|
+
if (!Array.isArray(array)) {
|
|
797
|
+
throw new Error('Array expected');
|
|
798
|
+
}
|
|
799
|
+
var size = arraySize(array);
|
|
800
|
+
if (index.length !== size.length) {
|
|
801
|
+
throw new DimensionError(index.length, size.length);
|
|
802
|
+
}
|
|
803
|
+
for (var x = 0; x < index.length; x++) {
|
|
804
|
+
validateIndex(index[x], size[x]);
|
|
805
|
+
}
|
|
806
|
+
return index.reduce((acc, curr) => acc[curr], array);
|
|
807
|
+
}
|
|
808
|
+
|
|
783
809
|
/**
|
|
784
810
|
* Deep clones a multidimensional array
|
|
785
811
|
* @param {Array} array
|
|
@@ -78,7 +78,7 @@ export function reduce(mat, dim, callback) {
|
|
|
78
78
|
throw new IndexError(dim, size.length);
|
|
79
79
|
}
|
|
80
80
|
if (isMatrix(mat)) {
|
|
81
|
-
return mat.create(_reduce(mat.valueOf(), dim, callback));
|
|
81
|
+
return mat.create(_reduce(mat.valueOf(), dim, callback), mat.datatype());
|
|
82
82
|
} else {
|
|
83
83
|
return _reduce(mat, dim, callback);
|
|
84
84
|
}
|
|
@@ -83,17 +83,4 @@ export function memoizeCompare(fn, isEqual) {
|
|
|
83
83
|
};
|
|
84
84
|
memoize.cache = [];
|
|
85
85
|
return memoize;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Find the maximum number of arguments expected by a typed function.
|
|
90
|
-
* @param {function} fn A typed function
|
|
91
|
-
* @return {number} Returns the maximum number of expected arguments.
|
|
92
|
-
* Returns -1 when no signatures where found on the function.
|
|
93
|
-
*/
|
|
94
|
-
export function maxArgumentCount(fn) {
|
|
95
|
-
return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
|
96
|
-
var count = (signature.match(/,/g) || []).length + 1;
|
|
97
|
-
return Math.max(args, count);
|
|
98
|
-
}, -1);
|
|
99
86
|
}
|
package/lib/esm/utils/is.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// for security reasons, so these functions are not exposed in the expression
|
|
13
13
|
// parser.
|
|
14
14
|
|
|
15
|
+
import { ObjectWrappingMap } from './map.js';
|
|
15
16
|
export function isNumber(x) {
|
|
16
17
|
return typeof x === 'number';
|
|
17
18
|
}
|
|
@@ -88,6 +89,29 @@ export function isRegExp(x) {
|
|
|
88
89
|
export function isObject(x) {
|
|
89
90
|
return !!(x && typeof x === 'object' && x.constructor === Object && !isComplex(x) && !isFraction(x));
|
|
90
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns `true` if the passed object appears to be a Map (i.e. duck typing).
|
|
95
|
+
*
|
|
96
|
+
* Methods looked for are `get`, `set`, `keys` and `has`.
|
|
97
|
+
*
|
|
98
|
+
* @param {Map | object} object
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export function isMap(object) {
|
|
102
|
+
// We can use the fast instanceof, or a slower duck typing check.
|
|
103
|
+
// The duck typing method needs to cover enough methods to not be confused with DenseMatrix.
|
|
104
|
+
if (!object) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return object instanceof Map || object instanceof ObjectWrappingMap || typeof object.set === 'function' && typeof object.get === 'function' && typeof object.keys === 'function' && typeof object.has === 'function';
|
|
108
|
+
}
|
|
109
|
+
export function isPartitionedMap(object) {
|
|
110
|
+
return isMap(object) && isMap(object.a) && isMap(object.b);
|
|
111
|
+
}
|
|
112
|
+
export function isObjectWrappingMap(object) {
|
|
113
|
+
return isMap(object) && isObject(object.wrappedObject);
|
|
114
|
+
}
|
|
91
115
|
export function isNull(x) {
|
|
92
116
|
return x === null;
|
|
93
117
|
}
|