mathjs 14.3.0 → 14.4.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.
@@ -75,7 +75,7 @@ function importFactory(typed, load, math, importedFactories) {
75
75
  function flattenImports(flatValues, value, name) {
76
76
  if (Array.isArray(value)) {
77
77
  value.forEach(item => flattenImports(flatValues, item));
78
- } else if (typeof value === 'object') {
78
+ } else if ((0, _is.isObject)(value) || isModule(value)) {
79
79
  for (const name in value) {
80
80
  if ((0, _object.hasOwnProperty)(value, name)) {
81
81
  flattenImports(flatValues, value[name], name);
@@ -316,6 +316,9 @@ function importFactory(typed, load, math, importedFactories) {
316
316
  function isSupportedType(object) {
317
317
  return typeof object === 'function' || typeof object === 'number' || typeof object === 'string' || typeof object === 'boolean' || object === null || (0, _is.isUnit)(object) || (0, _is.isComplex)(object) || (0, _is.isBigNumber)(object) || (0, _is.isFraction)(object) || (0, _is.isMatrix)(object) || Array.isArray(object);
318
318
  }
319
+ function isModule(object) {
320
+ return typeof object === 'object' && object[Symbol.toStringTag] === 'Module';
321
+ }
319
322
  function hasTypedFunctionSignature(fn) {
320
323
  return typeof fn === 'function' && typeof fn.signature === 'string';
321
324
  }
@@ -396,7 +396,7 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
396
396
  if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
397
397
  throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
398
398
  }
399
- } else if (nextCharacter(state) === '.') {
399
+ } else if (parse.isDecimalMark(nextCharacter(state), state.expression.charAt(state.index + 2))) {
400
400
  next(state);
401
401
  throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
402
402
  }
@@ -51,7 +51,7 @@ const createHypot = exports.createHypot = /* #__PURE__ */(0, _factory.factory)(n
51
51
  return typed(name, {
52
52
  '... number | BigNumber': _hypot,
53
53
  Array: _hypot,
54
- Matrix: M => _hypot((0, _array.flatten)(M.toArray()))
54
+ Matrix: M => _hypot((0, _array.flatten)(M.toArray(), true))
55
55
  });
56
56
 
57
57
  /**
@@ -70,8 +70,11 @@ const createFilter = exports.createFilter = /* #__PURE__ */(0, _factory.factory)
70
70
  */
71
71
  function _filterCallback(x, callback) {
72
72
  const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, x, 'filter');
73
+ if (fastCallback.isUnary) {
74
+ return (0, _array.filter)(x, fastCallback.fn);
75
+ }
73
76
  return (0, _array.filter)(x, function (value, index, array) {
74
77
  // invoke the callback function with the right number of arguments
75
- return fastCallback(value, [index], array);
78
+ return fastCallback.fn(value, [index], array);
76
79
  });
77
80
  }
@@ -38,7 +38,7 @@ const createFlatten = exports.createFlatten = /* #__PURE__ */(0, _factory.factor
38
38
  Matrix: 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
- return x.create((0, _array.flatten)(x.valueOf()), x.datatype());
41
+ return x.create((0, _array.flatten)(x.valueOf(), true), x.datatype());
42
42
  }
43
43
  });
44
44
  });
@@ -58,5 +58,6 @@ const createForEach = exports.createForEach = /* #__PURE__ */(0, _factory.factor
58
58
  * @private
59
59
  */
60
60
  function _forEach(array, callback) {
61
- (0, _array.deepForEach)(array, (0, _optimizeCallback.optimizeCallback)(callback, array, name));
61
+ const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, array, name);
62
+ (0, _array.deepForEach)(array, fastCallback.fn, fastCallback.isUnary);
62
63
  }
@@ -143,6 +143,7 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
143
143
  * @private
144
144
  */
145
145
  function _mapArray(array, callback) {
146
- return (0, _array.deepMap)(array, (0, _optimizeCallback.optimizeCallback)(callback, array, name));
146
+ const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, array, name);
147
+ return (0, _array.deepMap)(array, fastCallback.fn, fastCallback.isUnary);
147
148
  }
148
149
  });
package/lib/cjs/header.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 14.3.0
10
- * @date 2025-02-28
9
+ * @version 14.4.0
10
+ * @date 2025-03-28
11
11
  *
12
12
  * @license
13
13
  * Copyright (C) 2013-2025 Jos de Jong <wjosdejong@gmail.com>
@@ -528,39 +528,52 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
528
528
  * Applies a callback function to a reference to each element of the matrix
529
529
  * @memberof DenseMatrix
530
530
  * @param {Function} callback The callback function is invoked with three
531
- * parameters: an array, an integer index to that
532
- * array, and the Matrix being traversed.
531
+ * parameters: the array containing the element,
532
+ * the index of the element within that array (as an integer),
533
+ * and for non unarry callbacks copy of the current index (as an array of integers).
533
534
  */
534
535
  DenseMatrix.prototype._forEach = function (callback) {
535
- const me = this;
536
- const s = me.size();
537
- const maxDepth = s.length - 1;
538
- if (maxDepth < 0) {
536
+ const isUnary = callback.length === 2; // callback has 2 parameters: value, index
537
+ const maxDepth = this._size.length - 1;
538
+ if (maxDepth < 0) return;
539
+ if (isUnary) {
540
+ iterateUnary(this._data);
539
541
  return;
540
542
  }
541
543
  if (maxDepth === 0) {
542
- const thisSize = s[0];
543
- for (let i = 0; i < thisSize; i++) {
544
- callback(me._data, i, [i]);
544
+ for (let i = 0; i < this._data.length; i++) {
545
+ callback(this._data, i, [i]);
545
546
  }
546
547
  return;
547
548
  }
548
- const index = Array(s.length);
549
- function recurse(data, depth) {
550
- const thisSize = s[depth];
549
+ const index = new Array(maxDepth + 1);
550
+ iterate(this._data);
551
+ function iterate(data) {
552
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
551
553
  if (depth < maxDepth) {
552
- for (let i = 0; i < thisSize; i++) {
554
+ for (let i = 0; i < data.length; i++) {
553
555
  index[depth] = i;
554
- recurse(data[i], depth + 1);
556
+ iterate(data[i], depth + 1);
555
557
  }
556
558
  } else {
557
- for (let i = 0; i < thisSize; i++) {
559
+ for (let i = 0; i < data.length; i++) {
558
560
  index[depth] = i;
559
561
  callback(data, i, index.slice());
560
562
  }
561
563
  }
562
564
  }
563
- recurse(me._data, 0);
565
+ function iterateUnary(data) {
566
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
567
+ if (depth < maxDepth) {
568
+ for (let i = 0; i < data.length; i++) {
569
+ iterateUnary(data[i], depth + 1);
570
+ }
571
+ } else {
572
+ for (let i = 0; i < data.length; i++) {
573
+ callback(data, i);
574
+ }
575
+ }
576
+ }
564
577
  };
565
578
 
566
579
  /**
@@ -570,16 +583,23 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
570
583
  * @param {Function} callback The callback function is invoked with three
571
584
  * parameters: the value of the element, the index
572
585
  * of the element, and the Matrix being traversed.
586
+ * @param {boolean} skipZeros If true, the callback function is invoked only for non-zero entries
587
+ * @param {boolean} isUnary If true, the callback function is invoked with one parameter
573
588
  *
574
589
  * @return {DenseMatrix} matrix
575
590
  */
576
591
  DenseMatrix.prototype.map = function (callback) {
592
+ let skipZeros = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
593
+ let isUnary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
577
594
  const me = this;
578
595
  const result = new DenseMatrix(me);
579
- const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, me._data, 'map');
580
- result._forEach(function (arr, i, index) {
581
- arr[i] = fastCallback(arr[i], index, me);
582
- });
596
+ const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, me._data, 'map', isUnary);
597
+ const applyCallback = isUnary || fastCallback.isUnary ? (arr, i) => {
598
+ arr[i] = fastCallback.fn(arr[i]);
599
+ } : (arr, i, index) => {
600
+ arr[i] = fastCallback.fn(arr[i], index, me);
601
+ };
602
+ result._forEach(applyCallback);
583
603
  return result;
584
604
  };
585
605
 
@@ -589,13 +609,20 @@ const createDenseMatrixClass = exports.createDenseMatrixClass = /* #__PURE__ */(
589
609
  * @param {Function} callback The callback function is invoked with three
590
610
  * parameters: the value of the element, the index
591
611
  * of the element, and the Matrix being traversed.
612
+ * @param {boolean} skipZeros If true, the callback function is invoked only for non-zero entries
613
+ * @param {boolean} isUnary If true, the callback function is invoked with one parameter
592
614
  */
593
615
  DenseMatrix.prototype.forEach = function (callback) {
616
+ let skipZeros = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
617
+ let isUnary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
594
618
  const me = this;
595
- const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, me._data, 'map');
596
- me._forEach(function (arr, i, index) {
597
- fastCallback(arr[i], index, me);
598
- });
619
+ const fastCallback = (0, _optimizeCallback.optimizeCallback)(callback, me._data, 'map', isUnary);
620
+ const applyCallback = isUnary || fastCallback.isUnary ? (arr, i) => {
621
+ fastCallback.fn(arr[i]);
622
+ } : (arr, i, index) => {
623
+ fastCallback.fn(arr[i], index, me);
624
+ };
625
+ me._forEach(applyCallback);
599
626
  };
600
627
 
601
628
  /**
@@ -882,7 +882,7 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
882
882
  // invoke callback
883
883
  const invoke = function (v, i, j) {
884
884
  // invoke callback
885
- return fastCallback(v, [i, j], me);
885
+ return fastCallback.fn(v, [i, j], me);
886
886
  };
887
887
  // invoke _map
888
888
  return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
@@ -1000,7 +1000,8 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
1000
1000
  const i = this._index[k];
1001
1001
 
1002
1002
  // value @ k
1003
- fastCallback(this._values[k], [i, j], me);
1003
+ // TODO apply a non indexed version of algorithm in case fastCallback is not optimized
1004
+ fastCallback.fn(this._values[k], [i, j], me);
1004
1005
  }
1005
1006
  } else {
1006
1007
  // create a cache holding all defined values
@@ -1014,7 +1015,7 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
1014
1015
  // and either read the value or zero
1015
1016
  for (let i = 0; i < rows; i++) {
1016
1017
  const value = i in values ? values[i] : 0;
1017
- fastCallback(value, [i, j], me);
1018
+ fastCallback.fn(value, [i, j], me);
1018
1019
  }
1019
1020
  }
1020
1021
  }
@@ -278,7 +278,7 @@ function _resize(array, size, dim, defaultValue) {
278
278
  * not equal that of the old ones
279
279
  */
280
280
  function reshape(array, sizes) {
281
- const flatArray = flatten(array);
281
+ const flatArray = flatten(array, true); // since it has rectangular
282
282
  const currentLength = flatArray.length;
283
283
  if (!Array.isArray(array) || !Array.isArray(sizes)) {
284
284
  throw new TypeError('Array expected');
@@ -475,22 +475,46 @@ function _unsqueeze(array, dims, dim) {
475
475
  * Flatten a multi dimensional array, put all elements in a one dimensional
476
476
  * array
477
477
  * @param {Array} array A multi dimensional array
478
+ * @param {boolean} isRectangular Optional. If the array is rectangular (not jagged)
478
479
  * @return {Array} The flattened array (1 dimensional)
479
480
  */
480
481
  function flatten(array) {
482
+ let isRectangular = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
481
483
  if (!Array.isArray(array)) {
482
484
  // if not an array, return as is
483
485
  return array;
484
486
  }
487
+ if (typeof isRectangular !== 'boolean') {
488
+ throw new TypeError('Boolean expected for second argument of flatten');
489
+ }
485
490
  const flat = [];
486
- array.forEach(function callback(value) {
487
- if (Array.isArray(value)) {
488
- value.forEach(callback); // traverse through sub-arrays recursively
491
+ if (isRectangular) {
492
+ _flattenRectangular(array);
493
+ } else {
494
+ _flatten(array);
495
+ }
496
+ return flat;
497
+ function _flatten(array) {
498
+ for (let i = 0; i < array.length; i++) {
499
+ const item = array[i];
500
+ if (Array.isArray(item)) {
501
+ _flatten(item);
502
+ } else {
503
+ flat.push(item);
504
+ }
505
+ }
506
+ }
507
+ function _flattenRectangular(array) {
508
+ if (Array.isArray(array[0])) {
509
+ for (let i = 0; i < array.length; i++) {
510
+ _flattenRectangular(array[i]);
511
+ }
489
512
  } else {
490
- flat.push(value);
513
+ for (let i = 0; i < array.length; i++) {
514
+ flat.push(array[i]);
515
+ }
491
516
  }
492
- });
493
- return flat;
517
+ }
494
518
  }
495
519
 
496
520
  /**
@@ -36,7 +36,7 @@ function containsCollections(array) {
36
36
  */
37
37
  function deepForEach(array, callback) {
38
38
  if ((0, _is.isMatrix)(array)) {
39
- array.forEach(x => callback(x));
39
+ array.forEach(x => callback(x), false, true);
40
40
  } else {
41
41
  (0, _array.deepForEach)(array, callback, true);
42
42
  }
@@ -57,14 +57,14 @@ function deepForEach(array, callback) {
57
57
  function deepMap(array, callback, skipZeros) {
58
58
  if (!skipZeros) {
59
59
  if ((0, _is.isMatrix)(array)) {
60
- return array.map(x => callback(x));
60
+ return array.map(x => callback(x), false, true);
61
61
  } else {
62
62
  return (0, _array.deepMap)(array, callback, true);
63
63
  }
64
64
  }
65
65
  const skipZerosCallback = x => x === 0 ? x : callback(x);
66
66
  if ((0, _is.isMatrix)(array)) {
67
- return array.map(x => skipZerosCallback(x));
67
+ return array.map(x => skipZerosCallback(x), false, true);
68
68
  } else {
69
69
  return (0, _array.deepMap)(array, skipZerosCallback, true);
70
70
  }
@@ -161,6 +161,9 @@ const latexFunctions = exports.latexFunctions = {
161
161
  floor: {
162
162
  1: '\\left\\lfloor${args[0]}\\right\\rfloor'
163
163
  },
164
+ fraction: {
165
+ 2: '\\frac{${args[0]}}{${args[1]}}'
166
+ },
164
167
  gcd: '\\gcd\\left(${args}\\right)',
165
168
  hypot: '\\hypot\\left(${args}\\right)',
166
169
  log: {
@@ -189,7 +192,7 @@ const latexFunctions = exports.latexFunctions = {
189
192
  2: '\\sqrt[${args[1]}]{${args[0]}}'
190
193
  },
191
194
  nthRoots: {
192
- 2: '\\{y : $y^{args[1]} = {${args[0]}}\\}'
195
+ 2: '\\{y : y^${args[1]} = {${args[0]}}\\}'
193
196
  },
194
197
  pow: {
195
198
  2: `\\left(\${args[0]}\\right)${latexOperators.pow}{\${args[1]}}`
@@ -14,13 +14,20 @@ var _is = require("./is.js");
14
14
  * @param {Function} callback The original callback function to simplify.
15
15
  * @param {Array|Matrix} array The array that will be used with the callback function.
16
16
  * @param {string} name The name of the function that is using the callback.
17
+ * @param {boolean} [isUnary=false] If true, the callback function is unary and will be optimized as such.
17
18
  * @returns {Function} Returns a simplified version of the callback function.
18
19
  */
19
20
  function optimizeCallback(callback, array, name) {
21
+ let isUnary = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
20
22
  if (_typedFunction.default.isTypedFunction(callback)) {
21
- const firstIndex = (array.isMatrix ? array.size() : (0, _array.arraySize)(array)).map(() => 0);
22
- const firstValue = array.isMatrix ? array.get(firstIndex) : (0, _array.get)(array, firstIndex);
23
- const numberOfArguments = _findNumberOfArguments(callback, firstValue, firstIndex, array);
23
+ let numberOfArguments;
24
+ if (isUnary) {
25
+ numberOfArguments = 1;
26
+ } else {
27
+ const firstIndex = (array.isMatrix ? array.size() : (0, _array.arraySize)(array)).map(() => 0);
28
+ const firstValue = array.isMatrix ? array.get(firstIndex) : (0, _array.get)(array, firstIndex);
29
+ numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array);
30
+ }
24
31
  let fastCallback;
25
32
  if (array.isMatrix && array.dataType !== 'mixed' && array.dataType !== undefined) {
26
33
  const singleSignature = _findSingleSignatureWithArity(callback, numberOfArguments);
@@ -29,21 +36,37 @@ function optimizeCallback(callback, array, name) {
29
36
  fastCallback = callback;
30
37
  }
31
38
  if (numberOfArguments >= 1 && numberOfArguments <= 3) {
32
- return function () {
33
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
34
- args[_key] = arguments[_key];
39
+ return {
40
+ isUnary: numberOfArguments === 1,
41
+ fn: function () {
42
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
43
+ args[_key] = arguments[_key];
44
+ }
45
+ return _tryFunctionWithArgs(fastCallback, args.slice(0, numberOfArguments), name, callback.name);
35
46
  }
36
- return _tryFunctionWithArgs(fastCallback, args.slice(0, numberOfArguments), name, callback.name);
37
47
  };
38
48
  }
39
- return function () {
40
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
41
- args[_key2] = arguments[_key2];
49
+ return {
50
+ isUnary: false,
51
+ fn: function () {
52
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
53
+ args[_key2] = arguments[_key2];
54
+ }
55
+ return _tryFunctionWithArgs(fastCallback, args, name, callback.name);
42
56
  }
43
- return _tryFunctionWithArgs(fastCallback, args, name, callback.name);
44
57
  };
45
58
  }
46
- return callback;
59
+ if (isUnary === undefined) {
60
+ return {
61
+ isUnary: _findIfCallbackIsUnary(callback),
62
+ fn: callback
63
+ };
64
+ } else {
65
+ return {
66
+ isUnary,
67
+ fn: callback
68
+ };
69
+ }
47
70
  }
48
71
  function _findSingleSignatureWithArity(callback, arity) {
49
72
  const matchingFunctions = [];
@@ -57,7 +80,32 @@ function _findSingleSignatureWithArity(callback, arity) {
57
80
  return matchingFunctions[0];
58
81
  }
59
82
  }
60
- function _findNumberOfArguments(callback, value, index, array) {
83
+
84
+ /**
85
+ * Determines if a given callback function is unary (i.e., takes exactly one argument).
86
+ *
87
+ * This function checks the following conditions to determine if the callback is unary:
88
+ * 1. The callback function should have exactly one parameter.
89
+ * 2. The callback function should not use the `arguments` object.
90
+ * 3. The callback function should not use rest parameters (`...`).
91
+ * If in doubt, this function shall return `false` to be safe
92
+ *
93
+ * @param {Function} callback - The callback function to be checked.
94
+ * @returns {boolean} - Returns `true` if the callback is unary, otherwise `false`.
95
+ */
96
+ function _findIfCallbackIsUnary(callback) {
97
+ if (callback.length !== 1) return false;
98
+ const callbackStr = callback.toString();
99
+ // Check if the callback function uses `arguments`
100
+ if (/arguments/.test(callbackStr)) return false;
101
+
102
+ // Extract the parameters of the callback function
103
+ const paramsStr = callbackStr.match(/\(.*?\)/);
104
+ // Check if the callback function uses rest parameters
105
+ if (/\.\.\./.test(paramsStr)) return false;
106
+ return true;
107
+ }
108
+ function _findNumberOfArgumentsTyped(callback, value, index, array) {
61
109
  const testArgs = [value, index, array];
62
110
  for (let i = 3; i > 0; i--) {
63
111
  const args = testArgs.slice(0, i);
@@ -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.3.0';
7
+ const version = exports.version = '14.4.0';
8
8
  // Note: This file is automatically generated when building math.js.
9
9
  // Changes made in this file will be overwritten.
@@ -1,4 +1,4 @@
1
- import { isBigNumber, isComplex, isFraction, isMatrix, isUnit } from '../../utils/is.js';
1
+ import { isBigNumber, isComplex, isFraction, isMatrix, isObject, isUnit } from '../../utils/is.js';
2
2
  import { isFactory, stripOptionalNotation } from '../../utils/factory.js';
3
3
  import { hasOwnProperty, lazy } from '../../utils/object.js';
4
4
  import { ArgumentsError } from '../../error/ArgumentsError.js';
@@ -69,7 +69,7 @@ export function importFactory(typed, load, math, importedFactories) {
69
69
  function flattenImports(flatValues, value, name) {
70
70
  if (Array.isArray(value)) {
71
71
  value.forEach(item => flattenImports(flatValues, item));
72
- } else if (typeof value === 'object') {
72
+ } else if (isObject(value) || isModule(value)) {
73
73
  for (var _name in value) {
74
74
  if (hasOwnProperty(value, _name)) {
75
75
  flattenImports(flatValues, value[_name], _name);
@@ -310,6 +310,9 @@ export function importFactory(typed, load, math, importedFactories) {
310
310
  function isSupportedType(object) {
311
311
  return typeof object === 'function' || typeof object === 'number' || typeof object === 'string' || typeof object === 'boolean' || object === null || isUnit(object) || isComplex(object) || isBigNumber(object) || isFraction(object) || isMatrix(object) || Array.isArray(object);
312
312
  }
313
+ function isModule(object) {
314
+ return typeof object === 'object' && object[Symbol.toStringTag] === 'Module';
315
+ }
313
316
  function hasTypedFunctionSignature(fn) {
314
317
  return typeof fn === 'function' && typeof fn.signature === 'string';
315
318
  }
@@ -389,7 +389,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
389
389
  if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
390
390
  throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
391
391
  }
392
- } else if (nextCharacter(state) === '.') {
392
+ } else if (parse.isDecimalMark(nextCharacter(state), state.expression.charAt(state.index + 2))) {
393
393
  next(state);
394
394
  throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
395
395
  }
@@ -45,7 +45,7 @@ export var createHypot = /* #__PURE__ */factory(name, dependencies, _ref => {
45
45
  return typed(name, {
46
46
  '... number | BigNumber': _hypot,
47
47
  Array: _hypot,
48
- Matrix: M => _hypot(flatten(M.toArray()))
48
+ Matrix: M => _hypot(flatten(M.toArray(), true))
49
49
  });
50
50
 
51
51
  /**
@@ -64,8 +64,11 @@ export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
64
64
  */
65
65
  function _filterCallback(x, callback) {
66
66
  var fastCallback = optimizeCallback(callback, x, 'filter');
67
+ if (fastCallback.isUnary) {
68
+ return filter(x, fastCallback.fn);
69
+ }
67
70
  return filter(x, function (value, index, array) {
68
71
  // invoke the callback function with the right number of arguments
69
- return fastCallback(value, [index], array);
72
+ return fastCallback.fn(value, [index], array);
70
73
  });
71
74
  }
@@ -32,7 +32,7 @@ export var createFlatten = /* #__PURE__ */factory(name, dependencies, _ref => {
32
32
  Matrix: function Matrix(x) {
33
33
  // Return the same matrix type as x (Dense or Sparse Matrix)
34
34
  // Return the same data type as x
35
- return x.create(flattenArray(x.valueOf()), x.datatype());
35
+ return x.create(flattenArray(x.valueOf(), true), x.datatype());
36
36
  }
37
37
  });
38
38
  });
@@ -52,5 +52,6 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
52
52
  * @private
53
53
  */
54
54
  function _forEach(array, callback) {
55
- deepForEach(array, optimizeCallback(callback, array, name));
55
+ var fastCallback = optimizeCallback(callback, array, name);
56
+ deepForEach(array, fastCallback.fn, fastCallback.isUnary);
56
57
  }
@@ -137,6 +137,7 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
137
137
  * @private
138
138
  */
139
139
  function _mapArray(array, callback) {
140
- return deepMap(array, optimizeCallback(callback, array, name));
140
+ var fastCallback = optimizeCallback(callback, array, name);
141
+ return deepMap(array, fastCallback.fn, fastCallback.isUnary);
141
142
  }
142
143
  });