@jrc03c/make-key 0.0.34 → 0.0.36
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/.prettierrc.json +10 -0
- package/dist/make-key.js +1273 -2077
- package/dist/make-key.min.js +8 -18
- package/package.json +3 -3
package/dist/make-key.js
CHANGED
|
@@ -1,55 +1,25 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined")
|
|
12
|
-
return require.apply(this, arguments);
|
|
13
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
-
});
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
29
|
-
mod2
|
|
30
|
-
));
|
|
31
|
-
|
|
32
|
-
// node_modules/@jrc03c/js-math-tools/dist/js-math-tools.import.mjs
|
|
33
|
-
var __defProp2 = Object.defineProperty;
|
|
34
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
35
|
-
var __publicField = (obj, key, value) => {
|
|
36
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
37
|
-
return value;
|
|
38
|
-
};
|
|
2
|
+
// node_modules/@jrc03c/js-math-tools/src/is-number.mjs
|
|
39
3
|
function isNumber(x) {
|
|
40
4
|
return typeof x === "number" && !isNaN(x) || typeof x === "bigint";
|
|
41
5
|
}
|
|
42
|
-
var isBrowser = new Function(`
|
|
43
|
-
try {
|
|
44
|
-
return this === window
|
|
45
|
-
} catch(e) {}
|
|
46
6
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
7
|
+
// node_modules/@jrc03c/js-math-tools/src/is-browser.mjs
|
|
8
|
+
var isBrowser = new Function(
|
|
9
|
+
`
|
|
10
|
+
try {
|
|
11
|
+
return this === window
|
|
12
|
+
} catch(e) {}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
return !!importScripts
|
|
16
|
+
} catch(e){}
|
|
17
|
+
|
|
18
|
+
return false
|
|
19
|
+
`
|
|
20
|
+
);
|
|
50
21
|
|
|
51
|
-
|
|
52
|
-
`);
|
|
22
|
+
// node_modules/@jrc03c/js-math-tools/src/math-error.mjs
|
|
53
23
|
var MathError = class extends Error {
|
|
54
24
|
constructor(message) {
|
|
55
25
|
if (isBrowser()) {
|
|
@@ -59,10 +29,13 @@
|
|
|
59
29
|
}
|
|
60
30
|
}
|
|
61
31
|
};
|
|
32
|
+
|
|
33
|
+
// node_modules/@jrc03c/js-math-tools/src/assert.mjs
|
|
62
34
|
function assert(isTrue, message) {
|
|
63
|
-
if (!isTrue)
|
|
64
|
-
throw new MathError(message);
|
|
35
|
+
if (!isTrue) throw new MathError(message);
|
|
65
36
|
}
|
|
37
|
+
|
|
38
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/array-types.mjs
|
|
66
39
|
var arrayTypes = [
|
|
67
40
|
Array,
|
|
68
41
|
ArrayBuffer,
|
|
@@ -78,9 +51,13 @@
|
|
|
78
51
|
Uint8Array,
|
|
79
52
|
Uint8ClampedArray
|
|
80
53
|
];
|
|
54
|
+
|
|
55
|
+
// node_modules/@jrc03c/js-math-tools/src/is-undefined.mjs
|
|
81
56
|
function isUndefined(x) {
|
|
82
57
|
return x === null || typeof x === "undefined";
|
|
83
58
|
}
|
|
59
|
+
|
|
60
|
+
// node_modules/@jrc03c/js-math-tools/src/is-array.mjs
|
|
84
61
|
var typeStrings = arrayTypes.map((s2) => s2.name);
|
|
85
62
|
function isArray(obj) {
|
|
86
63
|
try {
|
|
@@ -95,6 +72,8 @@
|
|
|
95
72
|
return false;
|
|
96
73
|
}
|
|
97
74
|
}
|
|
75
|
+
|
|
76
|
+
// node_modules/@jrc03c/js-math-tools/src/is-dataframe.mjs
|
|
98
77
|
function isDataFrame(x) {
|
|
99
78
|
try {
|
|
100
79
|
return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/dataframe");
|
|
@@ -102,12 +81,18 @@
|
|
|
102
81
|
return false;
|
|
103
82
|
}
|
|
104
83
|
}
|
|
84
|
+
|
|
85
|
+
// node_modules/@jrc03c/js-math-tools/src/is-function.mjs
|
|
105
86
|
function isFunction(fn) {
|
|
106
87
|
return typeof fn === "function";
|
|
107
88
|
}
|
|
89
|
+
|
|
90
|
+
// node_modules/@jrc03c/js-math-tools/src/is-object.mjs
|
|
108
91
|
function isObject(x) {
|
|
109
92
|
return typeof x === "object" && !isUndefined(x) && !isArray(x);
|
|
110
93
|
}
|
|
94
|
+
|
|
95
|
+
// node_modules/@jrc03c/js-math-tools/src/is-series.mjs
|
|
111
96
|
function isSeries(x) {
|
|
112
97
|
try {
|
|
113
98
|
return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/series");
|
|
@@ -115,6 +100,8 @@
|
|
|
115
100
|
return false;
|
|
116
101
|
}
|
|
117
102
|
}
|
|
103
|
+
|
|
104
|
+
// node_modules/@jrc03c/js-math-tools/src/index-of.mjs
|
|
118
105
|
function indexOf(x, fn) {
|
|
119
106
|
if (isDataFrame(x)) {
|
|
120
107
|
const index = indexOf(x.values, fn);
|
|
@@ -133,12 +120,15 @@
|
|
|
133
120
|
}
|
|
134
121
|
return index;
|
|
135
122
|
}
|
|
136
|
-
assert(
|
|
123
|
+
assert(
|
|
124
|
+
isObject(x) || isArray(x),
|
|
125
|
+
"You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `indexOf` function!"
|
|
126
|
+
);
|
|
137
127
|
if (!isFunction(fn)) {
|
|
138
128
|
const value = fn;
|
|
139
129
|
fn = (v) => v === value;
|
|
140
130
|
}
|
|
141
|
-
function
|
|
131
|
+
function helper4(x2, fn2, checked) {
|
|
142
132
|
checked = checked || [];
|
|
143
133
|
if (checked.indexOf(x2) > -1) {
|
|
144
134
|
return null;
|
|
@@ -152,7 +142,7 @@
|
|
|
152
142
|
if (fn2(value)) {
|
|
153
143
|
return [key];
|
|
154
144
|
}
|
|
155
|
-
const results =
|
|
145
|
+
const results = helper4(value, fn2, checked);
|
|
156
146
|
if (results && results.length > 0) {
|
|
157
147
|
return [key].concat(results);
|
|
158
148
|
}
|
|
@@ -164,7 +154,7 @@
|
|
|
164
154
|
if (fn2(value)) {
|
|
165
155
|
return [i];
|
|
166
156
|
}
|
|
167
|
-
const results =
|
|
157
|
+
const results = helper4(value, fn2, checked);
|
|
168
158
|
if (results && results.length > 0) {
|
|
169
159
|
return [i].concat(results);
|
|
170
160
|
}
|
|
@@ -183,15 +173,17 @@
|
|
|
183
173
|
return false;
|
|
184
174
|
}
|
|
185
175
|
}
|
|
186
|
-
const paths =
|
|
176
|
+
const paths = helper4(x, safeFn);
|
|
187
177
|
if (paths && paths.length > 0) {
|
|
188
178
|
return paths;
|
|
189
179
|
} else {
|
|
190
180
|
return null;
|
|
191
181
|
}
|
|
192
182
|
}
|
|
183
|
+
|
|
184
|
+
// node_modules/@jrc03c/js-math-tools/src/copy.mjs
|
|
193
185
|
function copy(x) {
|
|
194
|
-
function
|
|
186
|
+
function helper4(x2) {
|
|
195
187
|
if (typeof x2 === "object") {
|
|
196
188
|
if (x2 === null) {
|
|
197
189
|
return null;
|
|
@@ -203,32 +195,32 @@
|
|
|
203
195
|
return x2.map((v) => copy(v));
|
|
204
196
|
}
|
|
205
197
|
if (isSeries(x2)) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
return
|
|
198
|
+
const out2 = x2.copy();
|
|
199
|
+
out2.values = copy(out2.values);
|
|
200
|
+
return out2;
|
|
209
201
|
}
|
|
210
202
|
if (isDataFrame(x2)) {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
return
|
|
203
|
+
const out2 = x2.copy();
|
|
204
|
+
out2.values = copy(x2.values);
|
|
205
|
+
return out2;
|
|
214
206
|
}
|
|
215
207
|
if (x2 instanceof Date) {
|
|
216
208
|
return new Date(x2.getTime());
|
|
217
209
|
}
|
|
218
210
|
x2 = decycle(x2);
|
|
219
|
-
const
|
|
211
|
+
const out = {};
|
|
220
212
|
Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)).forEach((key) => {
|
|
221
|
-
|
|
213
|
+
out[key] = copy(x2[key]);
|
|
222
214
|
});
|
|
223
|
-
return
|
|
215
|
+
return out;
|
|
224
216
|
} else {
|
|
225
217
|
return x2;
|
|
226
218
|
}
|
|
227
219
|
}
|
|
228
|
-
return
|
|
220
|
+
return helper4(decycle(x));
|
|
229
221
|
}
|
|
230
222
|
function decycle(x) {
|
|
231
|
-
function
|
|
223
|
+
function helper4(x2, checked, currentPath) {
|
|
232
224
|
checked = checked || [];
|
|
233
225
|
currentPath = currentPath || "";
|
|
234
226
|
if (checked.indexOf(x2) > -1) {
|
|
@@ -247,17 +239,16 @@
|
|
|
247
239
|
}
|
|
248
240
|
}
|
|
249
241
|
if (typeof x2 === "object") {
|
|
250
|
-
if (x2 === null)
|
|
251
|
-
return null;
|
|
242
|
+
if (x2 === null) return null;
|
|
252
243
|
checked.push(x2);
|
|
253
244
|
if (isArray(x2)) {
|
|
254
245
|
if (typeof x2.constructor !== "undefined" && x2.constructor.name !== "Array") {
|
|
255
246
|
return x2.slice();
|
|
256
247
|
}
|
|
257
|
-
return x2.map((v, i) =>
|
|
248
|
+
return x2.map((v, i) => helper4(v, checked, currentPath + "/" + i));
|
|
258
249
|
} else {
|
|
259
250
|
Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)).forEach((key) => {
|
|
260
|
-
x2[key] =
|
|
251
|
+
x2[key] = helper4(x2[key], checked, currentPath + "/" + key.toString());
|
|
261
252
|
});
|
|
262
253
|
return x2;
|
|
263
254
|
}
|
|
@@ -266,39 +257,40 @@
|
|
|
266
257
|
}
|
|
267
258
|
}
|
|
268
259
|
const orig = x;
|
|
269
|
-
let
|
|
260
|
+
let out = helper4(orig);
|
|
270
261
|
if (isDataFrame(x)) {
|
|
271
262
|
const temp = x.copy();
|
|
272
|
-
temp._values =
|
|
273
|
-
temp._columns =
|
|
274
|
-
temp._index =
|
|
275
|
-
|
|
263
|
+
temp._values = out.values;
|
|
264
|
+
temp._columns = out.columns;
|
|
265
|
+
temp._index = out.index;
|
|
266
|
+
out = temp;
|
|
276
267
|
}
|
|
277
268
|
if (isSeries(x)) {
|
|
278
269
|
const temp = x.copy();
|
|
279
|
-
temp.name =
|
|
280
|
-
temp._values =
|
|
281
|
-
temp._index =
|
|
282
|
-
|
|
270
|
+
temp.name = out.name;
|
|
271
|
+
temp._values = out.values;
|
|
272
|
+
temp._index = out.index;
|
|
273
|
+
out = temp;
|
|
283
274
|
}
|
|
284
|
-
return
|
|
275
|
+
return out;
|
|
285
276
|
}
|
|
277
|
+
|
|
278
|
+
// node_modules/@jrc03c/js-math-tools/src/is-date.mjs
|
|
286
279
|
function isDate(x) {
|
|
287
280
|
return x instanceof Date && x.toString() !== "Invalid Date";
|
|
288
281
|
}
|
|
282
|
+
|
|
283
|
+
// node_modules/@jrc03c/js-math-tools/src/is-equal.mjs
|
|
289
284
|
var numberTypes = ["number", "int", "float", "bigint"];
|
|
290
285
|
function isEqual(a, b) {
|
|
291
|
-
function
|
|
286
|
+
function helper4(a2, b2) {
|
|
292
287
|
const aType = typeof a2;
|
|
293
288
|
const bType = typeof b2;
|
|
294
289
|
if (aType !== bType && !numberTypes.includes(aType) && !numberTypes.includes(bType))
|
|
295
290
|
return false;
|
|
296
|
-
if (aType === "undefined" && bType === "undefined")
|
|
297
|
-
|
|
298
|
-
if (aType === "
|
|
299
|
-
return a2 === b2;
|
|
300
|
-
if (aType === "symbol")
|
|
301
|
-
return a2 === b2;
|
|
291
|
+
if (aType === "undefined" && bType === "undefined") return true;
|
|
292
|
+
if (aType === "boolean") return a2 === b2;
|
|
293
|
+
if (aType === "symbol") return a2 === b2;
|
|
302
294
|
if (aType === "number" || aType === "bigint") {
|
|
303
295
|
try {
|
|
304
296
|
const aString = a2.toString();
|
|
@@ -308,10 +300,8 @@
|
|
|
308
300
|
return false;
|
|
309
301
|
}
|
|
310
302
|
}
|
|
311
|
-
if (aType === "string")
|
|
312
|
-
|
|
313
|
-
if (aType === "function")
|
|
314
|
-
return a2 === b2;
|
|
303
|
+
if (aType === "string") return a2 === b2;
|
|
304
|
+
if (aType === "function") return a2 === b2;
|
|
315
305
|
if (aType === "object") {
|
|
316
306
|
if (a2 === null || b2 === null) {
|
|
317
307
|
return a2 === null && b2 === null;
|
|
@@ -333,29 +323,28 @@
|
|
|
333
323
|
}
|
|
334
324
|
const aKeys = Object.keys(a2).concat(Object.getOwnPropertySymbols(a2));
|
|
335
325
|
const bKeys = Object.keys(b2).concat(Object.getOwnPropertySymbols(b2));
|
|
336
|
-
if (aKeys.length !== bKeys.length)
|
|
337
|
-
return false;
|
|
326
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
338
327
|
for (let i = 0; i < aKeys.length; i++) {
|
|
339
328
|
const key = aKeys[i];
|
|
340
|
-
if (!
|
|
341
|
-
return false;
|
|
329
|
+
if (!helper4(a2[key], b2[key])) return false;
|
|
342
330
|
}
|
|
343
331
|
return true;
|
|
344
332
|
}
|
|
345
333
|
}
|
|
346
334
|
}
|
|
347
335
|
try {
|
|
348
|
-
return
|
|
336
|
+
return helper4(a, b);
|
|
349
337
|
} catch (e) {
|
|
350
|
-
return
|
|
338
|
+
return helper4(decycle(a), decycle(b));
|
|
351
339
|
}
|
|
352
340
|
}
|
|
341
|
+
|
|
342
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/counter.mjs
|
|
353
343
|
function makeKey(n) {
|
|
354
344
|
const alpha = "abcdefg1234567890";
|
|
355
|
-
let
|
|
356
|
-
while (
|
|
357
|
-
|
|
358
|
-
return out2;
|
|
345
|
+
let out = "";
|
|
346
|
+
while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
|
|
347
|
+
return out;
|
|
359
348
|
}
|
|
360
349
|
var NULL_KEY = makeKey(16);
|
|
361
350
|
var UNDEFINED_KEY = makeKey(16);
|
|
@@ -415,35 +404,42 @@
|
|
|
415
404
|
return this.values.map((v) => ({ value: v, count: this.get(v) }));
|
|
416
405
|
}
|
|
417
406
|
toObject() {
|
|
418
|
-
const
|
|
407
|
+
const out = {};
|
|
419
408
|
this.values.forEach((value) => {
|
|
420
|
-
|
|
409
|
+
out[value] = this.get(value);
|
|
421
410
|
});
|
|
422
|
-
return
|
|
411
|
+
return out;
|
|
423
412
|
}
|
|
424
413
|
};
|
|
414
|
+
|
|
415
|
+
// node_modules/@jrc03c/js-math-tools/src/flatten.mjs
|
|
425
416
|
function flatten(arr) {
|
|
426
417
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
427
418
|
return flatten(arr.values);
|
|
428
419
|
}
|
|
429
|
-
assert(
|
|
430
|
-
|
|
431
|
-
|
|
420
|
+
assert(
|
|
421
|
+
isArray(arr),
|
|
422
|
+
"The `flatten` function only works on arrays, Series, and DataFrames!"
|
|
423
|
+
);
|
|
424
|
+
function helper4(arr2) {
|
|
425
|
+
let out = [];
|
|
432
426
|
arr2.forEach((child) => {
|
|
433
427
|
if (isArray(child)) {
|
|
434
|
-
|
|
428
|
+
out = out.concat(helper4(child));
|
|
435
429
|
} else {
|
|
436
|
-
|
|
430
|
+
out.push(child);
|
|
437
431
|
}
|
|
438
432
|
});
|
|
439
|
-
return
|
|
433
|
+
return out;
|
|
440
434
|
}
|
|
441
|
-
return
|
|
435
|
+
return helper4(arr);
|
|
442
436
|
}
|
|
437
|
+
|
|
438
|
+
// node_modules/@jrc03c/js-math-tools/src/stats.mjs
|
|
443
439
|
function stats(x, options) {
|
|
444
440
|
options = options || {};
|
|
445
441
|
const counts = new Counter();
|
|
446
|
-
const
|
|
442
|
+
const out = {};
|
|
447
443
|
const xflat = flatten(x);
|
|
448
444
|
const xnums = [];
|
|
449
445
|
let max2 = -Infinity;
|
|
@@ -473,21 +469,23 @@
|
|
|
473
469
|
counts.increment(v);
|
|
474
470
|
}
|
|
475
471
|
const mean2 = sum2 / xnums.length;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (isNaN(
|
|
483
|
-
|
|
484
|
-
|
|
472
|
+
out.counts = counts;
|
|
473
|
+
out.max = max2;
|
|
474
|
+
out.mean = mean2;
|
|
475
|
+
out.min = min2;
|
|
476
|
+
out.n = xflat.length;
|
|
477
|
+
out.sum = sum2;
|
|
478
|
+
if (isNaN(out.mean)) {
|
|
479
|
+
out.max = NaN;
|
|
480
|
+
out.min = NaN;
|
|
485
481
|
}
|
|
486
482
|
if (options.shouldDropNaNs) {
|
|
487
|
-
|
|
483
|
+
out.nWithoutNaNs = xnums.length;
|
|
488
484
|
}
|
|
489
485
|
if (options.mode) {
|
|
490
|
-
const sortedCountPairs = Array.from(
|
|
486
|
+
const sortedCountPairs = Array.from(
|
|
487
|
+
counts.values.map((v) => [v, counts.get(v)])
|
|
488
|
+
).toSorted((a, b) => b[1] - a[1]);
|
|
491
489
|
const highestCount = sortedCountPairs[0][1];
|
|
492
490
|
const mode2 = [];
|
|
493
491
|
for (const pair of sortedCountPairs) {
|
|
@@ -497,26 +495,26 @@
|
|
|
497
495
|
break;
|
|
498
496
|
}
|
|
499
497
|
}
|
|
500
|
-
|
|
498
|
+
out.mode = mode2.toSorted();
|
|
501
499
|
}
|
|
502
500
|
if (options.median) {
|
|
503
501
|
if (isNaN(mean2)) {
|
|
504
|
-
|
|
502
|
+
out.median = NaN;
|
|
505
503
|
} else {
|
|
506
504
|
const xnumsSorted = xnums.toSorted((a, b) => Number(a) - Number(b));
|
|
507
505
|
const middle = Math.floor(xnumsSorted.length / 2);
|
|
508
506
|
if (xnumsSorted.length % 2 === 0) {
|
|
509
507
|
const left = xnumsSorted[middle - 1];
|
|
510
508
|
const right = xnumsSorted[middle];
|
|
511
|
-
|
|
509
|
+
out.median = (Number(left) + Number(right)) / 2;
|
|
512
510
|
if (resultsShouldIncludeBigInts && typeof left === "bigint" && typeof right === "bigint") {
|
|
513
511
|
try {
|
|
514
|
-
|
|
512
|
+
out.median = BigInt(out.median);
|
|
515
513
|
} catch (e) {
|
|
516
514
|
}
|
|
517
515
|
}
|
|
518
516
|
} else {
|
|
519
|
-
|
|
517
|
+
out.median = xnumsSorted[middle];
|
|
520
518
|
}
|
|
521
519
|
}
|
|
522
520
|
}
|
|
@@ -527,20 +525,20 @@
|
|
|
527
525
|
}
|
|
528
526
|
variance2 /= xnums.length;
|
|
529
527
|
const stdev2 = Math.sqrt(variance2);
|
|
530
|
-
|
|
531
|
-
|
|
528
|
+
out.stdev = stdev2;
|
|
529
|
+
out.variance = variance2;
|
|
532
530
|
}
|
|
533
531
|
if (resultsShouldIncludeBigInts) {
|
|
534
532
|
try {
|
|
535
|
-
|
|
533
|
+
out.sum = BigInt(out.sum);
|
|
536
534
|
} catch (e) {
|
|
537
535
|
}
|
|
538
536
|
try {
|
|
539
|
-
|
|
537
|
+
out.mean = BigInt(out.mean);
|
|
540
538
|
} catch (e) {
|
|
541
539
|
}
|
|
542
540
|
if (options.mode) {
|
|
543
|
-
|
|
541
|
+
out.mode = out.mode.map((v) => {
|
|
544
542
|
try {
|
|
545
543
|
return BigInt(v);
|
|
546
544
|
} catch (e) {
|
|
@@ -549,8 +547,10 @@
|
|
|
549
547
|
});
|
|
550
548
|
}
|
|
551
549
|
}
|
|
552
|
-
return
|
|
550
|
+
return out;
|
|
553
551
|
}
|
|
552
|
+
|
|
553
|
+
// node_modules/@jrc03c/js-math-tools/src/count.mjs
|
|
554
554
|
function count(arr, matcher) {
|
|
555
555
|
const { counts } = stats(arr);
|
|
556
556
|
if (!isUndefined(matcher)) {
|
|
@@ -570,6 +570,8 @@
|
|
|
570
570
|
}
|
|
571
571
|
return counts;
|
|
572
572
|
}
|
|
573
|
+
|
|
574
|
+
// node_modules/@jrc03c/js-math-tools/src/is-jagged.mjs
|
|
573
575
|
function helper(x) {
|
|
574
576
|
if (isDataFrame(x) || isSeries(x)) {
|
|
575
577
|
return helper(x.values);
|
|
@@ -602,11 +604,16 @@
|
|
|
602
604
|
function isJagged(x) {
|
|
603
605
|
return helper(decycle(x));
|
|
604
606
|
}
|
|
607
|
+
|
|
608
|
+
// node_modules/@jrc03c/js-math-tools/src/is-nested.mjs
|
|
605
609
|
function isNested(x) {
|
|
606
610
|
if (isDataFrame(x) || isSeries(x)) {
|
|
607
611
|
return isNested(x.values);
|
|
608
612
|
}
|
|
609
|
-
assert(
|
|
613
|
+
assert(
|
|
614
|
+
isArray(x),
|
|
615
|
+
"The `isNested` function only works on arrays, Series, and DataFrames!"
|
|
616
|
+
);
|
|
610
617
|
for (let i = 0; i < x.length; i++) {
|
|
611
618
|
if (isArray(x[i])) {
|
|
612
619
|
return true;
|
|
@@ -614,50 +621,67 @@
|
|
|
614
621
|
}
|
|
615
622
|
return false;
|
|
616
623
|
}
|
|
624
|
+
|
|
625
|
+
// node_modules/@jrc03c/js-math-tools/src/ndarray.mjs
|
|
617
626
|
var error = "You must pass a natural number or a one-dimensional array of natural numbers into the `ndarray` function!";
|
|
618
627
|
function ndarray(shape2) {
|
|
619
628
|
assert(!isUndefined(shape2), error);
|
|
620
|
-
if (!isArray(shape2))
|
|
621
|
-
shape2 = [shape2];
|
|
629
|
+
if (!isArray(shape2)) shape2 = [shape2];
|
|
622
630
|
assert(!isNested(shape2), error);
|
|
623
631
|
assert(shape2.length > 0, error);
|
|
624
632
|
let s2 = shape2[0];
|
|
625
|
-
if (typeof s2 === "bigint")
|
|
626
|
-
s2 = Number(s2);
|
|
633
|
+
if (typeof s2 === "bigint") s2 = Number(s2);
|
|
627
634
|
assert(isNumber(s2), error);
|
|
628
635
|
assert(s2 >= 0, error);
|
|
629
636
|
assert(Math.floor(s2) === s2, error);
|
|
630
|
-
assert(
|
|
637
|
+
assert(
|
|
638
|
+
s2 !== Infinity,
|
|
639
|
+
"We can't create an array containing an infinite number of values!"
|
|
640
|
+
);
|
|
631
641
|
if (shape2.length === 1) {
|
|
632
|
-
const
|
|
633
|
-
for (let i = 0; i < s2; i++)
|
|
634
|
-
|
|
635
|
-
return out2;
|
|
642
|
+
const out = [];
|
|
643
|
+
for (let i = 0; i < s2; i++) out.push(void 0);
|
|
644
|
+
return out;
|
|
636
645
|
} else {
|
|
637
|
-
const
|
|
646
|
+
const out = [];
|
|
638
647
|
for (let i = 0; i < s2; i++) {
|
|
639
|
-
|
|
648
|
+
out.push(ndarray(shape2.slice(1)));
|
|
640
649
|
}
|
|
641
|
-
return
|
|
650
|
+
return out;
|
|
642
651
|
}
|
|
643
652
|
}
|
|
653
|
+
|
|
654
|
+
// node_modules/@jrc03c/js-math-tools/src/reverse.mjs
|
|
644
655
|
function reverse(arr) {
|
|
645
656
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
return
|
|
650
|
-
}
|
|
651
|
-
assert(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
657
|
+
const out2 = arr.copy();
|
|
658
|
+
out2.values = reverse(out2.values);
|
|
659
|
+
out2.index = reverse(out2.index);
|
|
660
|
+
return out2;
|
|
661
|
+
}
|
|
662
|
+
assert(
|
|
663
|
+
isArray(arr),
|
|
664
|
+
"The `reverse` function only works on arrays, Series, and DataFrames!"
|
|
665
|
+
);
|
|
666
|
+
const out = [];
|
|
667
|
+
for (let i = arr.length - 1; i >= 0; i--) out.push(arr[i]);
|
|
668
|
+
return out;
|
|
656
669
|
}
|
|
670
|
+
|
|
671
|
+
// node_modules/@jrc03c/js-math-tools/src/range.mjs
|
|
657
672
|
function range(a, b, step = 1) {
|
|
658
|
-
assert(
|
|
659
|
-
|
|
660
|
-
|
|
673
|
+
assert(
|
|
674
|
+
!isUndefined(a) && !isUndefined(b) && !isUndefined(step),
|
|
675
|
+
"You must pass two numbers and optionally a step value to the `range` function!"
|
|
676
|
+
);
|
|
677
|
+
assert(
|
|
678
|
+
isNumber(a) && isNumber(b) && isNumber(step),
|
|
679
|
+
"You must pass two numbers and optionally a step value to the `range` function!"
|
|
680
|
+
);
|
|
681
|
+
assert(
|
|
682
|
+
step > 0,
|
|
683
|
+
"The step value must be greater than 0! (NOTE: The step value is a magnitude; it does not indicate direction.)"
|
|
684
|
+
);
|
|
661
685
|
let shouldReverse = false;
|
|
662
686
|
const shouldIncludeBigInts = typeof a === "bigint" || typeof b === "bigint" || typeof step === "bigint";
|
|
663
687
|
a = Number(a);
|
|
@@ -669,28 +693,28 @@
|
|
|
669
693
|
a = b + step;
|
|
670
694
|
b = buffer + step;
|
|
671
695
|
}
|
|
672
|
-
let
|
|
696
|
+
let out = [];
|
|
673
697
|
for (let i = a; i < b; i += step) {
|
|
674
698
|
if (shouldIncludeBigInts) {
|
|
675
699
|
try {
|
|
676
|
-
|
|
700
|
+
out.push(BigInt(i));
|
|
677
701
|
} catch (e) {
|
|
678
|
-
|
|
702
|
+
out.push(i);
|
|
679
703
|
}
|
|
680
704
|
} else {
|
|
681
|
-
|
|
705
|
+
out.push(i);
|
|
682
706
|
}
|
|
683
707
|
}
|
|
684
|
-
if (shouldReverse)
|
|
685
|
-
|
|
686
|
-
return out2;
|
|
708
|
+
if (shouldReverse) out = reverse(out);
|
|
709
|
+
return out;
|
|
687
710
|
}
|
|
711
|
+
|
|
712
|
+
// node_modules/@jrc03c/js-math-tools/src/set.mjs
|
|
688
713
|
function makeKey2(n) {
|
|
689
714
|
const alpha = "abcdefg1234567890";
|
|
690
|
-
let
|
|
691
|
-
while (
|
|
692
|
-
|
|
693
|
-
return out2;
|
|
715
|
+
let out = "";
|
|
716
|
+
while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
|
|
717
|
+
return out;
|
|
694
718
|
}
|
|
695
719
|
var NULL_KEY2 = makeKey2(256);
|
|
696
720
|
var UNDEFINED_KEY2 = makeKey2(256);
|
|
@@ -701,17 +725,21 @@
|
|
|
701
725
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
702
726
|
return set(arr.values);
|
|
703
727
|
}
|
|
704
|
-
assert(
|
|
705
|
-
|
|
728
|
+
assert(
|
|
729
|
+
isArray(arr),
|
|
730
|
+
"The `set` function only works on arrays, Series, and DataFrames!"
|
|
731
|
+
);
|
|
732
|
+
const out = [];
|
|
706
733
|
const temp = {};
|
|
707
734
|
flatten(arr).forEach((item) => {
|
|
708
735
|
const key = typeof item === "object" && item === null ? NULL_KEY2 : isUndefined(item) ? UNDEFINED_KEY2 : isFunction(item) ? item.toString() : typeof item === "symbol" ? item.toString() + " - " + SYMBOL_KEY2 : item === Infinity ? INFINITY_KEY2 : item === -Infinity ? MINUS_INFINITY_KEY2 : typeof item === "bigint" ? item.toString() : isDataFrame(item) ? item.toJSONString() : isSeries(item) ? JSON.stringify(item.toObject()) : JSON.stringify(item);
|
|
709
|
-
if (!temp[key])
|
|
710
|
-
out2.push(item);
|
|
736
|
+
if (!temp[key]) out.push(item);
|
|
711
737
|
temp[key] = true;
|
|
712
738
|
});
|
|
713
|
-
return
|
|
739
|
+
return out;
|
|
714
740
|
}
|
|
741
|
+
|
|
742
|
+
// node_modules/@jrc03c/js-math-tools/src/shape.mjs
|
|
715
743
|
function helper2(x) {
|
|
716
744
|
if (isArray(x)) {
|
|
717
745
|
const childShapes = helper2(x[0]);
|
|
@@ -724,105 +752,120 @@
|
|
|
724
752
|
if (isDataFrame(x) || isSeries(x)) {
|
|
725
753
|
return shape(x.values);
|
|
726
754
|
}
|
|
727
|
-
assert(
|
|
755
|
+
assert(
|
|
756
|
+
isArray(x),
|
|
757
|
+
"The `shape` function only works on arrays, Series, and DataFrames!"
|
|
758
|
+
);
|
|
728
759
|
return helper2(x);
|
|
729
760
|
}
|
|
761
|
+
|
|
762
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-append.mjs
|
|
730
763
|
function dfAppend(df, x, axis) {
|
|
731
764
|
if (isUndefined(axis)) {
|
|
732
765
|
axis = 0;
|
|
733
766
|
}
|
|
734
|
-
assert(
|
|
767
|
+
assert(
|
|
768
|
+
axis === 0 || axis === 1 || axis === "vertical" || axis === "horizontal",
|
|
769
|
+
'The only valid axis values for use when appending data to a DataFrame are 0, 1, "vertical", and "horizontal". Note that 0 == "horizontal" and 1 == "vertical".'
|
|
770
|
+
);
|
|
735
771
|
if (isArray(x)) {
|
|
736
|
-
assert(
|
|
772
|
+
assert(
|
|
773
|
+
!isJagged(x),
|
|
774
|
+
"The array of data you're trying to append to this DataFrame is jagged!"
|
|
775
|
+
);
|
|
737
776
|
const xShape = shape(x);
|
|
738
777
|
if (xShape.length === 1) {
|
|
739
778
|
if (axis === 0) {
|
|
740
|
-
const
|
|
741
|
-
|
|
779
|
+
const out = df.copy();
|
|
780
|
+
out._values.push(x);
|
|
742
781
|
const maxRowLength = Math.max(df.shape[1], xShape[0]);
|
|
743
|
-
|
|
782
|
+
out._values.forEach((row) => {
|
|
744
783
|
while (row.length < maxRowLength) {
|
|
745
784
|
row.push(void 0);
|
|
746
785
|
}
|
|
747
786
|
});
|
|
748
|
-
while (
|
|
749
|
-
|
|
787
|
+
while (out._index.length < out._values.length) {
|
|
788
|
+
out._index.push("row" + out._index.length);
|
|
750
789
|
}
|
|
751
|
-
while (
|
|
752
|
-
|
|
790
|
+
while (out._columns.length < maxRowLength) {
|
|
791
|
+
out._columns.push("col" + out._columns.length);
|
|
753
792
|
}
|
|
754
|
-
return
|
|
793
|
+
return out;
|
|
755
794
|
} else {
|
|
756
795
|
const maxColLength = Math.max(df.shape[0], xShape[0]);
|
|
757
|
-
const
|
|
796
|
+
const out = df.copy();
|
|
758
797
|
range(0, maxColLength).forEach((i) => {
|
|
759
|
-
if (i >=
|
|
760
|
-
|
|
798
|
+
if (i >= out._values.length) {
|
|
799
|
+
out._values.push(ndarray(df.shape[1]));
|
|
761
800
|
}
|
|
762
|
-
|
|
801
|
+
out._values[i].push(x[i]);
|
|
763
802
|
});
|
|
764
|
-
while (
|
|
765
|
-
|
|
803
|
+
while (out._index.length < out._values.length) {
|
|
804
|
+
out._index.push("row" + out._index.length);
|
|
766
805
|
}
|
|
767
|
-
while (
|
|
768
|
-
|
|
806
|
+
while (out._columns.length < out._values[0].length) {
|
|
807
|
+
out._columns.push("col" + out._columns.length);
|
|
769
808
|
}
|
|
770
|
-
return
|
|
809
|
+
return out;
|
|
771
810
|
}
|
|
772
811
|
} else if (xShape.length === 2) {
|
|
773
812
|
if (axis === 0) {
|
|
774
|
-
const maxRowLength = Math.max(
|
|
775
|
-
|
|
776
|
-
|
|
813
|
+
const maxRowLength = Math.max(
|
|
814
|
+
...x.map((row) => row.length).concat([df.shape[1]])
|
|
815
|
+
);
|
|
816
|
+
const out = df.copy();
|
|
817
|
+
out._values = out._values.concat(x).map((row) => {
|
|
777
818
|
while (row.length < maxRowLength) {
|
|
778
819
|
row.push(void 0);
|
|
779
820
|
}
|
|
780
821
|
return row;
|
|
781
822
|
});
|
|
782
|
-
while (
|
|
783
|
-
|
|
823
|
+
while (out._index.length < out._values.length) {
|
|
824
|
+
out._index.push("row" + out._index.length);
|
|
784
825
|
}
|
|
785
|
-
while (
|
|
786
|
-
|
|
826
|
+
while (out._columns.length < maxRowLength) {
|
|
827
|
+
out._columns.push("col" + out._columns.length);
|
|
787
828
|
}
|
|
788
|
-
return
|
|
829
|
+
return out;
|
|
789
830
|
} else {
|
|
790
831
|
const maxRowLength = Math.max(...x.map((row) => row.length)) + df.shape[1];
|
|
791
832
|
const maxColLength = Math.max(df.shape[0], xShape[0]);
|
|
792
|
-
const
|
|
833
|
+
const out = df.copy();
|
|
793
834
|
range(0, maxColLength).forEach((i) => {
|
|
794
|
-
if (i >=
|
|
795
|
-
|
|
835
|
+
if (i >= out._values.length) {
|
|
836
|
+
out._values.push(ndarray(df.shape[1]));
|
|
796
837
|
}
|
|
797
|
-
|
|
798
|
-
while (
|
|
799
|
-
|
|
838
|
+
out._values[i] = out._values[i].concat(x[i]);
|
|
839
|
+
while (out._values[i].length < maxRowLength) {
|
|
840
|
+
out._values[i].push(void 0);
|
|
800
841
|
}
|
|
801
842
|
});
|
|
802
|
-
while (
|
|
803
|
-
|
|
843
|
+
while (out._index.length < out._values.length) {
|
|
844
|
+
out._index.push("row" + out._index.length);
|
|
804
845
|
}
|
|
805
|
-
while (
|
|
806
|
-
|
|
846
|
+
while (out._columns.length < maxRowLength) {
|
|
847
|
+
out._columns.push("col" + out._columns.length);
|
|
807
848
|
}
|
|
808
|
-
return
|
|
849
|
+
return out;
|
|
809
850
|
}
|
|
810
851
|
} else {
|
|
811
|
-
throw new MathError(
|
|
852
|
+
throw new MathError(
|
|
853
|
+
"Only 1- and 2-dimensional arrays can be appended to a DataFrame!"
|
|
854
|
+
);
|
|
812
855
|
}
|
|
813
856
|
} else if (isSeries(x)) {
|
|
814
|
-
const
|
|
857
|
+
const out = dfAppend(df, x.values, axis);
|
|
815
858
|
if (axis === 0) {
|
|
816
|
-
|
|
859
|
+
out.index[out.index.length - 1] = out.index.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
|
|
817
860
|
} else {
|
|
818
|
-
|
|
861
|
+
out.columns[out.columns.length - 1] = out.columns.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
|
|
819
862
|
}
|
|
820
|
-
return
|
|
863
|
+
return out;
|
|
821
864
|
} else if (isDataFrame(x)) {
|
|
822
865
|
if (axis === 0) {
|
|
823
|
-
const
|
|
824
|
-
const maxRowLength = set(
|
|
825
|
-
|
|
866
|
+
const out = df.copy();
|
|
867
|
+
const maxRowLength = set(out._columns.concat(x._columns)).length;
|
|
868
|
+
out._values.forEach((row) => {
|
|
826
869
|
while (row.length < maxRowLength) {
|
|
827
870
|
row.push(void 0);
|
|
828
871
|
}
|
|
@@ -830,7 +873,7 @@
|
|
|
830
873
|
x.apply((row) => {
|
|
831
874
|
const rowCopy = row.copy();
|
|
832
875
|
const temp = [];
|
|
833
|
-
|
|
876
|
+
out._columns.forEach((col) => {
|
|
834
877
|
const index = rowCopy._index.indexOf(col);
|
|
835
878
|
if (index > -1) {
|
|
836
879
|
temp.push(rowCopy._values[index]);
|
|
@@ -840,42 +883,58 @@
|
|
|
840
883
|
temp.push(void 0);
|
|
841
884
|
}
|
|
842
885
|
});
|
|
843
|
-
|
|
886
|
+
out._values.push(temp.concat(rowCopy._values));
|
|
844
887
|
}, 1);
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
888
|
+
out._columns = out._columns.concat(
|
|
889
|
+
x._columns.filter((c) => out._columns.indexOf(c) < 0)
|
|
890
|
+
);
|
|
891
|
+
while (out._index.length < out._values.length) {
|
|
892
|
+
const newRowName = "row" + out._index.length;
|
|
893
|
+
out._index.push(
|
|
894
|
+
newRowName + (df._index.indexOf(newRowName) > -1 ? " (2)" : "")
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
return out;
|
|
851
898
|
} else {
|
|
852
|
-
const
|
|
853
|
-
|
|
899
|
+
const out = df.copy();
|
|
900
|
+
out._index.forEach((rowName, i) => {
|
|
854
901
|
const xIndex = x._index.indexOf(rowName);
|
|
855
902
|
if (xIndex > -1) {
|
|
856
|
-
|
|
903
|
+
out._values[i] = out._values[i].concat(x._values[xIndex]);
|
|
857
904
|
} else {
|
|
858
|
-
|
|
905
|
+
out._values[i] = out._values[i].concat(ndarray(x.shape[1]));
|
|
859
906
|
}
|
|
860
907
|
});
|
|
861
908
|
x._index.forEach((rowName, i) => {
|
|
862
|
-
const outIndex =
|
|
909
|
+
const outIndex = out._index.indexOf(rowName);
|
|
863
910
|
if (outIndex < 0) {
|
|
864
|
-
|
|
865
|
-
|
|
911
|
+
out._index.push(rowName);
|
|
912
|
+
out._values.push(ndarray(out._columns.length).concat(x._values[i]));
|
|
866
913
|
}
|
|
867
914
|
});
|
|
868
|
-
|
|
869
|
-
|
|
915
|
+
out._columns = out._columns.concat(
|
|
916
|
+
x._columns.map((c) => c + (out._columns.indexOf(c) > -1 ? " (2)" : ""))
|
|
917
|
+
);
|
|
918
|
+
return out;
|
|
870
919
|
}
|
|
871
920
|
} else {
|
|
872
|
-
throw new MathError(
|
|
921
|
+
throw new MathError(
|
|
922
|
+
"Only 1- or 2-dimensional arrays, Series, and DataFrames can be appended to a DataFrame!"
|
|
923
|
+
);
|
|
873
924
|
}
|
|
874
925
|
}
|
|
926
|
+
|
|
927
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-apply.mjs
|
|
875
928
|
function dfApply(DataFrame2, Series2, df, fn, axis) {
|
|
876
929
|
axis = axis || 0;
|
|
877
|
-
assert(
|
|
878
|
-
|
|
930
|
+
assert(
|
|
931
|
+
isFunction(fn),
|
|
932
|
+
"The first parameter to the `apply` method must be a function."
|
|
933
|
+
);
|
|
934
|
+
assert(
|
|
935
|
+
axis === 0 || axis === 1,
|
|
936
|
+
"The second parameter to the `apply` method (the `axis`) must be 0 or 1."
|
|
937
|
+
);
|
|
879
938
|
if (axis === 0) {
|
|
880
939
|
const temp = {};
|
|
881
940
|
let shouldReturnADataFrame;
|
|
@@ -894,13 +953,13 @@
|
|
|
894
953
|
}
|
|
895
954
|
});
|
|
896
955
|
if (shouldReturnADataFrame) {
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
return
|
|
956
|
+
const out = new DataFrame2(temp);
|
|
957
|
+
out.index = df.index;
|
|
958
|
+
return out;
|
|
900
959
|
} else {
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
return
|
|
960
|
+
const out = new Series2(df.columns.map((colName) => temp[colName]));
|
|
961
|
+
out.index = df.columns;
|
|
962
|
+
return out;
|
|
904
963
|
}
|
|
905
964
|
} else if (axis === 1) {
|
|
906
965
|
let shouldReturnADataFrame;
|
|
@@ -919,36 +978,48 @@
|
|
|
919
978
|
}
|
|
920
979
|
});
|
|
921
980
|
if (shouldReturnADataFrame) {
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
return
|
|
981
|
+
const out = new DataFrame2(temp);
|
|
982
|
+
out.index = df.index;
|
|
983
|
+
out.columns = df.columns;
|
|
984
|
+
return out;
|
|
926
985
|
} else {
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
return
|
|
986
|
+
const out = new Series2(temp);
|
|
987
|
+
out.index = df.index;
|
|
988
|
+
return out;
|
|
930
989
|
}
|
|
931
990
|
}
|
|
932
991
|
}
|
|
992
|
+
|
|
993
|
+
// node_modules/@jrc03c/js-math-tools/src/is-string.mjs
|
|
933
994
|
function isString(s2) {
|
|
934
995
|
return typeof s2 === "string";
|
|
935
996
|
}
|
|
997
|
+
|
|
998
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-assign.mjs
|
|
936
999
|
function dfAssign(DataFrame2, Series2, df, p1, p2) {
|
|
937
1000
|
const isDataFrame2 = (x) => x instanceof DataFrame2;
|
|
938
1001
|
const isSeries2 = (x) => x instanceof Series2;
|
|
939
1002
|
if (!isUndefined(p2)) {
|
|
940
|
-
assert(
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1003
|
+
assert(
|
|
1004
|
+
isString(p1),
|
|
1005
|
+
"If passing two arguments into the `assign` method, then the first argument must be a string name!"
|
|
1006
|
+
);
|
|
1007
|
+
assert(
|
|
1008
|
+
isArray(p2) && !isJagged(p2) && shape(p2).length === 1,
|
|
1009
|
+
"If passing two arguments into the `assign` method, then the second argument must be a 1-dimensional array!"
|
|
1010
|
+
);
|
|
1011
|
+
const out = df.append(p2, 1);
|
|
1012
|
+
out.columns[out.columns.length - 1] = p1;
|
|
1013
|
+
return out;
|
|
945
1014
|
} else {
|
|
946
1015
|
if (isDataFrame2(p1)) {
|
|
947
1016
|
return df.append(p1, 1);
|
|
948
1017
|
} else if (isSeries2(p1)) {
|
|
949
1018
|
return df.append(p1, 1);
|
|
950
1019
|
} else if (isObject(p1)) {
|
|
951
|
-
const maxColumnLength = Math.max(
|
|
1020
|
+
const maxColumnLength = Math.max(
|
|
1021
|
+
...Object.keys(p1).concat(Object.getOwnPropertySymbols(p1)).map((key) => p1[key].length)
|
|
1022
|
+
);
|
|
952
1023
|
Object.keys(p1).concat(Object.getOwnPropertySymbols(p1)).forEach((key) => {
|
|
953
1024
|
while (p1[key].length < maxColumnLength) {
|
|
954
1025
|
p1[key].push(void 0);
|
|
@@ -956,117 +1027,134 @@
|
|
|
956
1027
|
});
|
|
957
1028
|
return df.append(new DataFrame2(p1), 1);
|
|
958
1029
|
} else {
|
|
959
|
-
throw new MathError(
|
|
1030
|
+
throw new MathError(
|
|
1031
|
+
"You must pass a DataFrame, Series, or object into the `assign` method!"
|
|
1032
|
+
);
|
|
960
1033
|
}
|
|
961
1034
|
}
|
|
962
1035
|
}
|
|
1036
|
+
|
|
1037
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-copy.mjs
|
|
963
1038
|
function dfCopy(DataFrame2, df) {
|
|
964
|
-
if (df.isEmpty)
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
return out2;
|
|
1039
|
+
if (df.isEmpty) return new DataFrame2();
|
|
1040
|
+
const out = new DataFrame2(copy(df.values));
|
|
1041
|
+
out.columns = df.columns.slice();
|
|
1042
|
+
out.index = df.index.slice();
|
|
1043
|
+
return out;
|
|
970
1044
|
}
|
|
1045
|
+
|
|
1046
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop.mjs
|
|
971
1047
|
function dfDrop(DataFrame2, Series2, df, rows, cols) {
|
|
972
|
-
if (isUndefined(rows))
|
|
973
|
-
|
|
974
|
-
if (
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
rows
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
assert(
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1048
|
+
if (isUndefined(rows)) rows = [];
|
|
1049
|
+
if (isUndefined(cols)) cols = [];
|
|
1050
|
+
if (isString(rows) || isNumber(rows)) rows = [rows];
|
|
1051
|
+
if (isString(cols) || isNumber(cols)) cols = [cols];
|
|
1052
|
+
assert(
|
|
1053
|
+
isArray(rows),
|
|
1054
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1055
|
+
);
|
|
1056
|
+
assert(
|
|
1057
|
+
isArray(cols),
|
|
1058
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1059
|
+
);
|
|
1060
|
+
assert(
|
|
1061
|
+
shape(rows).length === 1,
|
|
1062
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1063
|
+
);
|
|
1064
|
+
assert(
|
|
1065
|
+
shape(cols).length === 1,
|
|
1066
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1067
|
+
);
|
|
984
1068
|
let outIndex, outColumns;
|
|
985
1069
|
df.index.forEach((row, i) => {
|
|
986
1070
|
if (rows.indexOf(row) < 0 && rows.indexOf(i) < 0) {
|
|
987
|
-
if (!outIndex)
|
|
988
|
-
outIndex = [];
|
|
1071
|
+
if (!outIndex) outIndex = [];
|
|
989
1072
|
outIndex.push(row);
|
|
990
1073
|
}
|
|
991
1074
|
});
|
|
992
1075
|
df.columns.forEach((col, i) => {
|
|
993
1076
|
if (cols.indexOf(col) < 0 && cols.indexOf(i) < 0) {
|
|
994
|
-
if (!outColumns)
|
|
995
|
-
outColumns = [];
|
|
1077
|
+
if (!outColumns) outColumns = [];
|
|
996
1078
|
outColumns.push(col);
|
|
997
1079
|
}
|
|
998
1080
|
});
|
|
999
|
-
let
|
|
1000
|
-
if (
|
|
1081
|
+
let out = df.get(outIndex, outColumns);
|
|
1082
|
+
if (out instanceof Series2) {
|
|
1001
1083
|
let temp = new DataFrame2();
|
|
1002
|
-
temp = temp.assign(
|
|
1003
|
-
if (df.index.indexOf(
|
|
1004
|
-
|
|
1005
|
-
out2 = temp;
|
|
1084
|
+
temp = temp.assign(out);
|
|
1085
|
+
if (df.index.indexOf(out.name) > -1) temp = temp.transpose();
|
|
1086
|
+
out = temp;
|
|
1006
1087
|
}
|
|
1007
|
-
return
|
|
1088
|
+
return out;
|
|
1008
1089
|
}
|
|
1090
|
+
|
|
1091
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/is-integer.mjs
|
|
1009
1092
|
function isInteger(x) {
|
|
1010
1093
|
return isNumber(x) && (x >= 0 ? Math.floor(x) === x : Math.ceil(x) === x);
|
|
1011
1094
|
}
|
|
1095
|
+
|
|
1096
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/is-whole-number.mjs
|
|
1012
1097
|
function isWholeNumber(x) {
|
|
1013
1098
|
return isInteger(x) && x >= 0;
|
|
1014
1099
|
}
|
|
1100
|
+
|
|
1101
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-missing.mjs
|
|
1015
1102
|
function dfDropMissing(DataFrame2, Series2, df, axis, condition, threshold) {
|
|
1016
1103
|
axis = axis || 0;
|
|
1017
|
-
assert(
|
|
1104
|
+
assert(
|
|
1105
|
+
axis === 0 || axis === 1,
|
|
1106
|
+
"The first parameter of the `dropMissing` method (the `axis`) must be 0 or 1."
|
|
1107
|
+
);
|
|
1018
1108
|
threshold = threshold || 0;
|
|
1019
|
-
assert(
|
|
1109
|
+
assert(
|
|
1110
|
+
isWholeNumber(threshold),
|
|
1111
|
+
"The third parameter of the `dropMissing` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` null values)."
|
|
1112
|
+
);
|
|
1020
1113
|
condition = threshold > 0 ? "none" : condition || "any";
|
|
1021
|
-
assert(
|
|
1022
|
-
|
|
1114
|
+
assert(
|
|
1115
|
+
condition === "any" || condition === "all" || condition === "none",
|
|
1116
|
+
"The second parameter of the `dropMissing` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains null values, then it should be dropped; or that if 'all' of the data contains null values, then it should be dropped)."
|
|
1117
|
+
);
|
|
1118
|
+
function helper4(values) {
|
|
1023
1119
|
if (threshold > 0) {
|
|
1024
1120
|
let count2 = 0;
|
|
1025
1121
|
for (let i = 0; i < values.length; i++) {
|
|
1026
1122
|
const value = values[i];
|
|
1027
|
-
if (isUndefined(value))
|
|
1028
|
-
|
|
1029
|
-
if (count2 >= threshold)
|
|
1030
|
-
return [];
|
|
1123
|
+
if (isUndefined(value)) count2++;
|
|
1124
|
+
if (count2 >= threshold) return [];
|
|
1031
1125
|
}
|
|
1032
1126
|
} else if (condition === "any") {
|
|
1033
1127
|
for (let i = 0; i < values.length; i++) {
|
|
1034
1128
|
const value = values[i];
|
|
1035
|
-
if (isUndefined(value))
|
|
1036
|
-
return [];
|
|
1129
|
+
if (isUndefined(value)) return [];
|
|
1037
1130
|
}
|
|
1038
1131
|
} else if (condition === "all") {
|
|
1039
1132
|
for (let i = 0; i < values.length; i++) {
|
|
1040
1133
|
const value = values[i];
|
|
1041
|
-
if (!isUndefined(value))
|
|
1042
|
-
return values;
|
|
1134
|
+
if (!isUndefined(value)) return values;
|
|
1043
1135
|
}
|
|
1044
1136
|
return [];
|
|
1045
1137
|
}
|
|
1046
1138
|
return values;
|
|
1047
1139
|
}
|
|
1048
|
-
let
|
|
1140
|
+
let out = df.copy();
|
|
1049
1141
|
const tempID = Math.random().toString();
|
|
1050
1142
|
if (axis === 0) {
|
|
1051
|
-
|
|
1052
|
-
const newValues =
|
|
1053
|
-
if (shape(newValues).length < 2)
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
if (newIndex instanceof Series2)
|
|
1062
|
-
newIndex = newIndex.values;
|
|
1063
|
-
out2.index = newIndex;
|
|
1064
|
-
out2 = out2.drop(null, tempID);
|
|
1143
|
+
out = out.assign(tempID, out.index);
|
|
1144
|
+
const newValues = out.values.map(helper4).filter((row) => row.length > 0);
|
|
1145
|
+
if (shape(newValues).length < 2) return new DataFrame2();
|
|
1146
|
+
out.values = newValues;
|
|
1147
|
+
let newIndex = out.get(null, tempID);
|
|
1148
|
+
if (isUndefined(newIndex)) return new DataFrame2();
|
|
1149
|
+
if (isString(newIndex)) newIndex = [newIndex];
|
|
1150
|
+
if (newIndex instanceof Series2) newIndex = newIndex.values;
|
|
1151
|
+
out.index = newIndex;
|
|
1152
|
+
out = out.drop(null, tempID);
|
|
1065
1153
|
} else if (axis === 1) {
|
|
1066
1154
|
const temp = {};
|
|
1067
|
-
|
|
1068
|
-
const values =
|
|
1069
|
-
const newValues =
|
|
1155
|
+
out.columns.forEach((colName, i) => {
|
|
1156
|
+
const values = out.values.map((row) => row[i]);
|
|
1157
|
+
const newValues = helper4(values);
|
|
1070
1158
|
if (newValues.length > 0) {
|
|
1071
1159
|
temp[colName] = newValues;
|
|
1072
1160
|
}
|
|
@@ -1075,90 +1163,105 @@
|
|
|
1075
1163
|
return new DataFrame2();
|
|
1076
1164
|
}
|
|
1077
1165
|
const newOut = new DataFrame2(temp);
|
|
1078
|
-
newOut.index =
|
|
1166
|
+
newOut.index = out.index;
|
|
1079
1167
|
return newOut;
|
|
1080
1168
|
}
|
|
1081
|
-
return
|
|
1169
|
+
return out;
|
|
1082
1170
|
}
|
|
1171
|
+
|
|
1172
|
+
// node_modules/@jrc03c/js-math-tools/src/drop-nan.mjs
|
|
1083
1173
|
function dropNaN(x) {
|
|
1084
1174
|
if (isDataFrame(x) || isSeries(x)) {
|
|
1085
1175
|
return x.dropNaN(...Object.values(arguments).slice(1));
|
|
1086
1176
|
}
|
|
1087
|
-
assert(
|
|
1088
|
-
|
|
1177
|
+
assert(
|
|
1178
|
+
isArray(x),
|
|
1179
|
+
"The `dropNaN` function only works on arrays, Series, and DataFrames!"
|
|
1180
|
+
);
|
|
1181
|
+
const out = [];
|
|
1089
1182
|
x.forEach((v) => {
|
|
1090
1183
|
try {
|
|
1091
|
-
return
|
|
1184
|
+
return out.push(dropNaN(v));
|
|
1092
1185
|
} catch (e) {
|
|
1093
1186
|
if (isNumber(v)) {
|
|
1094
|
-
return
|
|
1187
|
+
return out.push(v);
|
|
1095
1188
|
}
|
|
1096
1189
|
}
|
|
1097
1190
|
});
|
|
1098
|
-
return
|
|
1191
|
+
return out;
|
|
1099
1192
|
}
|
|
1193
|
+
|
|
1194
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-nan.mjs
|
|
1100
1195
|
function dfDropNaN(DataFrame2, df, axis, condition, threshold) {
|
|
1101
1196
|
axis = axis || 0;
|
|
1102
|
-
assert(
|
|
1197
|
+
assert(
|
|
1198
|
+
axis === 0 || axis === 1,
|
|
1199
|
+
"The first parameter of the `dropNaN` method (the `axis`) must be 0 or 1."
|
|
1200
|
+
);
|
|
1103
1201
|
threshold = threshold || 0;
|
|
1104
|
-
assert(
|
|
1202
|
+
assert(
|
|
1203
|
+
isWholeNumber(threshold),
|
|
1204
|
+
"The third parameter of the `dropNaN` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` NaN values)."
|
|
1205
|
+
);
|
|
1105
1206
|
condition = threshold > 0 ? "none" : condition || "any";
|
|
1106
|
-
assert(
|
|
1107
|
-
|
|
1207
|
+
assert(
|
|
1208
|
+
condition === "any" || condition === "all" || condition === "none",
|
|
1209
|
+
"The second parameter of the `dropNaN` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains NaN values, then it should be dropped; or that if 'all' of the data contains NaN values, then it should be dropped)."
|
|
1210
|
+
);
|
|
1211
|
+
function helper4(values) {
|
|
1108
1212
|
const numericalValues = dropNaN(values);
|
|
1109
|
-
if (threshold > 0)
|
|
1110
|
-
|
|
1111
|
-
if (condition === "
|
|
1112
|
-
return numericalValues.length === values.length;
|
|
1113
|
-
if (condition === "all")
|
|
1114
|
-
return numericalValues.length > 0;
|
|
1213
|
+
if (threshold > 0) return values.length - numericalValues.length < threshold;
|
|
1214
|
+
if (condition === "any") return numericalValues.length === values.length;
|
|
1215
|
+
if (condition === "all") return numericalValues.length > 0;
|
|
1115
1216
|
return true;
|
|
1116
1217
|
}
|
|
1117
|
-
const
|
|
1218
|
+
const out = df.copy();
|
|
1118
1219
|
if (axis === 0) {
|
|
1119
|
-
const rowsToKeep =
|
|
1120
|
-
const values =
|
|
1121
|
-
return
|
|
1220
|
+
const rowsToKeep = out.index.filter((row) => {
|
|
1221
|
+
const values = out.get(row, null).values;
|
|
1222
|
+
return helper4(values);
|
|
1122
1223
|
});
|
|
1123
|
-
if (rowsToKeep.length > 0)
|
|
1124
|
-
|
|
1125
|
-
else
|
|
1126
|
-
return new DataFrame2();
|
|
1224
|
+
if (rowsToKeep.length > 0) return out.get(rowsToKeep, null);
|
|
1225
|
+
else return new DataFrame2();
|
|
1127
1226
|
} else if (axis === 1) {
|
|
1128
|
-
const colsToKeep =
|
|
1129
|
-
const values =
|
|
1130
|
-
return
|
|
1227
|
+
const colsToKeep = out.columns.filter((col) => {
|
|
1228
|
+
const values = out.get(null, col).values;
|
|
1229
|
+
return helper4(values);
|
|
1131
1230
|
});
|
|
1132
|
-
if (colsToKeep.length > 0)
|
|
1133
|
-
|
|
1134
|
-
else
|
|
1135
|
-
return new DataFrame2();
|
|
1231
|
+
if (colsToKeep.length > 0) return out.get(null, colsToKeep);
|
|
1232
|
+
else return new DataFrame2();
|
|
1136
1233
|
}
|
|
1137
|
-
return
|
|
1234
|
+
return out;
|
|
1138
1235
|
}
|
|
1236
|
+
|
|
1237
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-filter.mjs
|
|
1139
1238
|
function arrayToObject(x) {
|
|
1140
|
-
const
|
|
1239
|
+
const out = {};
|
|
1141
1240
|
flatten(x).forEach((value, i) => {
|
|
1142
|
-
|
|
1241
|
+
out[value] = i;
|
|
1143
1242
|
});
|
|
1144
|
-
return
|
|
1243
|
+
return out;
|
|
1145
1244
|
}
|
|
1146
1245
|
function undoArrayToObject(obj) {
|
|
1147
1246
|
return Object.keys(obj).concat(Object.getOwnPropertySymbols(obj)).sort((a, b) => obj[a] - obj[b]);
|
|
1148
1247
|
}
|
|
1149
1248
|
function dfFilter(DataFrame2, Series2, df, fn, axis) {
|
|
1150
|
-
assert(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1249
|
+
assert(
|
|
1250
|
+
isFunction(fn),
|
|
1251
|
+
"The `filter` method takes a single parameter: a function that is used to filter the values."
|
|
1252
|
+
);
|
|
1253
|
+
if (isUndefined(axis)) axis = 0;
|
|
1254
|
+
assert(
|
|
1255
|
+
axis === 0 || axis === 1,
|
|
1256
|
+
"The `axis` parameter to the `filter` method must be 0 or 1."
|
|
1257
|
+
);
|
|
1258
|
+
let out = df.copy();
|
|
1259
|
+
if (out.isEmpty) return out;
|
|
1260
|
+
const index = arrayToObject(out.index);
|
|
1261
|
+
const columns = arrayToObject(out.columns);
|
|
1159
1262
|
if (axis === 0) {
|
|
1160
1263
|
let count2 = 0;
|
|
1161
|
-
const newValues =
|
|
1264
|
+
const newValues = out.values.filter((row, i) => {
|
|
1162
1265
|
const series = new Series2(row);
|
|
1163
1266
|
series.name = df.index[i];
|
|
1164
1267
|
series.index = df.columns;
|
|
@@ -1166,7 +1269,7 @@
|
|
|
1166
1269
|
if (shouldKeep) {
|
|
1167
1270
|
count2++;
|
|
1168
1271
|
} else {
|
|
1169
|
-
delete index[
|
|
1272
|
+
delete index[out.index[i]];
|
|
1170
1273
|
}
|
|
1171
1274
|
return shouldKeep;
|
|
1172
1275
|
});
|
|
@@ -1179,12 +1282,12 @@
|
|
|
1179
1282
|
temp.index = undoArrayToObject(columns);
|
|
1180
1283
|
return temp;
|
|
1181
1284
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1285
|
+
out.values = newValues;
|
|
1286
|
+
out.index = undoArrayToObject(index);
|
|
1184
1287
|
} else if (axis === 1) {
|
|
1185
|
-
|
|
1288
|
+
out = out.transpose();
|
|
1186
1289
|
let count2 = 0;
|
|
1187
|
-
const newValues =
|
|
1290
|
+
const newValues = out.values.filter((row, i) => {
|
|
1188
1291
|
const series = new Series2(row);
|
|
1189
1292
|
series.name = df.columns[i];
|
|
1190
1293
|
series.index = df.index;
|
|
@@ -1192,7 +1295,7 @@
|
|
|
1192
1295
|
if (shouldKeep) {
|
|
1193
1296
|
count2++;
|
|
1194
1297
|
} else {
|
|
1195
|
-
delete columns[
|
|
1298
|
+
delete columns[out.index[i]];
|
|
1196
1299
|
}
|
|
1197
1300
|
return shouldKeep;
|
|
1198
1301
|
});
|
|
@@ -1205,17 +1308,17 @@
|
|
|
1205
1308
|
temp.index = undoArrayToObject(index);
|
|
1206
1309
|
return temp;
|
|
1207
1310
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1311
|
+
out.values = newValues;
|
|
1312
|
+
out.index = undoArrayToObject(columns);
|
|
1313
|
+
out = out.transpose();
|
|
1211
1314
|
}
|
|
1212
|
-
return
|
|
1315
|
+
return out;
|
|
1213
1316
|
}
|
|
1317
|
+
|
|
1318
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-get.mjs
|
|
1214
1319
|
function dfGet(df, rows, cols) {
|
|
1215
|
-
if (isString(rows) || isNumber(rows))
|
|
1216
|
-
|
|
1217
|
-
if (isString(cols) || isNumber(cols))
|
|
1218
|
-
cols = [cols];
|
|
1320
|
+
if (isString(rows) || isNumber(rows)) rows = [rows];
|
|
1321
|
+
if (isString(cols) || isNumber(cols)) cols = [cols];
|
|
1219
1322
|
for (const i in rows) {
|
|
1220
1323
|
if (typeof rows[i] === "bigint") {
|
|
1221
1324
|
rows[i] = Number(rows[i]);
|
|
@@ -1227,13 +1330,25 @@
|
|
|
1227
1330
|
}
|
|
1228
1331
|
}
|
|
1229
1332
|
const types = set((rows || []).concat(cols || []).map((v) => typeof v));
|
|
1230
|
-
assert(
|
|
1333
|
+
assert(
|
|
1334
|
+
types.length <= 2,
|
|
1335
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1336
|
+
);
|
|
1231
1337
|
if (types.length === 1) {
|
|
1232
|
-
assert(
|
|
1338
|
+
assert(
|
|
1339
|
+
types[0] === "string" || types[0] === "number",
|
|
1340
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1341
|
+
);
|
|
1233
1342
|
}
|
|
1234
1343
|
if (types.length === 2) {
|
|
1235
|
-
assert(
|
|
1236
|
-
|
|
1344
|
+
assert(
|
|
1345
|
+
types.indexOf("string") > -1,
|
|
1346
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1347
|
+
);
|
|
1348
|
+
assert(
|
|
1349
|
+
types.indexOf("number") > -1,
|
|
1350
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1351
|
+
);
|
|
1237
1352
|
}
|
|
1238
1353
|
if (!isUndefined(rows)) {
|
|
1239
1354
|
rows = rows.map((r) => {
|
|
@@ -1265,47 +1380,52 @@
|
|
|
1265
1380
|
}
|
|
1266
1381
|
return df.getSubsetByNames(rows, cols);
|
|
1267
1382
|
}
|
|
1383
|
+
|
|
1384
|
+
// node_modules/@jrc03c/js-math-tools/src/sort.mjs
|
|
1268
1385
|
function alphaSort(a, b) {
|
|
1269
1386
|
try {
|
|
1270
|
-
if (a < b)
|
|
1271
|
-
|
|
1272
|
-
if (a > b)
|
|
1273
|
-
return 1;
|
|
1387
|
+
if (a < b) return -1;
|
|
1388
|
+
if (a > b) return 1;
|
|
1274
1389
|
return 0;
|
|
1275
1390
|
} catch (e) {
|
|
1276
1391
|
a = typeof a === "object" && a !== null ? JSON.stringify(a) : a.toString();
|
|
1277
1392
|
b = typeof b === "object" && b !== null ? JSON.stringify(b) : b.toString();
|
|
1278
|
-
if (a < b)
|
|
1279
|
-
|
|
1280
|
-
if (a > b)
|
|
1281
|
-
return 1;
|
|
1393
|
+
if (a < b) return -1;
|
|
1394
|
+
if (a > b) return 1;
|
|
1282
1395
|
return 0;
|
|
1283
1396
|
}
|
|
1284
1397
|
}
|
|
1285
1398
|
function sort(arr, fn) {
|
|
1286
|
-
if (isUndefined(fn))
|
|
1287
|
-
fn = alphaSort;
|
|
1399
|
+
if (isUndefined(fn)) fn = alphaSort;
|
|
1288
1400
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1289
1401
|
return arr.sort(...Object.values(arguments).slice(1));
|
|
1290
1402
|
}
|
|
1291
|
-
assert(
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1403
|
+
assert(
|
|
1404
|
+
isArray(arr),
|
|
1405
|
+
"The `sort` function only works on arrays, Series, and DataFrames!"
|
|
1406
|
+
);
|
|
1407
|
+
assert(
|
|
1408
|
+
isFunction(fn),
|
|
1409
|
+
"The second parameter of the `sort` function must be a comparison function!"
|
|
1410
|
+
);
|
|
1411
|
+
const out = arr.slice();
|
|
1412
|
+
out.sort(fn);
|
|
1413
|
+
return out;
|
|
1296
1414
|
}
|
|
1415
|
+
|
|
1416
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-dummies.mjs
|
|
1297
1417
|
function camelify(text) {
|
|
1298
1418
|
const temp = text.toLowerCase();
|
|
1299
|
-
let
|
|
1419
|
+
let out = "";
|
|
1300
1420
|
for (let i = 0; i < temp.length; i++) {
|
|
1301
1421
|
const char = temp[i];
|
|
1302
1422
|
if (char.match(/[a-z0-9]/g)) {
|
|
1303
|
-
|
|
1423
|
+
out += char;
|
|
1304
1424
|
} else {
|
|
1305
|
-
|
|
1425
|
+
out += " ";
|
|
1306
1426
|
}
|
|
1307
1427
|
}
|
|
1308
|
-
const words =
|
|
1428
|
+
const words = out.split(" ").filter((word) => word.length > 0);
|
|
1309
1429
|
return words[0] + words.slice(1).map((word) => word[0].toUpperCase() + word.substring(1)).join("");
|
|
1310
1430
|
}
|
|
1311
1431
|
function dfGetDummies(DataFrame2, df, columns) {
|
|
@@ -1316,9 +1436,15 @@
|
|
|
1316
1436
|
}
|
|
1317
1437
|
const temp = {};
|
|
1318
1438
|
columns.forEach((col) => {
|
|
1319
|
-
assert(
|
|
1439
|
+
assert(
|
|
1440
|
+
isString(col),
|
|
1441
|
+
"You must pass either a string or a one-dimensional array of strings into the `getDummies` (AKA `oneHotEncode`) method!"
|
|
1442
|
+
);
|
|
1320
1443
|
const colIndex = df.columns.indexOf(col);
|
|
1321
|
-
assert(
|
|
1444
|
+
assert(
|
|
1445
|
+
colIndex > -1,
|
|
1446
|
+
`The given DataFrame does not have a column called "${col}"!`
|
|
1447
|
+
);
|
|
1322
1448
|
const values = df.values.map((row) => row[colIndex]);
|
|
1323
1449
|
const valuesSet = sort(set(values));
|
|
1324
1450
|
values.forEach((value) => {
|
|
@@ -1335,56 +1461,100 @@
|
|
|
1335
1461
|
});
|
|
1336
1462
|
});
|
|
1337
1463
|
});
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
return
|
|
1464
|
+
const out = new DataFrame2(temp);
|
|
1465
|
+
out.index = df.index;
|
|
1466
|
+
return out;
|
|
1341
1467
|
}
|
|
1468
|
+
|
|
1469
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-indices.mjs
|
|
1342
1470
|
function dfGetSubsetByIndices(df, rowIndices, colIndices) {
|
|
1343
1471
|
const dataShape = df.shape;
|
|
1344
|
-
if (isUndefined(rowIndices))
|
|
1345
|
-
|
|
1346
|
-
if (
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
rowIndices
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
assert(
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1472
|
+
if (isUndefined(rowIndices)) rowIndices = range(0, dataShape[0]);
|
|
1473
|
+
if (isUndefined(colIndices)) colIndices = range(0, dataShape[1]);
|
|
1474
|
+
if (isNumber(rowIndices)) rowIndices = [rowIndices];
|
|
1475
|
+
if (isNumber(colIndices)) colIndices = [colIndices];
|
|
1476
|
+
assert(
|
|
1477
|
+
isArray(rowIndices) && isArray(colIndices),
|
|
1478
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1479
|
+
);
|
|
1480
|
+
assert(
|
|
1481
|
+
shape(rowIndices).length === 1 && shape(colIndices).length === 1,
|
|
1482
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1483
|
+
);
|
|
1484
|
+
assert(
|
|
1485
|
+
rowIndices.length > 0,
|
|
1486
|
+
"The `rowIndices` array must contain at least one index."
|
|
1487
|
+
);
|
|
1488
|
+
assert(
|
|
1489
|
+
colIndices.length > 0,
|
|
1490
|
+
"The `colIndices` array must contain at least one index."
|
|
1491
|
+
);
|
|
1356
1492
|
rowIndices.forEach((rowIndex) => {
|
|
1357
|
-
assert(
|
|
1358
|
-
|
|
1493
|
+
assert(
|
|
1494
|
+
isWholeNumber(rowIndex),
|
|
1495
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1496
|
+
);
|
|
1497
|
+
assert(
|
|
1498
|
+
rowIndex < df.index.length,
|
|
1499
|
+
`The row index ${rowIndex} is out of bounds.`
|
|
1500
|
+
);
|
|
1359
1501
|
});
|
|
1360
1502
|
colIndices.forEach((colIndex) => {
|
|
1361
|
-
assert(
|
|
1362
|
-
|
|
1503
|
+
assert(
|
|
1504
|
+
isWholeNumber(colIndex),
|
|
1505
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1506
|
+
);
|
|
1507
|
+
assert(
|
|
1508
|
+
colIndex < df.columns.length,
|
|
1509
|
+
`The column index ${colIndex} is out of bounds.`
|
|
1510
|
+
);
|
|
1363
1511
|
});
|
|
1364
1512
|
const rows = rowIndices.map((i) => df.index[i]);
|
|
1365
1513
|
const cols = colIndices.map((i) => df.columns[i]);
|
|
1366
1514
|
return df.getSubsetByNames(rows, cols);
|
|
1367
1515
|
}
|
|
1516
|
+
|
|
1517
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-names.mjs
|
|
1368
1518
|
function dfGetSubsetByNames(DataFrame2, Series2, df, rows, cols) {
|
|
1369
|
-
if (isUndefined(rows))
|
|
1370
|
-
|
|
1371
|
-
if (
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
rows
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
assert(
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1519
|
+
if (isUndefined(rows)) rows = df.index;
|
|
1520
|
+
if (isUndefined(cols)) cols = df.columns;
|
|
1521
|
+
if (isString(rows)) rows = [rows];
|
|
1522
|
+
if (isString(cols)) cols = [cols];
|
|
1523
|
+
assert(
|
|
1524
|
+
isArray(rows) && isArray(cols),
|
|
1525
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1526
|
+
);
|
|
1527
|
+
assert(
|
|
1528
|
+
shape(rows).length === 1 && shape(cols).length === 1,
|
|
1529
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1530
|
+
);
|
|
1531
|
+
assert(
|
|
1532
|
+
rows.length > 0,
|
|
1533
|
+
"The `rows` array must contain at least one row name."
|
|
1534
|
+
);
|
|
1535
|
+
assert(
|
|
1536
|
+
cols.length > 0,
|
|
1537
|
+
"The `cols` array must contain at least one column name."
|
|
1538
|
+
);
|
|
1381
1539
|
rows.forEach((row) => {
|
|
1382
|
-
assert(
|
|
1383
|
-
|
|
1540
|
+
assert(
|
|
1541
|
+
isString(row),
|
|
1542
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1543
|
+
);
|
|
1544
|
+
assert(
|
|
1545
|
+
df.index.indexOf(row) > -1,
|
|
1546
|
+
`The row name "${row}" does not exist in the list of rows.`
|
|
1547
|
+
);
|
|
1384
1548
|
});
|
|
1385
1549
|
cols.forEach((col) => {
|
|
1386
|
-
assert(
|
|
1387
|
-
|
|
1550
|
+
assert(
|
|
1551
|
+
isString(col),
|
|
1552
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1553
|
+
);
|
|
1554
|
+
assert(
|
|
1555
|
+
df.columns.indexOf(col) > -1,
|
|
1556
|
+
`The column name "${col}" does not exist in the list of columns.`
|
|
1557
|
+
);
|
|
1388
1558
|
});
|
|
1389
1559
|
const values = rows.map((row) => {
|
|
1390
1560
|
return cols.map((col) => {
|
|
@@ -1395,22 +1565,24 @@
|
|
|
1395
1565
|
return values[0][0];
|
|
1396
1566
|
}
|
|
1397
1567
|
if (rows.length === 1) {
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
return
|
|
1568
|
+
const out2 = new Series2(values[0]);
|
|
1569
|
+
out2.name = rows[0];
|
|
1570
|
+
out2.index = cols;
|
|
1571
|
+
return out2;
|
|
1402
1572
|
}
|
|
1403
1573
|
if (cols.length === 1) {
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
return
|
|
1408
|
-
}
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
return
|
|
1574
|
+
const out2 = new Series2(values.map((v) => v[0]));
|
|
1575
|
+
out2.name = cols[0];
|
|
1576
|
+
out2.index = rows;
|
|
1577
|
+
return out2;
|
|
1578
|
+
}
|
|
1579
|
+
const out = new DataFrame2(values);
|
|
1580
|
+
out.columns = cols;
|
|
1581
|
+
out.index = rows;
|
|
1582
|
+
return out;
|
|
1413
1583
|
}
|
|
1584
|
+
|
|
1585
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-print.mjs
|
|
1414
1586
|
function dfPrint(DataFrame2, Series2, df) {
|
|
1415
1587
|
function truncate(s2, maxLength2) {
|
|
1416
1588
|
if (isString(s2)) {
|
|
@@ -1430,10 +1602,14 @@
|
|
|
1430
1602
|
}
|
|
1431
1603
|
const maxRows = typeof window === "undefined" ? 20 : 10;
|
|
1432
1604
|
const halfMaxRows = Math.floor(maxRows / 2);
|
|
1433
|
-
const maxColumns =
|
|
1605
|
+
const maxColumns = 4;
|
|
1434
1606
|
const halfMaxColumns = Math.floor(maxColumns / 2);
|
|
1435
|
-
const tempRows = maxRows > df.index.length ? null : range(0, halfMaxRows).concat(
|
|
1436
|
-
|
|
1607
|
+
const tempRows = maxRows > df.index.length ? null : range(0, halfMaxRows).concat(
|
|
1608
|
+
range(df.index.length - halfMaxRows, df.index.length)
|
|
1609
|
+
);
|
|
1610
|
+
const tempColumns = maxColumns > df.columns.length ? null : range(0, halfMaxColumns).concat(
|
|
1611
|
+
range(df.columns.length - halfMaxColumns, df.columns.length)
|
|
1612
|
+
);
|
|
1437
1613
|
let temp = df.get(tempRows, tempColumns);
|
|
1438
1614
|
if (temp instanceof Series2) {
|
|
1439
1615
|
if (df.shape[0] === 1) {
|
|
@@ -1448,7 +1624,11 @@
|
|
|
1448
1624
|
}
|
|
1449
1625
|
if (maxRows <= df.index.length) {
|
|
1450
1626
|
temp._index.splice(halfMaxRows, 0, "...");
|
|
1451
|
-
temp._values.splice(
|
|
1627
|
+
temp._values.splice(
|
|
1628
|
+
halfMaxRows,
|
|
1629
|
+
0,
|
|
1630
|
+
range(0, temp.columns.length).map(() => "...")
|
|
1631
|
+
);
|
|
1452
1632
|
}
|
|
1453
1633
|
if (maxColumns <= df.columns.length) {
|
|
1454
1634
|
temp._columns.splice(halfMaxColumns, 0, "...");
|
|
@@ -1473,31 +1653,38 @@
|
|
|
1473
1653
|
console.log("Shape:", df.shape, "\n");
|
|
1474
1654
|
return df;
|
|
1475
1655
|
}
|
|
1656
|
+
|
|
1657
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/left-pad.mjs
|
|
1476
1658
|
function leftPad(x, maxLength) {
|
|
1477
1659
|
assert(isNumber(x), "The `leftPad` function only works on numbers!");
|
|
1478
|
-
let
|
|
1479
|
-
while (
|
|
1480
|
-
|
|
1481
|
-
return out2;
|
|
1660
|
+
let out = x.toString();
|
|
1661
|
+
while (out.length < maxLength) out = "0" + out;
|
|
1662
|
+
return out;
|
|
1482
1663
|
}
|
|
1664
|
+
|
|
1665
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-reset-index.mjs
|
|
1483
1666
|
function dfResetIndex(df, shouldSkipCopying) {
|
|
1484
|
-
const
|
|
1485
|
-
|
|
1486
|
-
return "row" + leftPad(i, (
|
|
1667
|
+
const out = shouldSkipCopying ? df : df.copy();
|
|
1668
|
+
out.index = range(0, df.shape[0]).map((i) => {
|
|
1669
|
+
return "row" + leftPad(i, (out.index.length - 1).toString().length);
|
|
1487
1670
|
});
|
|
1488
|
-
return
|
|
1671
|
+
return out;
|
|
1489
1672
|
}
|
|
1673
|
+
|
|
1674
|
+
// node_modules/@jrc03c/js-math-tools/src/product.mjs
|
|
1490
1675
|
function product(arr, shouldDropNaNs) {
|
|
1491
1676
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1492
1677
|
return product(arr.values, shouldDropNaNs);
|
|
1493
1678
|
}
|
|
1494
|
-
assert(
|
|
1679
|
+
assert(
|
|
1680
|
+
isArray(arr),
|
|
1681
|
+
"The `product` function only works on arrays, Series, and DataFrames!"
|
|
1682
|
+
);
|
|
1495
1683
|
try {
|
|
1496
|
-
if (arr.length === 0)
|
|
1497
|
-
return NaN;
|
|
1684
|
+
if (arr.length === 0) return NaN;
|
|
1498
1685
|
const temp = flatten(arr);
|
|
1499
1686
|
let resultShouldBeABigInt = false;
|
|
1500
|
-
let
|
|
1687
|
+
let out = 1;
|
|
1501
1688
|
for (let v of temp) {
|
|
1502
1689
|
if (!isNumber(v)) {
|
|
1503
1690
|
if (shouldDropNaNs) {
|
|
@@ -1510,36 +1697,51 @@
|
|
|
1510
1697
|
resultShouldBeABigInt = true;
|
|
1511
1698
|
v = Number(v);
|
|
1512
1699
|
}
|
|
1513
|
-
|
|
1700
|
+
out *= v;
|
|
1514
1701
|
}
|
|
1515
1702
|
if (resultShouldBeABigInt) {
|
|
1516
1703
|
try {
|
|
1517
|
-
return BigInt(
|
|
1704
|
+
return BigInt(out);
|
|
1518
1705
|
} catch (e) {
|
|
1519
1706
|
}
|
|
1520
1707
|
}
|
|
1521
|
-
return
|
|
1708
|
+
return out;
|
|
1522
1709
|
} catch (e) {
|
|
1523
1710
|
return NaN;
|
|
1524
1711
|
}
|
|
1525
1712
|
}
|
|
1713
|
+
|
|
1714
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/is-natural-number.mjs
|
|
1526
1715
|
function isNaturalNumber(x) {
|
|
1527
1716
|
return isInteger(x) && x > 0;
|
|
1528
1717
|
}
|
|
1718
|
+
|
|
1719
|
+
// node_modules/@jrc03c/js-math-tools/src/reshape.mjs
|
|
1529
1720
|
function reshape(x, newShape) {
|
|
1530
1721
|
if (isDataFrame(x) || isSeries(x)) {
|
|
1531
1722
|
return reshape(x.values, newShape);
|
|
1532
1723
|
}
|
|
1533
|
-
assert(
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1724
|
+
assert(
|
|
1725
|
+
isArray(x),
|
|
1726
|
+
"The first argument passed into the `reshape` function must be an array!"
|
|
1727
|
+
);
|
|
1728
|
+
if (isNumber(newShape)) newShape = [newShape];
|
|
1729
|
+
assert(
|
|
1730
|
+
isArray(newShape),
|
|
1731
|
+
"The second argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1732
|
+
);
|
|
1733
|
+
assert(
|
|
1734
|
+
shape(newShape).length === 1,
|
|
1735
|
+
"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1736
|
+
);
|
|
1538
1737
|
newShape = newShape.map((v) => {
|
|
1539
1738
|
if (typeof v === "bigint") {
|
|
1540
1739
|
v = Number(v);
|
|
1541
1740
|
}
|
|
1542
|
-
assert(
|
|
1741
|
+
assert(
|
|
1742
|
+
isNaturalNumber(v),
|
|
1743
|
+
"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1744
|
+
);
|
|
1543
1745
|
return Number(v);
|
|
1544
1746
|
});
|
|
1545
1747
|
if (newShape.length === 0) {
|
|
@@ -1549,31 +1751,35 @@
|
|
|
1549
1751
|
if (newShape.length === 1 && newShape[0] === temp.length) {
|
|
1550
1752
|
return temp;
|
|
1551
1753
|
}
|
|
1552
|
-
assert(
|
|
1553
|
-
|
|
1754
|
+
assert(
|
|
1755
|
+
product(newShape) === temp.length,
|
|
1756
|
+
"The new shape doesn't match the number of values available in `x` (the first argument passed into the `reshape` function)!"
|
|
1757
|
+
);
|
|
1758
|
+
const out = [];
|
|
1554
1759
|
const step = Math.floor(temp.length / newShape[0]);
|
|
1555
1760
|
for (let i = 0; i < newShape[0]; i++) {
|
|
1556
1761
|
const row = temp.slice(i * step, (i + 1) * step);
|
|
1557
|
-
|
|
1762
|
+
out.push(reshape(row, newShape.slice(1)));
|
|
1558
1763
|
}
|
|
1559
|
-
return
|
|
1764
|
+
return out;
|
|
1560
1765
|
}
|
|
1766
|
+
|
|
1767
|
+
// node_modules/@jrc03c/js-math-tools/src/random.mjs
|
|
1561
1768
|
var MAX = Math.pow(2, 64);
|
|
1562
1769
|
var s = [];
|
|
1563
1770
|
seed(Math.floor(Math.random() * MAX));
|
|
1564
1771
|
function splitmix64(state, n) {
|
|
1565
1772
|
state = uint(state);
|
|
1566
|
-
function
|
|
1773
|
+
function helper4() {
|
|
1567
1774
|
state += uint("0x9e3779b97f4a7c15");
|
|
1568
1775
|
let z = copy(state);
|
|
1569
1776
|
z = (z ^ z >> BigInt(30)) * uint("0xbf58476d1ce4e5b9");
|
|
1570
1777
|
z = (z ^ z >> BigInt(27)) * uint("0x94d049bb133111eb");
|
|
1571
1778
|
return z ^ z >> BigInt(31);
|
|
1572
1779
|
}
|
|
1573
|
-
const
|
|
1574
|
-
for (let i = 0; i < n; i++)
|
|
1575
|
-
|
|
1576
|
-
return out2;
|
|
1780
|
+
const out = [];
|
|
1781
|
+
for (let i = 0; i < n; i++) out.push(helper4());
|
|
1782
|
+
return out;
|
|
1577
1783
|
}
|
|
1578
1784
|
function uint(x) {
|
|
1579
1785
|
return BigInt.asUintN(64, BigInt(x));
|
|
@@ -1588,7 +1794,10 @@
|
|
|
1588
1794
|
val = Number(val);
|
|
1589
1795
|
}
|
|
1590
1796
|
if (!isUndefined(val)) {
|
|
1591
|
-
assert(
|
|
1797
|
+
assert(
|
|
1798
|
+
isNumber(val),
|
|
1799
|
+
"If passing a value into the `seed` function, then that value must be an integer!"
|
|
1800
|
+
);
|
|
1592
1801
|
const temp = splitmix64(Math.floor(val), 4);
|
|
1593
1802
|
s[0] = temp[0];
|
|
1594
1803
|
s[1] = temp[1];
|
|
@@ -1610,34 +1819,48 @@
|
|
|
1610
1819
|
return Math.floor(Number(result)) / MAX;
|
|
1611
1820
|
}
|
|
1612
1821
|
function random(shape2) {
|
|
1613
|
-
if (isUndefined(shape2))
|
|
1614
|
-
|
|
1615
|
-
if (!isArray(shape2))
|
|
1616
|
-
shape2 = [shape2];
|
|
1822
|
+
if (isUndefined(shape2)) return next();
|
|
1823
|
+
if (!isArray(shape2)) shape2 = [shape2];
|
|
1617
1824
|
return reshape(ndarray(product(shape2)).map(next), shape2);
|
|
1618
1825
|
}
|
|
1826
|
+
|
|
1827
|
+
// node_modules/@jrc03c/js-math-tools/src/shuffle.mjs
|
|
1619
1828
|
function shuffle(arr) {
|
|
1620
1829
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1621
1830
|
return arr.shuffle(...Object.values(arguments).slice(1));
|
|
1622
1831
|
}
|
|
1623
|
-
assert(
|
|
1624
|
-
|
|
1832
|
+
assert(
|
|
1833
|
+
isArray(arr),
|
|
1834
|
+
"The `shuffle` function only works on arrays, Series, and DataFrames!"
|
|
1835
|
+
);
|
|
1836
|
+
const out = [];
|
|
1625
1837
|
const temp = arr.slice();
|
|
1626
1838
|
for (let i = 0; i < arr.length; i++) {
|
|
1627
1839
|
const index = Math.floor(random() * temp.length);
|
|
1628
|
-
|
|
1840
|
+
out.push(temp.splice(index, 1)[0]);
|
|
1629
1841
|
}
|
|
1630
|
-
return
|
|
1842
|
+
return out;
|
|
1631
1843
|
}
|
|
1844
|
+
|
|
1845
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-shuffle.mjs
|
|
1632
1846
|
function dfShuffle(df, axis) {
|
|
1633
|
-
if (isUndefined(axis))
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1847
|
+
if (isUndefined(axis)) axis = 0;
|
|
1848
|
+
assert(
|
|
1849
|
+
axis === 0 || axis === 1,
|
|
1850
|
+
"The `axis` parameter to the `shuffle` must be 0, 1, or undefined."
|
|
1851
|
+
);
|
|
1852
|
+
return df.get(
|
|
1853
|
+
axis === 0 ? shuffle(df.index) : null,
|
|
1854
|
+
axis === 1 ? shuffle(df.columns) : null
|
|
1855
|
+
);
|
|
1637
1856
|
}
|
|
1857
|
+
|
|
1858
|
+
// node_modules/@jrc03c/js-math-tools/src/is-boolean.mjs
|
|
1638
1859
|
function isBoolean(x) {
|
|
1639
1860
|
return typeof x === "boolean";
|
|
1640
1861
|
}
|
|
1862
|
+
|
|
1863
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-sort.mjs
|
|
1641
1864
|
function dfSort(df, a, b) {
|
|
1642
1865
|
if (isFunction(a)) {
|
|
1643
1866
|
return dfSortByFunction(df, a, b);
|
|
@@ -1647,8 +1870,14 @@
|
|
|
1647
1870
|
}
|
|
1648
1871
|
function dfSortByFunction(df, fn, axis) {
|
|
1649
1872
|
axis = isUndefined(axis) ? 0 : axis;
|
|
1650
|
-
assert(
|
|
1651
|
-
|
|
1873
|
+
assert(
|
|
1874
|
+
isFunction(fn),
|
|
1875
|
+
"When sorting a DataFrame using a function, the first argument to the `sort` method must be a function!"
|
|
1876
|
+
);
|
|
1877
|
+
assert(
|
|
1878
|
+
isNumber(axis),
|
|
1879
|
+
"When sorting a DataFrame using a function, the second argument to the `sort` method must be null, undefined, 0, or 1 to indicate the axis along which the data should be sorted! An axis of 0 means that the rows will be sorted relative to each other, whereas an axis of 1 means that the columns will be sorted relative to each other."
|
|
1880
|
+
);
|
|
1652
1881
|
if (axis === 0) {
|
|
1653
1882
|
const index = sort(df.index, (a, b) => {
|
|
1654
1883
|
return fn(df.get(a, null), df.get(b, null));
|
|
@@ -1662,81 +1891,106 @@
|
|
|
1662
1891
|
}
|
|
1663
1892
|
}
|
|
1664
1893
|
function dfSortByColumns(df, cols, directions) {
|
|
1665
|
-
let
|
|
1894
|
+
let out = df.copy();
|
|
1666
1895
|
const indexID = random().toString();
|
|
1667
|
-
|
|
1896
|
+
out = out.assign(indexID, out.index);
|
|
1668
1897
|
if (isUndefined(cols)) {
|
|
1669
1898
|
cols = [indexID];
|
|
1670
1899
|
directions = [true];
|
|
1671
1900
|
}
|
|
1672
1901
|
if (isNumber(cols) || isString(cols)) {
|
|
1673
1902
|
cols = [cols];
|
|
1674
|
-
if (isBoolean(directions) || isString(directions))
|
|
1675
|
-
directions = [directions];
|
|
1903
|
+
if (isBoolean(directions) || isString(directions)) directions = [directions];
|
|
1676
1904
|
}
|
|
1677
|
-
assert(
|
|
1678
|
-
|
|
1905
|
+
assert(
|
|
1906
|
+
isArray(cols),
|
|
1907
|
+
"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."
|
|
1908
|
+
);
|
|
1909
|
+
assert(
|
|
1910
|
+
shape(cols).length === 1,
|
|
1911
|
+
"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."
|
|
1912
|
+
);
|
|
1679
1913
|
if (isUndefined(directions))
|
|
1680
1914
|
directions = range(0, cols.length).map(() => true);
|
|
1681
|
-
assert(
|
|
1682
|
-
|
|
1683
|
-
|
|
1915
|
+
assert(
|
|
1916
|
+
isArray(directions),
|
|
1917
|
+
"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."
|
|
1918
|
+
);
|
|
1919
|
+
assert(
|
|
1920
|
+
shape(directions).length === 1,
|
|
1921
|
+
"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."
|
|
1922
|
+
);
|
|
1923
|
+
assert(
|
|
1924
|
+
cols.length === directions.length,
|
|
1925
|
+
"The arrays passed into the `sort` method must be equal in length."
|
|
1926
|
+
);
|
|
1684
1927
|
cols = cols.map((col) => {
|
|
1685
|
-
assert(
|
|
1928
|
+
assert(
|
|
1929
|
+
isString(col) || isNumber(col),
|
|
1930
|
+
"Column references can either be column names (as strings) or column indices (as whole numbers)."
|
|
1931
|
+
);
|
|
1686
1932
|
if (isString(col)) {
|
|
1687
|
-
const index =
|
|
1933
|
+
const index = out.columns.indexOf(col);
|
|
1688
1934
|
assert(index > -1, `The column "${col}" does not exist!`);
|
|
1689
1935
|
return index;
|
|
1690
1936
|
}
|
|
1691
1937
|
if (isNumber(col)) {
|
|
1692
1938
|
assert(isWholeNumber(col), "Column indices must be whole numbers!");
|
|
1693
|
-
assert(col <
|
|
1939
|
+
assert(col < out.columns.length, `The index ${col} is out of bounds!`);
|
|
1694
1940
|
return col;
|
|
1695
1941
|
}
|
|
1696
1942
|
});
|
|
1697
1943
|
directions = directions.map((dir) => {
|
|
1698
|
-
assert(
|
|
1944
|
+
assert(
|
|
1945
|
+
isString(dir) || isBoolean(dir),
|
|
1946
|
+
"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
|
|
1947
|
+
);
|
|
1699
1948
|
if (isString(dir)) {
|
|
1700
1949
|
const value = dir.trim().toLowerCase();
|
|
1701
|
-
assert(
|
|
1950
|
+
assert(
|
|
1951
|
+
value === "ascending" || value === "descending",
|
|
1952
|
+
"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
|
|
1953
|
+
);
|
|
1702
1954
|
return value === "ascending";
|
|
1703
1955
|
}
|
|
1704
1956
|
if (isBoolean(dir)) {
|
|
1705
1957
|
return dir;
|
|
1706
1958
|
}
|
|
1707
1959
|
});
|
|
1708
|
-
|
|
1960
|
+
out.values = sort(out.values, (a, b) => {
|
|
1709
1961
|
let counter = 0;
|
|
1710
1962
|
while (a[cols[counter]] === b[cols[counter]] && counter < cols.length) {
|
|
1711
1963
|
counter++;
|
|
1712
1964
|
}
|
|
1713
1965
|
const isAscending = directions[counter];
|
|
1714
|
-
if (a[cols[counter]] === b[cols[counter]])
|
|
1715
|
-
|
|
1716
|
-
if (a[cols[counter]]
|
|
1717
|
-
return isAscending ? -1 : 1;
|
|
1718
|
-
if (a[cols[counter]] > b[cols[counter]])
|
|
1719
|
-
return isAscending ? 1 : -1;
|
|
1966
|
+
if (a[cols[counter]] === b[cols[counter]]) return 0;
|
|
1967
|
+
if (a[cols[counter]] < b[cols[counter]]) return isAscending ? -1 : 1;
|
|
1968
|
+
if (a[cols[counter]] > b[cols[counter]]) return isAscending ? 1 : -1;
|
|
1720
1969
|
});
|
|
1721
|
-
const indexNumber =
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
return
|
|
1970
|
+
const indexNumber = out.columns.indexOf(indexID);
|
|
1971
|
+
out.index = out.values.map((row) => row[indexNumber]);
|
|
1972
|
+
out = out.dropColumns(indexID);
|
|
1973
|
+
return out;
|
|
1725
1974
|
}
|
|
1975
|
+
|
|
1976
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-detailed-object.mjs
|
|
1726
1977
|
function dfToDetailedObject(df, axis) {
|
|
1727
1978
|
if (isUndefined(axis)) {
|
|
1728
1979
|
axis = 0;
|
|
1729
1980
|
} else {
|
|
1730
|
-
assert(
|
|
1981
|
+
assert(
|
|
1982
|
+
axis === 0 || axis === 1,
|
|
1983
|
+
"The axis parameter of the `toDetailedObject` method must be undefined, 0, or 1. An axis of 0 indicates that the returned object should be organized first by rows and then by columns. An axis of 1 indicates that the returned object should be organized first by columns and then by rows."
|
|
1984
|
+
);
|
|
1731
1985
|
}
|
|
1732
|
-
const
|
|
1986
|
+
const out = {};
|
|
1733
1987
|
if (axis === 0) {
|
|
1734
1988
|
df.index.forEach((rowName, i) => {
|
|
1735
1989
|
const temp = {};
|
|
1736
1990
|
df.columns.forEach((colName, j) => {
|
|
1737
1991
|
temp[colName] = df.values[i][j];
|
|
1738
1992
|
});
|
|
1739
|
-
|
|
1993
|
+
out[rowName] = temp;
|
|
1740
1994
|
});
|
|
1741
1995
|
} else {
|
|
1742
1996
|
df.columns.forEach((colName, j) => {
|
|
@@ -1744,114 +1998,107 @@
|
|
|
1744
1998
|
df.index.forEach((rowName, i) => {
|
|
1745
1999
|
temp[rowName] = df.values[i][j];
|
|
1746
2000
|
});
|
|
1747
|
-
|
|
2001
|
+
out[colName] = temp;
|
|
1748
2002
|
});
|
|
1749
2003
|
}
|
|
1750
|
-
return
|
|
2004
|
+
return out;
|
|
1751
2005
|
}
|
|
2006
|
+
|
|
2007
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json-string.mjs
|
|
1752
2008
|
function dfToJSONString(df, axis) {
|
|
1753
2009
|
return JSON.stringify(df.toObject(axis));
|
|
1754
2010
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
let browserError, nodeError;
|
|
1760
|
-
try {
|
|
1761
|
-
let newFilename = filename;
|
|
1762
|
-
if (filename.includes("/")) {
|
|
1763
|
-
const parts = filename.split("/");
|
|
1764
|
-
newFilename = parts[parts.length - 1];
|
|
1765
|
-
}
|
|
1766
|
-
const a = document.createElement("a");
|
|
1767
|
-
a.href = `data:application/json;charset=utf-8,${encodeURIComponent(out2)}`;
|
|
1768
|
-
a.download = newFilename;
|
|
1769
|
-
a.dispatchEvent(new MouseEvent("click"));
|
|
1770
|
-
downloadedInBrowser = true;
|
|
1771
|
-
} catch (e) {
|
|
1772
|
-
browserError = e;
|
|
1773
|
-
}
|
|
1774
|
-
try {
|
|
1775
|
-
const fs = await import("node:fs");
|
|
1776
|
-
const path = await import("node:path");
|
|
1777
|
-
fs.writeFileSync(path.resolve(filename), out2, "utf8");
|
|
1778
|
-
wroteToDiskInNode = true;
|
|
1779
|
-
} catch (e) {
|
|
1780
|
-
nodeError = e;
|
|
1781
|
-
}
|
|
1782
|
-
if (!downloadedInBrowser && !wroteToDiskInNode) {
|
|
1783
|
-
if (typeof window !== "undefined") {
|
|
1784
|
-
throw new MathError(browserError);
|
|
1785
|
-
} else if (typeof module !== "undefined") {
|
|
1786
|
-
throw new MathError(nodeError);
|
|
1787
|
-
} else {
|
|
1788
|
-
throw new MathError("I don't know what's going wrong, but it doesn't seem like you're in Node or the browser, and we couldn't download and/or write the file to disk!");
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
return df;
|
|
2011
|
+
|
|
2012
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json.mjs
|
|
2013
|
+
async function dfToJSON(df, axis) {
|
|
2014
|
+
return JSON.parse(dfToJSONString(df, axis));
|
|
1792
2015
|
}
|
|
2016
|
+
|
|
2017
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-object.mjs
|
|
1793
2018
|
function dfToObject(df) {
|
|
1794
|
-
const
|
|
2019
|
+
const out = {};
|
|
1795
2020
|
df.columns.forEach((col) => {
|
|
1796
|
-
|
|
2021
|
+
out[col] = df.get(col).values;
|
|
1797
2022
|
});
|
|
1798
|
-
return
|
|
2023
|
+
return out;
|
|
1799
2024
|
}
|
|
2025
|
+
|
|
2026
|
+
// node_modules/@jrc03c/js-math-tools/src/transpose.mjs
|
|
1800
2027
|
function transpose(arr) {
|
|
1801
2028
|
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1802
2029
|
return arr.transpose();
|
|
1803
2030
|
}
|
|
1804
|
-
assert(
|
|
2031
|
+
assert(
|
|
2032
|
+
isArray(arr),
|
|
2033
|
+
"The `transpose` function only works on arrays, Series, and DataFrames!"
|
|
2034
|
+
);
|
|
1805
2035
|
const theShape = shape(arr);
|
|
1806
|
-
assert(
|
|
2036
|
+
assert(
|
|
2037
|
+
theShape.length <= 2,
|
|
2038
|
+
"I'm not smart enough to know how to transpose arrays that have more than 2 dimensions. Sorry for the inconvenience! Please only pass 1- or 2-dimensional arrays into the `transpose` function!"
|
|
2039
|
+
);
|
|
1807
2040
|
if (theShape.length === 1) {
|
|
1808
2041
|
return reverse(arr);
|
|
1809
2042
|
} else if (theShape.length === 2) {
|
|
1810
|
-
const
|
|
2043
|
+
const out = ndarray(reverse(theShape));
|
|
1811
2044
|
for (let row = 0; row < theShape[0]; row++) {
|
|
1812
2045
|
for (let col = 0; col < theShape[1]; col++) {
|
|
1813
|
-
|
|
2046
|
+
out[col][row] = arr[row][col];
|
|
1814
2047
|
}
|
|
1815
2048
|
}
|
|
1816
|
-
return
|
|
2049
|
+
return out;
|
|
1817
2050
|
}
|
|
1818
2051
|
}
|
|
2052
|
+
|
|
2053
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-append.mjs
|
|
1819
2054
|
function seriesAppend(Series2, series, x) {
|
|
1820
2055
|
if (isSeries(x)) {
|
|
1821
2056
|
return new Series2(series.values.concat(x.values));
|
|
1822
2057
|
}
|
|
1823
2058
|
if (isArray(x)) {
|
|
1824
2059
|
const xShape = shape(x);
|
|
1825
|
-
assert(
|
|
1826
|
-
|
|
2060
|
+
assert(
|
|
2061
|
+
xShape.length === 1 && !isNested(xShape),
|
|
2062
|
+
"Only vectors can be appended to Series!"
|
|
2063
|
+
);
|
|
2064
|
+
const out = series.copy();
|
|
1827
2065
|
x.forEach((v, i) => {
|
|
1828
|
-
|
|
1829
|
-
|
|
2066
|
+
out._values.push(v);
|
|
2067
|
+
out._index.push("item" + (series.values.length + i));
|
|
1830
2068
|
});
|
|
1831
|
-
return
|
|
2069
|
+
return out;
|
|
1832
2070
|
}
|
|
1833
2071
|
return seriesAppend(series, [x]);
|
|
1834
2072
|
}
|
|
2073
|
+
|
|
2074
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-apply.mjs
|
|
1835
2075
|
function seriesApply(series, fn) {
|
|
1836
|
-
assert(
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
2076
|
+
assert(
|
|
2077
|
+
isFunction(fn),
|
|
2078
|
+
"The parameter to the `apply` method must be a function."
|
|
2079
|
+
);
|
|
2080
|
+
const out = series.copy();
|
|
2081
|
+
out._values = out._values.map((v, i) => fn(v, i));
|
|
2082
|
+
return out;
|
|
1840
2083
|
}
|
|
2084
|
+
|
|
2085
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-drop-missing.mjs
|
|
1841
2086
|
function seriesDropMissing(series) {
|
|
1842
|
-
const
|
|
2087
|
+
const out = series.copy();
|
|
1843
2088
|
const outIndex = [];
|
|
1844
|
-
|
|
2089
|
+
out._values = out.values.filter((v, i) => {
|
|
1845
2090
|
if (isUndefined(v)) {
|
|
1846
2091
|
return false;
|
|
1847
2092
|
} else {
|
|
1848
|
-
outIndex.push(
|
|
2093
|
+
outIndex.push(out.index[i]);
|
|
1849
2094
|
return true;
|
|
1850
2095
|
}
|
|
1851
2096
|
});
|
|
1852
|
-
|
|
1853
|
-
return
|
|
2097
|
+
out._index = outIndex;
|
|
2098
|
+
return out;
|
|
1854
2099
|
}
|
|
2100
|
+
|
|
2101
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-drop-nan.mjs
|
|
1855
2102
|
function seriesDropNaN(Series2, series) {
|
|
1856
2103
|
const index = [];
|
|
1857
2104
|
const values = [];
|
|
@@ -1861,49 +2108,63 @@
|
|
|
1861
2108
|
index.push(series.index[i]);
|
|
1862
2109
|
}
|
|
1863
2110
|
});
|
|
1864
|
-
const
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
return
|
|
2111
|
+
const out = new Series2(values);
|
|
2112
|
+
out.name = series.name;
|
|
2113
|
+
out.index = index;
|
|
2114
|
+
return out;
|
|
1868
2115
|
}
|
|
2116
|
+
|
|
2117
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-filter.mjs
|
|
1869
2118
|
function seriesFilter(Series2, series, fn) {
|
|
1870
|
-
let
|
|
1871
|
-
const index = copy(
|
|
2119
|
+
let out = series.copy();
|
|
2120
|
+
const index = copy(out.index);
|
|
1872
2121
|
const indicesToRemove = [];
|
|
1873
|
-
const newValues =
|
|
1874
|
-
const shouldKeep = fn(value, i,
|
|
1875
|
-
if (!shouldKeep)
|
|
1876
|
-
indicesToRemove.push(out2.index[i]);
|
|
2122
|
+
const newValues = out.values.filter((value, i) => {
|
|
2123
|
+
const shouldKeep = fn(value, i, out.values);
|
|
2124
|
+
if (!shouldKeep) indicesToRemove.push(out.index[i]);
|
|
1877
2125
|
return shouldKeep;
|
|
1878
2126
|
});
|
|
1879
2127
|
indicesToRemove.forEach((i) => {
|
|
1880
2128
|
index.splice(index.indexOf(i), 1);
|
|
1881
2129
|
});
|
|
1882
2130
|
if (newValues.length === 0) {
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
return
|
|
2131
|
+
out = new Series2();
|
|
2132
|
+
out.name = series.name;
|
|
2133
|
+
return out;
|
|
1886
2134
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
return
|
|
2135
|
+
out.values = newValues;
|
|
2136
|
+
out.index = index;
|
|
2137
|
+
return out;
|
|
1890
2138
|
}
|
|
2139
|
+
|
|
2140
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-get.mjs
|
|
1891
2141
|
function seriesGet(series, indices) {
|
|
1892
|
-
if (isString(indices) || isNumber(indices))
|
|
1893
|
-
indices = [indices];
|
|
2142
|
+
if (isString(indices) || isNumber(indices)) indices = [indices];
|
|
1894
2143
|
for (const i in indices) {
|
|
1895
2144
|
if (typeof indices[i] === "bigint") {
|
|
1896
2145
|
indices[i] = Number(indices[i]);
|
|
1897
2146
|
}
|
|
1898
2147
|
}
|
|
1899
2148
|
const types = set((indices || []).map((v) => typeof v));
|
|
1900
|
-
assert(
|
|
2149
|
+
assert(
|
|
2150
|
+
types.length <= 2,
|
|
2151
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2152
|
+
);
|
|
1901
2153
|
if (types.length === 1) {
|
|
1902
|
-
assert(
|
|
2154
|
+
assert(
|
|
2155
|
+
types[0] === "string" || types[0] === "number",
|
|
2156
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2157
|
+
);
|
|
1903
2158
|
}
|
|
1904
2159
|
if (types.length === 2) {
|
|
1905
|
-
assert(
|
|
1906
|
-
|
|
2160
|
+
assert(
|
|
2161
|
+
types.indexOf("string") > -1,
|
|
2162
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2163
|
+
);
|
|
2164
|
+
assert(
|
|
2165
|
+
types.indexOf("number") > -1,
|
|
2166
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2167
|
+
);
|
|
1907
2168
|
}
|
|
1908
2169
|
if (!isUndefined(indices)) {
|
|
1909
2170
|
indices = indices.map((i) => {
|
|
@@ -1921,68 +2182,109 @@
|
|
|
1921
2182
|
}
|
|
1922
2183
|
return series.getSubsetByNames(indices);
|
|
1923
2184
|
}
|
|
2185
|
+
|
|
2186
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-indices.mjs
|
|
1924
2187
|
function seriesGetSubsetByIndices(series, indices) {
|
|
1925
2188
|
const dataShape = series.shape;
|
|
1926
|
-
if (isUndefined(indices))
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2189
|
+
if (isUndefined(indices)) indices = range(0, dataShape[0]);
|
|
2190
|
+
assert(
|
|
2191
|
+
isArray(indices),
|
|
2192
|
+
"The `indices` array must be 1-dimensional array of whole numbers."
|
|
2193
|
+
);
|
|
2194
|
+
assert(
|
|
2195
|
+
shape(indices).length === 1,
|
|
2196
|
+
"The `indices` array must be a 1-dimensional array of whole numbers."
|
|
2197
|
+
);
|
|
2198
|
+
assert(
|
|
2199
|
+
indices.length > 0,
|
|
2200
|
+
"The `indices` array must contain at least one index."
|
|
2201
|
+
);
|
|
1931
2202
|
indices.forEach((index) => {
|
|
1932
|
-
assert(
|
|
1933
|
-
|
|
2203
|
+
assert(
|
|
2204
|
+
isWholeNumber(index),
|
|
2205
|
+
"The `indices` array must be a 1-dimensional array of whole numbers."
|
|
2206
|
+
);
|
|
2207
|
+
assert(
|
|
2208
|
+
index < series.index.length,
|
|
2209
|
+
`The row index ${index} is out of bounds.`
|
|
2210
|
+
);
|
|
1934
2211
|
});
|
|
1935
2212
|
const rows = indices.map((i) => series.index[i]);
|
|
1936
2213
|
return series.getSubsetByNames(rows);
|
|
1937
2214
|
}
|
|
2215
|
+
|
|
2216
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-names.mjs
|
|
1938
2217
|
function seriesGetSubsetByNames(Series2, series, indices) {
|
|
1939
|
-
if (isUndefined(indices))
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2218
|
+
if (isUndefined(indices)) indices = series.index;
|
|
2219
|
+
assert(
|
|
2220
|
+
isArray(indices),
|
|
2221
|
+
"The `indices` array must be a 1-dimensional array of strings."
|
|
2222
|
+
);
|
|
2223
|
+
assert(
|
|
2224
|
+
shape(indices).length === 1,
|
|
2225
|
+
"The `indices` array must be a 1-dimensional array of strings."
|
|
2226
|
+
);
|
|
2227
|
+
assert(
|
|
2228
|
+
indices.length > 0,
|
|
2229
|
+
"The `indices` array must contain at least one index name."
|
|
2230
|
+
);
|
|
1944
2231
|
indices.forEach((name) => {
|
|
1945
2232
|
assert(isString(name), "The `indices` array must contain only strings.");
|
|
1946
|
-
assert(
|
|
2233
|
+
assert(
|
|
2234
|
+
series.index.indexOf(name) > -1,
|
|
2235
|
+
`The name "${name}" does not exist in the index.`
|
|
2236
|
+
);
|
|
1947
2237
|
});
|
|
1948
2238
|
const values = indices.map((name) => {
|
|
1949
2239
|
return series.values[series.index.indexOf(name)];
|
|
1950
2240
|
});
|
|
1951
|
-
if (values.length === 1)
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
return out2;
|
|
2241
|
+
if (values.length === 1) return values[0];
|
|
2242
|
+
const out = new Series2(values);
|
|
2243
|
+
out.index = indices;
|
|
2244
|
+
out.name = series.name;
|
|
2245
|
+
return out;
|
|
1957
2246
|
}
|
|
2247
|
+
|
|
2248
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-print.mjs
|
|
1958
2249
|
function seriesPrint(series) {
|
|
1959
2250
|
let temp = series.copy();
|
|
1960
2251
|
const maxRows = typeof window === "undefined" ? 20 : 10;
|
|
1961
2252
|
if (temp.index.length > maxRows) {
|
|
1962
|
-
temp = temp.get(
|
|
2253
|
+
temp = temp.get(
|
|
2254
|
+
range(0, maxRows / 2).concat(
|
|
2255
|
+
range(temp.index.length - maxRows / 2, temp.index.length)
|
|
2256
|
+
)
|
|
2257
|
+
);
|
|
1963
2258
|
const tempIndex = copy(temp.index);
|
|
1964
2259
|
tempIndex.splice(Math.floor(tempIndex.length / 2), 0, "...");
|
|
1965
2260
|
temp.values.push("...");
|
|
1966
2261
|
temp.index.push("...");
|
|
1967
2262
|
temp = temp.get(tempIndex);
|
|
1968
2263
|
}
|
|
1969
|
-
const
|
|
2264
|
+
const out = {};
|
|
1970
2265
|
temp.values.forEach((value, i) => {
|
|
1971
2266
|
const obj = {};
|
|
1972
2267
|
obj[temp.name] = value;
|
|
1973
|
-
|
|
2268
|
+
out[temp.index[i]] = obj;
|
|
1974
2269
|
});
|
|
1975
|
-
console.table(
|
|
2270
|
+
console.table(out);
|
|
1976
2271
|
console.log("Shape:", series.shape, "\n");
|
|
1977
2272
|
return series;
|
|
1978
2273
|
}
|
|
2274
|
+
|
|
2275
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-shuffle.mjs
|
|
1979
2276
|
function seriesShuffle(series) {
|
|
1980
|
-
const
|
|
1981
|
-
return
|
|
2277
|
+
const out = series.copy();
|
|
2278
|
+
return out.get(shuffle(out.index));
|
|
1982
2279
|
}
|
|
2280
|
+
|
|
2281
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-sort.mjs
|
|
1983
2282
|
function seriesSort(Series2, series, fn) {
|
|
1984
2283
|
fn = fn || ((a, b) => a < b ? -1 : 1);
|
|
1985
|
-
assert(
|
|
2284
|
+
assert(
|
|
2285
|
+
isUndefined(fn) || isFunction(fn),
|
|
2286
|
+
"You must pass undefined, null, or a comparison function as the second argument to the `sort` method!"
|
|
2287
|
+
);
|
|
1986
2288
|
const pairs = transpose([series.values, series.index]);
|
|
1987
2289
|
const temp = sort(pairs, (aPair, bPair) => {
|
|
1988
2290
|
return fn(aPair[0], bPair[0]);
|
|
@@ -1993,35 +2295,40 @@
|
|
|
1993
2295
|
newValues.push(pair[0]);
|
|
1994
2296
|
newIndex.push(pair[1]);
|
|
1995
2297
|
});
|
|
1996
|
-
const
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
return
|
|
2298
|
+
const out = new Series2();
|
|
2299
|
+
out._values = newValues;
|
|
2300
|
+
out._index = newIndex;
|
|
2301
|
+
out.name = series.name;
|
|
2302
|
+
return out;
|
|
2001
2303
|
}
|
|
2304
|
+
|
|
2305
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-sort-by-index.mjs
|
|
2002
2306
|
function seriesSortByIndex(Series2, series) {
|
|
2003
2307
|
let temp = transpose([series.values, series.index]);
|
|
2004
|
-
temp = transpose(
|
|
2005
|
-
|
|
2006
|
-
return 0;
|
|
2007
|
-
|
|
2008
|
-
return
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
return out2;
|
|
2308
|
+
temp = transpose(
|
|
2309
|
+
sort(temp, (a, b) => {
|
|
2310
|
+
if (a[1] === b[1]) return 0;
|
|
2311
|
+
if (a[1] < b[1]) return -1;
|
|
2312
|
+
if (a[1] > b[1]) return 1;
|
|
2313
|
+
})
|
|
2314
|
+
);
|
|
2315
|
+
const out = new Series2(temp[0]);
|
|
2316
|
+
out.index = temp[1];
|
|
2317
|
+
out.name = series.name;
|
|
2318
|
+
return out;
|
|
2016
2319
|
}
|
|
2320
|
+
|
|
2321
|
+
// node_modules/@jrc03c/js-math-tools/src/series/series-to-object.mjs
|
|
2017
2322
|
function seriesToObject(series) {
|
|
2018
|
-
const
|
|
2019
|
-
|
|
2323
|
+
const out = {};
|
|
2324
|
+
out[series.name] = {};
|
|
2020
2325
|
series.index.forEach((index, i) => {
|
|
2021
|
-
|
|
2326
|
+
out[series.name][index] = series.values[i];
|
|
2022
2327
|
});
|
|
2023
|
-
return
|
|
2328
|
+
return out;
|
|
2024
2329
|
}
|
|
2330
|
+
|
|
2331
|
+
// node_modules/@jrc03c/js-math-tools/src/series/index.mjs
|
|
2025
2332
|
var SERIES_SYMBOL = Symbol.for("@jrc03c/js-math-tools/series");
|
|
2026
2333
|
function createSeriesClass(DataFrame2) {
|
|
2027
2334
|
class Series2 {
|
|
@@ -2055,13 +2362,18 @@
|
|
|
2055
2362
|
set(x) {
|
|
2056
2363
|
assert(isArray(x), "The new values must be a 1-dimensional array!");
|
|
2057
2364
|
const dataShape = shape(x);
|
|
2058
|
-
assert(
|
|
2365
|
+
assert(
|
|
2366
|
+
dataShape.length === 1,
|
|
2367
|
+
"The new array of values must be 1-dimensional!"
|
|
2368
|
+
);
|
|
2059
2369
|
if (dataShape[0] < this._index.length) {
|
|
2060
2370
|
this._index = this._index.slice(0, dataShape[0]);
|
|
2061
2371
|
} else if (dataShape[0] > this._index.length) {
|
|
2062
|
-
this._index = this._index.concat(
|
|
2063
|
-
|
|
2064
|
-
|
|
2372
|
+
this._index = this._index.concat(
|
|
2373
|
+
range(this._index.length, dataShape[0]).map((i) => {
|
|
2374
|
+
return "item" + leftPad(i, (x.length - 1).toString().length);
|
|
2375
|
+
})
|
|
2376
|
+
);
|
|
2065
2377
|
}
|
|
2066
2378
|
this._values = x;
|
|
2067
2379
|
}
|
|
@@ -2079,9 +2391,18 @@
|
|
|
2079
2391
|
return this._index;
|
|
2080
2392
|
},
|
|
2081
2393
|
set(x) {
|
|
2082
|
-
assert(
|
|
2083
|
-
|
|
2084
|
-
|
|
2394
|
+
assert(
|
|
2395
|
+
isArray(x),
|
|
2396
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2397
|
+
);
|
|
2398
|
+
assert(
|
|
2399
|
+
x.length === this.shape[0],
|
|
2400
|
+
"The new index must be the same length as the old index!"
|
|
2401
|
+
);
|
|
2402
|
+
assert(
|
|
2403
|
+
shape(x).length === 1,
|
|
2404
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2405
|
+
);
|
|
2085
2406
|
x.forEach((value) => {
|
|
2086
2407
|
assert(isString(value), "All of the row names must be strings!");
|
|
2087
2408
|
});
|
|
@@ -2095,14 +2416,23 @@
|
|
|
2095
2416
|
this.index = copy(data.index);
|
|
2096
2417
|
} else if (isArray(data)) {
|
|
2097
2418
|
const dataShape = shape(data);
|
|
2098
|
-
assert(
|
|
2419
|
+
assert(
|
|
2420
|
+
dataShape.length === 1,
|
|
2421
|
+
"When passing an array into the constructor of a Series, the array must be 1-dimensional!"
|
|
2422
|
+
);
|
|
2099
2423
|
this.values = data;
|
|
2100
2424
|
} else if (data instanceof Object) {
|
|
2101
2425
|
const keys = Object.keys(data).concat(Object.getOwnPropertySymbols(data)).map((v) => v.toString());
|
|
2102
|
-
assert(
|
|
2426
|
+
assert(
|
|
2427
|
+
keys.length === 1,
|
|
2428
|
+
"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!"
|
|
2429
|
+
);
|
|
2103
2430
|
const name = keys[0];
|
|
2104
2431
|
const values = data[name];
|
|
2105
|
-
assert(
|
|
2432
|
+
assert(
|
|
2433
|
+
shape(values).length === 1,
|
|
2434
|
+
"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!"
|
|
2435
|
+
);
|
|
2106
2436
|
this.name = name;
|
|
2107
2437
|
this.values = values.slice();
|
|
2108
2438
|
}
|
|
@@ -2118,11 +2448,11 @@
|
|
|
2118
2448
|
return this.values.filter((v) => !isUndefined(v)).length === 0;
|
|
2119
2449
|
}
|
|
2120
2450
|
clear() {
|
|
2121
|
-
const
|
|
2122
|
-
|
|
2123
|
-
|
|
2451
|
+
const out = this.copy();
|
|
2452
|
+
out.values.forEach((v, i) => {
|
|
2453
|
+
out.values[i] = void 0;
|
|
2124
2454
|
});
|
|
2125
|
-
return
|
|
2455
|
+
return out;
|
|
2126
2456
|
}
|
|
2127
2457
|
get(indices) {
|
|
2128
2458
|
return seriesGet(this, indices);
|
|
@@ -2140,24 +2470,24 @@
|
|
|
2140
2470
|
return this.getSubsetByIndices(indices);
|
|
2141
2471
|
}
|
|
2142
2472
|
reverse() {
|
|
2143
|
-
const
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
return
|
|
2473
|
+
const out = new Series2(reverse(this.values));
|
|
2474
|
+
out.index = reverse(this.index);
|
|
2475
|
+
out.name = this.name;
|
|
2476
|
+
return out;
|
|
2147
2477
|
}
|
|
2148
2478
|
resetIndex() {
|
|
2149
|
-
const
|
|
2150
|
-
|
|
2151
|
-
return "item" + leftPad(i, (
|
|
2479
|
+
const out = this.copy();
|
|
2480
|
+
out.index = range(0, this.shape[0]).map((i) => {
|
|
2481
|
+
return "item" + leftPad(i, (out.index.length - 1).toString().length);
|
|
2152
2482
|
});
|
|
2153
|
-
return
|
|
2483
|
+
return out;
|
|
2154
2484
|
}
|
|
2155
2485
|
copy() {
|
|
2156
|
-
const
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
return
|
|
2486
|
+
const out = new Series2();
|
|
2487
|
+
out._values = copy(this.values);
|
|
2488
|
+
out._index = copy(this.index);
|
|
2489
|
+
out.name = this.name;
|
|
2490
|
+
return out;
|
|
2161
2491
|
}
|
|
2162
2492
|
append(x) {
|
|
2163
2493
|
return seriesAppend(Series2, this, x);
|
|
@@ -2193,16 +2523,16 @@
|
|
|
2193
2523
|
return seriesFilter(Series2, this, fn);
|
|
2194
2524
|
}
|
|
2195
2525
|
toDataFrame() {
|
|
2196
|
-
const
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
return
|
|
2526
|
+
const out = new DataFrame2(transpose([this.values]));
|
|
2527
|
+
out.columns = [this.name];
|
|
2528
|
+
out.index = this.index;
|
|
2529
|
+
return out;
|
|
2200
2530
|
}
|
|
2201
2531
|
transpose() {
|
|
2202
|
-
const
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
return
|
|
2532
|
+
const out = this.copy();
|
|
2533
|
+
out.values = reverse(out.values);
|
|
2534
|
+
out.index = reverse(out.index);
|
|
2535
|
+
return out;
|
|
2206
2536
|
}
|
|
2207
2537
|
getDummies() {
|
|
2208
2538
|
return this.toDataFrame().getDummies();
|
|
@@ -2213,15 +2543,16 @@
|
|
|
2213
2543
|
}
|
|
2214
2544
|
return Series2;
|
|
2215
2545
|
}
|
|
2546
|
+
|
|
2547
|
+
// node_modules/@jrc03c/js-math-tools/src/dataframe/index.mjs
|
|
2216
2548
|
var DATAFRAME_SYMBOL = Symbol.for("@jrc03c/js-math-tools/dataframe");
|
|
2217
2549
|
function makeKey3(n) {
|
|
2218
2550
|
const alpha = "abcdefghijklmnopqrstuvwxyz1234567890";
|
|
2219
|
-
let
|
|
2220
|
-
for (let i = 0; i < n; i++)
|
|
2221
|
-
|
|
2222
|
-
return out2;
|
|
2551
|
+
let out = "";
|
|
2552
|
+
for (let i = 0; i < n; i++) out += alpha[Math.floor(random() * alpha.length)];
|
|
2553
|
+
return out;
|
|
2223
2554
|
}
|
|
2224
|
-
var DataFrame = class {
|
|
2555
|
+
var DataFrame = class _DataFrame {
|
|
2225
2556
|
static [Symbol.hasInstance](x) {
|
|
2226
2557
|
try {
|
|
2227
2558
|
return !!x._symbol && x._symbol === DATAFRAME_SYMBOL;
|
|
@@ -2254,20 +2585,27 @@
|
|
|
2254
2585
|
set(x) {
|
|
2255
2586
|
assert(isArray(x), "The new values must be a 2-dimensional array!");
|
|
2256
2587
|
const dataShape = shape(x);
|
|
2257
|
-
assert(
|
|
2588
|
+
assert(
|
|
2589
|
+
dataShape.length === 2,
|
|
2590
|
+
"The new array of values must be 2-dimensional!"
|
|
2591
|
+
);
|
|
2258
2592
|
if (dataShape[0] < this._index.length) {
|
|
2259
2593
|
this._index = this._index.slice(0, dataShape[0]);
|
|
2260
2594
|
} else if (dataShape[0] > this._index.length) {
|
|
2261
|
-
this._index = this._index.concat(
|
|
2262
|
-
|
|
2263
|
-
|
|
2595
|
+
this._index = this._index.concat(
|
|
2596
|
+
range(this._index.length, dataShape[0]).map((i) => {
|
|
2597
|
+
return "row" + leftPad(i, (dataShape[0] - 1).toString().length);
|
|
2598
|
+
})
|
|
2599
|
+
);
|
|
2264
2600
|
}
|
|
2265
2601
|
if (dataShape[1] < this._columns.length) {
|
|
2266
2602
|
this._columns = this._columns.slice(0, dataShape[1]);
|
|
2267
2603
|
} else if (dataShape[1] > this._columns.length) {
|
|
2268
|
-
this._columns = this._columns.concat(
|
|
2269
|
-
|
|
2270
|
-
|
|
2604
|
+
this._columns = this._columns.concat(
|
|
2605
|
+
range(this._columns.length, dataShape[1]).map((i) => {
|
|
2606
|
+
return "col" + leftPad(i, (dataShape[1] - 1).toString().length);
|
|
2607
|
+
})
|
|
2608
|
+
);
|
|
2271
2609
|
}
|
|
2272
2610
|
this._values = x;
|
|
2273
2611
|
}
|
|
@@ -2285,9 +2623,18 @@
|
|
|
2285
2623
|
return this._columns;
|
|
2286
2624
|
},
|
|
2287
2625
|
set(x) {
|
|
2288
|
-
assert(
|
|
2289
|
-
|
|
2290
|
-
|
|
2626
|
+
assert(
|
|
2627
|
+
isArray(x),
|
|
2628
|
+
"The new columns list must be a 1-dimensional array of strings!"
|
|
2629
|
+
);
|
|
2630
|
+
assert(
|
|
2631
|
+
this.isEmpty || x.length === this.shape[1],
|
|
2632
|
+
"The new columns list must be the same length as the old columns list!"
|
|
2633
|
+
);
|
|
2634
|
+
assert(
|
|
2635
|
+
shape(x).length === 1,
|
|
2636
|
+
"The new columns list must be a 1-dimensional array of strings!"
|
|
2637
|
+
);
|
|
2291
2638
|
x = x.map((v) => {
|
|
2292
2639
|
if (typeof v !== "string") {
|
|
2293
2640
|
v = JSON.stringify(v) || v.toString();
|
|
@@ -2299,11 +2646,11 @@
|
|
|
2299
2646
|
});
|
|
2300
2647
|
const counts = (() => {
|
|
2301
2648
|
const temp = count(x);
|
|
2302
|
-
const
|
|
2649
|
+
const out = {};
|
|
2303
2650
|
temp.values.forEach((v) => {
|
|
2304
|
-
|
|
2651
|
+
out[v] = temp.get(v);
|
|
2305
2652
|
});
|
|
2306
|
-
return
|
|
2653
|
+
return out;
|
|
2307
2654
|
})();
|
|
2308
2655
|
x = x.map((v) => {
|
|
2309
2656
|
if (counts[v] > 1) {
|
|
@@ -2327,9 +2674,18 @@
|
|
|
2327
2674
|
return this._index;
|
|
2328
2675
|
},
|
|
2329
2676
|
set(x) {
|
|
2330
|
-
assert(
|
|
2331
|
-
|
|
2332
|
-
|
|
2677
|
+
assert(
|
|
2678
|
+
isArray(x),
|
|
2679
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2680
|
+
);
|
|
2681
|
+
assert(
|
|
2682
|
+
this.isEmpty || x.length === this.shape[0],
|
|
2683
|
+
"The new index must be the same length as the old index!"
|
|
2684
|
+
);
|
|
2685
|
+
assert(
|
|
2686
|
+
shape(x).length === 1,
|
|
2687
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2688
|
+
);
|
|
2333
2689
|
x = x.map((v) => {
|
|
2334
2690
|
if (typeof v !== "string") {
|
|
2335
2691
|
v = JSON.stringify(v) || v.toString();
|
|
@@ -2341,11 +2697,11 @@
|
|
|
2341
2697
|
});
|
|
2342
2698
|
const counts = (() => {
|
|
2343
2699
|
const temp = count(x);
|
|
2344
|
-
const
|
|
2700
|
+
const out = {};
|
|
2345
2701
|
temp.values.forEach((v) => {
|
|
2346
|
-
|
|
2702
|
+
out[v] = temp.get(v);
|
|
2347
2703
|
});
|
|
2348
|
-
return
|
|
2704
|
+
return out;
|
|
2349
2705
|
})();
|
|
2350
2706
|
x = x.map((v) => {
|
|
2351
2707
|
if (counts[v] > 1) {
|
|
@@ -2356,16 +2712,25 @@
|
|
|
2356
2712
|
this._index = x;
|
|
2357
2713
|
}
|
|
2358
2714
|
});
|
|
2359
|
-
assert(
|
|
2715
|
+
assert(
|
|
2716
|
+
isUndefined(data) || isObject(data) || isArray(data),
|
|
2717
|
+
"The `data` passed into the constructor of a DataFrame must be either (1) an object where the key-value pairs are (respectively) column names and 1-dimensional arrays of values, or (2) a 2-dimensional array of values."
|
|
2718
|
+
);
|
|
2360
2719
|
if (data) {
|
|
2361
|
-
if (data instanceof
|
|
2720
|
+
if (data instanceof _DataFrame) {
|
|
2362
2721
|
this.values = copy(data.values);
|
|
2363
2722
|
this.columns = copy(data.columns);
|
|
2364
2723
|
this.index = copy(data.index);
|
|
2365
2724
|
} else if (isArray(data)) {
|
|
2366
2725
|
const dataShape = shape(data);
|
|
2367
|
-
assert(
|
|
2368
|
-
|
|
2726
|
+
assert(
|
|
2727
|
+
dataShape.length === 2,
|
|
2728
|
+
"The `data` array passed into the constructor of a DataFrame must be 2-dimensional!"
|
|
2729
|
+
);
|
|
2730
|
+
assert(
|
|
2731
|
+
!isJagged(data),
|
|
2732
|
+
"The 2-dimensional array passed into the constructor of a DataFrame must not contain sub-arrays (i.e., rows) of different lengths!"
|
|
2733
|
+
);
|
|
2369
2734
|
this.values = data;
|
|
2370
2735
|
} else {
|
|
2371
2736
|
this._columns = Object.keys(data).concat(Object.getOwnPropertySymbols(data)).map((v) => v.toString());
|
|
@@ -2377,7 +2742,10 @@
|
|
|
2377
2742
|
lastColName = col;
|
|
2378
2743
|
lastColLength = data[col].length;
|
|
2379
2744
|
}
|
|
2380
|
-
assert(
|
|
2745
|
+
assert(
|
|
2746
|
+
data[col].length === lastColLength,
|
|
2747
|
+
`The object passed into the DataFrame constructor contains arrays of different lengths! The key "${lastColName}" points to an array containing ${lastColLength} items, and the key "${col}" points to an array containing ${data[col].length} items.`
|
|
2748
|
+
);
|
|
2381
2749
|
lastColLength = data[col].length;
|
|
2382
2750
|
const values = data[col];
|
|
2383
2751
|
temp.push(values);
|
|
@@ -2409,10 +2777,10 @@
|
|
|
2409
2777
|
return this.values.length === 0 || this.values.every((row) => row.length === 0);
|
|
2410
2778
|
}
|
|
2411
2779
|
clear() {
|
|
2412
|
-
const
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
return
|
|
2780
|
+
const out = new _DataFrame(ndarray(this.shape));
|
|
2781
|
+
out.columns = this.columns.slice();
|
|
2782
|
+
out.index = this.index.slice();
|
|
2783
|
+
return out;
|
|
2416
2784
|
}
|
|
2417
2785
|
get(rows, cols) {
|
|
2418
2786
|
if (arguments.length === 0) {
|
|
@@ -2428,22 +2796,22 @@
|
|
|
2428
2796
|
return dfGet(this, rows, cols);
|
|
2429
2797
|
}
|
|
2430
2798
|
getSubsetByNames(rows, cols) {
|
|
2431
|
-
return dfGetSubsetByNames(
|
|
2799
|
+
return dfGetSubsetByNames(_DataFrame, Series, this, rows, cols);
|
|
2432
2800
|
}
|
|
2433
2801
|
getSubsetByIndices(rowIndices, colIndices) {
|
|
2434
2802
|
return dfGetSubsetByIndices(this, rowIndices, colIndices);
|
|
2435
2803
|
}
|
|
2436
2804
|
getDummies(columns) {
|
|
2437
|
-
return dfGetDummies(
|
|
2805
|
+
return dfGetDummies(_DataFrame, this, columns);
|
|
2438
2806
|
}
|
|
2439
2807
|
oneHotEncode(columns) {
|
|
2440
|
-
return dfGetDummies(
|
|
2808
|
+
return dfGetDummies(_DataFrame, this, columns);
|
|
2441
2809
|
}
|
|
2442
2810
|
transpose() {
|
|
2443
|
-
const
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
return
|
|
2811
|
+
const out = new _DataFrame(transpose(this.values));
|
|
2812
|
+
out.columns = this.index.slice();
|
|
2813
|
+
out.index = this.columns.slice();
|
|
2814
|
+
return out;
|
|
2447
2815
|
}
|
|
2448
2816
|
get T() {
|
|
2449
2817
|
return this.transpose();
|
|
@@ -2452,22 +2820,22 @@
|
|
|
2452
2820
|
return dfResetIndex(this, shouldSkipCopying);
|
|
2453
2821
|
}
|
|
2454
2822
|
copy() {
|
|
2455
|
-
return dfCopy(
|
|
2823
|
+
return dfCopy(_DataFrame, this);
|
|
2456
2824
|
}
|
|
2457
2825
|
assign(p1, p2) {
|
|
2458
|
-
return dfAssign(
|
|
2826
|
+
return dfAssign(_DataFrame, Series, this, p1, p2);
|
|
2459
2827
|
}
|
|
2460
2828
|
apply(fn, axis) {
|
|
2461
|
-
return dfApply(
|
|
2829
|
+
return dfApply(_DataFrame, Series, this, fn, axis);
|
|
2462
2830
|
}
|
|
2463
2831
|
dropMissing(axis, condition, threshold) {
|
|
2464
|
-
return dfDropMissing(
|
|
2832
|
+
return dfDropMissing(_DataFrame, Series, this, axis, condition, threshold);
|
|
2465
2833
|
}
|
|
2466
2834
|
dropNaN(axis, condition, threshold) {
|
|
2467
|
-
return dfDropNaN(
|
|
2835
|
+
return dfDropNaN(_DataFrame, this, axis, condition, threshold);
|
|
2468
2836
|
}
|
|
2469
2837
|
drop(rows, cols) {
|
|
2470
|
-
return dfDrop(
|
|
2838
|
+
return dfDrop(_DataFrame, Series, this, rows, cols);
|
|
2471
2839
|
}
|
|
2472
2840
|
dropColumns(columns) {
|
|
2473
2841
|
return this.drop(null, columns);
|
|
@@ -2488,7 +2856,7 @@
|
|
|
2488
2856
|
return dfToJSON(this, filename, axis);
|
|
2489
2857
|
}
|
|
2490
2858
|
print() {
|
|
2491
|
-
return dfPrint(
|
|
2859
|
+
return dfPrint(_DataFrame, Series, this);
|
|
2492
2860
|
}
|
|
2493
2861
|
sort(cols, directions) {
|
|
2494
2862
|
return dfSort(this, cols, directions);
|
|
@@ -2497,7 +2865,7 @@
|
|
|
2497
2865
|
return this.sort();
|
|
2498
2866
|
}
|
|
2499
2867
|
filter(fn, axis) {
|
|
2500
|
-
return dfFilter(
|
|
2868
|
+
return dfFilter(_DataFrame, Series, this, fn, axis);
|
|
2501
2869
|
}
|
|
2502
2870
|
shuffle(axis) {
|
|
2503
2871
|
return dfShuffle(this, axis);
|
|
@@ -2516,12 +2884,19 @@
|
|
|
2516
2884
|
}
|
|
2517
2885
|
};
|
|
2518
2886
|
var Series = createSeriesClass(DataFrame);
|
|
2887
|
+
|
|
2888
|
+
// node_modules/@jrc03c/js-math-tools/src/max.mjs
|
|
2519
2889
|
function max(arr, shouldDropNaNs) {
|
|
2520
2890
|
return stats(arr, { shouldDropNaNs }).max;
|
|
2521
2891
|
}
|
|
2892
|
+
|
|
2893
|
+
// node_modules/@jrc03c/js-math-tools/src/vectorize.mjs
|
|
2522
2894
|
function vectorize(fn) {
|
|
2523
|
-
assert(
|
|
2524
|
-
|
|
2895
|
+
assert(
|
|
2896
|
+
isFunction(fn),
|
|
2897
|
+
"You must pass a function into the `vectorize` function!"
|
|
2898
|
+
);
|
|
2899
|
+
return function helper4() {
|
|
2525
2900
|
let hasSeries, hasDataFrames;
|
|
2526
2901
|
const series = [];
|
|
2527
2902
|
const dataframes = [];
|
|
@@ -2542,11 +2917,19 @@
|
|
|
2542
2917
|
}
|
|
2543
2918
|
}).map((key) => arguments[key]);
|
|
2544
2919
|
childArrays.slice(0, -1).forEach((s2, i) => {
|
|
2545
|
-
assert(
|
|
2920
|
+
assert(
|
|
2921
|
+
isEqual(
|
|
2922
|
+
isArray(s2) ? shape(s2) : s2.shape,
|
|
2923
|
+
isArray(childArrays[i + 1]) ? shape(childArrays[i + 1]) : childArrays[i + 1].shape
|
|
2924
|
+
),
|
|
2925
|
+
`When passing multiple arrays into the \`${fn.name}\` function, all of the arrays must have the same shape!`
|
|
2926
|
+
);
|
|
2546
2927
|
});
|
|
2547
2928
|
if (childArrays.length > 0) {
|
|
2548
|
-
const maxLength = max(
|
|
2549
|
-
|
|
2929
|
+
const maxLength = max(
|
|
2930
|
+
childArrays.map((a) => a.length ? a.length : a.values.length)
|
|
2931
|
+
);
|
|
2932
|
+
const out = range(0, maxLength).map((i) => {
|
|
2550
2933
|
const args = Object.keys(arguments).map((key) => {
|
|
2551
2934
|
if (isArray(arguments[key])) {
|
|
2552
2935
|
return arguments[key][i];
|
|
@@ -2558,46 +2941,47 @@
|
|
|
2558
2941
|
return arguments[key];
|
|
2559
2942
|
}
|
|
2560
2943
|
});
|
|
2561
|
-
return
|
|
2944
|
+
return helper4(...args);
|
|
2562
2945
|
});
|
|
2563
2946
|
if (hasDataFrames) {
|
|
2564
2947
|
try {
|
|
2565
|
-
if (dataframes.length === 1 && isEqual(shape(dataframes[0]), shape(
|
|
2566
|
-
const temp = new DataFrame(
|
|
2948
|
+
if (dataframes.length === 1 && isEqual(shape(dataframes[0]), shape(out))) {
|
|
2949
|
+
const temp = new DataFrame(out);
|
|
2567
2950
|
temp.index = dataframes[0].index.slice();
|
|
2568
2951
|
temp.columns = dataframes[0].columns.slice();
|
|
2569
2952
|
return temp;
|
|
2570
2953
|
} else {
|
|
2571
|
-
return new DataFrame(
|
|
2954
|
+
return new DataFrame(out);
|
|
2572
2955
|
}
|
|
2573
2956
|
} catch (e) {
|
|
2574
|
-
return
|
|
2957
|
+
return out;
|
|
2575
2958
|
}
|
|
2576
2959
|
}
|
|
2577
2960
|
if (hasSeries) {
|
|
2578
2961
|
try {
|
|
2579
|
-
if (series.length === 1 && series[0].length ===
|
|
2580
|
-
const temp = new Series(
|
|
2962
|
+
if (series.length === 1 && series[0].length === out.length) {
|
|
2963
|
+
const temp = new Series(out);
|
|
2581
2964
|
temp.name = series[0].name;
|
|
2582
2965
|
temp.index = series[0].index.slice();
|
|
2583
2966
|
return temp;
|
|
2584
2967
|
} else {
|
|
2585
|
-
return new Series(
|
|
2968
|
+
return new Series(out);
|
|
2586
2969
|
}
|
|
2587
2970
|
} catch (e) {
|
|
2588
|
-
return
|
|
2971
|
+
return out;
|
|
2589
2972
|
}
|
|
2590
2973
|
}
|
|
2591
|
-
return
|
|
2974
|
+
return out;
|
|
2592
2975
|
} else {
|
|
2593
2976
|
return fn(...arguments);
|
|
2594
2977
|
}
|
|
2595
2978
|
};
|
|
2596
2979
|
}
|
|
2980
|
+
|
|
2981
|
+
// node_modules/@jrc03c/js-math-tools/src/abs.mjs
|
|
2597
2982
|
function abs(x) {
|
|
2598
2983
|
try {
|
|
2599
|
-
if (!isNumber(x))
|
|
2600
|
-
return NaN;
|
|
2984
|
+
if (!isNumber(x)) return NaN;
|
|
2601
2985
|
if (typeof x === "bigint") {
|
|
2602
2986
|
return x < 0 ? -x : x;
|
|
2603
2987
|
} else {
|
|
@@ -2608,32 +2992,35 @@
|
|
|
2608
2992
|
}
|
|
2609
2993
|
}
|
|
2610
2994
|
var vabs = vectorize(abs);
|
|
2995
|
+
|
|
2996
|
+
// node_modules/@jrc03c/js-math-tools/src/add.mjs
|
|
2611
2997
|
function add() {
|
|
2612
2998
|
try {
|
|
2613
|
-
let
|
|
2999
|
+
let out = 0;
|
|
2614
3000
|
let resultShouldBeABigInt = false;
|
|
2615
3001
|
const x = Object.values(arguments);
|
|
2616
3002
|
for (let v of x) {
|
|
2617
|
-
if (!isNumber(v))
|
|
2618
|
-
return NaN;
|
|
3003
|
+
if (!isNumber(v)) return NaN;
|
|
2619
3004
|
if (typeof v === "bigint") {
|
|
2620
3005
|
resultShouldBeABigInt = true;
|
|
2621
3006
|
v = Number(v);
|
|
2622
3007
|
}
|
|
2623
|
-
|
|
3008
|
+
out += v;
|
|
2624
3009
|
}
|
|
2625
3010
|
if (resultShouldBeABigInt) {
|
|
2626
3011
|
try {
|
|
2627
|
-
return BigInt(
|
|
3012
|
+
return BigInt(out);
|
|
2628
3013
|
} catch (e) {
|
|
2629
3014
|
}
|
|
2630
3015
|
}
|
|
2631
|
-
return
|
|
3016
|
+
return out;
|
|
2632
3017
|
} catch (e) {
|
|
2633
3018
|
return NaN;
|
|
2634
3019
|
}
|
|
2635
3020
|
}
|
|
2636
3021
|
var vadd = vectorize(add);
|
|
3022
|
+
|
|
3023
|
+
// node_modules/@jrc03c/js-math-tools/src/apply.mjs
|
|
2637
3024
|
function apply(x, fn) {
|
|
2638
3025
|
try {
|
|
2639
3026
|
return fn(x);
|
|
@@ -2642,10 +3029,11 @@
|
|
|
2642
3029
|
}
|
|
2643
3030
|
}
|
|
2644
3031
|
var vapply = vectorize(apply);
|
|
3032
|
+
|
|
3033
|
+
// node_modules/@jrc03c/js-math-tools/src/arccos.mjs
|
|
2645
3034
|
function arccos(x) {
|
|
2646
3035
|
try {
|
|
2647
|
-
if (!isNumber(x))
|
|
2648
|
-
return NaN;
|
|
3036
|
+
if (!isNumber(x)) return NaN;
|
|
2649
3037
|
if (typeof x === "bigint") {
|
|
2650
3038
|
x = Number(x);
|
|
2651
3039
|
}
|
|
@@ -2655,10 +3043,11 @@
|
|
|
2655
3043
|
}
|
|
2656
3044
|
}
|
|
2657
3045
|
var varccos = vectorize(arccos);
|
|
3046
|
+
|
|
3047
|
+
// node_modules/@jrc03c/js-math-tools/src/arcsin.mjs
|
|
2658
3048
|
function arcsin(x) {
|
|
2659
3049
|
try {
|
|
2660
|
-
if (!isNumber(x))
|
|
2661
|
-
return NaN;
|
|
3050
|
+
if (!isNumber(x)) return NaN;
|
|
2662
3051
|
if (typeof x === "bigint") {
|
|
2663
3052
|
x = Number(x);
|
|
2664
3053
|
}
|
|
@@ -2668,10 +3057,11 @@
|
|
|
2668
3057
|
}
|
|
2669
3058
|
}
|
|
2670
3059
|
var varcsin = vectorize(arcsin);
|
|
3060
|
+
|
|
3061
|
+
// node_modules/@jrc03c/js-math-tools/src/arctan.mjs
|
|
2671
3062
|
function arctan(x) {
|
|
2672
3063
|
try {
|
|
2673
|
-
if (!isNumber(x))
|
|
2674
|
-
return NaN;
|
|
3064
|
+
if (!isNumber(x)) return NaN;
|
|
2675
3065
|
if (typeof x === "bigint") {
|
|
2676
3066
|
x = Number(x);
|
|
2677
3067
|
}
|
|
@@ -2681,226 +3071,24 @@
|
|
|
2681
3071
|
}
|
|
2682
3072
|
}
|
|
2683
3073
|
var varctan = vectorize(arctan);
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
const index = argmax(x.values, shouldDropNaNs);
|
|
2687
|
-
return [x.index[index[0]], x.columns[index[1]]];
|
|
2688
|
-
}
|
|
2689
|
-
if (isSeries(x)) {
|
|
2690
|
-
const index = argmax(x.values, shouldDropNaNs);
|
|
2691
|
-
return x.index[index];
|
|
2692
|
-
}
|
|
2693
|
-
assert(isArray(x), "The `argmax` function only works on arrays, Series, and DataFrames!");
|
|
2694
|
-
try {
|
|
2695
|
-
const out2 = indexOf(x, max(x, shouldDropNaNs));
|
|
2696
|
-
if (out2) {
|
|
2697
|
-
if (out2.length === 0) {
|
|
2698
|
-
return void 0;
|
|
2699
|
-
} else if (out2.length === 1) {
|
|
2700
|
-
return out2[0];
|
|
2701
|
-
} else {
|
|
2702
|
-
return out2;
|
|
2703
|
-
}
|
|
2704
|
-
} else {
|
|
2705
|
-
return void 0;
|
|
2706
|
-
}
|
|
2707
|
-
} catch (e) {
|
|
2708
|
-
return void 0;
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
function min(arr, shouldDropNaNs) {
|
|
2712
|
-
return stats(arr, { shouldDropNaNs }).min;
|
|
2713
|
-
}
|
|
2714
|
-
function argmin(x, shouldDropNaNs) {
|
|
2715
|
-
if (isDataFrame(x)) {
|
|
2716
|
-
const index = argmin(x.values, shouldDropNaNs);
|
|
2717
|
-
return [x.index[index[0]], x.columns[index[1]]];
|
|
2718
|
-
}
|
|
2719
|
-
if (isSeries(x)) {
|
|
2720
|
-
const index = argmin(x.values, shouldDropNaNs);
|
|
2721
|
-
return x.index[index];
|
|
2722
|
-
}
|
|
2723
|
-
assert(isArray(x), "The `argmin` function only works on arrays, Series, and DataFrames!");
|
|
2724
|
-
try {
|
|
2725
|
-
const out2 = indexOf(x, min(x, shouldDropNaNs));
|
|
2726
|
-
if (out2) {
|
|
2727
|
-
if (out2.length === 0) {
|
|
2728
|
-
return void 0;
|
|
2729
|
-
} else if (out2.length === 1) {
|
|
2730
|
-
return out2[0];
|
|
2731
|
-
} else {
|
|
2732
|
-
return out2;
|
|
2733
|
-
}
|
|
2734
|
-
} else {
|
|
2735
|
-
return void 0;
|
|
2736
|
-
}
|
|
2737
|
-
} catch (e) {
|
|
2738
|
-
return void 0;
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
function cast(value, type) {
|
|
2742
|
-
if (isDataFrame(value) || isSeries(value)) {
|
|
2743
|
-
return value.apply((item) => cast(item, type));
|
|
2744
|
-
}
|
|
2745
|
-
if (isArray(value)) {
|
|
2746
|
-
return value.map((v) => cast(v, type));
|
|
2747
|
-
}
|
|
2748
|
-
if (type === "null") {
|
|
2749
|
-
return null;
|
|
2750
|
-
}
|
|
2751
|
-
if (type === "number") {
|
|
2752
|
-
if (isUndefined(value)) {
|
|
2753
|
-
return NaN;
|
|
2754
|
-
}
|
|
2755
|
-
const booleanValue = cast(value, "boolean");
|
|
2756
|
-
if (isBoolean(booleanValue)) {
|
|
2757
|
-
return booleanValue ? 1 : 0;
|
|
2758
|
-
}
|
|
2759
|
-
try {
|
|
2760
|
-
JSON.parse(value);
|
|
2761
|
-
} catch (e) {
|
|
2762
|
-
const dateValue = cast(value, "date");
|
|
2763
|
-
if (isDate(dateValue)) {
|
|
2764
|
-
return dateValue.getTime();
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
const out2 = parseFloat(value);
|
|
2768
|
-
if (isNaN(out2))
|
|
2769
|
-
return NaN;
|
|
2770
|
-
return out2;
|
|
2771
|
-
}
|
|
2772
|
-
if (type === "int") {
|
|
2773
|
-
const out2 = cast(value, "number");
|
|
2774
|
-
return out2 >= 0 ? Math.floor(out2) : Math.ceil(out2);
|
|
2775
|
-
}
|
|
2776
|
-
if (type === "float") {
|
|
2777
|
-
return cast(value, "number");
|
|
2778
|
-
}
|
|
2779
|
-
if (type === "bigint") {
|
|
2780
|
-
if (typeof value === "bigint") {
|
|
2781
|
-
return value;
|
|
2782
|
-
}
|
|
2783
|
-
return BigInt(cast(value, "int"));
|
|
2784
|
-
}
|
|
2785
|
-
if (type === "boolean") {
|
|
2786
|
-
if (isBoolean(value)) {
|
|
2787
|
-
return value;
|
|
2788
|
-
}
|
|
2789
|
-
if (isNumber(value)) {
|
|
2790
|
-
if (value === 0) {
|
|
2791
|
-
return false;
|
|
2792
|
-
}
|
|
2793
|
-
if (value === 1) {
|
|
2794
|
-
return true;
|
|
2795
|
-
}
|
|
2796
|
-
return null;
|
|
2797
|
-
}
|
|
2798
|
-
try {
|
|
2799
|
-
const vBool = (typeof value === "object" ? value.toString() === "null" ? "false" : JSON.stringify(value) : value.toString()).trim().toLowerCase();
|
|
2800
|
-
if (vBool === "true" || vBool === "yes" || vBool === "y") {
|
|
2801
|
-
return true;
|
|
2802
|
-
}
|
|
2803
|
-
if (vBool === "false" || vBool === "no" || vBool === "n") {
|
|
2804
|
-
return false;
|
|
2805
|
-
}
|
|
2806
|
-
return null;
|
|
2807
|
-
} catch (e) {
|
|
2808
|
-
return null;
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
if (type === "date") {
|
|
2812
|
-
if (isDate(value)) {
|
|
2813
|
-
return value;
|
|
2814
|
-
}
|
|
2815
|
-
if (isUndefined(value)) {
|
|
2816
|
-
return null;
|
|
2817
|
-
}
|
|
2818
|
-
const valueFloat = parseFloat(value);
|
|
2819
|
-
if (!isNaN(valueFloat)) {
|
|
2820
|
-
const out2 = new Date(value);
|
|
2821
|
-
if (!isDate(out2))
|
|
2822
|
-
return null;
|
|
2823
|
-
return out2;
|
|
2824
|
-
}
|
|
2825
|
-
const valueDate = Date.parse(value);
|
|
2826
|
-
if (!isNaN(valueDate)) {
|
|
2827
|
-
return new Date(valueDate);
|
|
2828
|
-
}
|
|
2829
|
-
return null;
|
|
2830
|
-
}
|
|
2831
|
-
if (type === "object") {
|
|
2832
|
-
if (isObject(value)) {
|
|
2833
|
-
return value;
|
|
2834
|
-
}
|
|
2835
|
-
const booleanValue = cast(value, "boolean");
|
|
2836
|
-
if (isBoolean(booleanValue)) {
|
|
2837
|
-
return null;
|
|
2838
|
-
}
|
|
2839
|
-
try {
|
|
2840
|
-
const numberValue = cast(value, "number");
|
|
2841
|
-
if (isNumber(numberValue)) {
|
|
2842
|
-
JSON.parse(value);
|
|
2843
|
-
return null;
|
|
2844
|
-
}
|
|
2845
|
-
} catch (e) {
|
|
2846
|
-
}
|
|
2847
|
-
const dateValue = cast(value, "date");
|
|
2848
|
-
if (dateValue) {
|
|
2849
|
-
return dateValue;
|
|
2850
|
-
}
|
|
2851
|
-
try {
|
|
2852
|
-
const out2 = JSON.parse(value);
|
|
2853
|
-
if (isArray(out2)) {
|
|
2854
|
-
return out2.map((v) => cast(v, type));
|
|
2855
|
-
} else {
|
|
2856
|
-
return out2;
|
|
2857
|
-
}
|
|
2858
|
-
} catch (e) {
|
|
2859
|
-
return null;
|
|
2860
|
-
}
|
|
2861
|
-
}
|
|
2862
|
-
if (type === "string") {
|
|
2863
|
-
if (isUndefined(value)) {
|
|
2864
|
-
if (isEqual(value, void 0)) {
|
|
2865
|
-
return "undefined";
|
|
2866
|
-
}
|
|
2867
|
-
return "null";
|
|
2868
|
-
}
|
|
2869
|
-
if (value instanceof Date) {
|
|
2870
|
-
return value.toJSON();
|
|
2871
|
-
}
|
|
2872
|
-
const valueString = (() => {
|
|
2873
|
-
if (typeof value === "object") {
|
|
2874
|
-
if (value === null) {
|
|
2875
|
-
return "null";
|
|
2876
|
-
} else {
|
|
2877
|
-
return JSON.stringify(value);
|
|
2878
|
-
}
|
|
2879
|
-
} else {
|
|
2880
|
-
return value.toString();
|
|
2881
|
-
}
|
|
2882
|
-
})();
|
|
2883
|
-
return valueString;
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
3074
|
+
|
|
3075
|
+
// node_modules/@jrc03c/js-math-tools/src/ceil.mjs
|
|
2886
3076
|
function ceil(x) {
|
|
2887
3077
|
try {
|
|
2888
|
-
if (!isNumber(x))
|
|
2889
|
-
|
|
2890
|
-
if (typeof x === "bigint")
|
|
2891
|
-
return x;
|
|
3078
|
+
if (!isNumber(x)) return NaN;
|
|
3079
|
+
if (typeof x === "bigint") return x;
|
|
2892
3080
|
return Math.ceil(x);
|
|
2893
3081
|
} catch (e) {
|
|
2894
3082
|
return NaN;
|
|
2895
3083
|
}
|
|
2896
3084
|
}
|
|
2897
3085
|
var vceil = vectorize(ceil);
|
|
3086
|
+
|
|
3087
|
+
// node_modules/@jrc03c/js-math-tools/src/chop.mjs
|
|
2898
3088
|
function chop(x, threshold) {
|
|
2899
3089
|
try {
|
|
2900
|
-
if (!isNumber(x))
|
|
2901
|
-
|
|
2902
|
-
if (typeof x === "bigint")
|
|
2903
|
-
return x;
|
|
3090
|
+
if (!isNumber(x)) return NaN;
|
|
3091
|
+
if (typeof x === "bigint") return x;
|
|
2904
3092
|
if (isUndefined(threshold)) {
|
|
2905
3093
|
threshold = 1e-10;
|
|
2906
3094
|
} else if (!isNumber(threshold)) {
|
|
@@ -2912,19 +3100,21 @@
|
|
|
2912
3100
|
}
|
|
2913
3101
|
}
|
|
2914
3102
|
var vchop = vectorize(chop);
|
|
3103
|
+
|
|
3104
|
+
// node_modules/@jrc03c/js-math-tools/src/int.mjs
|
|
2915
3105
|
function int(x) {
|
|
2916
3106
|
if (isDataFrame(x) || isSeries(x)) {
|
|
2917
|
-
const
|
|
2918
|
-
|
|
2919
|
-
return
|
|
3107
|
+
const out = x.copy();
|
|
3108
|
+
out.values = int(out.values);
|
|
3109
|
+
return out;
|
|
2920
3110
|
}
|
|
2921
3111
|
if (isArray(x)) {
|
|
2922
3112
|
return x.map((v) => int(v));
|
|
2923
3113
|
} else {
|
|
2924
3114
|
try {
|
|
2925
|
-
const
|
|
2926
|
-
if (isNumber(
|
|
2927
|
-
return typeof
|
|
3115
|
+
const out = JSON.parse(x);
|
|
3116
|
+
if (isNumber(out)) {
|
|
3117
|
+
return typeof out === "bigint" ? Number(out) : out >= 0 ? Math.floor(out) : Math.ceil(out);
|
|
2928
3118
|
}
|
|
2929
3119
|
return NaN;
|
|
2930
3120
|
} catch (e) {
|
|
@@ -2933,199 +3123,29 @@
|
|
|
2933
3123
|
}
|
|
2934
3124
|
}
|
|
2935
3125
|
var vint = vectorize(int);
|
|
3126
|
+
|
|
3127
|
+
// node_modules/@jrc03c/js-math-tools/src/clamp.mjs
|
|
2936
3128
|
function clamp(x, a, b) {
|
|
2937
3129
|
try {
|
|
2938
|
-
if (!isNumber(x))
|
|
2939
|
-
|
|
2940
|
-
if (!isNumber(
|
|
2941
|
-
return NaN;
|
|
2942
|
-
if (!isNumber(b))
|
|
2943
|
-
return NaN;
|
|
3130
|
+
if (!isNumber(x)) return NaN;
|
|
3131
|
+
if (!isNumber(a)) return NaN;
|
|
3132
|
+
if (!isNumber(b)) return NaN;
|
|
2944
3133
|
if (typeof x === "bigint") {
|
|
2945
3134
|
return BigInt(clamp(vint(x), a, b));
|
|
2946
3135
|
}
|
|
2947
|
-
if (x < a)
|
|
2948
|
-
|
|
2949
|
-
if (x > b)
|
|
2950
|
-
return b;
|
|
3136
|
+
if (x < a) return a;
|
|
3137
|
+
if (x > b) return b;
|
|
2951
3138
|
return x;
|
|
2952
3139
|
} catch (e) {
|
|
2953
3140
|
return NaN;
|
|
2954
3141
|
}
|
|
2955
3142
|
}
|
|
2956
3143
|
var vclamp = vectorize(clamp);
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
if (r2 > x2.length) {
|
|
2960
|
-
yield x2;
|
|
2961
|
-
} else if (r2 <= 0) {
|
|
2962
|
-
yield [];
|
|
2963
|
-
} else if (x2.length < 2) {
|
|
2964
|
-
yield x2;
|
|
2965
|
-
} else {
|
|
2966
|
-
for (let i = 0; i < x2.length; i++) {
|
|
2967
|
-
const item = x2[i];
|
|
2968
|
-
const after = x2.slice(i + 1);
|
|
2969
|
-
if (after.length < r2 - 1) {
|
|
2970
|
-
continue;
|
|
2971
|
-
}
|
|
2972
|
-
if (r2 - 1 >= 0) {
|
|
2973
|
-
for (const child of combinationsIterator(after, r2 - 1)) {
|
|
2974
|
-
yield [item].concat(child);
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
if (isDataFrame(x) || isSeries(x)) {
|
|
2981
|
-
return combinationsIterator(x.values, r);
|
|
2982
|
-
}
|
|
2983
|
-
assert(isArray(x), "The `combinations` function only works on arrays, Series, and DataFrames!");
|
|
2984
|
-
assert(isNumber(r) && vint(r) === r && r >= 0, "`r` must be a non-negative integer!");
|
|
2985
|
-
return helper5(flatten(x), r);
|
|
2986
|
-
}
|
|
2987
|
-
function combinations(x, r) {
|
|
2988
|
-
const out2 = [];
|
|
2989
|
-
for (const combo of combinationsIterator(x, r)) {
|
|
2990
|
-
out2.push(combo.slice());
|
|
2991
|
-
}
|
|
2992
|
-
return out2;
|
|
2993
|
-
}
|
|
2994
|
-
function intersect() {
|
|
2995
|
-
const arrays = Object.values(arguments).map((x) => {
|
|
2996
|
-
if (isDataFrame(x) || isSeries(x)) {
|
|
2997
|
-
return set(x.values);
|
|
2998
|
-
}
|
|
2999
|
-
assert(isArray(x), "The `intersect` function only works on arrays, Series, and DataFrames!");
|
|
3000
|
-
return set(x);
|
|
3001
|
-
});
|
|
3002
|
-
const all = set(arrays);
|
|
3003
|
-
return all.filter((v) => {
|
|
3004
|
-
return arrays.every((arr) => arr.findIndex((other) => isEqual(other, v)) > -1);
|
|
3005
|
-
});
|
|
3006
|
-
}
|
|
3007
|
-
var _IndexMatcher = class {
|
|
3008
|
-
constructor(mode2) {
|
|
3009
|
-
assert(isUndefined(mode2) || mode2 === _IndexMatcher.DROP_NAN_MODE || mode2 === _IndexMatcher.DROP_MISSING_MODE, "The `mode` value passed into the `IndexMatcher` constructor must be undefined or one of [IndexMatcher.DROP_NAN_MODE, IndexMatcher.DROP_MISSING_MODE]! (By default, the mode is `Indexer.DROP_MISSING_MODE`.)");
|
|
3010
|
-
this.mode = !isUndefined(mode2) ? mode2 : _IndexMatcher.DROP_NAN_MODE;
|
|
3011
|
-
this.index = null;
|
|
3012
|
-
}
|
|
3013
|
-
fit() {
|
|
3014
|
-
const indices = [];
|
|
3015
|
-
Object.values(arguments).forEach((x) => {
|
|
3016
|
-
if (isArray(x)) {
|
|
3017
|
-
const xshape = shape(x);
|
|
3018
|
-
if (xshape.length === 1) {
|
|
3019
|
-
x = new Series(x);
|
|
3020
|
-
} else if (xshape.length === 2) {
|
|
3021
|
-
x = new DataFrame(x);
|
|
3022
|
-
} else {
|
|
3023
|
-
throw new Error("The `IndexMatcher.fit` method only works on arrays, Series, and DataFrames!");
|
|
3024
|
-
}
|
|
3025
|
-
}
|
|
3026
|
-
assert(isDataFrame(x) || isSeries(x), "The `IndexMatcher.fit` method only works on arrays, Series, and DataFrames!");
|
|
3027
|
-
if (this.mode === _IndexMatcher.DROP_MISSING_MODE) {
|
|
3028
|
-
indices.push(x.dropMissing().index);
|
|
3029
|
-
} else {
|
|
3030
|
-
indices.push(x.dropNaN().index);
|
|
3031
|
-
}
|
|
3032
|
-
});
|
|
3033
|
-
this.index = intersect(...indices);
|
|
3034
|
-
return this;
|
|
3035
|
-
}
|
|
3036
|
-
transform() {
|
|
3037
|
-
assert(!!this.index, "The IndexMatcher hasn't been fitted yet! Please call the `fit` method before calling the `transform` method.");
|
|
3038
|
-
const out2 = Object.values(arguments).map((x) => {
|
|
3039
|
-
if (isArray(x)) {
|
|
3040
|
-
const xshape = shape(x);
|
|
3041
|
-
if (xshape.length === 1) {
|
|
3042
|
-
return new Series(x).get(this.index).values;
|
|
3043
|
-
} else if (xshape.length === 2) {
|
|
3044
|
-
return new DataFrame(x).get(this.index, null).values;
|
|
3045
|
-
} else {
|
|
3046
|
-
throw new Error("The `IndexMatcher.fit` method only works on arrays, Series, and DataFrames!");
|
|
3047
|
-
}
|
|
3048
|
-
}
|
|
3049
|
-
assert(isDataFrame(x) || isSeries(x), "The `IndexMatcher.fit` method only works on arrays, Series, and DataFrames!");
|
|
3050
|
-
return x.get(this.index, null);
|
|
3051
|
-
});
|
|
3052
|
-
return out2.length === 1 ? out2[0] : out2;
|
|
3053
|
-
}
|
|
3054
|
-
fitAndTransform() {
|
|
3055
|
-
return this.fit(...arguments).transform(...arguments);
|
|
3056
|
-
}
|
|
3057
|
-
};
|
|
3058
|
-
var IndexMatcher = _IndexMatcher;
|
|
3059
|
-
__publicField(IndexMatcher, "DROP_NAN_MODE", "DROP_NAN_MODE");
|
|
3060
|
-
__publicField(IndexMatcher, "DROP_MISSING_MODE", "DROP_MISSING_MODE");
|
|
3061
|
-
function covariance(x, y, shouldDropNaNs, shouldAlsoReturnStatsObjects) {
|
|
3062
|
-
if (isSeries(x)) {
|
|
3063
|
-
return covariance(x.values, y, shouldDropNaNs, shouldAlsoReturnStatsObjects);
|
|
3064
|
-
}
|
|
3065
|
-
if (isSeries(y)) {
|
|
3066
|
-
return covariance(x, y.values, shouldDropNaNs, shouldAlsoReturnStatsObjects);
|
|
3067
|
-
}
|
|
3068
|
-
assert(isArray(x) && isArray(y) && shape(x).length === 1 && shape(y).length === 1, "The `covariance` function only works on 1-dimensional arrays and Series!");
|
|
3069
|
-
assert(x.length === y.length, "The two arrays or Series passed into the `covariance` function must have the same length!");
|
|
3070
|
-
if (shouldDropNaNs) {
|
|
3071
|
-
return covariance(...new IndexMatcher().fitAndTransform(x, y), false, shouldAlsoReturnStatsObjects);
|
|
3072
|
-
}
|
|
3073
|
-
try {
|
|
3074
|
-
const xstats = stats(x, { stdev: shouldAlsoReturnStatsObjects });
|
|
3075
|
-
const ystats = stats(y, { stdev: shouldAlsoReturnStatsObjects });
|
|
3076
|
-
const mx = Number(xstats.mean);
|
|
3077
|
-
const my = Number(ystats.mean);
|
|
3078
|
-
if (!isNumber(mx) || !isNumber(my)) {
|
|
3079
|
-
return NaN;
|
|
3080
|
-
}
|
|
3081
|
-
const n = Math.max(x.length, y.length);
|
|
3082
|
-
let out2 = 0;
|
|
3083
|
-
for (let i = 0; i < n; i++) {
|
|
3084
|
-
let vx = x[i];
|
|
3085
|
-
let vy = y[i];
|
|
3086
|
-
if (!isNumber(vx))
|
|
3087
|
-
return NaN;
|
|
3088
|
-
if (!isNumber(vy))
|
|
3089
|
-
return NaN;
|
|
3090
|
-
if (typeof vx === "bigint") {
|
|
3091
|
-
vx = Number(vx);
|
|
3092
|
-
}
|
|
3093
|
-
if (typeof vy === "bigint") {
|
|
3094
|
-
vy = Number(vy);
|
|
3095
|
-
}
|
|
3096
|
-
out2 += (vx - mx) * (vy - my);
|
|
3097
|
-
}
|
|
3098
|
-
if (shouldAlsoReturnStatsObjects) {
|
|
3099
|
-
return [out2 / x.length, xstats, ystats];
|
|
3100
|
-
} else {
|
|
3101
|
-
return out2 / x.length;
|
|
3102
|
-
}
|
|
3103
|
-
} catch (e) {
|
|
3104
|
-
return NaN;
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
function correl(x, y, shouldDropNaNs) {
|
|
3108
|
-
if (isSeries(x)) {
|
|
3109
|
-
return correl(x.values, y, shouldDropNaNs);
|
|
3110
|
-
}
|
|
3111
|
-
if (isSeries(y)) {
|
|
3112
|
-
return correl(x, y.values, shouldDropNaNs);
|
|
3113
|
-
}
|
|
3114
|
-
assert(isArray(x) && isArray(y) && shape(x).length === 1 && shape(y).length === 1, "The `correl` function only works on 1-dimensional arrays and Series!");
|
|
3115
|
-
assert(x.length === y.length, "The two arrays or Series passed into the `correl` function must have the same length!");
|
|
3116
|
-
try {
|
|
3117
|
-
const shouldAlsoReturnStatsObjects = true;
|
|
3118
|
-
const [num, xstats, ystats] = covariance(x, y, shouldDropNaNs, shouldAlsoReturnStatsObjects);
|
|
3119
|
-
const den = xstats.stdev * ystats.stdev;
|
|
3120
|
-
return num / den;
|
|
3121
|
-
} catch (e) {
|
|
3122
|
-
return NaN;
|
|
3123
|
-
}
|
|
3124
|
-
}
|
|
3144
|
+
|
|
3145
|
+
// node_modules/@jrc03c/js-math-tools/src/cos.mjs
|
|
3125
3146
|
function cos(x) {
|
|
3126
3147
|
try {
|
|
3127
|
-
if (!isNumber(x))
|
|
3128
|
-
return NaN;
|
|
3148
|
+
if (!isNumber(x)) return NaN;
|
|
3129
3149
|
if (typeof x === "bigint") {
|
|
3130
3150
|
x = Number(x);
|
|
3131
3151
|
}
|
|
@@ -3135,6 +3155,8 @@
|
|
|
3135
3155
|
}
|
|
3136
3156
|
}
|
|
3137
3157
|
var vcos = vectorize(cos);
|
|
3158
|
+
|
|
3159
|
+
// node_modules/@jrc03c/js-math-tools/src/helpers/data-types.mjs
|
|
3138
3160
|
var dataTypes = Object.freeze({
|
|
3139
3161
|
boolean: "boolean",
|
|
3140
3162
|
date: "date",
|
|
@@ -3143,36 +3165,18 @@
|
|
|
3143
3165
|
object: "object",
|
|
3144
3166
|
string: "string"
|
|
3145
3167
|
});
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
return diff(a.values, b);
|
|
3149
|
-
}
|
|
3150
|
-
if (isDataFrame(b) || isSeries(b)) {
|
|
3151
|
-
return diff(a, b.values);
|
|
3152
|
-
}
|
|
3153
|
-
assert(isArray(a) && isArray(b), "The `diff` function only works on arrays, Series, and DataFrames!");
|
|
3154
|
-
const aTemp = set(a);
|
|
3155
|
-
const bTemp = set(b);
|
|
3156
|
-
const out2 = [];
|
|
3157
|
-
aTemp.forEach((item) => {
|
|
3158
|
-
if (bTemp.findIndex((other) => isEqual(other, item)) < 0) {
|
|
3159
|
-
out2.push(item);
|
|
3160
|
-
}
|
|
3161
|
-
});
|
|
3162
|
-
return out2;
|
|
3163
|
-
}
|
|
3168
|
+
|
|
3169
|
+
// node_modules/@jrc03c/js-math-tools/src/pow.mjs
|
|
3164
3170
|
function pow(x, p) {
|
|
3165
3171
|
try {
|
|
3166
|
-
if (!isNumber(x))
|
|
3167
|
-
|
|
3168
|
-
if (!isNumber(p))
|
|
3169
|
-
return NaN;
|
|
3172
|
+
if (!isNumber(x)) return NaN;
|
|
3173
|
+
if (!isNumber(p)) return NaN;
|
|
3170
3174
|
if (typeof x === "bigint" || typeof p === "bigint") {
|
|
3171
|
-
const
|
|
3175
|
+
const out = pow(Number(x), Number(p));
|
|
3172
3176
|
try {
|
|
3173
|
-
return BigInt(
|
|
3177
|
+
return BigInt(out);
|
|
3174
3178
|
} catch (e) {
|
|
3175
|
-
return
|
|
3179
|
+
return out;
|
|
3176
3180
|
}
|
|
3177
3181
|
}
|
|
3178
3182
|
return Math.pow(x, p);
|
|
@@ -3181,16 +3185,17 @@
|
|
|
3181
3185
|
}
|
|
3182
3186
|
}
|
|
3183
3187
|
var vpow = vectorize(pow);
|
|
3188
|
+
|
|
3189
|
+
// node_modules/@jrc03c/js-math-tools/src/sqrt.mjs
|
|
3184
3190
|
function sqrt(x) {
|
|
3185
3191
|
try {
|
|
3186
|
-
if (!isNumber(x))
|
|
3187
|
-
return NaN;
|
|
3192
|
+
if (!isNumber(x)) return NaN;
|
|
3188
3193
|
if (typeof x === "bigint") {
|
|
3189
|
-
const
|
|
3194
|
+
const out = sqrt(Number(x));
|
|
3190
3195
|
try {
|
|
3191
|
-
return BigInt(
|
|
3196
|
+
return BigInt(out);
|
|
3192
3197
|
} catch (e) {
|
|
3193
|
-
return
|
|
3198
|
+
return out;
|
|
3194
3199
|
}
|
|
3195
3200
|
}
|
|
3196
3201
|
return Math.sqrt(x);
|
|
@@ -3199,218 +3204,39 @@
|
|
|
3199
3204
|
}
|
|
3200
3205
|
}
|
|
3201
3206
|
var vsqrt = vectorize(sqrt);
|
|
3207
|
+
|
|
3208
|
+
// node_modules/@jrc03c/js-math-tools/src/multiply.mjs
|
|
3202
3209
|
function multiply() {
|
|
3203
3210
|
try {
|
|
3204
3211
|
const x = Object.values(arguments);
|
|
3205
|
-
if (x.length === 0)
|
|
3206
|
-
return NaN;
|
|
3212
|
+
if (x.length === 0) return NaN;
|
|
3207
3213
|
let resultShouldBeABigInt = false;
|
|
3208
|
-
let
|
|
3214
|
+
let out = 1;
|
|
3209
3215
|
for (let v of x) {
|
|
3210
|
-
if (!isNumber(v))
|
|
3211
|
-
return NaN;
|
|
3216
|
+
if (!isNumber(v)) return NaN;
|
|
3212
3217
|
if (typeof v === "bigint") {
|
|
3213
3218
|
resultShouldBeABigInt = true;
|
|
3214
3219
|
v = Number(v);
|
|
3215
3220
|
}
|
|
3216
|
-
|
|
3221
|
+
out *= v;
|
|
3217
3222
|
}
|
|
3218
3223
|
if (resultShouldBeABigInt) {
|
|
3219
3224
|
try {
|
|
3220
|
-
return BigInt(
|
|
3225
|
+
return BigInt(out);
|
|
3221
3226
|
} catch (e) {
|
|
3222
3227
|
}
|
|
3223
3228
|
}
|
|
3224
|
-
return
|
|
3229
|
+
return out;
|
|
3225
3230
|
} catch (e) {
|
|
3226
3231
|
return NaN;
|
|
3227
3232
|
}
|
|
3228
3233
|
}
|
|
3229
3234
|
var vmultiply = vectorize(multiply);
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
}
|
|
3233
|
-
function subtract(a, b) {
|
|
3234
|
-
return vadd(a, scale(b, -1));
|
|
3235
|
-
}
|
|
3236
|
-
function sum(arr, shouldDropNaNs) {
|
|
3237
|
-
return stats(arr, { shouldDropNaNs }).sum;
|
|
3238
|
-
}
|
|
3239
|
-
function distance(a, b) {
|
|
3240
|
-
if (isNumber(a) && isNumber(b)) {
|
|
3241
|
-
return vabs(a - b);
|
|
3242
|
-
}
|
|
3243
|
-
if (isDataFrame(a) || isSeries(a)) {
|
|
3244
|
-
return distance(a.values, b);
|
|
3245
|
-
}
|
|
3246
|
-
if (isDataFrame(b) || isSeries(b)) {
|
|
3247
|
-
return distance(a, b.values);
|
|
3248
|
-
}
|
|
3249
|
-
if (isArray(a) && isArray(b)) {
|
|
3250
|
-
assert(isEqual(shape(a), shape(b)), "If passing two arrays, Series, or DataFrames into the `distance` function, then those objects must have the same shape!");
|
|
3251
|
-
}
|
|
3252
|
-
try {
|
|
3253
|
-
return vsqrt(sum(vpow(subtract(a, b), 2)));
|
|
3254
|
-
} catch (e) {
|
|
3255
|
-
return NaN;
|
|
3256
|
-
}
|
|
3257
|
-
}
|
|
3258
|
-
function divide(a, b) {
|
|
3259
|
-
return scale(a, vpow(b, -1));
|
|
3260
|
-
}
|
|
3261
|
-
function dot(a, b) {
|
|
3262
|
-
if (isDataFrame(a)) {
|
|
3263
|
-
const temp = dot(a.values, b);
|
|
3264
|
-
if (shape(temp).length === 1) {
|
|
3265
|
-
const out2 = new Series(temp);
|
|
3266
|
-
out2.name = isSeries(b) ? b.name : out2.name;
|
|
3267
|
-
out2.index = a.index.slice();
|
|
3268
|
-
return out2;
|
|
3269
|
-
} else {
|
|
3270
|
-
const out2 = new DataFrame(temp);
|
|
3271
|
-
out2.index = a.index.slice();
|
|
3272
|
-
if (isDataFrame(b)) {
|
|
3273
|
-
out2.columns = b.columns.slice();
|
|
3274
|
-
}
|
|
3275
|
-
return out2;
|
|
3276
|
-
}
|
|
3277
|
-
}
|
|
3278
|
-
if (isDataFrame(b)) {
|
|
3279
|
-
const temp = dot(a, b.values);
|
|
3280
|
-
if (shape(temp).length === 1) {
|
|
3281
|
-
const out2 = new Series(temp);
|
|
3282
|
-
out2.name = isSeries(a) ? a.name : out2.name;
|
|
3283
|
-
out2.index = b.columns.slice();
|
|
3284
|
-
return out2;
|
|
3285
|
-
} else {
|
|
3286
|
-
const out2 = new DataFrame(temp);
|
|
3287
|
-
out2.columns = b.columns.slice();
|
|
3288
|
-
return out2;
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
3291
|
-
if (isSeries(a)) {
|
|
3292
|
-
return dot(a.values, b);
|
|
3293
|
-
}
|
|
3294
|
-
if (isSeries(b)) {
|
|
3295
|
-
return dot(a, b.values);
|
|
3296
|
-
}
|
|
3297
|
-
assert(isArray(a) && isArray(b), "The `dot` function only works on arrays, Series, and DataFrames!");
|
|
3298
|
-
const aShape = shape(a);
|
|
3299
|
-
const bShape = shape(b);
|
|
3300
|
-
assert(aShape.length <= 2 && bShape.length <= 2, "I'm not smart enough to know how to get the dot-product of arrays that have more than 2 dimensions. Sorry for the inconvenience! Please only pass 1- or 2-dimensional arrays into the `dot` function!");
|
|
3301
|
-
assert(aShape[aShape.length - 1] === bShape[0], `There's a dimension misalignment in the two arrays you passed into the \`dot\` function. (${aShape[aShape.length - 1]} !== ${bShape[0]})`);
|
|
3302
|
-
if (aShape.length === 1 && bShape.length === 1) {
|
|
3303
|
-
return sum(scale(a, b));
|
|
3304
|
-
} else if (aShape.length === 1 && bShape.length === 2) {
|
|
3305
|
-
return transpose(b).map((col) => dot(a, col));
|
|
3306
|
-
} else if (aShape.length === 2 && bShape.length === 1) {
|
|
3307
|
-
return a.map((row) => dot(row, b));
|
|
3308
|
-
} else if (aShape.length === 2 && bShape.length === 2) {
|
|
3309
|
-
const bTranspose = transpose(b);
|
|
3310
|
-
const out2 = [];
|
|
3311
|
-
for (let i = 0; i < a.length; i++) {
|
|
3312
|
-
const row = [];
|
|
3313
|
-
for (let j = 0; j < bTranspose.length; j++) {
|
|
3314
|
-
row.push(dot(a[i], bTranspose[j]));
|
|
3315
|
-
}
|
|
3316
|
-
out2.push(row);
|
|
3317
|
-
}
|
|
3318
|
-
return out2;
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
function dropMissing(x) {
|
|
3322
|
-
if (isDataFrame(x) || isSeries(x)) {
|
|
3323
|
-
return x.dropMissing(...Object.values(arguments).slice(1));
|
|
3324
|
-
}
|
|
3325
|
-
assert(isArray(x), "The `dropMissing` function only works on arrays, Series, and DataFrames!");
|
|
3326
|
-
const out2 = [];
|
|
3327
|
-
x.forEach((v) => {
|
|
3328
|
-
try {
|
|
3329
|
-
return out2.push(dropMissing(v));
|
|
3330
|
-
} catch (e) {
|
|
3331
|
-
if (!isUndefined(v)) {
|
|
3332
|
-
out2.push(v);
|
|
3333
|
-
}
|
|
3334
|
-
}
|
|
3335
|
-
});
|
|
3336
|
-
return out2;
|
|
3337
|
-
}
|
|
3338
|
-
function dropMissingPairwise(a, b) {
|
|
3339
|
-
if (isDataFrame(a) || isSeries(a)) {
|
|
3340
|
-
return dropMissingPairwise(a.values, b);
|
|
3341
|
-
}
|
|
3342
|
-
if (isDataFrame(b) || isSeries(b)) {
|
|
3343
|
-
return dropMissingPairwise(a, b.values);
|
|
3344
|
-
}
|
|
3345
|
-
assert(isArray(a) && isArray(b), "The `dropMissingPairwise` function only works on arrays, Series, and DataFrames!");
|
|
3346
|
-
assert(isEqual(shape(a), shape(b)), "The two arrays, Series, and/or DataFrames passed into the `dropMissingPairwise` function must have the same shape!");
|
|
3347
|
-
const aOut = [];
|
|
3348
|
-
const bOut = [];
|
|
3349
|
-
for (let i = 0; i < a.length; i++) {
|
|
3350
|
-
try {
|
|
3351
|
-
const [aChildren, bChildren] = dropMissingPairwise(a[i], b[i]);
|
|
3352
|
-
aOut.push(aChildren);
|
|
3353
|
-
bOut.push(bChildren);
|
|
3354
|
-
} catch (e) {
|
|
3355
|
-
if (!isUndefined(a[i]) && !isUndefined(b[i])) {
|
|
3356
|
-
aOut.push(a[i]);
|
|
3357
|
-
bOut.push(b[i]);
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
return [aOut, bOut];
|
|
3362
|
-
}
|
|
3363
|
-
function dropNaNPairwise(a, b) {
|
|
3364
|
-
if (isDataFrame(a) || isSeries(a)) {
|
|
3365
|
-
return dropNaNPairwise(a.values, b);
|
|
3366
|
-
}
|
|
3367
|
-
if (isDataFrame(b) || isSeries(b)) {
|
|
3368
|
-
return dropNaNPairwise(a, b.values);
|
|
3369
|
-
}
|
|
3370
|
-
assert(isArray(a) && isArray(b), "The `dropNaNPairwise` only works on arrays, Series, and DataFrames!");
|
|
3371
|
-
assert(isEqual(shape(a), shape(b)), "The two arrays, Series, and/or DataFrames passed into the `dropNaNPairwise` must have the same shape!");
|
|
3372
|
-
const aOut = [];
|
|
3373
|
-
const bOut = [];
|
|
3374
|
-
for (let i = 0; i < a.length; i++) {
|
|
3375
|
-
try {
|
|
3376
|
-
const [aChildren, bChildren] = dropNaNPairwise(a[i], b[i]);
|
|
3377
|
-
aOut.push(aChildren);
|
|
3378
|
-
bOut.push(bChildren);
|
|
3379
|
-
} catch (e) {
|
|
3380
|
-
if (isNumber(a[i]) && isNumber(b[i])) {
|
|
3381
|
-
aOut.push(a[i]);
|
|
3382
|
-
bOut.push(b[i]);
|
|
3383
|
-
}
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
return [aOut, bOut];
|
|
3387
|
-
}
|
|
3388
|
-
function dropUndefined(x) {
|
|
3389
|
-
return dropMissing(x);
|
|
3390
|
-
}
|
|
3391
|
-
function every(x, fn) {
|
|
3392
|
-
if (isDataFrame(x) || isSeries(x)) {
|
|
3393
|
-
return every(x.values, fn);
|
|
3394
|
-
}
|
|
3395
|
-
assert(isArray(x), "The first argument passed into the `every` function must be an array, Series, or DataFrame!");
|
|
3396
|
-
assert(isFunction(fn), "The second argument passed into the `every` function must be a function!");
|
|
3397
|
-
for (const v of x) {
|
|
3398
|
-
if (isArray(v)) {
|
|
3399
|
-
if (!every(v, fn)) {
|
|
3400
|
-
return false;
|
|
3401
|
-
}
|
|
3402
|
-
} else {
|
|
3403
|
-
if (!fn(v)) {
|
|
3404
|
-
return false;
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
return true;
|
|
3409
|
-
}
|
|
3235
|
+
|
|
3236
|
+
// node_modules/@jrc03c/js-math-tools/src/exp.mjs
|
|
3410
3237
|
function exp(x) {
|
|
3411
3238
|
try {
|
|
3412
|
-
if (!isNumber(x))
|
|
3413
|
-
return NaN;
|
|
3239
|
+
if (!isNumber(x)) return NaN;
|
|
3414
3240
|
if (typeof x === "bigint") {
|
|
3415
3241
|
if (x === 0n) {
|
|
3416
3242
|
return 1n;
|
|
@@ -3424,152 +3250,23 @@
|
|
|
3424
3250
|
}
|
|
3425
3251
|
}
|
|
3426
3252
|
var vexp = vectorize(exp);
|
|
3253
|
+
|
|
3254
|
+
// node_modules/@jrc03c/js-math-tools/src/factorial.mjs
|
|
3427
3255
|
function factorial(n) {
|
|
3428
3256
|
try {
|
|
3429
3257
|
if (typeof n === "bigint") {
|
|
3430
3258
|
return BigInt(factorial(vint(n)));
|
|
3431
3259
|
}
|
|
3432
|
-
if (n !== vint(n))
|
|
3433
|
-
|
|
3434
|
-
if (n <= 1)
|
|
3435
|
-
return 1;
|
|
3260
|
+
if (n !== vint(n)) return NaN;
|
|
3261
|
+
if (n <= 1) return 1;
|
|
3436
3262
|
return n * factorial(n - 1);
|
|
3437
3263
|
} catch (e) {
|
|
3438
3264
|
return NaN;
|
|
3439
3265
|
}
|
|
3440
3266
|
}
|
|
3441
3267
|
var vfactorial = vectorize(factorial);
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
return find(x.values, fn);
|
|
3445
|
-
}
|
|
3446
|
-
if (isSeries(x)) {
|
|
3447
|
-
return find(x.values, fn);
|
|
3448
|
-
}
|
|
3449
|
-
assert(isObject(x) || isArray(x), "You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `find` function!");
|
|
3450
|
-
if (!isFunction(fn)) {
|
|
3451
|
-
const value = fn;
|
|
3452
|
-
fn = (v) => v === value;
|
|
3453
|
-
}
|
|
3454
|
-
function helper5(x2, fn2, checked) {
|
|
3455
|
-
checked = checked || [];
|
|
3456
|
-
if (checked.indexOf(x2) > -1) {
|
|
3457
|
-
return null;
|
|
3458
|
-
}
|
|
3459
|
-
if (isObject(x2)) {
|
|
3460
|
-
checked.push(x2);
|
|
3461
|
-
const keys = Object.keys(x2).concat(Object.getOwnPropertySymbols(x2));
|
|
3462
|
-
for (let i = 0; i < keys.length; i++) {
|
|
3463
|
-
const key = keys[i];
|
|
3464
|
-
const value = x2[key];
|
|
3465
|
-
if (fn2(value)) {
|
|
3466
|
-
return value;
|
|
3467
|
-
}
|
|
3468
|
-
const result = helper5(value, fn2, checked);
|
|
3469
|
-
if (result) {
|
|
3470
|
-
return result;
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
} else if (isArray(x2)) {
|
|
3474
|
-
checked.push(x2);
|
|
3475
|
-
for (let i = 0; i < x2.length; i++) {
|
|
3476
|
-
const value = x2[i];
|
|
3477
|
-
if (fn2(value)) {
|
|
3478
|
-
return value;
|
|
3479
|
-
}
|
|
3480
|
-
const result = helper5(value, fn2, checked);
|
|
3481
|
-
if (result) {
|
|
3482
|
-
return result;
|
|
3483
|
-
}
|
|
3484
|
-
}
|
|
3485
|
-
} else {
|
|
3486
|
-
if (fn2(x2)) {
|
|
3487
|
-
return x2;
|
|
3488
|
-
}
|
|
3489
|
-
}
|
|
3490
|
-
return null;
|
|
3491
|
-
}
|
|
3492
|
-
function safeFn(v) {
|
|
3493
|
-
try {
|
|
3494
|
-
return fn(v);
|
|
3495
|
-
} catch (e) {
|
|
3496
|
-
return false;
|
|
3497
|
-
}
|
|
3498
|
-
}
|
|
3499
|
-
return helper5(x, safeFn);
|
|
3500
|
-
}
|
|
3501
|
-
function findAll(x, fn) {
|
|
3502
|
-
if (isDataFrame(x)) {
|
|
3503
|
-
return findAll(x.values, fn);
|
|
3504
|
-
}
|
|
3505
|
-
if (isSeries(x)) {
|
|
3506
|
-
return findAll(x.values, fn);
|
|
3507
|
-
}
|
|
3508
|
-
assert(isObject(x) || isArray(x), "You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `findAll` function!");
|
|
3509
|
-
if (!isFunction(fn)) {
|
|
3510
|
-
const value = fn;
|
|
3511
|
-
fn = (v) => v === value;
|
|
3512
|
-
}
|
|
3513
|
-
function helper5(x2, fn2, checked) {
|
|
3514
|
-
checked = checked || [];
|
|
3515
|
-
if (checked.indexOf(x2) > -1) {
|
|
3516
|
-
return null;
|
|
3517
|
-
}
|
|
3518
|
-
if (isObject(x2)) {
|
|
3519
|
-
checked.push(x2);
|
|
3520
|
-
const keys = Object.keys(x2).concat(Object.getOwnPropertySymbols(x2));
|
|
3521
|
-
const out2 = [];
|
|
3522
|
-
for (let i = 0; i < keys.length; i++) {
|
|
3523
|
-
const key = keys[i];
|
|
3524
|
-
const value = x2[key];
|
|
3525
|
-
let alreadyStoredThisValue = false;
|
|
3526
|
-
if (fn2(value)) {
|
|
3527
|
-
out2.push(value);
|
|
3528
|
-
alreadyStoredThisValue = true;
|
|
3529
|
-
}
|
|
3530
|
-
const results2 = helper5(value, fn2, checked);
|
|
3531
|
-
if (results2 && results2.length > 0) {
|
|
3532
|
-
results2.slice(alreadyStoredThisValue ? 1 : 0).forEach((r) => out2.push(r));
|
|
3533
|
-
}
|
|
3534
|
-
}
|
|
3535
|
-
return out2;
|
|
3536
|
-
} else if (isArray(x2)) {
|
|
3537
|
-
checked.push(x2);
|
|
3538
|
-
const out2 = [];
|
|
3539
|
-
for (let i = 0; i < x2.length; i++) {
|
|
3540
|
-
const value = x2[i];
|
|
3541
|
-
let alreadyStoredThisValue = false;
|
|
3542
|
-
if (fn2(value)) {
|
|
3543
|
-
out2.push(value);
|
|
3544
|
-
alreadyStoredThisValue = true;
|
|
3545
|
-
}
|
|
3546
|
-
const results2 = helper5(value, fn2, checked);
|
|
3547
|
-
if (results2 && results2.length > 0) {
|
|
3548
|
-
results2.slice(alreadyStoredThisValue ? 1 : 0).forEach((r) => out2.push(r));
|
|
3549
|
-
}
|
|
3550
|
-
}
|
|
3551
|
-
return out2;
|
|
3552
|
-
} else {
|
|
3553
|
-
if (fn2(x2)) {
|
|
3554
|
-
return [x2];
|
|
3555
|
-
}
|
|
3556
|
-
}
|
|
3557
|
-
return null;
|
|
3558
|
-
}
|
|
3559
|
-
function safeFn(v) {
|
|
3560
|
-
try {
|
|
3561
|
-
return fn(v);
|
|
3562
|
-
} catch (e) {
|
|
3563
|
-
return false;
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3566
|
-
const results = helper5(x, safeFn);
|
|
3567
|
-
if (results && results.length > 0) {
|
|
3568
|
-
return results;
|
|
3569
|
-
} else {
|
|
3570
|
-
return null;
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3268
|
+
|
|
3269
|
+
// node_modules/@jrc03c/js-math-tools/src/float.mjs
|
|
3573
3270
|
function float(x) {
|
|
3574
3271
|
try {
|
|
3575
3272
|
if (x === "Infinity") {
|
|
@@ -3578,19 +3275,19 @@
|
|
|
3578
3275
|
if (x === "-Infinity") {
|
|
3579
3276
|
return -Infinity;
|
|
3580
3277
|
}
|
|
3581
|
-
const
|
|
3582
|
-
if (isNumber(
|
|
3583
|
-
return out2;
|
|
3278
|
+
const out = JSON.parse(x);
|
|
3279
|
+
if (isNumber(out)) return out;
|
|
3584
3280
|
return NaN;
|
|
3585
3281
|
} catch (e) {
|
|
3586
3282
|
return NaN;
|
|
3587
3283
|
}
|
|
3588
3284
|
}
|
|
3589
3285
|
var vfloat = vectorize(float);
|
|
3286
|
+
|
|
3287
|
+
// node_modules/@jrc03c/js-math-tools/src/floor.mjs
|
|
3590
3288
|
function floor(x) {
|
|
3591
3289
|
try {
|
|
3592
|
-
if (!isNumber(x))
|
|
3593
|
-
return NaN;
|
|
3290
|
+
if (!isNumber(x)) return NaN;
|
|
3594
3291
|
if (typeof x === "bigint") {
|
|
3595
3292
|
return x;
|
|
3596
3293
|
}
|
|
@@ -3600,203 +3297,19 @@
|
|
|
3600
3297
|
}
|
|
3601
3298
|
}
|
|
3602
3299
|
var vfloor = vectorize(floor);
|
|
3603
|
-
function zeros(shape2) {
|
|
3604
|
-
if (isNumber(shape2))
|
|
3605
|
-
shape2 = [shape2];
|
|
3606
|
-
const out2 = [];
|
|
3607
|
-
const n = product(shape2);
|
|
3608
|
-
for (let i = 0; i < n; i++)
|
|
3609
|
-
out2.push(0);
|
|
3610
|
-
return reshape(out2, shape2);
|
|
3611
|
-
}
|
|
3612
|
-
function identity(size) {
|
|
3613
|
-
if (typeof size === "bigint") {
|
|
3614
|
-
size = vint(size);
|
|
3615
|
-
}
|
|
3616
|
-
assert(!isUndefined(size), "You must pass an integer greater than 0 (representing the size) into the `identity` function!");
|
|
3617
|
-
assert(isNumber(size), "You must pass an integer greater than 0 (representing the size) into the `identity` function!");
|
|
3618
|
-
assert(vint(size) === size, "You must pass an integer greater than 0 (representing the size) into the `identity` function!");
|
|
3619
|
-
assert(size > 0, "You must pass an integer greater than 0 (representing the size) into the `identity` function!");
|
|
3620
|
-
const out2 = zeros([size, size]);
|
|
3621
|
-
for (let i = 0; i < size; i++)
|
|
3622
|
-
out2[i][i] = 1;
|
|
3623
|
-
return out2;
|
|
3624
|
-
}
|
|
3625
|
-
var booleanValues = ["true", "false", "yes", "no"];
|
|
3626
|
-
var nullValues = ["null", "none", "nan", "na", "n/a", "", "undefined"];
|
|
3627
|
-
function checkIfInteger(results) {
|
|
3628
|
-
if (results.type === "number") {
|
|
3629
|
-
if (typeof results.value !== "undefined") {
|
|
3630
|
-
results.isInteger = vint(results.value) === results.value;
|
|
3631
|
-
} else {
|
|
3632
|
-
results.isInteger = every(results.values, (v) => isNumber(v) ? vint(v) === v : true);
|
|
3633
|
-
}
|
|
3634
|
-
}
|
|
3635
|
-
return results;
|
|
3636
|
-
}
|
|
3637
|
-
function inferType(arr) {
|
|
3638
|
-
if (isDataFrame(arr)) {
|
|
3639
|
-
const out2 = arr.copy();
|
|
3640
|
-
const results = inferType(arr.values);
|
|
3641
|
-
out2.values = results.values;
|
|
3642
|
-
return checkIfInteger({ type: results.type, values: out2 });
|
|
3643
|
-
}
|
|
3644
|
-
if (isSeries(arr)) {
|
|
3645
|
-
const out2 = arr.copy();
|
|
3646
|
-
const results = inferType(arr.values);
|
|
3647
|
-
out2.values = results.values;
|
|
3648
|
-
return checkIfInteger({ type: results.type, values: out2 });
|
|
3649
|
-
}
|
|
3650
|
-
if (!isArray(arr)) {
|
|
3651
|
-
const out2 = inferType([arr]);
|
|
3652
|
-
out2.value = out2.values[0];
|
|
3653
|
-
delete out2.values;
|
|
3654
|
-
return checkIfInteger(out2);
|
|
3655
|
-
}
|
|
3656
|
-
assert(isArray(arr), "The `inferType` function only works on arrays, Series, and DataFrames!");
|
|
3657
|
-
const types = flatten(arr).map((v) => {
|
|
3658
|
-
if (v === void 0)
|
|
3659
|
-
return "null";
|
|
3660
|
-
try {
|
|
3661
|
-
if (typeof v === "object") {
|
|
3662
|
-
const temp = new Date(v.getTime());
|
|
3663
|
-
if (isDate(temp)) {
|
|
3664
|
-
return "date";
|
|
3665
|
-
}
|
|
3666
|
-
}
|
|
3667
|
-
} catch (e) {
|
|
3668
|
-
}
|
|
3669
|
-
if (!isString(v)) {
|
|
3670
|
-
if (typeof v === "bigint") {
|
|
3671
|
-
v = v.toString() + "n";
|
|
3672
|
-
} else {
|
|
3673
|
-
v = JSON.stringify(v);
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
const vLower = v.toLowerCase();
|
|
3677
|
-
const vLowerTrimmed = vLower.trim();
|
|
3678
|
-
if (nullValues.indexOf(vLowerTrimmed) > -1) {
|
|
3679
|
-
return "null";
|
|
3680
|
-
}
|
|
3681
|
-
if (booleanValues.indexOf(vLowerTrimmed) > -1) {
|
|
3682
|
-
return "boolean";
|
|
3683
|
-
}
|
|
3684
|
-
try {
|
|
3685
|
-
if (v.match(/^-?\d+n$/g)) {
|
|
3686
|
-
return "bigint";
|
|
3687
|
-
}
|
|
3688
|
-
const vParsed = JSON.parse(v);
|
|
3689
|
-
if (isNumber(vParsed)) {
|
|
3690
|
-
return "number";
|
|
3691
|
-
}
|
|
3692
|
-
if (typeof vParsed === "object") {
|
|
3693
|
-
if (isArray(vParsed))
|
|
3694
|
-
return "string";
|
|
3695
|
-
return "object";
|
|
3696
|
-
}
|
|
3697
|
-
return "string";
|
|
3698
|
-
} catch (e) {
|
|
3699
|
-
const vDate = new Date(v);
|
|
3700
|
-
if (isDate(vDate)) {
|
|
3701
|
-
return "date";
|
|
3702
|
-
}
|
|
3703
|
-
return "string";
|
|
3704
|
-
}
|
|
3705
|
-
});
|
|
3706
|
-
const counts = count(types);
|
|
3707
|
-
const sortedValues = counts.values.toSorted((a, b) => counts.get(b) - counts.get(a));
|
|
3708
|
-
const primaryType = sortedValues[0];
|
|
3709
|
-
return checkIfInteger({
|
|
3710
|
-
type: primaryType,
|
|
3711
|
-
values: vapply(arr, (v) => cast(v, primaryType))
|
|
3712
|
-
});
|
|
3713
|
-
}
|
|
3714
|
-
function inverse(x) {
|
|
3715
|
-
if (isDataFrame(x)) {
|
|
3716
|
-
const out2 = x.copy();
|
|
3717
|
-
out2.values = inverse(out2.values);
|
|
3718
|
-
return out2;
|
|
3719
|
-
}
|
|
3720
|
-
assert(isArray(x), "The `inverse` function only works on square 2-dimensional arrays or DataFrames!");
|
|
3721
|
-
const xShape = shape(x);
|
|
3722
|
-
assert(xShape.length === 2, "The array passed into the `inverse` function must be exactly two-dimensional and square!");
|
|
3723
|
-
assert(xShape[0] === xShape[1], "The array passed into the `inverse` function must be exactly two-dimensional and square!");
|
|
3724
|
-
assert(xShape[0] >= 0, "The array passed into the `inverse` function must be exactly two-dimensional and square!");
|
|
3725
|
-
if (xShape[0] === 0) {
|
|
3726
|
-
return x;
|
|
3727
|
-
} else if (xShape[0] === 1) {
|
|
3728
|
-
assert(x[0][0] !== 0, "This matrix cannot be inverted!");
|
|
3729
|
-
let v = x[0][0];
|
|
3730
|
-
if (typeof v === "bigint")
|
|
3731
|
-
v = Number(v);
|
|
3732
|
-
return 1 / v;
|
|
3733
|
-
} else if (xShape[0] === 2) {
|
|
3734
|
-
let a = x[0][0];
|
|
3735
|
-
let b = x[0][1];
|
|
3736
|
-
let c = x[1][0];
|
|
3737
|
-
let d = x[1][1];
|
|
3738
|
-
if (typeof a === "bigint")
|
|
3739
|
-
a = Number(a);
|
|
3740
|
-
if (typeof b === "bigint")
|
|
3741
|
-
b = Number(b);
|
|
3742
|
-
if (typeof c === "bigint")
|
|
3743
|
-
c = Number(c);
|
|
3744
|
-
if (typeof d === "bigint")
|
|
3745
|
-
d = Number(d);
|
|
3746
|
-
const det = a * d - b * c;
|
|
3747
|
-
assert(det !== 0, "This matrix cannot be inverted!");
|
|
3748
|
-
const out2 = [
|
|
3749
|
-
[d, -b],
|
|
3750
|
-
[-c, a]
|
|
3751
|
-
];
|
|
3752
|
-
return scale(out2, 1 / det);
|
|
3753
|
-
} else if (xShape[0] > 1) {
|
|
3754
|
-
const times = (a, b) => isNumber(a) || isNumber(b) ? scale(a, b) : dot(a, b);
|
|
3755
|
-
for (let divider = 1; divider < xShape[0] - 1; divider++) {
|
|
3756
|
-
try {
|
|
3757
|
-
const A = x.slice(0, divider).map((row) => row.slice(0, divider));
|
|
3758
|
-
const B = x.slice(0, divider).map((row) => row.slice(divider, xShape[0]));
|
|
3759
|
-
const C = x.slice(divider, xShape[0]).map((row) => row.slice(0, divider));
|
|
3760
|
-
const D = x.slice(divider, xShape[0]).map((row) => row.slice(divider, xShape[0]));
|
|
3761
|
-
const AInv = inverse(A);
|
|
3762
|
-
const CompInv = inverse(vadd(D, times(-1, times(times(C, AInv), B))));
|
|
3763
|
-
const topLeft = vadd(AInv, times(times(times(times(AInv, B), CompInv), C), AInv));
|
|
3764
|
-
const topRight = times(-1, times(times(AInv, B), CompInv));
|
|
3765
|
-
const bottomLeft = times(-1, times(times(CompInv, C), AInv));
|
|
3766
|
-
const bottomRight = CompInv;
|
|
3767
|
-
const out2 = topLeft.map((row, i) => row.concat(topRight[i])).concat(bottomLeft.map((row, i) => row.concat(bottomRight[i])));
|
|
3768
|
-
return out2;
|
|
3769
|
-
} catch (e) {
|
|
3770
|
-
}
|
|
3771
|
-
}
|
|
3772
|
-
assert(false, "This matrix cannot be inverted!");
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
|
-
var isBrowser2 = new Function(`
|
|
3776
|
-
try {
|
|
3777
|
-
return this === window
|
|
3778
|
-
} catch(e) {}
|
|
3779
|
-
|
|
3780
|
-
try {
|
|
3781
|
-
return !!importScripts
|
|
3782
|
-
} catch(e){}
|
|
3783
3300
|
|
|
3784
|
-
|
|
3785
|
-
`);
|
|
3301
|
+
// node_modules/@jrc03c/js-math-tools/src/lerp.mjs
|
|
3786
3302
|
function lerp(a, b, f) {
|
|
3787
3303
|
try {
|
|
3788
|
-
if (!isNumber(a))
|
|
3789
|
-
|
|
3790
|
-
if (!isNumber(
|
|
3791
|
-
return NaN;
|
|
3792
|
-
if (!isNumber(f))
|
|
3793
|
-
return NaN;
|
|
3304
|
+
if (!isNumber(a)) return NaN;
|
|
3305
|
+
if (!isNumber(b)) return NaN;
|
|
3306
|
+
if (!isNumber(f)) return NaN;
|
|
3794
3307
|
if (typeof a === "bigint" || typeof b === "bigint") {
|
|
3795
|
-
const
|
|
3308
|
+
const out = lerp(Number(a), Number(b), f);
|
|
3796
3309
|
try {
|
|
3797
|
-
return BigInt(
|
|
3310
|
+
return BigInt(out);
|
|
3798
3311
|
} catch (e) {
|
|
3799
|
-
return
|
|
3312
|
+
return out;
|
|
3800
3313
|
}
|
|
3801
3314
|
}
|
|
3802
3315
|
return f * (b - a) + a;
|
|
@@ -3805,19 +3318,19 @@
|
|
|
3805
3318
|
}
|
|
3806
3319
|
}
|
|
3807
3320
|
var vlerp = vectorize(lerp);
|
|
3321
|
+
|
|
3322
|
+
// node_modules/@jrc03c/js-math-tools/src/log.mjs
|
|
3808
3323
|
function log(x, base) {
|
|
3809
3324
|
try {
|
|
3810
3325
|
base = isUndefined(base) ? Math.E : base;
|
|
3811
|
-
if (!isNumber(x))
|
|
3812
|
-
|
|
3813
|
-
if (!isNumber(base))
|
|
3814
|
-
return NaN;
|
|
3326
|
+
if (!isNumber(x)) return NaN;
|
|
3327
|
+
if (!isNumber(base)) return NaN;
|
|
3815
3328
|
if (typeof x === "bigint" || typeof base === "bigint") {
|
|
3816
|
-
const
|
|
3329
|
+
const out = log(Number(x), Number(base));
|
|
3817
3330
|
try {
|
|
3818
|
-
return BigInt(
|
|
3331
|
+
return BigInt(out);
|
|
3819
3332
|
} catch (e) {
|
|
3820
|
-
return
|
|
3333
|
+
return out;
|
|
3821
3334
|
}
|
|
3822
3335
|
}
|
|
3823
3336
|
return Math.log(x) / Math.log(base);
|
|
@@ -3826,24 +3339,18 @@
|
|
|
3826
3339
|
}
|
|
3827
3340
|
}
|
|
3828
3341
|
var vlog = vectorize(log);
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
}
|
|
3832
|
-
function median(arr, shouldDropNaNs) {
|
|
3833
|
-
return stats(arr, { shouldDropNaNs, median: true }).median;
|
|
3834
|
-
}
|
|
3342
|
+
|
|
3343
|
+
// node_modules/@jrc03c/js-math-tools/src/mod.mjs
|
|
3835
3344
|
function mod(a, b) {
|
|
3836
3345
|
try {
|
|
3837
|
-
if (!isNumber(a))
|
|
3838
|
-
|
|
3839
|
-
if (!isNumber(b))
|
|
3840
|
-
return NaN;
|
|
3346
|
+
if (!isNumber(a)) return NaN;
|
|
3347
|
+
if (!isNumber(b)) return NaN;
|
|
3841
3348
|
if (typeof a === "bigint" || typeof b === "bigint") {
|
|
3842
|
-
const
|
|
3349
|
+
const out = mod(Number(a), Number(b));
|
|
3843
3350
|
try {
|
|
3844
|
-
return BigInt(
|
|
3351
|
+
return BigInt(out);
|
|
3845
3352
|
} catch (e) {
|
|
3846
|
-
return
|
|
3353
|
+
return out;
|
|
3847
3354
|
}
|
|
3848
3355
|
}
|
|
3849
3356
|
return a % b;
|
|
@@ -3852,97 +3359,9 @@
|
|
|
3852
3359
|
}
|
|
3853
3360
|
}
|
|
3854
3361
|
var vmod = vectorize(mod);
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
function helper3() {
|
|
3859
|
-
const u1 = random();
|
|
3860
|
-
const u2 = random();
|
|
3861
|
-
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
3862
|
-
}
|
|
3863
|
-
function normal(shape2) {
|
|
3864
|
-
if (isUndefined(shape2))
|
|
3865
|
-
return helper3();
|
|
3866
|
-
return vapply(ndarray(shape2), helper3);
|
|
3867
|
-
}
|
|
3868
|
-
function ones(shape2) {
|
|
3869
|
-
return vapply(ndarray(shape2), () => 1);
|
|
3870
|
-
}
|
|
3871
|
-
function permutationsIterator(x, r) {
|
|
3872
|
-
function* helper5(x2, r2) {
|
|
3873
|
-
r2 = r2 || x2.length;
|
|
3874
|
-
if (x2.length === 1) {
|
|
3875
|
-
yield [x2];
|
|
3876
|
-
return;
|
|
3877
|
-
}
|
|
3878
|
-
for (const c of combinations(x2, r2)) {
|
|
3879
|
-
if (!c.slice)
|
|
3880
|
-
continue;
|
|
3881
|
-
const state = zeros(c.length);
|
|
3882
|
-
yield c;
|
|
3883
|
-
let i = 1;
|
|
3884
|
-
while (i < c.length) {
|
|
3885
|
-
if (state[i] < i) {
|
|
3886
|
-
if (i % 2 === 0) {
|
|
3887
|
-
const buf = c[0];
|
|
3888
|
-
c[0] = c[i];
|
|
3889
|
-
c[i] = buf;
|
|
3890
|
-
} else {
|
|
3891
|
-
const buf = c[state[i]];
|
|
3892
|
-
c[state[i]] = c[i];
|
|
3893
|
-
c[i] = buf;
|
|
3894
|
-
}
|
|
3895
|
-
yield c;
|
|
3896
|
-
state[i] += 1;
|
|
3897
|
-
i = 1;
|
|
3898
|
-
} else {
|
|
3899
|
-
state[i] = 0;
|
|
3900
|
-
i += 1;
|
|
3901
|
-
}
|
|
3902
|
-
}
|
|
3903
|
-
}
|
|
3904
|
-
}
|
|
3905
|
-
if (isDataFrame(x) || isSeries(x)) {
|
|
3906
|
-
return permutationsIterator(x.values, r);
|
|
3907
|
-
}
|
|
3908
|
-
assert(isArray(x), "The `permutations` function only works on arrays, Series, and DataFrames!");
|
|
3909
|
-
if (isUndefined(r)) {
|
|
3910
|
-
r = x.length;
|
|
3911
|
-
}
|
|
3912
|
-
assert(isNumber(r) && vint(r) === r && r >= 0, "`r` must be a non-negative integer!");
|
|
3913
|
-
return helper5(flatten(x), r);
|
|
3914
|
-
}
|
|
3915
|
-
function permutations(x, r) {
|
|
3916
|
-
const out2 = [];
|
|
3917
|
-
for (const perm of permutationsIterator(x, r)) {
|
|
3918
|
-
out2.push(perm.slice());
|
|
3919
|
-
}
|
|
3920
|
-
return out2;
|
|
3921
|
-
}
|
|
3922
|
-
function print() {
|
|
3923
|
-
Object.keys(arguments).forEach((key) => {
|
|
3924
|
-
const x = arguments[key];
|
|
3925
|
-
if (isArray(x)) {
|
|
3926
|
-
if (!isJagged(x)) {
|
|
3927
|
-
const xShape = shape(x);
|
|
3928
|
-
if (xShape.length === 1) {
|
|
3929
|
-
new Series(x).print();
|
|
3930
|
-
} else if (xShape.length == 2) {
|
|
3931
|
-
new DataFrame(x).print();
|
|
3932
|
-
} else {
|
|
3933
|
-
console.log(x);
|
|
3934
|
-
}
|
|
3935
|
-
} else {
|
|
3936
|
-
console.log(x);
|
|
3937
|
-
}
|
|
3938
|
-
} else if (isDataFrame(x) || isSeries(x)) {
|
|
3939
|
-
x.print();
|
|
3940
|
-
} else {
|
|
3941
|
-
console.log(x);
|
|
3942
|
-
}
|
|
3943
|
-
});
|
|
3944
|
-
}
|
|
3945
|
-
var helper4 = vectorize((x, a, b, c, d) => {
|
|
3362
|
+
|
|
3363
|
+
// node_modules/@jrc03c/js-math-tools/src/remap.mjs
|
|
3364
|
+
var helper3 = vectorize((x, a, b, c, d) => {
|
|
3946
3365
|
try {
|
|
3947
3366
|
let resultShouldBeABigInt = false;
|
|
3948
3367
|
for (const v of [x, a, b, c, d]) {
|
|
@@ -3962,62 +3381,50 @@
|
|
|
3962
3381
|
}
|
|
3963
3382
|
const num = (d - c) * (x - a);
|
|
3964
3383
|
const den = b - a;
|
|
3965
|
-
if (den === 0)
|
|
3966
|
-
|
|
3967
|
-
const out2 = num / den + c;
|
|
3384
|
+
if (den === 0) return NaN;
|
|
3385
|
+
const out = num / den + c;
|
|
3968
3386
|
if (resultShouldBeABigInt) {
|
|
3969
3387
|
try {
|
|
3970
|
-
return BigInt(
|
|
3388
|
+
return BigInt(out);
|
|
3971
3389
|
} catch (e) {
|
|
3972
3390
|
}
|
|
3973
3391
|
}
|
|
3974
|
-
return
|
|
3392
|
+
return out;
|
|
3975
3393
|
} catch (e) {
|
|
3976
3394
|
return NaN;
|
|
3977
3395
|
}
|
|
3978
3396
|
});
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
c = a;
|
|
3982
|
-
d = b;
|
|
3983
|
-
const results = stats(x);
|
|
3984
|
-
a = results.min;
|
|
3985
|
-
b = results.max;
|
|
3986
|
-
}
|
|
3987
|
-
return helper4(x, a, b, c, d);
|
|
3988
|
-
}
|
|
3397
|
+
|
|
3398
|
+
// node_modules/@jrc03c/js-math-tools/src/round.mjs
|
|
3989
3399
|
function round(x) {
|
|
3990
3400
|
try {
|
|
3991
|
-
if (!isNumber(x))
|
|
3992
|
-
|
|
3993
|
-
if (typeof x === "bigint")
|
|
3994
|
-
return x;
|
|
3401
|
+
if (!isNumber(x)) return NaN;
|
|
3402
|
+
if (typeof x === "bigint") return x;
|
|
3995
3403
|
return Math.round(x);
|
|
3996
3404
|
} catch (e) {
|
|
3997
3405
|
return NaN;
|
|
3998
3406
|
}
|
|
3999
3407
|
}
|
|
4000
3408
|
var vround = vectorize(round);
|
|
3409
|
+
|
|
3410
|
+
// node_modules/@jrc03c/js-math-tools/src/sign.mjs
|
|
4001
3411
|
function sign(x) {
|
|
4002
3412
|
try {
|
|
4003
|
-
if (!isNumber(x))
|
|
4004
|
-
|
|
4005
|
-
if (
|
|
4006
|
-
|
|
4007
|
-
if (x < 0)
|
|
4008
|
-
return -1;
|
|
4009
|
-
if (x > 0)
|
|
4010
|
-
return 1;
|
|
3413
|
+
if (!isNumber(x)) return NaN;
|
|
3414
|
+
if (typeof x === "bigint") return BigInt(sign(Number(x)));
|
|
3415
|
+
if (x < 0) return -1;
|
|
3416
|
+
if (x > 0) return 1;
|
|
4011
3417
|
return 0;
|
|
4012
3418
|
} catch (e) {
|
|
4013
3419
|
return NaN;
|
|
4014
3420
|
}
|
|
4015
3421
|
}
|
|
4016
3422
|
var vsign = vectorize(sign);
|
|
3423
|
+
|
|
3424
|
+
// node_modules/@jrc03c/js-math-tools/src/sin.mjs
|
|
4017
3425
|
function sin(x) {
|
|
4018
3426
|
try {
|
|
4019
|
-
if (!isNumber(x))
|
|
4020
|
-
return NaN;
|
|
3427
|
+
if (!isNumber(x)) return NaN;
|
|
4021
3428
|
if (typeof x === "bigint") {
|
|
4022
3429
|
x = Number(x);
|
|
4023
3430
|
}
|
|
@@ -4027,35 +3434,11 @@
|
|
|
4027
3434
|
}
|
|
4028
3435
|
}
|
|
4029
3436
|
var vsin = vectorize(sin);
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
return some(x.values, fn);
|
|
4033
|
-
}
|
|
4034
|
-
assert(isArray(x), "The first argument passed into the `some` function must be an array, Series, or DataFrame!");
|
|
4035
|
-
assert(isFunction(fn), "The second argument passed into the `some` function must be a function!");
|
|
4036
|
-
for (const v of x) {
|
|
4037
|
-
if (isArray(v)) {
|
|
4038
|
-
if (some(v, fn)) {
|
|
4039
|
-
return true;
|
|
4040
|
-
}
|
|
4041
|
-
} else {
|
|
4042
|
-
if (fn(v)) {
|
|
4043
|
-
return true;
|
|
4044
|
-
}
|
|
4045
|
-
}
|
|
4046
|
-
}
|
|
4047
|
-
return false;
|
|
4048
|
-
}
|
|
4049
|
-
function std(arr, shouldDropNaNs) {
|
|
4050
|
-
return stats(arr, { shouldDropNaNs, stdev: true }).stdev;
|
|
4051
|
-
}
|
|
4052
|
-
function stdev(x) {
|
|
4053
|
-
return std(x);
|
|
4054
|
-
}
|
|
3437
|
+
|
|
3438
|
+
// node_modules/@jrc03c/js-math-tools/src/tan.mjs
|
|
4055
3439
|
function tan(x) {
|
|
4056
3440
|
try {
|
|
4057
|
-
if (!isNumber(x))
|
|
4058
|
-
return NaN;
|
|
3441
|
+
if (!isNumber(x)) return NaN;
|
|
4059
3442
|
if (typeof x === "bigint") {
|
|
4060
3443
|
x = Number(x);
|
|
4061
3444
|
}
|
|
@@ -4065,193 +3448,6 @@
|
|
|
4065
3448
|
}
|
|
4066
3449
|
}
|
|
4067
3450
|
var vtan = vectorize(tan);
|
|
4068
|
-
function timeSync(fn, args) {
|
|
4069
|
-
assert(isFunction(fn), "`fn` must be a function!");
|
|
4070
|
-
const start = /* @__PURE__ */ new Date();
|
|
4071
|
-
if (args) {
|
|
4072
|
-
fn(...args);
|
|
4073
|
-
} else {
|
|
4074
|
-
fn();
|
|
4075
|
-
}
|
|
4076
|
-
return /* @__PURE__ */ new Date() - start;
|
|
4077
|
-
}
|
|
4078
|
-
async function timeAsync(fn, args) {
|
|
4079
|
-
assert(isFunction(fn), "`fn` must be a function!");
|
|
4080
|
-
const start = /* @__PURE__ */ new Date();
|
|
4081
|
-
if (args) {
|
|
4082
|
-
await fn(...args);
|
|
4083
|
-
} else {
|
|
4084
|
-
await fn();
|
|
4085
|
-
}
|
|
4086
|
-
return /* @__PURE__ */ new Date() - start;
|
|
4087
|
-
}
|
|
4088
|
-
function union() {
|
|
4089
|
-
return set([...arguments].map((v) => {
|
|
4090
|
-
if (isArray(v))
|
|
4091
|
-
return v;
|
|
4092
|
-
if (isDataFrame(v))
|
|
4093
|
-
return v.values;
|
|
4094
|
-
if (isSeries(v))
|
|
4095
|
-
return v.values;
|
|
4096
|
-
return [v];
|
|
4097
|
-
}));
|
|
4098
|
-
}
|
|
4099
|
-
function variance(arr, shouldDropNaNs) {
|
|
4100
|
-
return stats(arr, { shouldDropNaNs, variance: true }).variance;
|
|
4101
|
-
}
|
|
4102
|
-
function zip() {
|
|
4103
|
-
const out2 = [];
|
|
4104
|
-
const arrays = Object.values(arguments).map((arr) => {
|
|
4105
|
-
if (isDataFrame(arr) || isSeries(arr)) {
|
|
4106
|
-
arr = arr.values;
|
|
4107
|
-
}
|
|
4108
|
-
assert(isArray(arr), "The `zip` function only works on arrays, Series, and DataFrames!");
|
|
4109
|
-
return arr;
|
|
4110
|
-
});
|
|
4111
|
-
range(0, max(arrays.map((arr) => arr.length))).forEach((i) => {
|
|
4112
|
-
const row = [];
|
|
4113
|
-
arrays.forEach((arr) => {
|
|
4114
|
-
const value = arr[i];
|
|
4115
|
-
row.push(isUndefined(value) ? void 0 : value);
|
|
4116
|
-
});
|
|
4117
|
-
out2.push(row);
|
|
4118
|
-
});
|
|
4119
|
-
return out2;
|
|
4120
|
-
}
|
|
4121
|
-
var out = {
|
|
4122
|
-
abs: vabs,
|
|
4123
|
-
add: vadd,
|
|
4124
|
-
apply: vapply,
|
|
4125
|
-
arccos: varccos,
|
|
4126
|
-
arcsin: varcsin,
|
|
4127
|
-
arctan: varctan,
|
|
4128
|
-
argmax,
|
|
4129
|
-
argmin,
|
|
4130
|
-
assert,
|
|
4131
|
-
cast,
|
|
4132
|
-
ceil: vceil,
|
|
4133
|
-
chop: vchop,
|
|
4134
|
-
clamp: vclamp,
|
|
4135
|
-
combinations,
|
|
4136
|
-
combinationsIterator,
|
|
4137
|
-
copy,
|
|
4138
|
-
correl,
|
|
4139
|
-
cos: vcos,
|
|
4140
|
-
count,
|
|
4141
|
-
covariance,
|
|
4142
|
-
DataFrame,
|
|
4143
|
-
dataTypes,
|
|
4144
|
-
decycle,
|
|
4145
|
-
diff,
|
|
4146
|
-
distance,
|
|
4147
|
-
divide,
|
|
4148
|
-
dot,
|
|
4149
|
-
dropMissing,
|
|
4150
|
-
dropMissingPairwise,
|
|
4151
|
-
dropNaN,
|
|
4152
|
-
dropNaNPairwise,
|
|
4153
|
-
dropUndefined,
|
|
4154
|
-
every,
|
|
4155
|
-
exp: vexp,
|
|
4156
|
-
factorial: vfactorial,
|
|
4157
|
-
find,
|
|
4158
|
-
findAll,
|
|
4159
|
-
flatten,
|
|
4160
|
-
float: vfloat,
|
|
4161
|
-
floor: vfloor,
|
|
4162
|
-
identity,
|
|
4163
|
-
IndexMatcher,
|
|
4164
|
-
indexOf,
|
|
4165
|
-
inferType,
|
|
4166
|
-
int: vint,
|
|
4167
|
-
intersect,
|
|
4168
|
-
inverse,
|
|
4169
|
-
isArray,
|
|
4170
|
-
isBoolean,
|
|
4171
|
-
isBrowser: isBrowser2,
|
|
4172
|
-
isDataFrame,
|
|
4173
|
-
isDate,
|
|
4174
|
-
isEqual,
|
|
4175
|
-
isFunction,
|
|
4176
|
-
isJagged,
|
|
4177
|
-
isNested,
|
|
4178
|
-
isNumber,
|
|
4179
|
-
isObject,
|
|
4180
|
-
isSeries,
|
|
4181
|
-
isString,
|
|
4182
|
-
isUndefined,
|
|
4183
|
-
lerp: vlerp,
|
|
4184
|
-
log: vlog,
|
|
4185
|
-
MathError,
|
|
4186
|
-
max,
|
|
4187
|
-
mean,
|
|
4188
|
-
median,
|
|
4189
|
-
min,
|
|
4190
|
-
mod: vmod,
|
|
4191
|
-
mode,
|
|
4192
|
-
multiply: vmultiply,
|
|
4193
|
-
ndarray,
|
|
4194
|
-
normal,
|
|
4195
|
-
ones,
|
|
4196
|
-
permutations,
|
|
4197
|
-
permutationsIterator,
|
|
4198
|
-
pow: vpow,
|
|
4199
|
-
print,
|
|
4200
|
-
product,
|
|
4201
|
-
random,
|
|
4202
|
-
range,
|
|
4203
|
-
remap,
|
|
4204
|
-
reshape,
|
|
4205
|
-
reverse,
|
|
4206
|
-
round: vround,
|
|
4207
|
-
scale,
|
|
4208
|
-
seed,
|
|
4209
|
-
Series,
|
|
4210
|
-
set,
|
|
4211
|
-
shape,
|
|
4212
|
-
shuffle,
|
|
4213
|
-
sign: vsign,
|
|
4214
|
-
sin: vsin,
|
|
4215
|
-
some,
|
|
4216
|
-
sort,
|
|
4217
|
-
sqrt: vsqrt,
|
|
4218
|
-
stats,
|
|
4219
|
-
std,
|
|
4220
|
-
stdev,
|
|
4221
|
-
subtract,
|
|
4222
|
-
sum,
|
|
4223
|
-
tan: vtan,
|
|
4224
|
-
timeAsync,
|
|
4225
|
-
timeSync,
|
|
4226
|
-
time: timeSync,
|
|
4227
|
-
transpose,
|
|
4228
|
-
union,
|
|
4229
|
-
variance,
|
|
4230
|
-
vectorize,
|
|
4231
|
-
zeros,
|
|
4232
|
-
zip,
|
|
4233
|
-
dump() {
|
|
4234
|
-
const context = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : void 0;
|
|
4235
|
-
if (!context) {
|
|
4236
|
-
throw new out.MathError("Cannot dump functions into global scope because none of `globalThis`, `global`, `window`, or `self` exist in the current context!");
|
|
4237
|
-
}
|
|
4238
|
-
Object.keys(out).forEach((key) => {
|
|
4239
|
-
try {
|
|
4240
|
-
Object.defineProperty(context, key, {
|
|
4241
|
-
configurable: false,
|
|
4242
|
-
enumerable: true,
|
|
4243
|
-
writable: false,
|
|
4244
|
-
value: out[key]
|
|
4245
|
-
});
|
|
4246
|
-
} catch (e) {
|
|
4247
|
-
context[key] = out[key];
|
|
4248
|
-
}
|
|
4249
|
-
});
|
|
4250
|
-
}
|
|
4251
|
-
};
|
|
4252
|
-
if (typeof window !== "undefined") {
|
|
4253
|
-
window.JSMathTools = out;
|
|
4254
|
-
}
|
|
4255
3451
|
|
|
4256
3452
|
// src/index.mjs
|
|
4257
3453
|
function makeKey4(keyLength, keySeed, charset) {
|
|
@@ -4277,12 +3473,12 @@
|
|
|
4277
3473
|
if (charset) {
|
|
4278
3474
|
assert(isString(charset), "`charset` must be a string!");
|
|
4279
3475
|
}
|
|
4280
|
-
let
|
|
3476
|
+
let out = "";
|
|
4281
3477
|
charset = charset || "abcdefg1234567890";
|
|
4282
3478
|
for (let i = 0; i < keyLength; i++) {
|
|
4283
|
-
|
|
3479
|
+
out += charset[vint(random() * charset.length)];
|
|
4284
3480
|
}
|
|
4285
|
-
return
|
|
3481
|
+
return out;
|
|
4286
3482
|
}
|
|
4287
3483
|
|
|
4288
3484
|
// src/iife.mjs
|