@danielsimonjr/mathts-compat 0.1.8 → 0.1.9
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.
- package/dist/index.d.ts +11 -3
- package/dist/index.js +63 -5
- package/package.json +56 -56
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,9 @@ declare function atan(x: number): number;
|
|
|
66
66
|
declare function atan2(y: number, x: number): number;
|
|
67
67
|
declare const sum: typeof sum$1;
|
|
68
68
|
declare const mean: typeof mean$1;
|
|
69
|
+
type Normalization = 'unbiased' | 'uncorrected' | 'biased';
|
|
70
|
+
declare function variance(data: unknown, normalization?: Normalization): number;
|
|
71
|
+
declare function std(data: unknown, normalization?: Normalization): number;
|
|
69
72
|
declare const min: typeof min$1;
|
|
70
73
|
declare const max: typeof max$1;
|
|
71
74
|
declare const gcd: typeof gcd$1;
|
|
@@ -90,9 +93,10 @@ declare function im(c: Complex | number): number;
|
|
|
90
93
|
*/
|
|
91
94
|
declare function arg(c: Complex): number;
|
|
92
95
|
/**
|
|
93
|
-
* Transpose matrix (mathjs-compatible)
|
|
96
|
+
* Transpose matrix (mathjs-compatible). Array in → array out (mathjs returns a
|
|
97
|
+
* plain nested array for array input, a Matrix for Matrix input).
|
|
94
98
|
*/
|
|
95
|
-
declare function transpose(m: DenseMatrix | SparseMatrix | number[][]): DenseMatrix | SparseMatrix;
|
|
99
|
+
declare function transpose(m: DenseMatrix | SparseMatrix | number[][]): DenseMatrix | SparseMatrix | number[][];
|
|
96
100
|
/**
|
|
97
101
|
* Matrix determinant (mathjs-compatible)
|
|
98
102
|
*
|
|
@@ -157,6 +161,8 @@ declare const shims: {
|
|
|
157
161
|
atan2: typeof atan2;
|
|
158
162
|
sum: typeof sum$1;
|
|
159
163
|
mean: typeof mean$1;
|
|
164
|
+
std: typeof std;
|
|
165
|
+
variance: typeof variance;
|
|
160
166
|
min: typeof min$1;
|
|
161
167
|
max: typeof max$1;
|
|
162
168
|
gcd: typeof gcd$1;
|
|
@@ -263,6 +269,8 @@ interface MathInstance {
|
|
|
263
269
|
atan2: typeof shims.atan2;
|
|
264
270
|
sum: typeof shims.sum;
|
|
265
271
|
mean: typeof shims.mean;
|
|
272
|
+
std: typeof shims.std;
|
|
273
|
+
variance: typeof shims.variance;
|
|
266
274
|
min: typeof shims.min;
|
|
267
275
|
max: typeof shims.max;
|
|
268
276
|
gcd: typeof shims.gcd;
|
|
@@ -326,4 +334,4 @@ declare function create(factories?: Record<string, unknown>, config?: Partial<Ma
|
|
|
326
334
|
*/
|
|
327
335
|
declare const all: Record<string, unknown>;
|
|
328
336
|
|
|
329
|
-
export { Infinity_, LN10, LN2, LOG10E, LOG2E, type MathInstance, type MathJSConfig, NaN_, SQRT1_2, SQRT2, abs, acos, add, all, arg, asin, atan, atan2, bignumber, ceil, complex, conj, cos, create, det, divide, e, exp, floor, fraction, gcd, i, identity, im, isBigNumber_, isComplex_, isFraction_, isMatrix, isNumber_, lcm, log, matrix, max, mean, min, multiply, ones, phi, pi, pow, re, round, shims, sin, size, sparse, sqrt, subtract, sum, tan, tau, transpose, zeros };
|
|
337
|
+
export { Infinity_, LN10, LN2, LOG10E, LOG2E, type MathInstance, type MathJSConfig, NaN_, SQRT1_2, SQRT2, abs, acos, add, all, arg, asin, atan, atan2, bignumber, ceil, complex, conj, cos, create, det, divide, e, exp, floor, fraction, gcd, i, identity, im, isBigNumber_, isComplex_, isFraction_, isMatrix, isNumber_, lcm, log, matrix, max, mean, min, multiply, ones, phi, pi, pow, re, round, shims, sin, size, sparse, sqrt, std, subtract, sum, tan, tau, transpose, variance, zeros };
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,13 @@ import {
|
|
|
33
33
|
floor as _floor,
|
|
34
34
|
ceil as _ceil
|
|
35
35
|
} from "@danielsimonjr/mathts-functions";
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
DenseMatrix,
|
|
38
|
+
SparseMatrix,
|
|
39
|
+
add as _matAdd,
|
|
40
|
+
subtract as _matSubtract,
|
|
41
|
+
multiply as _matMultiply
|
|
42
|
+
} from "@danielsimonjr/mathts-matrix";
|
|
37
43
|
function complex(re2, im2) {
|
|
38
44
|
if (re2 === void 0) {
|
|
39
45
|
return COMPLEX_ZERO;
|
|
@@ -92,9 +98,38 @@ function sparse(data) {
|
|
|
92
98
|
}
|
|
93
99
|
return SparseMatrix.fromDense(DenseMatrix.fromArray(data));
|
|
94
100
|
}
|
|
95
|
-
var
|
|
96
|
-
var
|
|
97
|
-
var
|
|
101
|
+
var isMatrixLike = (x) => x instanceof DenseMatrix || Array.isArray(x) && x.length > 0 && Array.isArray(x[0]);
|
|
102
|
+
var toDenseMatrix = (x) => x instanceof DenseMatrix ? x : DenseMatrix.fromArray(x);
|
|
103
|
+
var unwrap = (r) => r instanceof DenseMatrix ? r.toArray() : r;
|
|
104
|
+
var applyArithmetic = (scalarFn, matrixFn, a, b) => {
|
|
105
|
+
if (isMatrixLike(a) || isMatrixLike(b)) {
|
|
106
|
+
const aa = isMatrixLike(a) ? toDenseMatrix(a) : a;
|
|
107
|
+
const bb = isMatrixLike(b) ? toDenseMatrix(b) : b;
|
|
108
|
+
return unwrap(matrixFn(aa, bb));
|
|
109
|
+
}
|
|
110
|
+
return scalarFn(a, b);
|
|
111
|
+
};
|
|
112
|
+
var makeArithmetic = (scalarFn, matrixFn) => (...args) => {
|
|
113
|
+
if (args.length === 0) {
|
|
114
|
+
throw new TypeError("Too few arguments (expected at least 1)");
|
|
115
|
+
}
|
|
116
|
+
if (args.length === 1) {
|
|
117
|
+
return args[0];
|
|
118
|
+
}
|
|
119
|
+
return args.reduce((acc, next) => applyArithmetic(scalarFn, matrixFn, acc, next));
|
|
120
|
+
};
|
|
121
|
+
var add = makeArithmetic(
|
|
122
|
+
_add,
|
|
123
|
+
_matAdd
|
|
124
|
+
);
|
|
125
|
+
var subtract = makeArithmetic(
|
|
126
|
+
_subtract,
|
|
127
|
+
_matSubtract
|
|
128
|
+
);
|
|
129
|
+
var multiply = makeArithmetic(
|
|
130
|
+
_multiply,
|
|
131
|
+
_matMultiply
|
|
132
|
+
);
|
|
98
133
|
var divide = _divide;
|
|
99
134
|
var pow = _pow;
|
|
100
135
|
var sqrt = _sqrt;
|
|
@@ -118,6 +153,23 @@ function atan2(y, x) {
|
|
|
118
153
|
}
|
|
119
154
|
var sum = _sum;
|
|
120
155
|
var mean = _mean;
|
|
156
|
+
function toNumericArray(data) {
|
|
157
|
+
if (data instanceof DenseMatrix) return data.toArray().flat(Infinity);
|
|
158
|
+
if (Array.isArray(data)) return data.flat(Infinity);
|
|
159
|
+
return [data];
|
|
160
|
+
}
|
|
161
|
+
function variance(data, normalization = "unbiased") {
|
|
162
|
+
const arr = toNumericArray(data);
|
|
163
|
+
const n = arr.length;
|
|
164
|
+
if (n === 0) return NaN;
|
|
165
|
+
const mu = arr.reduce((s, x) => s + x, 0) / n;
|
|
166
|
+
const ss = arr.reduce((s, x) => s + (x - mu) * (x - mu), 0);
|
|
167
|
+
const denom = normalization === "uncorrected" ? n : normalization === "biased" ? n + 1 : n > 1 ? n - 1 : n;
|
|
168
|
+
return ss / denom;
|
|
169
|
+
}
|
|
170
|
+
function std(data, normalization = "unbiased") {
|
|
171
|
+
return Math.sqrt(variance(data, normalization));
|
|
172
|
+
}
|
|
121
173
|
var min = _min;
|
|
122
174
|
var max = _max;
|
|
123
175
|
var gcd = _gcd;
|
|
@@ -149,7 +201,7 @@ function arg(c) {
|
|
|
149
201
|
}
|
|
150
202
|
function transpose(m) {
|
|
151
203
|
if (Array.isArray(m)) {
|
|
152
|
-
return DenseMatrix.fromArray(m).transpose();
|
|
204
|
+
return DenseMatrix.fromArray(m).transpose().toArray();
|
|
153
205
|
}
|
|
154
206
|
return m.transpose();
|
|
155
207
|
}
|
|
@@ -281,6 +333,8 @@ var shims = {
|
|
|
281
333
|
// Statistics
|
|
282
334
|
sum,
|
|
283
335
|
mean,
|
|
336
|
+
std,
|
|
337
|
+
variance,
|
|
284
338
|
min,
|
|
285
339
|
max,
|
|
286
340
|
// Number theory
|
|
@@ -389,6 +443,8 @@ function create(factories = all, config = {}) {
|
|
|
389
443
|
// Statistics
|
|
390
444
|
sum: shims.sum,
|
|
391
445
|
mean: shims.mean,
|
|
446
|
+
std: shims.std,
|
|
447
|
+
variance: shims.variance,
|
|
392
448
|
min: shims.min,
|
|
393
449
|
max: shims.max,
|
|
394
450
|
// Number theory
|
|
@@ -506,10 +562,12 @@ export {
|
|
|
506
562
|
size,
|
|
507
563
|
sparse,
|
|
508
564
|
sqrt,
|
|
565
|
+
std,
|
|
509
566
|
subtract,
|
|
510
567
|
sum,
|
|
511
568
|
tan,
|
|
512
569
|
tau,
|
|
513
570
|
transpose,
|
|
571
|
+
variance,
|
|
514
572
|
zeros
|
|
515
573
|
};
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@danielsimonjr/mathts-compat",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "mathjs compatibility layer for MathTS",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist",
|
|
16
|
-
"README.md"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
20
|
-
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
21
|
-
"typecheck": "tsc --noEmit",
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"test:coverage": "vitest run --coverage",
|
|
24
|
-
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@danielsimonjr/mathts-core": "^0.1.
|
|
28
|
-
"@danielsimonjr/mathts-functions": "^0.2.
|
|
29
|
-
"@danielsimonjr/mathts-matrix": "^0.1.6",
|
|
30
|
-
"@danielsimonjr/mathts-parallel": "^0.2.2"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@types/node": "^25.5.2",
|
|
34
|
-
"tsup": "^8.0.0",
|
|
35
|
-
"typescript": "^5.3.0",
|
|
36
|
-
"vitest": "^4.1.5"
|
|
37
|
-
},
|
|
38
|
-
"keywords": [
|
|
39
|
-
"math",
|
|
40
|
-
"mathjs",
|
|
41
|
-
"compat",
|
|
42
|
-
"compatibility",
|
|
43
|
-
"migration"
|
|
44
|
-
],
|
|
45
|
-
"author": "Daniel Simon Jr.",
|
|
46
|
-
"license": "MIT",
|
|
47
|
-
"repository": {
|
|
48
|
-
"type": "git",
|
|
49
|
-
"url": "https://github.com/danielsimonjr/mathts",
|
|
50
|
-
"directory": "compat"
|
|
51
|
-
},
|
|
52
|
-
"module": "./dist/index.js",
|
|
53
|
-
"publishConfig": {
|
|
54
|
-
"access": "public"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielsimonjr/mathts-compat",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "mathjs compatibility layer for MathTS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
20
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:coverage": "vitest run --coverage",
|
|
24
|
+
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@danielsimonjr/mathts-core": "^0.1.5",
|
|
28
|
+
"@danielsimonjr/mathts-functions": "^0.2.8",
|
|
29
|
+
"@danielsimonjr/mathts-matrix": "^0.1.6",
|
|
30
|
+
"@danielsimonjr/mathts-parallel": "^0.2.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.5.2",
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"typescript": "^5.3.0",
|
|
36
|
+
"vitest": "^4.1.5"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"math",
|
|
40
|
+
"mathjs",
|
|
41
|
+
"compat",
|
|
42
|
+
"compatibility",
|
|
43
|
+
"migration"
|
|
44
|
+
],
|
|
45
|
+
"author": "Daniel Simon Jr.",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/danielsimonjr/mathts",
|
|
50
|
+
"directory": "compat"
|
|
51
|
+
},
|
|
52
|
+
"module": "./dist/index.js",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|