mathjs 12.3.1 → 12.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/HISTORY.md +23 -0
  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/entry/pureFunctionsAny.generated.js +1 -0
  6. package/lib/cjs/expression/node/OperatorNode.js +2 -1
  7. package/lib/cjs/expression/parse.js +8 -4
  8. package/lib/cjs/expression/transform/utils/compileInlineExpression.js +5 -4
  9. package/lib/cjs/function/arithmetic/multiply.js +30 -29
  10. package/lib/cjs/function/arithmetic/round.js +38 -7
  11. package/lib/cjs/function/matrix/dot.js +3 -3
  12. package/lib/cjs/header.js +2 -2
  13. package/lib/cjs/type/matrix/utils/matAlgo01xDSid.js +4 -4
  14. package/lib/cjs/type/matrix/utils/matAlgo02xDS0.js +4 -4
  15. package/lib/cjs/type/matrix/utils/matAlgo03xDSf.js +4 -4
  16. package/lib/cjs/type/matrix/utils/matAlgo04xSidSid.js +4 -4
  17. package/lib/cjs/type/matrix/utils/matAlgo05xSfSf.js +4 -4
  18. package/lib/cjs/type/matrix/utils/matAlgo06xS0S0.js +4 -4
  19. package/lib/cjs/type/matrix/utils/matAlgo07xSSf.js +4 -4
  20. package/lib/cjs/type/matrix/utils/matAlgo08xS0Sid.js +4 -4
  21. package/lib/cjs/type/matrix/utils/matAlgo09xS0Sf.js +4 -4
  22. package/lib/cjs/utils/map.js +176 -14
  23. package/lib/cjs/utils/scope.js +4 -10
  24. package/lib/cjs/version.js +1 -1
  25. package/lib/esm/entry/pureFunctionsAny.generated.js +1 -0
  26. package/lib/esm/expression/node/OperatorNode.js +2 -1
  27. package/lib/esm/expression/parse.js +8 -4
  28. package/lib/esm/expression/transform/utils/compileInlineExpression.js +5 -4
  29. package/lib/esm/function/arithmetic/multiply.js +30 -29
  30. package/lib/esm/function/arithmetic/round.js +38 -7
  31. package/lib/esm/function/matrix/dot.js +3 -3
  32. package/lib/esm/type/matrix/utils/matAlgo01xDSid.js +4 -4
  33. package/lib/esm/type/matrix/utils/matAlgo02xDS0.js +4 -4
  34. package/lib/esm/type/matrix/utils/matAlgo03xDSf.js +4 -4
  35. package/lib/esm/type/matrix/utils/matAlgo04xSidSid.js +4 -4
  36. package/lib/esm/type/matrix/utils/matAlgo05xSfSf.js +4 -4
  37. package/lib/esm/type/matrix/utils/matAlgo06xS0S0.js +4 -4
  38. package/lib/esm/type/matrix/utils/matAlgo07xSSf.js +4 -4
  39. package/lib/esm/type/matrix/utils/matAlgo08xS0Sid.js +4 -4
  40. package/lib/esm/type/matrix/utils/matAlgo09xS0Sf.js +4 -4
  41. package/lib/esm/utils/map.js +99 -1
  42. package/lib/esm/utils/scope.js +5 -11
  43. package/lib/esm/version.js +1 -1
  44. package/package.json +9 -9
  45. package/types/index.d.ts +5 -5
@@ -12,9 +12,10 @@ import { isObject } from './is.js';
12
12
  export class ObjectWrappingMap {
13
13
  constructor(object) {
14
14
  this.wrappedObject = object;
15
+ this[Symbol.iterator] = this.entries;
15
16
  }
16
17
  keys() {
17
- return Object.keys(this.wrappedObject);
18
+ return Object.keys(this.wrappedObject).values();
18
19
  }
19
20
  get(key) {
20
21
  return getSafeProperty(this.wrappedObject, key);
@@ -26,6 +27,103 @@ export class ObjectWrappingMap {
26
27
  has(key) {
27
28
  return hasSafeProperty(this.wrappedObject, key);
28
29
  }
30
+ entries() {
31
+ return mapIterator(this.keys(), key => [key, this.get(key)]);
32
+ }
33
+ forEach(callback) {
34
+ for (var key of this.keys()) {
35
+ callback(this.get(key), key, this);
36
+ }
37
+ }
38
+ delete(key) {
39
+ delete this.wrappedObject[key];
40
+ }
41
+ clear() {
42
+ for (var key of this.keys()) {
43
+ this.delete(key);
44
+ }
45
+ }
46
+ get size() {
47
+ return Object.keys(this.wrappedObject).length;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Create a map with two partitions: a and b.
53
+ * The set with bKeys determines which keys/values are read/written to map b,
54
+ * all other values are read/written to map a
55
+ *
56
+ * For example:
57
+ *
58
+ * const a = new Map()
59
+ * const b = new Map()
60
+ * const p = new PartitionedMap(a, b, new Set(['x', 'y']))
61
+ *
62
+ * In this case, values `x` and `y` are read/written to map `b`,
63
+ * all other values are read/written to map `a`.
64
+ */
65
+ export class PartitionedMap {
66
+ /**
67
+ * @param {Map} a
68
+ * @param {Map} b
69
+ * @param {Set} bKeys
70
+ */
71
+ constructor(a, b, bKeys) {
72
+ this.a = a;
73
+ this.b = b;
74
+ this.bKeys = bKeys;
75
+ this[Symbol.iterator] = this.entries;
76
+ }
77
+ get(key) {
78
+ return this.bKeys.has(key) ? this.b.get(key) : this.a.get(key);
79
+ }
80
+ set(key, value) {
81
+ if (this.bKeys.has(key)) {
82
+ this.b.set(key, value);
83
+ } else {
84
+ this.a.set(key, value);
85
+ }
86
+ return this;
87
+ }
88
+ has(key) {
89
+ return this.b.has(key) || this.a.has(key);
90
+ }
91
+ keys() {
92
+ return new Set([...this.a.keys(), ...this.b.keys()])[Symbol.iterator]();
93
+ }
94
+ entries() {
95
+ return mapIterator(this.keys(), key => [key, this.get(key)]);
96
+ }
97
+ forEach(callback) {
98
+ for (var key of this.keys()) {
99
+ callback(this.get(key), key, this);
100
+ }
101
+ }
102
+ delete(key) {
103
+ return this.bKeys.has(key) ? this.b.delete(key) : this.a.delete(key);
104
+ }
105
+ clear() {
106
+ this.a.clear();
107
+ this.b.clear();
108
+ }
109
+ get size() {
110
+ return [...this.keys()].length;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Create a new iterator that maps over the provided iterator, applying a mapping function to each item
116
+ */
117
+ function mapIterator(it, callback) {
118
+ return {
119
+ next: () => {
120
+ var n = it.next();
121
+ return n.done ? n : {
122
+ value: callback(n.value),
123
+ done: false
124
+ };
125
+ }
126
+ };
29
127
  }
30
128
 
31
129
  /**
@@ -1,4 +1,4 @@
1
- import { createEmptyMap, assign } from './map.js';
1
+ import { ObjectWrappingMap, PartitionedMap } from './map.js';
2
2
 
3
3
  /**
4
4
  * Create a new scope which can access the parent scope,
@@ -10,15 +10,9 @@ import { createEmptyMap, assign } from './map.js';
10
10
  * the remaining `args`.
11
11
  *
12
12
  * @param {Map} parentScope
13
- * @param {...any} args
14
- * @returns {Map}
13
+ * @param {Object} args
14
+ * @returns {PartitionedMap}
15
15
  */
16
- export function createSubScope(parentScope) {
17
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
18
- args[_key - 1] = arguments[_key];
19
- }
20
- if (typeof parentScope.createSubScope === 'function') {
21
- return assign(parentScope.createSubScope(), ...args);
22
- }
23
- return assign(createEmptyMap(), parentScope, ...args);
16
+ export function createSubScope(parentScope, args) {
17
+ return new PartitionedMap(parentScope, new ObjectWrappingMap(args), new Set(Object.keys(args)));
24
18
  }
@@ -1,3 +1,3 @@
1
- export var version = '12.3.1';
1
+ export var version = '12.4.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": "12.3.1",
3
+ "version": "12.4.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",
@@ -43,21 +43,21 @@
43
43
  "@babel/register": "7.23.7",
44
44
  "@types/assert": "1.5.10",
45
45
  "@types/mocha": "10.0.6",
46
- "@typescript-eslint/eslint-plugin": "6.20.0",
47
- "@typescript-eslint/parser": "6.20.0",
46
+ "@typescript-eslint/eslint-plugin": "7.0.2",
47
+ "@typescript-eslint/parser": "7.0.2",
48
48
  "assert": "2.1.0",
49
49
  "babel-loader": "9.1.3",
50
50
  "benchmark": "2.1.4",
51
51
  "c8": "9.1.0",
52
52
  "codecov": "3.8.3",
53
- "core-js": "3.35.1",
53
+ "core-js": "3.36.0",
54
54
  "del": "6.1.1",
55
55
  "dtslint": "4.2.1",
56
56
  "eslint": "8.56.0",
57
57
  "eslint-config-prettier": "9.1.0",
58
58
  "eslint-config-standard": "17.1.0",
59
59
  "eslint-plugin-import": "2.29.1",
60
- "eslint-plugin-mocha": "10.2.0",
60
+ "eslint-plugin-mocha": "10.3.0",
61
61
  "eslint-plugin-n": "16.6.2",
62
62
  "eslint-plugin-prettier": "5.1.3",
63
63
  "eslint-plugin-promise": "6.1.1",
@@ -74,9 +74,9 @@
74
74
  "karma-firefox-launcher": "2.1.2",
75
75
  "karma-mocha": "2.0.1",
76
76
  "karma-mocha-reporter": "2.2.5",
77
- "karma-webpack": "5.0.0",
77
+ "karma-webpack": "5.0.1",
78
78
  "mkdirp": "3.0.1",
79
- "mocha": "10.2.0",
79
+ "mocha": "10.3.0",
80
80
  "mocha-junit-reporter": "2.2.1",
81
81
  "ndarray": "1.0.19",
82
82
  "ndarray-determinant": "1.0.0",
@@ -85,12 +85,12 @@
85
85
  "ndarray-pack": "1.2.1",
86
86
  "numericjs": "1.2.6",
87
87
  "pad-right": "0.2.2",
88
- "prettier": "3.2.4",
88
+ "prettier": "3.2.5",
89
89
  "process": "0.11.10",
90
90
  "sylvester": "0.0.21",
91
91
  "ts-node": "10.9.2",
92
92
  "typescript": "5.3.3",
93
- "webpack": "5.90.0",
93
+ "webpack": "5.90.3",
94
94
  "zeros": "1.0.0"
95
95
  },
96
96
  "type": "module",
package/types/index.d.ts CHANGED
@@ -2760,22 +2760,22 @@ export interface MathJsInstance extends MathJsFactory {
2760
2760
  * @param args Multiple scalar values
2761
2761
  * @returns The mode of all values
2762
2762
  */
2763
- mode<T extends MathScalarType>(...args: T[]): T
2763
+ mode<T extends MathScalarType>(...args: T[]): T[]
2764
2764
  /**
2765
2765
  * @param args Multiple scalar values
2766
2766
  * @returns The mode of all values
2767
2767
  */
2768
- mode(...args: MathScalarType[]): MathScalarType
2768
+ mode(...args: MathScalarType[]): MathScalarType[]
2769
2769
  /**
2770
2770
  * @param A A single matrix
2771
- * @returns The median value
2771
+ * @returns The mode value
2772
2772
  */
2773
- mode<T extends MathScalarType>(A: T[] | T[][]): T
2773
+ mode<T extends MathScalarType>(A: T[] | T[][]): T[]
2774
2774
  /**
2775
2775
  * @param A A single matrix
2776
2776
  * @returns The mode of all values
2777
2777
  */
2778
- mode(A: MathCollection): MathScalarType
2778
+ mode(A: MathCollection): MathScalarType[]
2779
2779
 
2780
2780
  /**
2781
2781
  * Compute the product of a matrix or a list with values. In case of a