mathjs 13.0.3 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. package/HISTORY.md +17 -1
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +2 -2
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/core/create.js +12 -9
  6. package/lib/cjs/core/function/typed.js +3 -4
  7. package/lib/cjs/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
  8. package/lib/cjs/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
  9. package/lib/cjs/entry/impureFunctionsAny.generated.js +2 -2
  10. package/lib/cjs/entry/pureFunctionsAny.generated.js +6 -8
  11. package/lib/cjs/entry/typeChecks.js +18 -0
  12. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -2
  13. package/lib/cjs/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
  14. package/lib/cjs/expression/embeddedDocs/function/matrix/diff.js +1 -1
  15. package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +1 -1
  16. package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +1 -1
  17. package/lib/cjs/expression/embeddedDocs/function/matrix/kron.js +1 -1
  18. package/lib/cjs/expression/embeddedDocs/function/matrix/map.js +3 -3
  19. package/lib/cjs/expression/embeddedDocs/function/special/zeta.js +1 -1
  20. package/lib/cjs/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
  21. package/lib/cjs/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
  22. package/lib/cjs/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
  23. package/lib/cjs/expression/embeddedDocs/function/utils/clone.js +1 -1
  24. package/lib/cjs/expression/function/evaluate.js +5 -0
  25. package/lib/cjs/expression/node/FunctionNode.js +1 -1
  26. package/lib/cjs/expression/transform/filter.transform.js +2 -2
  27. package/lib/cjs/expression/transform/map.transform.js +104 -37
  28. package/lib/cjs/expression/transform/utils/dimToZeroBase.js +23 -0
  29. package/lib/cjs/expression/transform/utils/lastDimToZeroBase.js +3 -4
  30. package/lib/cjs/function/arithmetic/hypot.js +3 -3
  31. package/lib/cjs/function/matrix/apply.js +1 -1
  32. package/lib/cjs/function/matrix/fft.js +3 -3
  33. package/lib/cjs/function/matrix/filter.js +2 -2
  34. package/lib/cjs/function/matrix/flatten.js +5 -6
  35. package/lib/cjs/function/matrix/ifft.js +2 -2
  36. package/lib/cjs/function/matrix/kron.js +4 -4
  37. package/lib/cjs/function/matrix/map.js +109 -18
  38. package/lib/cjs/function/matrix/size.js +7 -7
  39. package/lib/cjs/function/matrix/squeeze.js +3 -4
  40. package/lib/cjs/function/probability/random.js +1 -1
  41. package/lib/cjs/function/probability/randomInt.js +1 -1
  42. package/lib/cjs/function/statistics/cumsum.js +2 -2
  43. package/lib/cjs/function/trigonometry/acoth.js +2 -2
  44. package/lib/cjs/function/trigonometry/acsch.js +2 -2
  45. package/lib/cjs/header.js +2 -2
  46. package/lib/cjs/type/matrix/DenseMatrix.js +3 -28
  47. package/lib/cjs/type/matrix/SparseMatrix.js +5 -8
  48. package/lib/cjs/utils/array.js +27 -0
  49. package/lib/cjs/utils/collection.js +1 -1
  50. package/lib/cjs/utils/function.js +0 -14
  51. package/lib/cjs/utils/is.js +27 -0
  52. package/lib/cjs/utils/map.js +2 -20
  53. package/lib/cjs/version.js +1 -1
  54. package/lib/esm/core/create.js +9 -6
  55. package/lib/esm/core/function/typed.js +2 -3
  56. package/lib/esm/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
  57. package/lib/esm/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
  58. package/lib/esm/entry/impureFunctionsAny.generated.js +3 -3
  59. package/lib/esm/entry/pureFunctionsAny.generated.js +7 -9
  60. package/lib/esm/entry/typeChecks.js +1 -1
  61. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -2
  62. package/lib/esm/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
  63. package/lib/esm/expression/embeddedDocs/function/matrix/diff.js +1 -1
  64. package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +1 -1
  65. package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +1 -1
  66. package/lib/esm/expression/embeddedDocs/function/matrix/kron.js +1 -1
  67. package/lib/esm/expression/embeddedDocs/function/matrix/map.js +3 -3
  68. package/lib/esm/expression/embeddedDocs/function/special/zeta.js +1 -1
  69. package/lib/esm/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
  70. package/lib/esm/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
  71. package/lib/esm/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
  72. package/lib/esm/expression/embeddedDocs/function/utils/clone.js +1 -1
  73. package/lib/esm/expression/function/compile.js +1 -1
  74. package/lib/esm/expression/function/evaluate.js +8 -3
  75. package/lib/esm/expression/node/FunctionNode.js +1 -1
  76. package/lib/esm/expression/parse.js +2 -2
  77. package/lib/esm/expression/transform/filter.transform.js +4 -4
  78. package/lib/esm/expression/transform/forEach.transform.js +4 -4
  79. package/lib/esm/expression/transform/map.transform.js +104 -37
  80. package/lib/esm/expression/transform/print.transform.js +2 -2
  81. package/lib/esm/expression/transform/utils/dimToZeroBase.js +16 -0
  82. package/lib/esm/expression/transform/utils/lastDimToZeroBase.js +4 -6
  83. package/lib/esm/function/algebra/decomposition/slu.js +1 -1
  84. package/lib/esm/function/algebra/derivative.js +15 -15
  85. package/lib/esm/function/algebra/lyap.js +4 -4
  86. package/lib/esm/function/algebra/simplify/util.js +3 -3
  87. package/lib/esm/function/algebra/simplifyConstant.js +9 -9
  88. package/lib/esm/function/algebra/solver/lsolve.js +3 -3
  89. package/lib/esm/function/algebra/solver/lsolveAll.js +3 -3
  90. package/lib/esm/function/algebra/solver/lusolve.js +5 -5
  91. package/lib/esm/function/algebra/solver/usolve.js +3 -3
  92. package/lib/esm/function/algebra/solver/usolveAll.js +3 -3
  93. package/lib/esm/function/algebra/sylvester.js +7 -7
  94. package/lib/esm/function/arithmetic/addScalar.js +4 -4
  95. package/lib/esm/function/arithmetic/ceil.js +6 -6
  96. package/lib/esm/function/arithmetic/divide.js +5 -5
  97. package/lib/esm/function/arithmetic/divideScalar.js +5 -5
  98. package/lib/esm/function/arithmetic/fix.js +5 -5
  99. package/lib/esm/function/arithmetic/floor.js +6 -6
  100. package/lib/esm/function/arithmetic/hypot.js +3 -3
  101. package/lib/esm/function/arithmetic/mod.js +3 -3
  102. package/lib/esm/function/arithmetic/multiply.js +7 -7
  103. package/lib/esm/function/arithmetic/multiplyScalar.js +4 -4
  104. package/lib/esm/function/arithmetic/norm.js +2 -2
  105. package/lib/esm/function/arithmetic/pow.js +6 -6
  106. package/lib/esm/function/arithmetic/round.js +7 -7
  107. package/lib/esm/function/arithmetic/subtractScalar.js +4 -4
  108. package/lib/esm/function/arithmetic/xgcd.js +1 -1
  109. package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
  110. package/lib/esm/function/combinatorics/catalan.js +1 -1
  111. package/lib/esm/function/combinatorics/composition.js +1 -1
  112. package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
  113. package/lib/esm/function/geometry/distance.js +4 -4
  114. package/lib/esm/function/geometry/intersect.js +2 -2
  115. package/lib/esm/function/logical/and.js +2 -2
  116. package/lib/esm/function/logical/or.js +2 -2
  117. package/lib/esm/function/logical/xor.js +2 -2
  118. package/lib/esm/function/matrix/apply.js +2 -2
  119. package/lib/esm/function/matrix/column.js +1 -1
  120. package/lib/esm/function/matrix/concat.js +1 -1
  121. package/lib/esm/function/matrix/count.js +1 -1
  122. package/lib/esm/function/matrix/cross.js +3 -3
  123. package/lib/esm/function/matrix/diag.js +10 -10
  124. package/lib/esm/function/matrix/diff.js +2 -2
  125. package/lib/esm/function/matrix/eigs.js +3 -3
  126. package/lib/esm/function/matrix/fft.js +3 -3
  127. package/lib/esm/function/matrix/filter.js +4 -4
  128. package/lib/esm/function/matrix/flatten.js +5 -6
  129. package/lib/esm/function/matrix/forEach.js +4 -4
  130. package/lib/esm/function/matrix/identity.js +6 -6
  131. package/lib/esm/function/matrix/ifft.js +3 -3
  132. package/lib/esm/function/matrix/inv.js +1 -1
  133. package/lib/esm/function/matrix/kron.js +7 -7
  134. package/lib/esm/function/matrix/map.js +110 -19
  135. package/lib/esm/function/matrix/matrixFromFunction.js +6 -6
  136. package/lib/esm/function/matrix/ones.js +2 -2
  137. package/lib/esm/function/matrix/partitionSelect.js +2 -2
  138. package/lib/esm/function/matrix/pinv.js +1 -1
  139. package/lib/esm/function/matrix/range.js +10 -10
  140. package/lib/esm/function/matrix/reshape.js +2 -2
  141. package/lib/esm/function/matrix/rotate.js +4 -4
  142. package/lib/esm/function/matrix/rotationMatrix.js +6 -6
  143. package/lib/esm/function/matrix/row.js +1 -1
  144. package/lib/esm/function/matrix/size.js +8 -8
  145. package/lib/esm/function/matrix/sort.js +4 -4
  146. package/lib/esm/function/matrix/sqrtm.js +1 -1
  147. package/lib/esm/function/matrix/squeeze.js +3 -4
  148. package/lib/esm/function/matrix/subset.js +2 -2
  149. package/lib/esm/function/matrix/zeros.js +2 -2
  150. package/lib/esm/function/probability/combinations.js +1 -1
  151. package/lib/esm/function/probability/combinationsWithRep.js +2 -2
  152. package/lib/esm/function/probability/kldivergence.js +4 -4
  153. package/lib/esm/function/probability/multinomial.js +1 -1
  154. package/lib/esm/function/probability/permutations.js +2 -2
  155. package/lib/esm/function/probability/pickRandom.js +6 -6
  156. package/lib/esm/function/probability/random.js +1 -1
  157. package/lib/esm/function/probability/randomInt.js +1 -1
  158. package/lib/esm/function/relational/compare.js +6 -6
  159. package/lib/esm/function/relational/deepEqual.js +1 -1
  160. package/lib/esm/function/relational/equal.js +1 -1
  161. package/lib/esm/function/relational/equalScalar.js +7 -7
  162. package/lib/esm/function/relational/equalText.js +1 -1
  163. package/lib/esm/function/relational/larger.js +3 -3
  164. package/lib/esm/function/relational/largerEq.js +4 -4
  165. package/lib/esm/function/relational/smaller.js +3 -3
  166. package/lib/esm/function/relational/smallerEq.js +3 -3
  167. package/lib/esm/function/relational/unequal.js +1 -1
  168. package/lib/esm/function/set/setCartesian.js +1 -1
  169. package/lib/esm/function/set/setDifference.js +1 -1
  170. package/lib/esm/function/set/setDistinct.js +1 -1
  171. package/lib/esm/function/set/setIntersect.js +1 -1
  172. package/lib/esm/function/set/setIsSubset.js +1 -1
  173. package/lib/esm/function/set/setMultiplicity.js +1 -1
  174. package/lib/esm/function/set/setPowerset.js +1 -1
  175. package/lib/esm/function/set/setSize.js +2 -2
  176. package/lib/esm/function/set/setSymDifference.js +1 -1
  177. package/lib/esm/function/set/setUnion.js +1 -1
  178. package/lib/esm/function/signal/freqz.js +6 -6
  179. package/lib/esm/function/statistics/corr.js +2 -2
  180. package/lib/esm/function/statistics/cumsum.js +3 -3
  181. package/lib/esm/function/statistics/max.js +1 -1
  182. package/lib/esm/function/statistics/median.js +3 -3
  183. package/lib/esm/function/statistics/min.js +1 -1
  184. package/lib/esm/function/statistics/prod.js +1 -1
  185. package/lib/esm/function/statistics/variance.js +2 -2
  186. package/lib/esm/function/string/bin.js +2 -2
  187. package/lib/esm/function/string/hex.js +2 -2
  188. package/lib/esm/function/string/oct.js +2 -2
  189. package/lib/esm/function/trigonometry/acoth.js +2 -2
  190. package/lib/esm/function/trigonometry/acsch.js +2 -2
  191. package/lib/esm/type/bigint.js +1 -1
  192. package/lib/esm/type/complex/function/complex.js +2 -2
  193. package/lib/esm/type/fraction/function/fraction.js +1 -1
  194. package/lib/esm/type/matrix/DenseMatrix.js +13 -38
  195. package/lib/esm/type/matrix/SparseMatrix.js +5 -8
  196. package/lib/esm/type/matrix/function/index.js +1 -1
  197. package/lib/esm/type/matrix/function/matrix.js +1 -1
  198. package/lib/esm/type/matrix/function/sparse.js +2 -2
  199. package/lib/esm/type/number.js +1 -1
  200. package/lib/esm/type/unit/function/createUnit.js +3 -3
  201. package/lib/esm/type/unit/function/splitUnit.js +1 -1
  202. package/lib/esm/type/unit/function/unit.js +2 -2
  203. package/lib/esm/utils/array.js +26 -0
  204. package/lib/esm/utils/collection.js +1 -1
  205. package/lib/esm/utils/function.js +0 -13
  206. package/lib/esm/utils/is.js +24 -0
  207. package/lib/esm/utils/map.js +2 -19
  208. package/lib/esm/version.js +1 -1
  209. package/package.json +13 -13
  210. 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 ArrayMatrixArrayMatrix(a1, a2) {
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 ArrayArray(b, a) {
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 ArrayArrayArray(b, a, w) {
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 ArrayArrayNumber(b, a, w) {
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 MatrixMatrix(b, a) {
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 MatrixMatrixMatrix(b, a, w) {
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 MatrixMatrixNumber(b, a, w) {
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 ArrayArray(A, B) {
38
+ 'Array, Array': function Array_Array(A, B) {
39
39
  return _corr(A, B);
40
40
  },
41
- 'Matrix, Matrix': function MatrixMatrix(A, B) {
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 MatrixNumberBigNumber(matrix, dim) {
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 ArrayMatrixNumberBigNumber(array, dim) {
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 numberBigNumberComplexUnit(value) {
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 numberBigNumberComplexUnitNumberBigNumberComplexUnit(left, right) {
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 ArrayMatrixNumberBigNumber(array, dim) {
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 ArrayMatrixNumberBigNumber(array, dim) {
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 ArrayMatrixNumberBigNumber(array, dim) {
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 ArrayMatrix(array) {
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 ArrayMatrixNumberBigNumber(array, dim) {
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 numberBigNumber(n) {
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 numberBigNumberNumberBigNumber(n, wordSize) {
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 numberBigNumber(n) {
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 numberBigNumberNumberBigNumber(n, wordSize) {
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 numberBigNumber(n) {
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 numberBigNumberNumberBigNumber(n, wordSize) {
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 arccotangent of a value,
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 arccotangent, this
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 arccosecant of a value,
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 arccosecant, this function
14
+ * To avoid confusion with the matrix inverse hyperbolic cosecant, this function
15
15
  * does not apply to matrices.
16
16
  *
17
17
  * Syntax:
@@ -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 stringBoolean(x) {
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 numberNumber(re, im) {
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 BigNumberBigNumber(re, im) {
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 numberNumber(numerator, denominator) {
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 { maxArgumentCount } from '../../utils/function.js';
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
- if (!isArray(index)) {
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 args = maxArgumentCount(callback);
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 recurse(child, index.concat(i));
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
- if (args === 1) {
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 = recurse(this._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 recurse = function recurse(value, index) {
560
+ var _recurse2 = function recurse(value, index) {
586
561
  if (isArray(value)) {
587
562
  value.forEach(function (child, i) {
588
- recurse(child, index.concat(i));
563
+ _recurse2(child, index.concat(i));
589
564
  });
590
565
  } else {
591
566
  callback(value, index, me);
592
567
  }
593
568
  };
594
- recurse(this._data, []);
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 recurse = function* recurse(value, index) {
577
+ var _recurse3 = function* recurse(value, index) {
603
578
  if (isArray(value)) {
604
579
  for (var i = 0; i < value.length; i++) {
605
- yield* recurse(value[i], index.concat(i));
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* recurse(this._data, []);
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 { maxArgumentCount } from '../../utils/function.js';
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
- if (args === 1) return callback(v);
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
- v = callback(v, x, y);
908
+ var value = callback(v, x, y);
912
909
  // check value != 0
913
- if (!eq(v, zero)) {
910
+ if (!eq(value, zero)) {
914
911
  // store value
915
- values.push(v);
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 numberStringBigNumberRangeArrayMatrix(args) {
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 stringString(format, datatype) {
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 ArrayMatrix(data) {
49
+ 'Array | Matrix': function Array__Matrix(data) {
50
50
  return new SparseMatrix(data);
51
51
  },
52
- 'Array | Matrix, string': function ArrayMatrixString(data, datatype) {
52
+ 'Array | Matrix, string': function Array__Matrix_string(data, datatype) {
53
53
  return new SparseMatrix(data, datatype);
54
54
  }
55
55
  });
@@ -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 UnitStringUnit(unit, valuelessUnit) {
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 ObjectObject(obj, options) {
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 stringUnitStringObjectObject(name, def, options) {
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 stringUnitStringObject(name, def) {
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 UnitArray(unit, parts) {
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 numberBigNumberFractionComplexStringUnit(value, unit) {
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 numberBigNumberFraction(value) {
54
+ 'number | BigNumber | Fraction': function number__BigNumber__Fraction(value) {
55
55
  // dimensionless
56
56
  return new Unit(value);
57
57
  },
@@ -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
  }
@@ -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
  }