mathjs 14.9.1 → 15.0.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 (50) hide show
  1. package/HISTORY.md +19 -0
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +1 -1
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/core/config.js +5 -1
  6. package/lib/cjs/core/function/config.js +4 -0
  7. package/lib/cjs/entry/dependenciesAny/dependenciesSize.generated.js +0 -2
  8. package/lib/cjs/entry/dependenciesNumber/dependenciesSize.generated.js +0 -2
  9. package/lib/cjs/entry/impureFunctionsAny.generated.js +40 -40
  10. package/lib/cjs/entry/pureFunctionsAny.generated.js +143 -144
  11. package/lib/cjs/entry/pureFunctionsNumber.generated.js +0 -2
  12. package/lib/cjs/expression/node/IndexNode.js +1 -1
  13. package/lib/cjs/expression/parse.js +38 -34
  14. package/lib/cjs/function/algebra/sylvester.js +6 -5
  15. package/lib/cjs/function/logical/nullish.js +2 -2
  16. package/lib/cjs/function/matrix/column.js +2 -1
  17. package/lib/cjs/function/matrix/dot.js +4 -9
  18. package/lib/cjs/function/matrix/flatten.js +6 -3
  19. package/lib/cjs/function/matrix/kron.js +31 -30
  20. package/lib/cjs/function/matrix/row.js +2 -1
  21. package/lib/cjs/function/matrix/size.js +11 -17
  22. package/lib/cjs/function/matrix/subset.js +21 -11
  23. package/lib/cjs/header.js +1 -1
  24. package/lib/cjs/type/matrix/DenseMatrix.js +52 -41
  25. package/lib/cjs/type/matrix/MatrixIndex.js +19 -20
  26. package/lib/cjs/type/matrix/SparseMatrix.js +13 -7
  27. package/lib/cjs/version.js +1 -1
  28. package/lib/esm/core/config.js +5 -1
  29. package/lib/esm/core/function/config.js +4 -0
  30. package/lib/esm/entry/dependenciesAny/dependenciesSize.generated.js +0 -2
  31. package/lib/esm/entry/dependenciesNumber/dependenciesSize.generated.js +0 -2
  32. package/lib/esm/entry/impureFunctionsAny.generated.js +42 -42
  33. package/lib/esm/entry/pureFunctionsAny.generated.js +144 -145
  34. package/lib/esm/entry/pureFunctionsNumber.generated.js +0 -2
  35. package/lib/esm/expression/node/IndexNode.js +1 -1
  36. package/lib/esm/expression/parse.js +38 -34
  37. package/lib/esm/function/algebra/sylvester.js +6 -5
  38. package/lib/esm/function/logical/nullish.js +2 -2
  39. package/lib/esm/function/matrix/column.js +2 -1
  40. package/lib/esm/function/matrix/dot.js +4 -9
  41. package/lib/esm/function/matrix/flatten.js +6 -3
  42. package/lib/esm/function/matrix/kron.js +31 -30
  43. package/lib/esm/function/matrix/row.js +2 -1
  44. package/lib/esm/function/matrix/size.js +11 -17
  45. package/lib/esm/function/matrix/subset.js +21 -11
  46. package/lib/esm/type/matrix/DenseMatrix.js +52 -41
  47. package/lib/esm/type/matrix/MatrixIndex.js +20 -21
  48. package/lib/esm/type/matrix/SparseMatrix.js +13 -7
  49. package/lib/esm/version.js +1 -1
  50. package/package.json +1 -1
@@ -44,8 +44,8 @@ const createDot = exports.createDot = /* #__PURE__ */(0, _factory.factory)(name,
44
44
  'SparseMatrix, SparseMatrix': _sparseDot
45
45
  });
46
46
  function _validateDim(x, y) {
47
- const xSize = _size(x);
48
- const ySize = _size(y);
47
+ const xSize = size(x);
48
+ const ySize = size(y);
49
49
  let xLen, yLen;
50
50
  if (xSize.length === 1) {
51
51
  xLen = xSize[0];
@@ -73,8 +73,8 @@ const createDot = exports.createDot = /* #__PURE__ */(0, _factory.factory)(name,
73
73
  const bdt = (0, _is.isMatrix)(b) ? b._datatype || b.getDataType() : undefined;
74
74
 
75
75
  // are these 2-dimensional column vectors? (as opposed to 1-dimensional vectors)
76
- const aIsColumn = _size(a).length === 2;
77
- const bIsColumn = _size(b).length === 2;
76
+ const aIsColumn = size(a).length === 2;
77
+ const bIsColumn = size(b).length === 2;
78
78
  let add = addScalar;
79
79
  let mul = multiplyScalar;
80
80
 
@@ -154,9 +154,4 @@ const createDot = exports.createDot = /* #__PURE__ */(0, _factory.factory)(name,
154
154
  }
155
155
  return c;
156
156
  }
157
-
158
- // TODO remove this once #1771 is fixed
159
- function _size(x) {
160
- return (0, _is.isMatrix)(x) ? x.size() : size(x);
161
- }
162
157
  });
@@ -28,17 +28,20 @@ const createFlatten = exports.createFlatten = /* #__PURE__ */(0, _factory.factor
28
28
  *
29
29
  * concat, resize, size, squeeze
30
30
  *
31
- * @param {Matrix | Array} x Matrix to be flattened
32
- * @return {Matrix | Array} Returns the flattened matrix
31
+ * @param {DenseMatrix | Array} x Matrix to be flattened
32
+ * @return {DenseMatrix | Array} Returns the flattened matrix
33
33
  */
34
34
  return typed(name, {
35
35
  Array: function (x) {
36
36
  return (0, _array.flatten)(x);
37
37
  },
38
- Matrix: function (x) {
38
+ DenseMatrix: function (x) {
39
39
  // Return the same matrix type as x (Dense or Sparse Matrix)
40
40
  // Return the same data type as x
41
41
  return x.create((0, _array.flatten)(x.valueOf(), true), x.datatype());
42
+ },
43
+ SparseMatrix: function (_x) {
44
+ throw new TypeError('SparseMatrix is not supported by function flatten ' + 'because it does not support 1D vectors. ' + 'Convert to a DenseMatrix or Array first. Example: flatten(x.toArray())');
42
45
  }
43
46
  });
44
47
  });
@@ -31,7 +31,7 @@ const createKron = exports.createKron = /* #__PURE__ */(0, _factory.factory)(nam
31
31
  * // returns [ [ 1, 2, 0, 0 ], [ 3, 4, 0, 0 ], [ 0, 0, 1, 2 ], [ 0, 0, 3, 4 ] ]
32
32
  *
33
33
  * math.kron([1,1], [2,3,4])
34
- * // returns [ [ 2, 3, 4, 2, 3, 4 ] ]
34
+ * // returns [2, 3, 4, 2, 3, 4]
35
35
  *
36
36
  * See also:
37
37
  *
@@ -55,37 +55,38 @@ const createKron = exports.createKron = /* #__PURE__ */(0, _factory.factory)(nam
55
55
  });
56
56
 
57
57
  /**
58
- * Calculate the Kronecker product of two matrices / vectors
59
- * @param {Array} a First vector
60
- * @param {Array} b Second vector
61
- * @returns {Array} Returns the Kronecker product of x and y
62
- * @private
58
+ * Calculate the Kronecker product of two (1-dimensional) vectors,
59
+ * with no dimension checking
60
+ * @param {Array} a First vector
61
+ * @param {Array} b Second vector
62
+ * @returns {Array} the 1-dimensional Kronecker product of a and b
63
+ * @private
64
+ */
65
+ function _kron1d(a, b) {
66
+ // TODO in core overhaul: would be faster to see if we can choose a
67
+ // particular implementation of multiplyScalar at the beginning,
68
+ // rather than re-dispatch for _every_ ordered pair of entries.
69
+ return a.flatMap(x => b.map(y => multiplyScalar(x, y)));
70
+ }
71
+
72
+ /**
73
+ * Calculate the Kronecker product of two possibly multidimensional arrays
74
+ * @param {Array} a First array
75
+ * @param {Array} b Second array
76
+ * @param {number} [d] common dimension; if missing, compute and match args
77
+ * @returns {Array} Returns the Kronecker product of x and y
78
+ * @private
63
79
  */
64
80
  function _kron(a, b) {
65
- // Deal with the dimensions of the matricies.
66
- if ((0, _array.arraySize)(a).length === 1) {
67
- // Wrap it in a 2D Matrix
68
- a = [a];
69
- }
70
- if ((0, _array.arraySize)(b).length === 1) {
71
- // Wrap it in a 2D Matrix
72
- b = [b];
73
- }
74
- if ((0, _array.arraySize)(a).length > 2 || (0, _array.arraySize)(b).length > 2) {
75
- throw new RangeError('Vectors with dimensions greater then 2 are not supported expected ' + '(Size x = ' + JSON.stringify(a.length) + ', y = ' + JSON.stringify(b.length) + ')');
81
+ let d = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
82
+ if (d < 0) {
83
+ let adim = (0, _array.arraySize)(a).length;
84
+ let bdim = (0, _array.arraySize)(b).length;
85
+ d = Math.max(adim, bdim);
86
+ while (adim++ < d) a = [a];
87
+ while (bdim++ < d) b = [b];
76
88
  }
77
- const t = [];
78
- let r = [];
79
- return a.map(function (a) {
80
- return b.map(function (b) {
81
- r = [];
82
- t.push(r);
83
- return a.map(function (y) {
84
- return b.map(function (x) {
85
- return r.push(multiplyScalar(y, x));
86
- });
87
- });
88
- });
89
- }) && t;
89
+ if (d === 1) return _kron1d(a, b);
90
+ return a.flatMap(aSlice => b.map(bSlice => _kron(aSlice, bSlice, d - 1)));
90
91
  }
91
92
  });
@@ -58,8 +58,9 @@ const createRow = exports.createRow = /* #__PURE__ */(0, _factory.factory)(name,
58
58
  }
59
59
  (0, _array.validateIndex)(row, value.size()[0]);
60
60
  const columnRange = range(0, value.size()[1]);
61
- const index = new Index(row, columnRange);
61
+ const index = new Index([row], columnRange);
62
62
  const result = value.subset(index);
63
+ // once config.legacySubset just return result
63
64
  return (0, _is.isMatrix)(result) ? result : matrix([[result]]);
64
65
  }
65
66
  });
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createSize = void 0;
7
7
  var _array = require("../../utils/array.js");
8
8
  var _factory = require("../../utils/factory.js");
9
- var _noop = require("../../utils/noop.js");
10
9
  const name = 'size';
11
- const dependencies = ['typed', 'config', '?matrix'];
10
+ const dependencies = ['typed'];
12
11
  const createSize = exports.createSize = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
13
12
  let {
14
- typed,
15
- config,
16
- matrix
13
+ typed
17
14
  } = _ref;
18
15
  /**
19
- * Calculate the size of a matrix or scalar.
16
+ * Calculate the size of a matrix or scalar. Always returns an Array containing numbers.
17
+ *
18
+ * Note that in mathjs v14 and older, function size could return a Matrix depending on
19
+ * the input type and configuration.
20
20
  *
21
21
  * Syntax:
22
22
  *
@@ -36,19 +36,13 @@ const createSize = exports.createSize = /* #__PURE__ */(0, _factory.factory)(nam
36
36
  * count, resize, squeeze, subset
37
37
  *
38
38
  * @param {boolean | number | Complex | Unit | string | Array | Matrix} x A matrix
39
- * @return {Array | Matrix} A vector with size of `x`.
39
+ * @return {Array} A vector with size of `x`.
40
40
  */
41
41
  return typed(name, {
42
- Matrix: function (x) {
43
- return x.create(x.size(), 'number');
44
- },
42
+ Matrix: x => x.size(),
45
43
  Array: _array.arraySize,
46
- string: function (x) {
47
- return config.matrix === 'Array' ? [x.length] : matrix([x.length], 'dense', 'number');
48
- },
49
- 'number | Complex | BigNumber | Unit | boolean | null': function (x) {
50
- // scalar
51
- return config.matrix === 'Array' ? [] : matrix ? matrix([], 'dense', 'number') : (0, _noop.noMatrix)();
52
- }
44
+ string: x => [x.length],
45
+ // scalar
46
+ 'number | Complex | BigNumber | Unit | boolean | null': _x => []
53
47
  });
54
48
  });
@@ -31,8 +31,8 @@ const createSubset = exports.createSubset = /* #__PURE__ */(0, _factory.factory)
31
31
  * // get a subset
32
32
  * const d = [[1, 2], [3, 4]]
33
33
  * math.subset(d, math.index(1, 0)) // returns 3
34
- * math.subset(d, math.index([0, 1], 1)) // returns [[2], [4]]
35
- * math.subset(d, math.index([false, true], 0)) // returns [[3]]
34
+ * math.subset(d, math.index([0, 1], [1])) // returns [[2], [4]]
35
+ * math.subset(d, math.index([false, true], [0])) // returns [[3]]
36
36
  *
37
37
  * // replace a subset
38
38
  * const e = []
@@ -42,9 +42,9 @@ const createSubset = exports.createSubset = /* #__PURE__ */(0, _factory.factory)
42
42
  *
43
43
  * // get submatrix using ranges
44
44
  * const M = [
45
- * [1,2,3],
46
- * [4,5,6],
47
- * [7,8,9]
45
+ * [1, 2, 3],
46
+ * [4, 5, 6],
47
+ * [7, 8, 9]
48
48
  * ]
49
49
  * math.subset(M, math.index(math.range(0,2), math.range(0,3))) // [[1, 2, 3], [4, 5, 6]]
50
50
  *
@@ -123,7 +123,7 @@ const createSubset = exports.createSubset = /* #__PURE__ */(0, _factory.factory)
123
123
  if (typeof replacement === 'string') {
124
124
  throw new Error('can\'t boradcast a string');
125
125
  }
126
- if (index._isScalar) {
126
+ if (index.isScalar()) {
127
127
  return replacement;
128
128
  }
129
129
  const indexSize = index.size();
@@ -165,9 +165,14 @@ function _getSubstring(str, index) {
165
165
  (0, _array.validateIndex)(index.max()[0], strLen);
166
166
  const range = index.dimension(0);
167
167
  let substr = '';
168
- range.forEach(function (v) {
168
+ function callback(v) {
169
169
  substr += str.charAt(v);
170
- });
170
+ }
171
+ if (Number.isInteger(range)) {
172
+ callback(range);
173
+ } else {
174
+ range.forEach(callback);
175
+ }
171
176
  return substr;
172
177
  }
173
178
 
@@ -201,7 +206,7 @@ function _setSubstring(str, index, replacement, defaultValue) {
201
206
  defaultValue = ' ';
202
207
  }
203
208
  const range = index.dimension(0);
204
- const len = range.size()[0];
209
+ const len = Number.isInteger(range) ? 1 : range.size()[0];
205
210
  if (len !== replacement.length) {
206
211
  throw new _DimensionError.DimensionError(range.size()[0], replacement.length);
207
212
  }
@@ -216,9 +221,14 @@ function _setSubstring(str, index, replacement, defaultValue) {
216
221
  for (let i = 0; i < strLen; i++) {
217
222
  chars[i] = str.charAt(i);
218
223
  }
219
- range.forEach(function (v, i) {
224
+ function callback(v, i) {
220
225
  chars[v] = replacement.charAt(i[0]);
221
- });
226
+ }
227
+ if (Number.isInteger(range)) {
228
+ callback(range, [0]);
229
+ } else {
230
+ range.forEach(callback);
231
+ }
222
232
 
223
233
  // initialize undefined characters with a space
224
234
  if (chars.length > strLen) {
package/lib/cjs/header.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 14.9.1
9
+ * @version 15.0.0
10
10
  * @date 2025-10-10
11
11
  *
12
12
  * @license
@@ -15,10 +15,11 @@ var _optimizeCallback = require("../../utils/optimizeCallback.js");
15
15
  // deno-lint-ignore-file no-this-alias
16
16
 
17
17
  const name = 'DenseMatrix';
18
- const dependencies = ['Matrix'];
18
+ const dependencies = ['Matrix', 'config'];
19
19
  const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
20
20
  let {
21
- Matrix
21
+ Matrix,
22
+ config
22
23
  } = _ref;
23
24
  /**
24
25
  * Dense Matrix implementation. A regular, dense matrix, supporting multi-dimensional matrices. This is the default matrix type.
@@ -228,7 +229,7 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
228
229
  if (!(0, _is.isIndex)(index)) {
229
230
  throw new TypeError('Invalid index');
230
231
  }
231
- const isScalar = index.isScalar();
232
+ const isScalar = config.legacySubset ? index.size().every(idx => idx === 1) : index.isScalar();
232
233
  if (isScalar) {
233
234
  // return a scalar
234
235
  return matrix.get(index.min());
@@ -248,12 +249,12 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
248
249
  }
249
250
 
250
251
  // retrieve submatrix
251
- const returnMatrix = new DenseMatrix([]);
252
+ const returnMatrix = new DenseMatrix();
252
253
  const submatrix = _getSubmatrix(matrix._data, index);
253
254
  returnMatrix._size = submatrix.size;
254
255
  returnMatrix._datatype = matrix._datatype;
255
256
  returnMatrix._data = submatrix.data;
256
- return returnMatrix;
257
+ return config.legacySubset ? returnMatrix.reshape(index.size()) : returnMatrix;
257
258
  }
258
259
  }
259
260
 
@@ -271,22 +272,30 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
271
272
  const size = Array(maxDepth);
272
273
  return {
273
274
  data: getSubmatrixRecursive(data),
274
- size
275
+ size: size.filter(x => x !== null)
275
276
  };
276
277
  function getSubmatrixRecursive(data) {
277
278
  let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
278
- const ranges = index.dimension(depth);
279
- size[depth] = ranges.size()[0];
279
+ const dims = index.dimension(depth);
280
+ function _mapIndex(dim, callback) {
281
+ // applies a callback for when the index is a Number or a Matrix
282
+ if ((0, _is.isNumber)(dim)) return callback(dim);else return dim.map(callback).valueOf();
283
+ }
284
+ if ((0, _is.isNumber)(dims)) {
285
+ size[depth] = null;
286
+ } else {
287
+ size[depth] = dims.size()[0];
288
+ }
280
289
  if (depth < maxDepth) {
281
- return ranges.map(rangeIndex => {
282
- (0, _array.validateIndex)(rangeIndex, data.length);
283
- return getSubmatrixRecursive(data[rangeIndex], depth + 1);
284
- }).valueOf();
290
+ return _mapIndex(dims, dimIndex => {
291
+ (0, _array.validateIndex)(dimIndex, data.length);
292
+ return getSubmatrixRecursive(data[dimIndex], depth + 1);
293
+ });
285
294
  } else {
286
- return ranges.map(rangeIndex => {
287
- (0, _array.validateIndex)(rangeIndex, data.length);
288
- return data[rangeIndex];
289
- }).valueOf();
295
+ return _mapIndex(dims, dimIndex => {
296
+ (0, _array.validateIndex)(dimIndex, data.length);
297
+ return data[dimIndex];
298
+ });
290
299
  }
291
300
  }
292
301
  }
@@ -313,18 +322,18 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
313
322
  const isScalar = index.isScalar();
314
323
 
315
324
  // calculate the size of the submatrix, and convert it into an Array if needed
316
- let sSize;
325
+ let submatrixSize;
317
326
  if ((0, _is.isMatrix)(submatrix)) {
318
- sSize = submatrix.size();
327
+ submatrixSize = submatrix.size();
319
328
  submatrix = submatrix.valueOf();
320
329
  } else {
321
- sSize = (0, _array.arraySize)(submatrix);
330
+ submatrixSize = (0, _array.arraySize)(submatrix);
322
331
  }
323
332
  if (isScalar) {
324
333
  // set a scalar
325
334
 
326
335
  // check whether submatrix is a scalar
327
- if (sSize.length !== 0) {
336
+ if (submatrixSize.length !== 0) {
328
337
  throw new TypeError('Scalar expected');
329
338
  }
330
339
  matrix.set(index.min(), submatrix, defaultValue);
@@ -332,26 +341,26 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
332
341
  // set a submatrix
333
342
 
334
343
  // broadcast submatrix
335
- if (!(0, _object.deepStrictEqual)(sSize, iSize)) {
336
- try {
337
- if (sSize.length === 0) {
338
- submatrix = (0, _array.broadcastTo)([submatrix], iSize);
339
- } else {
344
+ if (!(0, _object.deepStrictEqual)(submatrixSize, iSize)) {
345
+ if (submatrixSize.length === 0) {
346
+ submatrix = (0, _array.broadcastTo)([submatrix], iSize);
347
+ } else {
348
+ try {
340
349
  submatrix = (0, _array.broadcastTo)(submatrix, iSize);
341
- }
342
- sSize = (0, _array.arraySize)(submatrix);
343
- } catch (_unused) {}
350
+ } catch (error) {}
351
+ }
352
+ submatrixSize = (0, _array.arraySize)(submatrix);
344
353
  }
345
354
 
346
355
  // validate dimensions
347
356
  if (iSize.length < matrix._size.length) {
348
357
  throw new _DimensionError.DimensionError(iSize.length, matrix._size.length, '<');
349
358
  }
350
- if (sSize.length < iSize.length) {
359
+ if (submatrixSize.length < iSize.length) {
351
360
  // calculate number of missing outer dimensions
352
361
  let i = 0;
353
362
  let outer = 0;
354
- while (iSize[i] === 1 && sSize[i] === 1) {
363
+ while (iSize[i] === 1 && submatrixSize[i] === 1) {
355
364
  i++;
356
365
  }
357
366
  while (iSize[i] === 1) {
@@ -360,12 +369,12 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
360
369
  }
361
370
 
362
371
  // unsqueeze both outer and inner dimensions
363
- submatrix = (0, _array.unsqueeze)(submatrix, iSize.length, outer, sSize);
372
+ submatrix = (0, _array.unsqueeze)(submatrix, iSize.length, outer, submatrixSize);
364
373
  }
365
374
 
366
375
  // check whether the size of the submatrix matches the index size
367
- if (!(0, _object.deepStrictEqual)(iSize, sSize)) {
368
- throw new _DimensionError.DimensionError(iSize, sSize, '>');
376
+ if (!(0, _object.deepStrictEqual)(iSize, submatrixSize)) {
377
+ throw new _DimensionError.DimensionError(iSize, submatrixSize, '>');
369
378
  }
370
379
 
371
380
  // enlarge matrix when needed
@@ -394,16 +403,18 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
394
403
  function setSubmatrixRecursive(data, submatrix) {
395
404
  let depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
396
405
  const range = index.dimension(depth);
406
+ const recursiveCallback = (rangeIndex, i) => {
407
+ (0, _array.validateIndex)(rangeIndex, data.length);
408
+ setSubmatrixRecursive(data[rangeIndex], submatrix[i[0]], depth + 1);
409
+ };
410
+ const finalCallback = (rangeIndex, i) => {
411
+ (0, _array.validateIndex)(rangeIndex, data.length);
412
+ data[rangeIndex] = submatrix[i[0]];
413
+ };
397
414
  if (depth < maxDepth) {
398
- range.forEach((rangeIndex, i) => {
399
- (0, _array.validateIndex)(rangeIndex, data.length);
400
- setSubmatrixRecursive(data[rangeIndex], submatrix[i[0]], depth + 1);
401
- });
415
+ if ((0, _is.isNumber)(range)) recursiveCallback(range, [0]);else range.forEach(recursiveCallback);
402
416
  } else {
403
- range.forEach((rangeIndex, i) => {
404
- (0, _array.validateIndex)(rangeIndex, data.length);
405
- data[rangeIndex] = submatrix[i[0]];
406
- });
417
+ if ((0, _is.isNumber)(range)) finalCallback(range, [0]);else range.forEach(finalCallback);
407
418
  }
408
419
  }
409
420
  }
@@ -37,7 +37,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
37
37
  * @Constructor Index
38
38
  * @param {...*} ranges
39
39
  */
40
- function Index(ranges) {
40
+ function Index() {
41
41
  if (!(this instanceof Index)) {
42
42
  throw new SyntaxError('Constructor must be called with the new operator');
43
43
  }
@@ -45,7 +45,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
45
45
  this._sourceSize = [];
46
46
  this._isScalar = true;
47
47
  for (let i = 0, ii = arguments.length; i < ii; i++) {
48
- const arg = arguments[i];
48
+ const arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
49
49
  const argIsArray = (0, _is.isArray)(arg);
50
50
  const argIsMatrix = (0, _is.isMatrix)(arg);
51
51
  const argType = typeof arg;
@@ -56,6 +56,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
56
56
  } else if (argIsArray || argIsMatrix) {
57
57
  // create matrix
58
58
  let m;
59
+ this._isScalar = false;
59
60
  if (getMatrixDataType(arg) === 'boolean') {
60
61
  if (argIsArray) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg).valueOf());
61
62
  if (argIsMatrix) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg._data).valueOf());
@@ -64,16 +65,10 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
64
65
  m = _createImmutableMatrix(arg.valueOf());
65
66
  }
66
67
  this._dimensions.push(m);
67
- // size
68
- const size = m.size();
69
- // scalar
70
- if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
71
- this._isScalar = false;
72
- }
73
68
  } else if (argType === 'number') {
74
- this._dimensions.push(_createImmutableMatrix([arg]));
69
+ this._dimensions.push(arg);
75
70
  } else if (argType === 'bigint') {
76
- this._dimensions.push(_createImmutableMatrix([Number(arg)]));
71
+ this._dimensions.push(Number(arg));
77
72
  } else if (argType === 'string') {
78
73
  // object property (arguments.count should be 1)
79
74
  this._dimensions.push(arg);
@@ -93,12 +88,15 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
93
88
  function _createImmutableMatrix(arg) {
94
89
  // loop array elements
95
90
  for (let i = 0, l = arg.length; i < l; i++) {
96
- if (typeof arg[i] !== 'number' || !(0, _number.isInteger)(arg[i])) {
91
+ if (!(0, _is.isNumber)(arg[i]) || !(0, _number.isInteger)(arg[i])) {
97
92
  throw new TypeError('Index parameters must be positive integer numbers');
98
93
  }
99
94
  }
100
95
  // create matrix
101
- return new ImmutableDenseMatrix(arg);
96
+ const matrix = new ImmutableDenseMatrix();
97
+ matrix._data = arg;
98
+ matrix._size = [arg.length];
99
+ return matrix;
102
100
  }
103
101
 
104
102
  /**
@@ -136,7 +134,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
136
134
  const size = [];
137
135
  for (let i = 0, ii = this._dimensions.length; i < ii; i++) {
138
136
  const d = this._dimensions[i];
139
- size[i] = typeof d === 'string' ? 1 : d.size()[0];
137
+ size[i] = (0, _is.isString)(d) || (0, _is.isNumber)(d) ? 1 : d.size()[0];
140
138
  }
141
139
  return size;
142
140
  };
@@ -150,7 +148,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
150
148
  const values = [];
151
149
  for (let i = 0, ii = this._dimensions.length; i < ii; i++) {
152
150
  const range = this._dimensions[i];
153
- values[i] = typeof range === 'string' ? range : range.max();
151
+ values[i] = (0, _is.isString)(range) || (0, _is.isNumber)(range) ? range : range.max();
154
152
  }
155
153
  return values;
156
154
  };
@@ -164,7 +162,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
164
162
  const values = [];
165
163
  for (let i = 0, ii = this._dimensions.length; i < ii; i++) {
166
164
  const range = this._dimensions[i];
167
- values[i] = typeof range === 'string' ? range : range.min();
165
+ values[i] = (0, _is.isString)(range) || (0, _is.isNumber)(range) ? range : range.min();
168
166
  }
169
167
  return values;
170
168
  };
@@ -189,10 +187,11 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
189
187
  * @returns {Range | null} range
190
188
  */
191
189
  Index.prototype.dimension = function (dim) {
192
- if (typeof dim !== 'number') {
190
+ var _this$_dimensions$dim;
191
+ if (!(0, _is.isNumber)(dim)) {
193
192
  return null;
194
193
  }
195
- return this._dimensions[dim] || null;
194
+ return (_this$_dimensions$dim = this._dimensions[dim]) !== null && _this$_dimensions$dim !== void 0 ? _this$_dimensions$dim : null;
196
195
  };
197
196
 
198
197
  /**
@@ -200,7 +199,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
200
199
  * @returns {boolean} Returns true if the index is an object property
201
200
  */
202
201
  Index.prototype.isObjectProperty = function () {
203
- return this._dimensions.length === 1 && typeof this._dimensions[0] === 'string';
202
+ return this._dimensions.length === 1 && (0, _is.isString)(this._dimensions[0]);
204
203
  };
205
204
 
206
205
  /**
@@ -234,7 +233,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
234
233
  const array = [];
235
234
  for (let i = 0, ii = this._dimensions.length; i < ii; i++) {
236
235
  const dimension = this._dimensions[i];
237
- array.push(typeof dimension === 'string' ? dimension : dimension.toArray());
236
+ array.push((0, _is.isString)(dimension) || (0, _is.isNumber)(dimension) ? dimension : dimension.toArray());
238
237
  }
239
238
  return array;
240
239
  };
@@ -256,7 +255,7 @@ const createIndexClass = exports.createIndexClass = /* #__PURE__ */(0, _factory.
256
255
  const strings = [];
257
256
  for (let i = 0, ii = this._dimensions.length; i < ii; i++) {
258
257
  const dimension = this._dimensions[i];
259
- if (typeof dimension === 'string') {
258
+ if ((0, _is.isString)(dimension)) {
260
259
  strings.push(JSON.stringify(dimension));
261
260
  } else {
262
261
  strings.push(dimension.toString());
@@ -304,12 +304,13 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
304
304
  const pv = [];
305
305
 
306
306
  // loop rows in resulting matrix
307
- rows.forEach(function (i, r) {
307
+ function rowsCallback(i, r) {
308
308
  // update permutation vector
309
309
  pv[i] = r[0];
310
310
  // mark i in workspace
311
311
  w[i] = true;
312
- });
312
+ }
313
+ if (Number.isInteger(rows)) rowsCallback(rows, [0]);else rows.forEach(rowsCallback);
313
314
 
314
315
  // result matrix arrays
315
316
  const values = mvalues ? [] : undefined;
@@ -317,7 +318,7 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
317
318
  const ptr = [];
318
319
 
319
320
  // loop columns in result matrix
320
- columns.forEach(function (j) {
321
+ function columnsCallback(j) {
321
322
  // update ptr
322
323
  ptr.push(index.length);
323
324
  // loop values in column j
@@ -334,7 +335,8 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
334
335
  }
335
336
  }
336
337
  }
337
- });
338
+ }
339
+ if (Number.isInteger(columns)) columnsCallback(columns);else columns.forEach(columnsCallback);
338
340
  // update ptr
339
341
  ptr.push(index.length);
340
342
 
@@ -408,7 +410,7 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
408
410
  if (iSize.length === 1) {
409
411
  // if the replacement index only has 1 dimension, go trough each one and set its value
410
412
  const range = index.dimension(0);
411
- range.forEach(function (dataIndex, subIndex) {
413
+ _forEachIndex(range, (dataIndex, subIndex) => {
412
414
  (0, _array.validateIndex)(dataIndex);
413
415
  matrix.set([dataIndex, 0], submatrix[subIndex[0]], defaultValue);
414
416
  });
@@ -416,9 +418,9 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
416
418
  // if the replacement index has 2 dimensions, go through each one and set the value in the correct index
417
419
  const firstDimensionRange = index.dimension(0);
418
420
  const secondDimensionRange = index.dimension(1);
419
- firstDimensionRange.forEach(function (firstDataIndex, firstSubIndex) {
421
+ _forEachIndex(firstDimensionRange, (firstDataIndex, firstSubIndex) => {
420
422
  (0, _array.validateIndex)(firstDataIndex);
421
- secondDimensionRange.forEach(function (secondDataIndex, secondSubIndex) {
423
+ _forEachIndex(secondDimensionRange, (secondDataIndex, secondSubIndex) => {
422
424
  (0, _array.validateIndex)(secondDataIndex);
423
425
  matrix.set([firstDataIndex, secondDataIndex], submatrix[firstSubIndex[0]][secondSubIndex[0]], defaultValue);
424
426
  });
@@ -426,6 +428,10 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
426
428
  }
427
429
  }
428
430
  return matrix;
431
+ function _forEachIndex(index, callback) {
432
+ // iterate cases where index is a Matrix or a Number
433
+ if ((0, _is.isNumber)(index)) callback(index, [0]);else index.forEach(callback);
434
+ }
429
435
  }
430
436
 
431
437
  /**
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- const version = exports.version = '14.9.1';
7
+ const version = exports.version = '15.0.0';
8
8
  // Note: This file is automatically generated when building math.js.
9
9
  // Changes made in this file will be overwritten.