mathjs 14.0.1 → 14.2.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.
Files changed (142) hide show
  1. package/HISTORY.md +20 -0
  2. package/NOTICE +1 -1
  3. package/README.md +7 -7
  4. package/bin/cli.js +1 -1
  5. package/lib/browser/math.js +1 -1
  6. package/lib/browser/math.js.LICENSE.txt +5 -5
  7. package/lib/browser/math.js.map +1 -1
  8. package/lib/cjs/core/function/import.js +14 -4
  9. package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  10. package/lib/cjs/entry/dependenciesAny/{dependenciesApply.generated.js → dependenciesMapSlices.generated.js} +3 -3
  11. package/lib/cjs/entry/dependenciesAny/{dependenciesApplyTransform.generated.js → dependenciesMapSlicesTransform.generated.js} +3 -3
  12. package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
  13. package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +2 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesVariance.generated.js +2 -2
  17. package/lib/cjs/entry/dependenciesAny/dependenciesVarianceTransform.generated.js +2 -2
  18. package/lib/cjs/entry/dependenciesAny.generated.js +14 -14
  19. package/lib/cjs/entry/dependenciesNumber/{dependenciesApply.generated.js → dependenciesMapSlices.generated.js} +3 -3
  20. package/lib/cjs/entry/dependenciesNumber/{dependenciesApplyTransform.generated.js → dependenciesMapSlicesTransform.generated.js} +3 -3
  21. package/lib/cjs/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
  22. package/lib/cjs/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
  23. package/lib/cjs/entry/dependenciesNumber/dependenciesVariance.generated.js +2 -2
  24. package/lib/cjs/entry/dependenciesNumber/dependenciesVarianceTransform.generated.js +2 -2
  25. package/lib/cjs/entry/dependenciesNumber.generated.js +14 -14
  26. package/lib/cjs/entry/impureFunctionsAny.generated.js +86 -85
  27. package/lib/cjs/entry/impureFunctionsNumber.generated.js +14 -14
  28. package/lib/cjs/entry/pureFunctionsAny.generated.js +330 -325
  29. package/lib/cjs/entry/pureFunctionsNumber.generated.js +18 -15
  30. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
  31. package/lib/cjs/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
  32. package/lib/cjs/expression/embeddedDocs/function/matrix/mapSlices.js +17 -0
  33. package/lib/cjs/expression/transform/index.transform.js +2 -2
  34. package/lib/cjs/expression/transform/{apply.transform.js → mapSlices.transform.js} +11 -10
  35. package/lib/cjs/expression/transform/quantileSeq.transform.js +5 -3
  36. package/lib/cjs/expression/transform/variance.transform.js +3 -3
  37. package/lib/cjs/factoriesAny.js +14 -14
  38. package/lib/cjs/factoriesNumber.js +16 -15
  39. package/lib/cjs/function/arithmetic/ceil.js +34 -26
  40. package/lib/cjs/function/arithmetic/fix.js +3 -0
  41. package/lib/cjs/function/arithmetic/floor.js +41 -26
  42. package/lib/cjs/function/arithmetic/log.js +12 -5
  43. package/lib/cjs/function/arithmetic/log10.js +15 -7
  44. package/lib/cjs/function/arithmetic/log2.js +9 -4
  45. package/lib/cjs/function/arithmetic/round.js +4 -0
  46. package/lib/cjs/function/matrix/ctranspose.js +1 -1
  47. package/lib/cjs/function/matrix/{apply.js → mapSlices.js} +19 -12
  48. package/lib/cjs/function/matrix/matrixFromFunction.js +36 -3
  49. package/lib/cjs/function/matrix/range.js +54 -5
  50. package/lib/cjs/function/probability/randomInt.js +26 -3
  51. package/lib/cjs/function/relational/larger.js +12 -4
  52. package/lib/cjs/function/relational/smaller.js +12 -4
  53. package/lib/cjs/function/statistics/max.js +1 -1
  54. package/lib/cjs/function/statistics/min.js +1 -1
  55. package/lib/cjs/function/statistics/quantileSeq.js +4 -9
  56. package/lib/cjs/function/statistics/variance.js +3 -3
  57. package/lib/cjs/function/string/hex.js +1 -1
  58. package/lib/cjs/function/string/print.js +2 -2
  59. package/lib/cjs/function/trigonometry/acoth.js +1 -1
  60. package/lib/cjs/function/trigonometry/acsc.js +1 -1
  61. package/lib/cjs/function/trigonometry/asin.js +1 -1
  62. package/lib/cjs/function/trigonometry/atan2.js +2 -1
  63. package/lib/cjs/function/trigonometry/cos.js +1 -1
  64. package/lib/cjs/function/trigonometry/sin.js +1 -1
  65. package/lib/cjs/function/utils/isInteger.js +1 -1
  66. package/lib/cjs/header.js +3 -3
  67. package/lib/cjs/type/matrix/MatrixIndex.js +6 -3
  68. package/lib/cjs/type/matrix/Range.js +15 -8
  69. package/lib/cjs/utils/bigint.js +33 -0
  70. package/lib/cjs/utils/factory.js +5 -2
  71. package/lib/cjs/utils/number.js +7 -19
  72. package/lib/cjs/utils/snapshot.js +8 -1
  73. package/lib/cjs/version.js +1 -1
  74. package/lib/esm/core/function/import.js +14 -4
  75. package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
  76. package/lib/esm/entry/{dependenciesNumber/dependenciesApply.generated.js → dependenciesAny/dependenciesMapSlices.generated.js} +3 -3
  77. package/lib/esm/entry/{dependenciesNumber/dependenciesApplyTransform.generated.js → dependenciesAny/dependenciesMapSlicesTransform.generated.js} +3 -3
  78. package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
  79. package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +2 -0
  80. package/lib/esm/entry/dependenciesAny/dependenciesRandomInt.generated.js +2 -0
  81. package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
  82. package/lib/esm/entry/dependenciesAny/dependenciesVariance.generated.js +2 -2
  83. package/lib/esm/entry/dependenciesAny/dependenciesVarianceTransform.generated.js +2 -2
  84. package/lib/esm/entry/dependenciesAny.generated.js +2 -2
  85. package/lib/esm/entry/{dependenciesAny/dependenciesApply.generated.js → dependenciesNumber/dependenciesMapSlices.generated.js} +3 -3
  86. package/lib/esm/entry/{dependenciesAny/dependenciesApplyTransform.generated.js → dependenciesNumber/dependenciesMapSlicesTransform.generated.js} +3 -3
  87. package/lib/esm/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
  88. package/lib/esm/entry/dependenciesNumber/dependenciesRandomInt.generated.js +2 -0
  89. package/lib/esm/entry/dependenciesNumber/dependenciesVariance.generated.js +2 -2
  90. package/lib/esm/entry/dependenciesNumber/dependenciesVarianceTransform.generated.js +2 -2
  91. package/lib/esm/entry/dependenciesNumber.generated.js +2 -2
  92. package/lib/esm/entry/impureFunctionsAny.generated.js +88 -87
  93. package/lib/esm/entry/impureFunctionsNumber.generated.js +16 -16
  94. package/lib/esm/entry/pureFunctionsAny.generated.js +328 -323
  95. package/lib/esm/entry/pureFunctionsNumber.generated.js +17 -14
  96. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
  97. package/lib/esm/expression/embeddedDocs/function/arithmetic/sign.js +1 -1
  98. package/lib/esm/expression/embeddedDocs/function/matrix/mapSlices.js +11 -0
  99. package/lib/esm/expression/transform/index.transform.js +3 -3
  100. package/lib/esm/expression/transform/mapSlices.transform.js +47 -0
  101. package/lib/esm/expression/transform/quantileSeq.transform.js +5 -3
  102. package/lib/esm/expression/transform/variance.transform.js +3 -3
  103. package/lib/esm/factoriesAny.js +2 -2
  104. package/lib/esm/factoriesNumber.js +2 -2
  105. package/lib/esm/function/arithmetic/ceil.js +35 -27
  106. package/lib/esm/function/arithmetic/fix.js +3 -0
  107. package/lib/esm/function/arithmetic/floor.js +42 -27
  108. package/lib/esm/function/arithmetic/log.js +12 -5
  109. package/lib/esm/function/arithmetic/log10.js +16 -8
  110. package/lib/esm/function/arithmetic/log2.js +9 -4
  111. package/lib/esm/function/arithmetic/round.js +4 -0
  112. package/lib/esm/function/matrix/ctranspose.js +1 -1
  113. package/lib/esm/function/matrix/{apply.js → mapSlices.js} +18 -11
  114. package/lib/esm/function/matrix/matrixFromFunction.js +36 -3
  115. package/lib/esm/function/matrix/range.js +54 -5
  116. package/lib/esm/function/probability/randomInt.js +26 -3
  117. package/lib/esm/function/relational/larger.js +12 -4
  118. package/lib/esm/function/relational/smaller.js +12 -4
  119. package/lib/esm/function/statistics/max.js +1 -1
  120. package/lib/esm/function/statistics/min.js +1 -1
  121. package/lib/esm/function/statistics/quantileSeq.js +4 -9
  122. package/lib/esm/function/statistics/variance.js +3 -3
  123. package/lib/esm/function/string/hex.js +1 -1
  124. package/lib/esm/function/string/print.js +2 -2
  125. package/lib/esm/function/trigonometry/acoth.js +1 -1
  126. package/lib/esm/function/trigonometry/acsc.js +1 -1
  127. package/lib/esm/function/trigonometry/asin.js +1 -1
  128. package/lib/esm/function/trigonometry/atan2.js +2 -1
  129. package/lib/esm/function/trigonometry/cos.js +1 -1
  130. package/lib/esm/function/trigonometry/sin.js +1 -1
  131. package/lib/esm/function/utils/isInteger.js +1 -1
  132. package/lib/esm/header.js +1 -1
  133. package/lib/esm/type/matrix/MatrixIndex.js +6 -3
  134. package/lib/esm/type/matrix/Range.js +16 -9
  135. package/lib/esm/utils/bigint.js +27 -0
  136. package/lib/esm/utils/factory.js +5 -2
  137. package/lib/esm/utils/number.js +6 -17
  138. package/lib/esm/utils/snapshot.js +8 -1
  139. package/lib/esm/version.js +1 -1
  140. package/package.json +13 -11
  141. package/types/index.d.ts +75 -12
  142. package/lib/esm/expression/transform/apply.transform.js +0 -44
@@ -42,6 +42,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
42
42
  var arg = arguments[i];
43
43
  var argIsArray = isArray(arg);
44
44
  var argIsMatrix = isMatrix(arg);
45
+ var argType = typeof arg;
45
46
  var sourceSize = null;
46
47
  if (isRange(arg)) {
47
48
  this._dimensions.push(arg);
@@ -63,13 +64,15 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
63
64
  if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
64
65
  this._isScalar = false;
65
66
  }
66
- } else if (typeof arg === 'number') {
67
+ } else if (argType === 'number') {
67
68
  this._dimensions.push(_createImmutableMatrix([arg]));
68
- } else if (typeof arg === 'string') {
69
+ } else if (argType === 'bigint') {
70
+ this._dimensions.push(_createImmutableMatrix([Number(arg)]));
71
+ } else if (argType === 'string') {
69
72
  // object property (arguments.count should be 1)
70
73
  this._dimensions.push(arg);
71
74
  } else {
72
- throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
75
+ throw new TypeError('Dimension must be an Array, Matrix, number, bigint, string, or Range');
73
76
  }
74
77
  this._sourceSize.push(sourceSize);
75
78
  // TODO: implement support for wildcard '*'
@@ -1,18 +1,25 @@
1
- import { isBigNumber } from '../../utils/is.js';
1
+ import { isBigInt, isBigNumber } from '../../utils/is.js';
2
2
  import { format, sign } from '../../utils/number.js';
3
3
  import { factory } from '../../utils/factory.js';
4
4
  var name = 'Range';
5
5
  var dependencies = [];
6
6
  export var createRangeClass = /* #__PURE__ */factory(name, dependencies, () => {
7
7
  /**
8
- * Create a range. A range has a start, step, and end, and contains functions
9
- * to iterate over the range.
8
+ * Create a range of numbers. A range has a start, step, and end,
9
+ * and contains functions to iterate over the range.
10
10
  *
11
11
  * A range can be constructed as:
12
12
  *
13
13
  * const range = new Range(start, end)
14
14
  * const range = new Range(start, end, step)
15
15
  *
16
+ * Note that the endpoints and step may be specified with other numeric
17
+ * types such as bigint or BigNumber, but they will be demoted to the
18
+ * built-in `number` type and the Range will only contain numbers. The
19
+ * rationale for this demotion is that Range objects are primarily used
20
+ * for indexing Matrix objects, and Matrix objects may only be indexed
21
+ * with `number`s.
22
+ *
16
23
  * To get the result of the range:
17
24
  * range.forEach(function (x) {
18
25
  * console.log(x)
@@ -45,22 +52,22 @@ export var createRangeClass = /* #__PURE__ */factory(name, dependencies, () => {
45
52
  if (hasStart) {
46
53
  if (isBigNumber(start)) {
47
54
  start = start.toNumber();
48
- } else if (typeof start !== 'number') {
49
- throw new TypeError('Parameter start must be a number');
55
+ } else if (typeof start !== 'number' && !isBigInt(start)) {
56
+ throw new TypeError('Parameter start must be a number or bigint');
50
57
  }
51
58
  }
52
59
  if (hasEnd) {
53
60
  if (isBigNumber(end)) {
54
61
  end = end.toNumber();
55
- } else if (typeof end !== 'number') {
56
- throw new TypeError('Parameter end must be a number');
62
+ } else if (typeof end !== 'number' && !isBigInt(end)) {
63
+ throw new TypeError('Parameter end must be a number or bigint');
57
64
  }
58
65
  }
59
66
  if (hasStep) {
60
67
  if (isBigNumber(step)) {
61
68
  step = step.toNumber();
62
- } else if (typeof step !== 'number') {
63
- throw new TypeError('Parameter step must be a number');
69
+ } else if (typeof step !== 'number' && !isBigInt(step)) {
70
+ throw new TypeError('Parameter step must be a number or bigint');
64
71
  }
65
72
  }
66
73
  this.start = hasStart ? parseFloat(start) : 0;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Build a bigint logarithm function from a number logarithm,
3
+ * still returning a number. The idea is that 15 hexadecimal digits
4
+ * (60 bits) saturates the mantissa of the log, and each additional hex
5
+ * digit effectively just adds the log of 16 to the resulting value. So
6
+ * convert the most significant 15 hex digits to a number and take its
7
+ * log, and then add the log of 16 for each additional hex digit that
8
+ * was in the bigint.
9
+ * For negative numbers (complex logarithms), following the bignum
10
+ * implementation, it just downgrades to number and uses the complex result.
11
+ * @param {number} log16 the log of 16
12
+ * @param {(number) -> number} numberLog the logarithm function for numbers
13
+ * @param {ConfigurationObject} config the mathjs configuration
14
+ * @param {(number) -> Complex} cplx the associated Complex log
15
+ * @returns {(bigint) -> number} the corresponding logarithm for bigints
16
+ */
17
+ export function promoteLogarithm(log16, numberLog, config, cplx) {
18
+ return function (b) {
19
+ if (b > 0 || config.predictable) {
20
+ if (b <= 0) return NaN;
21
+ var s = b.toString(16);
22
+ var s15 = s.substring(0, 15);
23
+ return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15));
24
+ }
25
+ return cplx(b.toNumber());
26
+ };
27
+ }
@@ -20,8 +20,11 @@ import { pickShallow } from './object.js';
20
20
  * @param {string} name Name of the function to be created
21
21
  * @param {string[]} dependencies The names of all required dependencies
22
22
  * @param {function} create Callback function called with an object with all dependencies
23
- * @param {Object} [meta] Optional object with meta information that will be attached
24
- * to the created factory function as property `meta`.
23
+ * @param {Object} [meta]
24
+ * Optional object with meta information that will be attached
25
+ * to the created factory function as property `meta`. For explanation
26
+ * of what meta properties can be specified and what they mean, see
27
+ * docs/core/extension.md.
25
28
  * @returns {function}
26
29
  */
27
30
  export function factory(name, dependencies, create, meta) {
@@ -16,16 +16,6 @@ export function isInteger(value) {
16
16
  return isFinite(value) ? value === Math.round(value) : false;
17
17
  }
18
18
 
19
- /**
20
- * Check if a string contains an integer
21
- * @param {string} str
22
- * @return {boolean} isInteger
23
- */
24
- export function isIntegerStr(str) {
25
- // regex matching strings like "123" and "-123"
26
- return /^-?\d+$/.test(str);
27
- }
28
-
29
19
  /**
30
20
  * Ensure the number type is compatible with the provided value.
31
21
  * If not, return 'number' instead.
@@ -45,8 +35,12 @@ export function isIntegerStr(str) {
45
35
  * @returns {'number' | 'BigNumber' | 'bigint' | 'Fraction'}
46
36
  */
47
37
  export function safeNumberType(numberStr, config) {
48
- if (config.number === 'bigint' && !isIntegerStr(numberStr)) {
49
- return config.numberFallback;
38
+ if (config.number === 'bigint') {
39
+ try {
40
+ BigInt(numberStr);
41
+ } catch (_unused) {
42
+ return config.numberFallback;
43
+ }
50
44
  }
51
45
  return config.number;
52
46
  }
@@ -610,11 +604,6 @@ export function digits(value) {
610
604
  .length;
611
605
  }
612
606
 
613
- /**
614
- * Minimum number added to one that makes the result different than one
615
- */
616
- export var DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16;
617
-
618
607
  /**
619
608
  * Compares two floating point numbers.
620
609
  * @param {number} a - First value to compare
@@ -101,16 +101,22 @@ export function createSnapshotFromFactories(factories) {
101
101
  var allClasses = {};
102
102
  var allNodeClasses = {};
103
103
  Object.keys(factories).forEach(factoryName => {
104
+ var _factory$meta$formerl, _factory$meta;
104
105
  var factory = factories[factoryName];
105
106
  var name = factory.fn;
106
107
  var isTransformFunction = factory.meta && factory.meta.isTransformFunction;
107
108
  var isClass = !isLowerCase(name[0]) && validateTypeOf(math[name]) === 'function';
108
109
  var dependenciesName = factory.fn + (isTransformFunction ? 'Transform' : '') + 'Dependencies';
110
+ var former = (_factory$meta$formerl = (_factory$meta = factory.meta) === null || _factory$meta === void 0 ? void 0 : _factory$meta.formerly) !== null && _factory$meta$formerl !== void 0 ? _factory$meta$formerl : '';
109
111
  allFactoryFunctions[factoryName] = 'function';
110
112
  allFunctionsConstantsClasses[name] = validateTypeOf(math[name]);
113
+ if (former) {
114
+ allFunctionsConstantsClasses[former] = allFunctionsConstantsClasses[name];
115
+ }
111
116
  allDependencyCollections[dependenciesName] = 'Object';
112
117
  if (isTransformFunction) {
113
118
  allTransformFunctions[name] = 'function';
119
+ if (former) allTransformFunctions[former] = 'function';
114
120
  }
115
121
  if (isClass) {
116
122
  if (endsWith(name, 'Node')) {
@@ -120,6 +126,7 @@ export function createSnapshotFromFactories(factories) {
120
126
  }
121
127
  } else {
122
128
  allFunctionsConstants[name] = validateTypeOf(math[name]);
129
+ if (former) allFunctionsConstants[former] = allFunctionsConstants[name];
123
130
  }
124
131
  });
125
132
  var embeddedDocs = {};
@@ -131,7 +138,7 @@ export function createSnapshotFromFactories(factories) {
131
138
  embeddedDocs[name] = 'Object';
132
139
  }
133
140
  });
134
- embeddedDocs = exclude(embeddedDocs, ['equalScalar', 'apply', 'addScalar', 'subtractScalar', 'multiplyScalar', 'print', 'divideScalar', 'parse', 'compile', 'parser', 'chain', 'reviver', 'replacer']);
141
+ embeddedDocs = exclude(embeddedDocs, ['equalScalar', 'addScalar', 'subtractScalar', 'multiplyScalar', 'print', 'divideScalar', 'parse', 'compile', 'parser', 'chain', 'reviver', 'replacer']);
135
142
  var allTypeChecks = {};
136
143
  Object.keys(allIsFunctions).forEach(name => {
137
144
  if (name.indexOf('is') === 0) {
@@ -1,3 +1,3 @@
1
- export var version = '14.0.1';
1
+ export var version = '14.2.0';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "14.0.1",
3
+ "version": "14.2.0",
4
4
  "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
5
5
  "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
6
6
  "homepage": "https://mathjs.org",
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.25.7",
29
+ "@lambdatest/node-tunnel": "^4.0.8",
29
30
  "complex.js": "^2.2.5",
30
31
  "decimal.js": "^10.4.3",
31
32
  "escape-latex": "^1.2.0",
@@ -44,13 +45,13 @@
44
45
  "@babel/register": "7.25.9",
45
46
  "@types/assert": "1.5.11",
46
47
  "@types/mocha": "10.0.10",
47
- "@typescript-eslint/eslint-plugin": "8.18.0",
48
- "@typescript-eslint/parser": "8.18.0",
48
+ "@typescript-eslint/eslint-plugin": "8.21.0",
49
+ "@typescript-eslint/parser": "8.21.0",
49
50
  "assert": "2.1.0",
50
51
  "babel-loader": "9.2.1",
51
52
  "c8": "10.1.3",
52
53
  "codecov": "3.8.3",
53
- "core-js": "3.39.0",
54
+ "core-js": "3.40.0",
54
55
  "del": "8.0.0",
55
56
  "dtslint": "4.2.1",
56
57
  "eigen": "0.2.2",
@@ -60,24 +61,25 @@
60
61
  "eslint-plugin-import": "2.31.0",
61
62
  "eslint-plugin-mocha": "10.5.0",
62
63
  "eslint-plugin-n": "16.6.2",
63
- "eslint-plugin-prettier": "5.2.1",
64
+ "eslint-plugin-prettier": "5.2.3",
64
65
  "eslint-plugin-promise": "6.6.0",
65
66
  "expect-type": "1.1.0",
66
67
  "expr-eval": "2.0.2",
67
68
  "fancy-log": "2.0.0",
68
- "glob": "11.0.0",
69
+ "glob": "11.0.1",
69
70
  "gulp": "5.0.0",
70
71
  "gulp-babel": "8.0.0",
71
72
  "handlebars": "4.7.8",
72
73
  "jsep": "1.4.0",
73
74
  "karma": "6.4.4",
74
- "karma-browserstack-launcher": "1.6.0",
75
75
  "karma-firefox-launcher": "2.1.3",
76
76
  "karma-mocha": "2.0.1",
77
77
  "karma-mocha-reporter": "2.2.5",
78
+ "karma-spec-reporter": "0.0.36",
79
+ "karma-webdriver-launcher": "1.0.8",
78
80
  "karma-webpack": "5.0.1",
79
81
  "mkdirp": "3.0.1",
80
- "mocha": "11.0.1",
82
+ "mocha": "11.1.0",
81
83
  "mocha-junit-reporter": "2.2.1",
82
84
  "ndarray": "1.0.19",
83
85
  "ndarray-determinant": "1.0.0",
@@ -89,9 +91,9 @@
89
91
  "process": "0.11.10",
90
92
  "sinon": "19.0.2",
91
93
  "sylvester": "0.0.21",
92
- "tinybench": "3.0.7",
94
+ "tinybench": "3.1.0",
93
95
  "ts-node": "10.9.2",
94
- "typescript": "5.7.2",
96
+ "typescript": "5.7.3",
95
97
  "webpack": "5.97.1",
96
98
  "zeros": "1.0.0"
97
99
  },
@@ -151,7 +153,7 @@
151
153
  "test:node": "mocha test/node-tests/*.test.js test/node-tests/**/*.test.js",
152
154
  "test:all": "npm run test:src && npm run test:generated && npm run test:node && npm run test:types",
153
155
  "test:browser": "karma start test/browser-test-config/local-karma.js",
154
- "test:browserstack": "karma start test/browser-test-config/browserstack-karma.js",
156
+ "test:lambdatest": "karma start test/browser-test-config/lambdatest-karma.js",
155
157
  "test:types": " tsc -p ./tsconfig.json && node --loader ts-node/esm ./test/typescript-tests/testTypes.ts",
156
158
  "coverage": "c8 --reporter=lcov --reporter=text-summary mocha test/unit-tests && echo \"\nDetailed coverage report is available at ./coverage/lcov-report/index.html\"",
157
159
  "prepublishOnly": "npm run test:all && npm run lint",
package/types/index.d.ts CHANGED
@@ -21,6 +21,12 @@ export type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>
21
21
  export type MathType = MathScalarType | MathCollection
22
22
  export type MathExpression = string | string[] | MathCollection
23
23
 
24
+ // add type for Matrix Callback Function and Matrix Storage Format
25
+ export type MatrixStorageFormat = 'dense' | 'sparse'
26
+ export type MatrixFromFunctionCallback<T extends MathScalarType> = (
27
+ index: number[]
28
+ ) => T
29
+
24
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
31
  export type FactoryFunction<T> = (scope: any) => T
26
32
 
@@ -743,7 +749,7 @@ export interface MathJsInstance extends MathJsFactory {
743
749
  * @param format The Matrix storage format
744
750
  * @returns The created Matrix
745
751
  */
746
- matrix(format?: 'sparse' | 'dense'): Matrix
752
+ matrix(format?: MatrixStorageFormat): Matrix
747
753
  /**
748
754
  * @param data A multi dimensional array
749
755
  * @param format The Matrix storage format
@@ -752,12 +758,12 @@ export interface MathJsInstance extends MathJsFactory {
752
758
  */
753
759
  matrix(
754
760
  data: MathCollection | string[],
755
- format?: 'sparse' | 'dense',
761
+ format?: MatrixStorageFormat,
756
762
  dataType?: string
757
763
  ): Matrix
758
764
  matrix<T extends MathScalarType>(
759
765
  data: MathCollection<T>,
760
- format?: 'sparse' | 'dense',
766
+ format?: MatrixStorageFormat,
761
767
  dataType?: string
762
768
  ): Matrix<T>
763
769
 
@@ -1322,6 +1328,58 @@ export interface MathJsInstance extends MathJsFactory {
1322
1328
  hypot<T extends number | BigNumber>(...args: T[]): T
1323
1329
  hypot<T extends number | BigNumber>(args: T[]): T
1324
1330
 
1331
+ /**
1332
+ * Create a dense matrix from vectors as individual rows. If you pass column vectors, they will be transposed (but not conjugated!)
1333
+ * @param rows - a multi-dimensional number array or matrix
1334
+ */
1335
+ matrixFromRows(...rows: Matrix[]): Matrix
1336
+ matrixFromRows<T extends MathScalarType>(
1337
+ ...rows: (T[] | [T][] | Matrix)[]
1338
+ ): T[][]
1339
+
1340
+ /**
1341
+ * Create a dense matrix from vectors as individual columns. If you pass row vectors, they will be transposed (but not conjugated!)
1342
+ * @param cols - a multi-dimensional number array or matrix
1343
+ */
1344
+ matrixFromColumns(...cols: Matrix[]): Matrix
1345
+ matrixFromColumns<T extends MathScalarType>(
1346
+ ...cols: (T[] | [T][] | Matrix)[]
1347
+ ): T[][]
1348
+ /**
1349
+ * Create a matrix by evaluating a generating function at each index. The simplest overload returns a multi-dimensional array as long as size is an array. Passing size as a Matrix or specifying a format will result in returning a Matrix.
1350
+ * @param size - the size of the matrix to be created
1351
+ * @param fn - Callback function invoked for every entry in the matrix
1352
+ * @param format - The Matrix storage format, either 'dense' or 'sparse'
1353
+ * @param datatype - Type of the values
1354
+ */
1355
+ matrixFromFunction<T extends MathScalarType>(
1356
+ size: [number],
1357
+ fn: MatrixFromFunctionCallback<T>
1358
+ ): T[]
1359
+ matrixFromFunction<T extends MathScalarType>(
1360
+ size: [number, number],
1361
+ fn: MatrixFromFunctionCallback<T>
1362
+ ): T[][]
1363
+ matrixFromFunction<T extends MathScalarType>(
1364
+ size: number[],
1365
+ fn: MatrixFromFunctionCallback<T>
1366
+ ): MathArray<T>
1367
+ matrixFromFunction(
1368
+ size: Matrix<number>,
1369
+ fn: MatrixFromFunctionCallback<MathScalarType>
1370
+ ): Matrix
1371
+ matrixFromFunction(
1372
+ size: number[] | Matrix<number>,
1373
+ fn: MatrixFromFunctionCallback<MathScalarType>,
1374
+ format: MatrixStorageFormat,
1375
+ datatype?: string
1376
+ ): Matrix
1377
+ matrixFromFunction(
1378
+ size: number[] | Matrix<number>,
1379
+ format: MatrixStorageFormat,
1380
+ fn: MatrixFromFunctionCallback<MathScalarType>,
1381
+ datatype?: string
1382
+ ): Matrix
1325
1383
  /**
1326
1384
  * Calculate the least common multiple for two or more values or arrays.
1327
1385
  * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
@@ -1805,11 +1863,15 @@ export interface MathJsInstance extends MathJsFactory {
1805
1863
  * array or 1-d matrix as an input and return a number.
1806
1864
  * @returns The residual matrix with the function applied over some dimension.
1807
1865
  */
1808
- apply<T extends MathCollection>(
1866
+ mapSlices<T extends MathCollection>(
1809
1867
  array: T,
1810
1868
  dim: number,
1811
1869
  callback: (array: MathCollection) => number
1812
1870
  ): T
1871
+ /**
1872
+ * @deprecated backwards-compatibility old name of mapSlices
1873
+ */
1874
+ apply: MathJsInstance['mapSlices']
1813
1875
 
1814
1876
  /**
1815
1877
  * Concatenate two or more matrices. dim: number is a zero-based
@@ -3705,7 +3767,7 @@ export const {
3705
3767
  unaryMinusDependencies,
3706
3768
  unaryPlusDependencies,
3707
3769
  absDependencies,
3708
- applyDependencies,
3770
+ mapSlicesDependencies,
3709
3771
  addScalarDependencies,
3710
3772
  cbrtDependencies,
3711
3773
  ceilDependencies,
@@ -3984,7 +4046,7 @@ export const {
3984
4046
  vacuumImpedanceDependencies,
3985
4047
  weakMixingAngleDependencies,
3986
4048
  wienDisplacementDependencies,
3987
- applyTransformDependencies,
4049
+ mapSlicesTransformDependencies,
3988
4050
  columnTransformDependencies,
3989
4051
  filterTransformDependencies,
3990
4052
  forEachTransformDependencies,
@@ -4010,10 +4072,6 @@ export interface Matrix<T = MathGeneric> {
4010
4072
  density(): number
4011
4073
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4012
4074
  subset(index: Index, replacement?: any, defaultValue?: any): Matrix
4013
- apply(
4014
- dim: number,
4015
- callback: (array: MathCollection) => number
4016
- ): MathCollection
4017
4075
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4018
4076
  get(index: number[]): any
4019
4077
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -4996,11 +5054,15 @@ export interface MathJsChain<TValue> {
4996
5054
  * array or 1-d matrix as an input and return a number.
4997
5055
  * @returns The residual matrix with the function applied over some dimension.
4998
5056
  */
4999
- apply<T extends MathCollection>(
5057
+ mapSlices<T extends MathCollection>(
5000
5058
  this: MathJsChain<T>,
5001
5059
  dim: number,
5002
5060
  callback: (array: Array<MathType> | Matrix) => number
5003
5061
  ): MathJsChain<T>
5062
+ /**
5063
+ * @deprecated backwards-compatibility old name of mapSlices
5064
+ **/
5065
+ apply: MathJsChain<TValue>['mapSlices']
5004
5066
 
5005
5067
  /**
5006
5068
  * Calculate the cubic root of a value. For matrices, the function is
@@ -7162,7 +7224,8 @@ export const {
7162
7224
  xor,
7163
7225
 
7164
7226
  // matrix functions
7165
- apply,
7227
+ mapSlices,
7228
+ apply, // @deprecated prior name of mapSlices
7166
7229
  concat,
7167
7230
  cross,
7168
7231
  det,
@@ -1,44 +0,0 @@
1
- import { errorTransform } from './utils/errorTransform.js';
2
- import { factory } from '../../utils/factory.js';
3
- import { createApply } from '../../function/matrix/apply.js';
4
- import { isBigNumber, isNumber } from '../../utils/is.js';
5
- var name = 'apply';
6
- var dependencies = ['typed', 'isInteger'];
7
-
8
- /**
9
- * Attach a transform function to math.apply
10
- * Adds a property transform containing the transform function.
11
- *
12
- * This transform changed the last `dim` parameter of function apply
13
- * from one-based to zero based
14
- */
15
- export var createApplyTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
16
- var {
17
- typed,
18
- isInteger
19
- } = _ref;
20
- var apply = createApply({
21
- typed,
22
- isInteger
23
- });
24
-
25
- // @see: comment of concat itself
26
- return typed('apply', {
27
- '...any': function any(args) {
28
- // change dim from one-based to zero-based
29
- var dim = args[1];
30
- if (isNumber(dim)) {
31
- args[1] = dim - 1;
32
- } else if (isBigNumber(dim)) {
33
- args[1] = dim.minus(1);
34
- }
35
- try {
36
- return apply.apply(null, args);
37
- } catch (err) {
38
- throw errorTransform(err);
39
- }
40
- }
41
- });
42
- }, {
43
- isTransformFunction: true
44
- });