@jrc03c/data-class 0.0.2
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/build.mjs +38 -0
- package/dist/data-class.js +3638 -0
- package/dist/data-class.min.js +17 -0
- package/eslint.config.js +37 -0
- package/package.json +29 -0
- package/pnpm-workspace.yaml +2 -0
- package/readme.md +134 -0
- package/src/iife.mjs +3 -0
- package/src/index.mjs +42 -0
- package/src/index.test.mjs +71 -0
|
@@ -0,0 +1,3638 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-number.mjs
|
|
3
|
+
function isNumber(x) {
|
|
4
|
+
return typeof x === "number" && !isNaN(x) || typeof x === "bigint";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/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
|
+
);
|
|
21
|
+
|
|
22
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/math-error.mjs
|
|
23
|
+
var MathError = class extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
if (isBrowser()) {
|
|
26
|
+
super(message);
|
|
27
|
+
} else {
|
|
28
|
+
super("\n\n\x1B[31m" + message + "\n\x1B[0m");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/assert.mjs
|
|
34
|
+
function assert(isTrue, message) {
|
|
35
|
+
if (!isTrue) throw new MathError(message);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/for-each.mjs
|
|
39
|
+
function forEach(x, fn) {
|
|
40
|
+
for (let i = 0; i < x.length; i++) {
|
|
41
|
+
fn(x[i], i, x);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/array-types.mjs
|
|
46
|
+
var arrayTypes = [
|
|
47
|
+
Array,
|
|
48
|
+
ArrayBuffer,
|
|
49
|
+
BigInt64Array,
|
|
50
|
+
BigUint64Array,
|
|
51
|
+
Float32Array,
|
|
52
|
+
Float64Array,
|
|
53
|
+
Int16Array,
|
|
54
|
+
Int32Array,
|
|
55
|
+
Int8Array,
|
|
56
|
+
Uint16Array,
|
|
57
|
+
Uint32Array,
|
|
58
|
+
Uint8Array,
|
|
59
|
+
Uint8ClampedArray
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-undefined.mjs
|
|
63
|
+
function isUndefined(x) {
|
|
64
|
+
return x === null || typeof x === "undefined";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/map.mjs
|
|
68
|
+
function map(x, fn) {
|
|
69
|
+
const out = new Array(x.length);
|
|
70
|
+
for (let i = 0; i < x.length; i++) {
|
|
71
|
+
out[i] = fn(x[i], i, x);
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-array.mjs
|
|
77
|
+
var typeStrings = map(arrayTypes, (s2) => s2.name);
|
|
78
|
+
function isArray(obj) {
|
|
79
|
+
try {
|
|
80
|
+
if (obj instanceof Array) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (!isUndefined(obj.constructor)) {
|
|
84
|
+
return arrayTypes.indexOf(obj.constructor) > -1 || typeStrings.indexOf(obj.constructor.name) > -1;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-dataframe.mjs
|
|
93
|
+
function isDataFrame(x) {
|
|
94
|
+
try {
|
|
95
|
+
return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/dataframe");
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-function.mjs
|
|
102
|
+
function isFunction(fn) {
|
|
103
|
+
return typeof fn === "function";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-object.mjs
|
|
107
|
+
function isObject(x) {
|
|
108
|
+
return typeof x === "object" && !isUndefined(x) && !isArray(x);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-series.mjs
|
|
112
|
+
function isSeries(x) {
|
|
113
|
+
try {
|
|
114
|
+
return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/series");
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/index-of.mjs
|
|
121
|
+
function indexOf(x, fn) {
|
|
122
|
+
if (isDataFrame(x)) {
|
|
123
|
+
const index = indexOf(x.values, fn);
|
|
124
|
+
if (index.length > 0 && isNumber(index[0]) && index[0] >= 0 && index[0] < x.index.length) {
|
|
125
|
+
index[0] = x.index[index[0]];
|
|
126
|
+
}
|
|
127
|
+
if (index.length > 1 && isNumber(index[1]) && index[1] >= 0 && index[1] < x.columns.length) {
|
|
128
|
+
index[1] = x.columns[index[1]];
|
|
129
|
+
}
|
|
130
|
+
return index;
|
|
131
|
+
}
|
|
132
|
+
if (isSeries(x)) {
|
|
133
|
+
const index = indexOf(x.values, fn);
|
|
134
|
+
if (index.length > 0 && isNumber(index[0]) && index[0] >= 0 && index[0] < x.index.length) {
|
|
135
|
+
index[0] = x.index[index[0]];
|
|
136
|
+
}
|
|
137
|
+
return index;
|
|
138
|
+
}
|
|
139
|
+
assert(
|
|
140
|
+
isObject(x) || isArray(x),
|
|
141
|
+
"You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `indexOf` function!"
|
|
142
|
+
);
|
|
143
|
+
if (!isFunction(fn)) {
|
|
144
|
+
const value = fn;
|
|
145
|
+
fn = (v) => v === value;
|
|
146
|
+
}
|
|
147
|
+
function helper4(x2, fn2, checked) {
|
|
148
|
+
checked = checked || [];
|
|
149
|
+
if (checked.indexOf(x2) > -1) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
if (isObject(x2)) {
|
|
153
|
+
checked.push(x2);
|
|
154
|
+
const keys = Object.keys(x2).concat(Object.getOwnPropertySymbols(x2));
|
|
155
|
+
for (let i = 0; i < keys.length; i++) {
|
|
156
|
+
const key = keys[i];
|
|
157
|
+
const value = x2[key];
|
|
158
|
+
if (fn2(value)) {
|
|
159
|
+
return [key];
|
|
160
|
+
}
|
|
161
|
+
const results = helper4(value, fn2, checked);
|
|
162
|
+
if (results && results.length > 0) {
|
|
163
|
+
return [key].concat(results);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else if (isArray(x2)) {
|
|
167
|
+
checked.push(x2);
|
|
168
|
+
for (let i = 0; i < x2.length; i++) {
|
|
169
|
+
const value = x2[i];
|
|
170
|
+
if (fn2(value)) {
|
|
171
|
+
return [i];
|
|
172
|
+
}
|
|
173
|
+
const results = helper4(value, fn2, checked);
|
|
174
|
+
if (results && results.length > 0) {
|
|
175
|
+
return [i].concat(results);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
if (fn2(x2)) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
function safeFn(v) {
|
|
186
|
+
try {
|
|
187
|
+
return fn(v);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const paths = helper4(x, safeFn);
|
|
193
|
+
if (paths && paths.length > 0) {
|
|
194
|
+
return paths;
|
|
195
|
+
} else {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/copy.mjs
|
|
201
|
+
function copy(x) {
|
|
202
|
+
function helper4(x2) {
|
|
203
|
+
if (typeof x2 === "object") {
|
|
204
|
+
if (x2 === null) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
if (isArray(x2)) {
|
|
208
|
+
if (!(x2 instanceof Array)) {
|
|
209
|
+
return x2.slice();
|
|
210
|
+
}
|
|
211
|
+
return map(x2, (v) => copy(v));
|
|
212
|
+
}
|
|
213
|
+
if (isSeries(x2)) {
|
|
214
|
+
const out2 = x2.copy();
|
|
215
|
+
out2.values = copy(out2.values);
|
|
216
|
+
return out2;
|
|
217
|
+
}
|
|
218
|
+
if (isDataFrame(x2)) {
|
|
219
|
+
const out2 = x2.copy();
|
|
220
|
+
out2.values = copy(x2.values);
|
|
221
|
+
return out2;
|
|
222
|
+
}
|
|
223
|
+
if (x2 instanceof Date) {
|
|
224
|
+
return new Date(x2.getTime());
|
|
225
|
+
}
|
|
226
|
+
x2 = decycle(x2);
|
|
227
|
+
const out = {};
|
|
228
|
+
forEach(
|
|
229
|
+
Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)),
|
|
230
|
+
(key) => {
|
|
231
|
+
out[key] = copy(x2[key]);
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
return out;
|
|
235
|
+
} else {
|
|
236
|
+
return x2;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return helper4(decycle(x));
|
|
240
|
+
}
|
|
241
|
+
function decycle(x) {
|
|
242
|
+
function helper4(x2, checked, currentPath) {
|
|
243
|
+
checked = checked || [];
|
|
244
|
+
currentPath = currentPath || "";
|
|
245
|
+
if (checked.indexOf(x2) > -1) {
|
|
246
|
+
const parts = currentPath.split("/").slice(currentPath.startsWith("/") ? 1 : 0);
|
|
247
|
+
const isANestedCopy = parts.some((v, i) => {
|
|
248
|
+
const subParts = parts.slice(0, parts.length - i - 1);
|
|
249
|
+
let temp = orig;
|
|
250
|
+
forEach(subParts, (part) => {
|
|
251
|
+
temp = temp[part];
|
|
252
|
+
});
|
|
253
|
+
return temp === x2;
|
|
254
|
+
});
|
|
255
|
+
if (isANestedCopy) {
|
|
256
|
+
const pathToCopy = orig === x2 ? "/" : "/" + indexOf(orig, x2).join("/");
|
|
257
|
+
return `<reference to "${pathToCopy}">`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (typeof x2 === "object") {
|
|
261
|
+
if (x2 === null) return null;
|
|
262
|
+
checked.push(x2);
|
|
263
|
+
if (isArray(x2)) {
|
|
264
|
+
if (typeof x2.constructor !== "undefined" && x2.constructor.name !== "Array") {
|
|
265
|
+
return x2.slice();
|
|
266
|
+
}
|
|
267
|
+
return map(x2, (v, i) => helper4(v, checked, currentPath + "/" + i));
|
|
268
|
+
} else {
|
|
269
|
+
forEach(
|
|
270
|
+
Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)),
|
|
271
|
+
(key) => {
|
|
272
|
+
x2[key] = helper4(x2[key], checked, currentPath + "/" + key.toString());
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
return x2;
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
return x2;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const orig = x;
|
|
282
|
+
let out = helper4(orig);
|
|
283
|
+
if (isDataFrame(x)) {
|
|
284
|
+
const temp = x.copy();
|
|
285
|
+
temp._values = out.values;
|
|
286
|
+
temp._columns = out.columns;
|
|
287
|
+
temp._index = out.index;
|
|
288
|
+
out = temp;
|
|
289
|
+
}
|
|
290
|
+
if (isSeries(x)) {
|
|
291
|
+
const temp = x.copy();
|
|
292
|
+
temp.name = out.name;
|
|
293
|
+
temp._values = out.values;
|
|
294
|
+
temp._index = out.index;
|
|
295
|
+
out = temp;
|
|
296
|
+
}
|
|
297
|
+
return out;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-date.mjs
|
|
301
|
+
function isDate(x) {
|
|
302
|
+
return x instanceof Date && x.toString() !== "Invalid Date";
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-equal.mjs
|
|
306
|
+
var numberTypes = ["number", "int", "float", "bigint"];
|
|
307
|
+
function isEqual(a, b) {
|
|
308
|
+
function helper4(a2, b2) {
|
|
309
|
+
const aType = typeof a2;
|
|
310
|
+
const bType = typeof b2;
|
|
311
|
+
if (aType !== bType && !numberTypes.includes(aType) && !numberTypes.includes(bType))
|
|
312
|
+
return false;
|
|
313
|
+
if (aType === "undefined" && bType === "undefined") return true;
|
|
314
|
+
if (aType === "boolean") return a2 === b2;
|
|
315
|
+
if (aType === "symbol") return a2 === b2;
|
|
316
|
+
if (aType === "number" || aType === "bigint") {
|
|
317
|
+
try {
|
|
318
|
+
const aString = a2.toString();
|
|
319
|
+
const bString = b2.toString();
|
|
320
|
+
return aString === bString;
|
|
321
|
+
} catch (e) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (aType === "string") return a2 === b2;
|
|
326
|
+
if (aType === "function") return a2 === b2;
|
|
327
|
+
if (aType === "object") {
|
|
328
|
+
if (a2 === null || b2 === null) {
|
|
329
|
+
return a2 === null && b2 === null;
|
|
330
|
+
} else {
|
|
331
|
+
if (isDate(a2)) {
|
|
332
|
+
if (isDate(b2)) {
|
|
333
|
+
return a2.getTime() === b2.getTime();
|
|
334
|
+
} else {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
} else if (isDate(b2)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
if (a2 instanceof RegExp && b2 instanceof RegExp) {
|
|
341
|
+
return a2.toString() === b2.toString();
|
|
342
|
+
}
|
|
343
|
+
if (isArray(a2) !== isArray(b2)) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
const aKeys = Object.keys(a2).concat(Object.getOwnPropertySymbols(a2));
|
|
347
|
+
const bKeys = Object.keys(b2).concat(Object.getOwnPropertySymbols(b2));
|
|
348
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
349
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
350
|
+
const key = aKeys[i];
|
|
351
|
+
if (!helper4(a2[key], b2[key])) return false;
|
|
352
|
+
}
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
return helper4(a, b);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
return helper4(decycle(a), decycle(b));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/counter.mjs
|
|
365
|
+
function makeKey(n) {
|
|
366
|
+
const alpha = "abcdefg1234567890";
|
|
367
|
+
let out = "";
|
|
368
|
+
while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
var NULL_KEY = makeKey(16);
|
|
372
|
+
var UNDEFINED_KEY = makeKey(16);
|
|
373
|
+
var INFINITY_KEY = makeKey(16);
|
|
374
|
+
var MINUS_INFINITY_KEY = makeKey(16);
|
|
375
|
+
var SYMBOL_KEY = makeKey(16);
|
|
376
|
+
var Counter = class {
|
|
377
|
+
constructor() {
|
|
378
|
+
this.clear();
|
|
379
|
+
}
|
|
380
|
+
get counts() {
|
|
381
|
+
return map(this.values, (v) => this.get(v));
|
|
382
|
+
}
|
|
383
|
+
get values() {
|
|
384
|
+
return Object.values(this.valuesDict);
|
|
385
|
+
}
|
|
386
|
+
clear() {
|
|
387
|
+
this.countsDict = {};
|
|
388
|
+
this.valuesDict = {};
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
count(x) {
|
|
392
|
+
for (const v of x) {
|
|
393
|
+
if (isArray(v)) {
|
|
394
|
+
this.count(v);
|
|
395
|
+
} else {
|
|
396
|
+
this.increment(v);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
delete(value) {
|
|
402
|
+
const key = this.getStandardizedKey(value);
|
|
403
|
+
delete this.countsDict[key];
|
|
404
|
+
delete this.valuesDict[key];
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
get(value) {
|
|
408
|
+
return this.countsDict[this.getStandardizedKey(value)] || 0;
|
|
409
|
+
}
|
|
410
|
+
getStandardizedKey(value) {
|
|
411
|
+
return typeof value === "object" && value === null ? NULL_KEY : isUndefined(value) ? UNDEFINED_KEY : isFunction(value) ? value.toString() : typeof value === "symbol" ? value.toString() + " - " + SYMBOL_KEY : value === Infinity ? INFINITY_KEY : value === -Infinity ? MINUS_INFINITY_KEY : typeof value === "bigint" ? value.toString() : isDataFrame(value) ? value.toJSONString() : isSeries(value) ? JSON.stringify(value.toObject()) : JSON.stringify(value);
|
|
412
|
+
}
|
|
413
|
+
has(value) {
|
|
414
|
+
return !isUndefined(this.countsDict[this.getStandardizedKey(value)]);
|
|
415
|
+
}
|
|
416
|
+
increment(value) {
|
|
417
|
+
return this.set(value, this.get(value) + 1);
|
|
418
|
+
}
|
|
419
|
+
set(value, count2) {
|
|
420
|
+
const key = this.getStandardizedKey(value);
|
|
421
|
+
this.countsDict[key] = count2;
|
|
422
|
+
this.valuesDict[key] = value;
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
toArray() {
|
|
426
|
+
return map(this.values, (v) => ({ value: v, count: this.get(v) }));
|
|
427
|
+
}
|
|
428
|
+
toObject() {
|
|
429
|
+
const out = {};
|
|
430
|
+
forEach(this.values, (value) => {
|
|
431
|
+
out[value] = this.get(value);
|
|
432
|
+
});
|
|
433
|
+
return out;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/flatten.mjs
|
|
438
|
+
function flatten(arr) {
|
|
439
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
440
|
+
return flatten(arr.values);
|
|
441
|
+
}
|
|
442
|
+
assert(
|
|
443
|
+
isArray(arr),
|
|
444
|
+
"The `flatten` function only works on arrays, Series, and DataFrames!"
|
|
445
|
+
);
|
|
446
|
+
function helper4(arr2) {
|
|
447
|
+
let out = [];
|
|
448
|
+
forEach(arr2, (child) => {
|
|
449
|
+
if (isArray(child)) {
|
|
450
|
+
out = out.concat(helper4(child));
|
|
451
|
+
} else {
|
|
452
|
+
out.push(child);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
return out;
|
|
456
|
+
}
|
|
457
|
+
return helper4(arr);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/stats.mjs
|
|
461
|
+
function stats(x, options) {
|
|
462
|
+
options = options || {};
|
|
463
|
+
const counts = new Counter();
|
|
464
|
+
const out = {};
|
|
465
|
+
const xflat = flatten(x);
|
|
466
|
+
const xnums = [];
|
|
467
|
+
let max2 = -Infinity;
|
|
468
|
+
let min2 = Infinity;
|
|
469
|
+
let resultsShouldIncludeBigInts = false;
|
|
470
|
+
let sum2 = 0;
|
|
471
|
+
for (const v of xflat) {
|
|
472
|
+
if (typeof v === "bigint") {
|
|
473
|
+
resultsShouldIncludeBigInts = true;
|
|
474
|
+
}
|
|
475
|
+
if (!options.shouldDropNaNs || isNumber(v)) {
|
|
476
|
+
try {
|
|
477
|
+
if (v > max2) {
|
|
478
|
+
max2 = v;
|
|
479
|
+
}
|
|
480
|
+
if (v < min2) {
|
|
481
|
+
min2 = v;
|
|
482
|
+
}
|
|
483
|
+
sum2 += Number(v);
|
|
484
|
+
xnums.push(v);
|
|
485
|
+
} catch (e) {
|
|
486
|
+
max2 = NaN;
|
|
487
|
+
min2 = NaN;
|
|
488
|
+
sum2 = NaN;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
counts.increment(v);
|
|
492
|
+
}
|
|
493
|
+
const mean2 = sum2 / xnums.length;
|
|
494
|
+
out.counts = counts;
|
|
495
|
+
out.max = max2;
|
|
496
|
+
out.mean = mean2;
|
|
497
|
+
out.min = min2;
|
|
498
|
+
out.n = xflat.length;
|
|
499
|
+
out.sum = sum2;
|
|
500
|
+
if (isNaN(out.mean)) {
|
|
501
|
+
out.max = NaN;
|
|
502
|
+
out.min = NaN;
|
|
503
|
+
}
|
|
504
|
+
if (options.shouldDropNaNs) {
|
|
505
|
+
out.nWithoutNaNs = xnums.length;
|
|
506
|
+
}
|
|
507
|
+
if (options.mode) {
|
|
508
|
+
const sortedCountPairs = Array.from(
|
|
509
|
+
map(counts.values, (v) => [v, counts.get(v)])
|
|
510
|
+
).toSorted((a, b) => b[1] - a[1]);
|
|
511
|
+
const highestCount = sortedCountPairs[0][1];
|
|
512
|
+
const mode2 = [];
|
|
513
|
+
for (const pair of sortedCountPairs) {
|
|
514
|
+
if (pair[1] == highestCount) {
|
|
515
|
+
mode2.push(pair[0]);
|
|
516
|
+
} else {
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
out.mode = mode2.toSorted();
|
|
521
|
+
}
|
|
522
|
+
if (options.median) {
|
|
523
|
+
if (isNaN(mean2)) {
|
|
524
|
+
out.median = NaN;
|
|
525
|
+
} else {
|
|
526
|
+
const xnumsSorted = xnums.toSorted((a, b) => Number(a) - Number(b));
|
|
527
|
+
const middle = Math.floor(xnumsSorted.length / 2);
|
|
528
|
+
if (xnumsSorted.length % 2 === 0) {
|
|
529
|
+
const left = xnumsSorted[middle - 1];
|
|
530
|
+
const right = xnumsSorted[middle];
|
|
531
|
+
out.median = (Number(left) + Number(right)) / 2;
|
|
532
|
+
if (resultsShouldIncludeBigInts && typeof left === "bigint" && typeof right === "bigint") {
|
|
533
|
+
try {
|
|
534
|
+
out.median = BigInt(out.median);
|
|
535
|
+
} catch (e) {
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
} else {
|
|
539
|
+
out.median = xnumsSorted[middle];
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (options.stdev || options.variance) {
|
|
544
|
+
let variance2 = 0;
|
|
545
|
+
for (const v of xnums) {
|
|
546
|
+
variance2 += Math.pow(Number(v) - mean2, 2);
|
|
547
|
+
}
|
|
548
|
+
variance2 /= xnums.length;
|
|
549
|
+
const stdev2 = Math.sqrt(variance2);
|
|
550
|
+
out.stdev = stdev2;
|
|
551
|
+
out.variance = variance2;
|
|
552
|
+
}
|
|
553
|
+
if (resultsShouldIncludeBigInts) {
|
|
554
|
+
try {
|
|
555
|
+
out.sum = BigInt(out.sum);
|
|
556
|
+
} catch (e) {
|
|
557
|
+
}
|
|
558
|
+
try {
|
|
559
|
+
out.mean = BigInt(out.mean);
|
|
560
|
+
} catch (e) {
|
|
561
|
+
}
|
|
562
|
+
if (options.mode) {
|
|
563
|
+
out.mode = map(out.mode, (v) => {
|
|
564
|
+
try {
|
|
565
|
+
return BigInt(v);
|
|
566
|
+
} catch (e) {
|
|
567
|
+
return v;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return out;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/count.mjs
|
|
576
|
+
function count(arr, matcher) {
|
|
577
|
+
const { counts } = stats(arr);
|
|
578
|
+
if (!isUndefined(matcher)) {
|
|
579
|
+
if (isFunction(matcher)) {
|
|
580
|
+
forEach(counts.values, (v) => {
|
|
581
|
+
if (!matcher(v)) {
|
|
582
|
+
counts.delete(v);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
} else {
|
|
586
|
+
forEach(counts.values, (v) => {
|
|
587
|
+
if (!isEqual(v, matcher)) {
|
|
588
|
+
counts.delete(v);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return counts;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/filter.mjs
|
|
597
|
+
function filter(x, fn) {
|
|
598
|
+
const out = [];
|
|
599
|
+
for (let i = 0; i < x.length; i++) {
|
|
600
|
+
if (fn(x[i], i, x)) {
|
|
601
|
+
out.push(x[i]);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return out;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-jagged.mjs
|
|
608
|
+
function helper(x) {
|
|
609
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
610
|
+
return helper(x.values);
|
|
611
|
+
}
|
|
612
|
+
if (isArray(x)) {
|
|
613
|
+
let hasArrayValues = false;
|
|
614
|
+
let hasNonArrayValues = false;
|
|
615
|
+
let arrayLength = null;
|
|
616
|
+
for (const v of x) {
|
|
617
|
+
if (helper(v)) {
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
if (isArray(v)) {
|
|
621
|
+
if (arrayLength === null) {
|
|
622
|
+
arrayLength = v.length;
|
|
623
|
+
} else if (v.length !== arrayLength) {
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
hasArrayValues = true;
|
|
627
|
+
} else {
|
|
628
|
+
hasNonArrayValues = true;
|
|
629
|
+
}
|
|
630
|
+
if (hasArrayValues && hasNonArrayValues) {
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
function isJagged(x) {
|
|
638
|
+
return helper(decycle(x));
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-nested.mjs
|
|
642
|
+
function isNested(x) {
|
|
643
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
644
|
+
return isNested(x.values);
|
|
645
|
+
}
|
|
646
|
+
assert(
|
|
647
|
+
isArray(x),
|
|
648
|
+
"The `isNested` function only works on arrays, Series, and DataFrames!"
|
|
649
|
+
);
|
|
650
|
+
for (let i = 0; i < x.length; i++) {
|
|
651
|
+
if (isArray(x[i])) {
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/ndarray.mjs
|
|
659
|
+
var error = "You must pass a natural number or a one-dimensional array of natural numbers into the `ndarray` function!";
|
|
660
|
+
function ndarray(shape2) {
|
|
661
|
+
assert(!isUndefined(shape2), error);
|
|
662
|
+
if (!isArray(shape2)) shape2 = [shape2];
|
|
663
|
+
assert(!isNested(shape2), error);
|
|
664
|
+
assert(shape2.length > 0, error);
|
|
665
|
+
let s2 = shape2[0];
|
|
666
|
+
if (typeof s2 === "bigint") s2 = Number(s2);
|
|
667
|
+
assert(isNumber(s2), error);
|
|
668
|
+
assert(s2 >= 0, error);
|
|
669
|
+
assert(Math.floor(s2) === s2, error);
|
|
670
|
+
assert(
|
|
671
|
+
s2 !== Infinity,
|
|
672
|
+
"We can't create an array containing an infinite number of values!"
|
|
673
|
+
);
|
|
674
|
+
if (shape2.length === 1) {
|
|
675
|
+
const out = [];
|
|
676
|
+
for (let i = 0; i < s2; i++) out.push(void 0);
|
|
677
|
+
return out;
|
|
678
|
+
} else {
|
|
679
|
+
const out = [];
|
|
680
|
+
for (let i = 0; i < s2; i++) {
|
|
681
|
+
out.push(ndarray(shape2.slice(1)));
|
|
682
|
+
}
|
|
683
|
+
return out;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/range.mjs
|
|
688
|
+
var RangeIterator = class _RangeIterator {
|
|
689
|
+
static from(data) {
|
|
690
|
+
return new _RangeIterator(data.a, data.b);
|
|
691
|
+
}
|
|
692
|
+
a = 0;
|
|
693
|
+
b = 0;
|
|
694
|
+
step = 0;
|
|
695
|
+
constructor(a, b, step) {
|
|
696
|
+
this.a = a;
|
|
697
|
+
this.b = b;
|
|
698
|
+
this.step = step ?? 1;
|
|
699
|
+
}
|
|
700
|
+
get length() {
|
|
701
|
+
return Math.abs(
|
|
702
|
+
(Math.max(this.a, this.b) - Math.min(this.a, this.b)) / this.step
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
get pairIterator() {
|
|
706
|
+
const iterator = this[Symbol.iterator]();
|
|
707
|
+
function* helper4() {
|
|
708
|
+
let i = 0;
|
|
709
|
+
for (const v of iterator) {
|
|
710
|
+
yield [v, i];
|
|
711
|
+
i++;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return helper4();
|
|
715
|
+
}
|
|
716
|
+
[Symbol.iterator]() {
|
|
717
|
+
const shouldIncludeBigInts = typeof this.a === "bigint" || typeof this.b === "bigint" || typeof this.step === "bigint";
|
|
718
|
+
const a = shouldIncludeBigInts ? BigInt(this.a) : this.a;
|
|
719
|
+
const b = shouldIncludeBigInts ? BigInt(this.b) : this.b;
|
|
720
|
+
let step = shouldIncludeBigInts ? BigInt(this.step) : this.step;
|
|
721
|
+
if (a <= b && step < 0 || a > b && step > 0) {
|
|
722
|
+
step *= shouldIncludeBigInts ? BigInt(-1) : -1;
|
|
723
|
+
}
|
|
724
|
+
function* helper4() {
|
|
725
|
+
if (a <= b) {
|
|
726
|
+
for (let i = a; i < b; i += step) {
|
|
727
|
+
yield i;
|
|
728
|
+
}
|
|
729
|
+
} else {
|
|
730
|
+
for (let i = a; i > b; i += step) {
|
|
731
|
+
yield i;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return helper4();
|
|
736
|
+
}
|
|
737
|
+
drop(limit) {
|
|
738
|
+
return new _RangeIterator(this.a + limit * this.step, this.b);
|
|
739
|
+
}
|
|
740
|
+
every(fn) {
|
|
741
|
+
for (const pair of this.pairIterator) {
|
|
742
|
+
if (!fn(...pair)) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
filter(fn) {
|
|
749
|
+
const out = [];
|
|
750
|
+
for (const pair of this.pairIterator) {
|
|
751
|
+
if (fn(...pair)) {
|
|
752
|
+
out.push(pair[0]);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return out;
|
|
756
|
+
}
|
|
757
|
+
find(fn) {
|
|
758
|
+
for (const pair of this.pairIterator) {
|
|
759
|
+
if (fn(...pair)) {
|
|
760
|
+
return pair[0];
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
flatMap() {
|
|
765
|
+
throw new Error("The `RangeIterator.flatMap` method has no implementation!");
|
|
766
|
+
}
|
|
767
|
+
forEach(fn) {
|
|
768
|
+
for (const pair of this.pairIterator) {
|
|
769
|
+
fn(...pair);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
map(fn) {
|
|
773
|
+
const out = [];
|
|
774
|
+
for (const pair of this.pairIterator) {
|
|
775
|
+
out.push(fn(...pair));
|
|
776
|
+
}
|
|
777
|
+
return out;
|
|
778
|
+
}
|
|
779
|
+
reduce(fn, out) {
|
|
780
|
+
for (const pair of this.pairIterator) {
|
|
781
|
+
out = fn(pair[0], out, pair[1]);
|
|
782
|
+
}
|
|
783
|
+
return out;
|
|
784
|
+
}
|
|
785
|
+
some(fn) {
|
|
786
|
+
for (const pair of this.pairIterator) {
|
|
787
|
+
if (fn(...pair)) {
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
take(limit) {
|
|
794
|
+
return new _RangeIterator(this.a, this.a + limit * this.step);
|
|
795
|
+
}
|
|
796
|
+
toArray() {
|
|
797
|
+
const out = [];
|
|
798
|
+
for (const i of this) {
|
|
799
|
+
out.push(i);
|
|
800
|
+
}
|
|
801
|
+
return out;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
function range(a, b, step = 1) {
|
|
805
|
+
assert(
|
|
806
|
+
!isUndefined(a) && !isUndefined(b) && !isUndefined(step),
|
|
807
|
+
"You must pass two numbers and optionally a step value to the `range` function!"
|
|
808
|
+
);
|
|
809
|
+
assert(
|
|
810
|
+
isNumber(a) && isNumber(b) && isNumber(step),
|
|
811
|
+
"You must pass two numbers and optionally a step value to the `range` function!"
|
|
812
|
+
);
|
|
813
|
+
assert(
|
|
814
|
+
step !== 0,
|
|
815
|
+
"The step value must be greater than 0! (NOTE: The step value is a magnitude; it does not indicate direction.)"
|
|
816
|
+
);
|
|
817
|
+
return new RangeIterator(a, b, step);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/set.mjs
|
|
821
|
+
function makeKey2(n) {
|
|
822
|
+
const alpha = "abcdefg1234567890";
|
|
823
|
+
let out = "";
|
|
824
|
+
while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
|
|
825
|
+
return out;
|
|
826
|
+
}
|
|
827
|
+
var NULL_KEY2 = makeKey2(256);
|
|
828
|
+
var UNDEFINED_KEY2 = makeKey2(256);
|
|
829
|
+
var INFINITY_KEY2 = makeKey2(256);
|
|
830
|
+
var MINUS_INFINITY_KEY2 = makeKey2(256);
|
|
831
|
+
var SYMBOL_KEY2 = makeKey2(256);
|
|
832
|
+
function set(arr) {
|
|
833
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
834
|
+
return set(arr.values);
|
|
835
|
+
}
|
|
836
|
+
assert(
|
|
837
|
+
isArray(arr),
|
|
838
|
+
"The `set` function only works on arrays, Series, and DataFrames!"
|
|
839
|
+
);
|
|
840
|
+
const out = [];
|
|
841
|
+
const temp = {};
|
|
842
|
+
forEach(flatten(arr), (item) => {
|
|
843
|
+
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);
|
|
844
|
+
if (typeof temp[key] === "undefined") {
|
|
845
|
+
out.push(item);
|
|
846
|
+
}
|
|
847
|
+
temp[key] = true;
|
|
848
|
+
});
|
|
849
|
+
return out;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/shape.mjs
|
|
853
|
+
function helper2(x) {
|
|
854
|
+
if (isArray(x)) {
|
|
855
|
+
const childShapes = helper2(x[0]);
|
|
856
|
+
return [x.length].concat(childShapes || []);
|
|
857
|
+
} else {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function shape(x) {
|
|
862
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
863
|
+
return shape(x.values);
|
|
864
|
+
}
|
|
865
|
+
assert(
|
|
866
|
+
isArray(x),
|
|
867
|
+
"The `shape` function only works on arrays, Series, and DataFrames!"
|
|
868
|
+
);
|
|
869
|
+
return helper2(x);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-append.mjs
|
|
873
|
+
function dfAppend(df, x, axis) {
|
|
874
|
+
if (isUndefined(axis)) {
|
|
875
|
+
axis = 0;
|
|
876
|
+
}
|
|
877
|
+
assert(
|
|
878
|
+
axis === 0 || axis === 1 || axis === "vertical" || axis === "horizontal",
|
|
879
|
+
'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".'
|
|
880
|
+
);
|
|
881
|
+
if (isArray(x)) {
|
|
882
|
+
assert(
|
|
883
|
+
!isJagged(x),
|
|
884
|
+
"The array of data you're trying to append to this DataFrame is jagged!"
|
|
885
|
+
);
|
|
886
|
+
const xShape = shape(x);
|
|
887
|
+
if (xShape.length === 1) {
|
|
888
|
+
if (axis === 0) {
|
|
889
|
+
const out = df.copy();
|
|
890
|
+
out._values.push(x);
|
|
891
|
+
const maxRowLength = Math.max(df.shape[1], xShape[0]);
|
|
892
|
+
forEach(out._values, (row) => {
|
|
893
|
+
while (row.length < maxRowLength) {
|
|
894
|
+
row.push(void 0);
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
while (out._index.length < out._values.length) {
|
|
898
|
+
out._index.push("row" + out._index.length);
|
|
899
|
+
}
|
|
900
|
+
while (out._columns.length < maxRowLength) {
|
|
901
|
+
out._columns.push("col" + out._columns.length);
|
|
902
|
+
}
|
|
903
|
+
return out;
|
|
904
|
+
} else {
|
|
905
|
+
const maxColLength = Math.max(df.shape[0], xShape[0]);
|
|
906
|
+
const out = df.copy();
|
|
907
|
+
range(0, maxColLength).forEach((i) => {
|
|
908
|
+
if (i >= out._values.length) {
|
|
909
|
+
out._values.push(ndarray(df.shape[1]));
|
|
910
|
+
}
|
|
911
|
+
out._values[i].push(x[i]);
|
|
912
|
+
});
|
|
913
|
+
while (out._index.length < out._values.length) {
|
|
914
|
+
out._index.push("row" + out._index.length);
|
|
915
|
+
}
|
|
916
|
+
while (out._columns.length < out._values[0].length) {
|
|
917
|
+
out._columns.push("col" + out._columns.length);
|
|
918
|
+
}
|
|
919
|
+
return out;
|
|
920
|
+
}
|
|
921
|
+
} else if (xShape.length === 2) {
|
|
922
|
+
if (axis === 0) {
|
|
923
|
+
const maxRowLength = Math.max(
|
|
924
|
+
...map(x, (row) => row.length).concat([df.shape[1]])
|
|
925
|
+
);
|
|
926
|
+
const out = df.copy();
|
|
927
|
+
out._values = map(out._values.concat(x), (row) => {
|
|
928
|
+
while (row.length < maxRowLength) {
|
|
929
|
+
row.push(void 0);
|
|
930
|
+
}
|
|
931
|
+
return row;
|
|
932
|
+
});
|
|
933
|
+
while (out._index.length < out._values.length) {
|
|
934
|
+
out._index.push("row" + out._index.length);
|
|
935
|
+
}
|
|
936
|
+
while (out._columns.length < maxRowLength) {
|
|
937
|
+
out._columns.push("col" + out._columns.length);
|
|
938
|
+
}
|
|
939
|
+
return out;
|
|
940
|
+
} else {
|
|
941
|
+
const maxRowLength = Math.max(...map(x, (row) => row.length)) + df.shape[1];
|
|
942
|
+
const maxColLength = Math.max(df.shape[0], xShape[0]);
|
|
943
|
+
const out = df.copy();
|
|
944
|
+
range(0, maxColLength).forEach((i) => {
|
|
945
|
+
if (i >= out._values.length) {
|
|
946
|
+
out._values.push(ndarray(df.shape[1]));
|
|
947
|
+
}
|
|
948
|
+
out._values[i] = out._values[i].concat(x[i]);
|
|
949
|
+
while (out._values[i].length < maxRowLength) {
|
|
950
|
+
out._values[i].push(void 0);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
while (out._index.length < out._values.length) {
|
|
954
|
+
out._index.push("row" + out._index.length);
|
|
955
|
+
}
|
|
956
|
+
while (out._columns.length < maxRowLength) {
|
|
957
|
+
out._columns.push("col" + out._columns.length);
|
|
958
|
+
}
|
|
959
|
+
return out;
|
|
960
|
+
}
|
|
961
|
+
} else {
|
|
962
|
+
throw new MathError(
|
|
963
|
+
"Only 1- and 2-dimensional arrays can be appended to a DataFrame!"
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
} else if (isSeries(x)) {
|
|
967
|
+
const out = dfAppend(df, x.values, axis);
|
|
968
|
+
if (axis === 0) {
|
|
969
|
+
out.index[out.index.length - 1] = out.index.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
|
|
970
|
+
} else {
|
|
971
|
+
out.columns[out.columns.length - 1] = out.columns.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
|
|
972
|
+
}
|
|
973
|
+
return out;
|
|
974
|
+
} else if (isDataFrame(x)) {
|
|
975
|
+
if (axis === 0) {
|
|
976
|
+
const out = df.copy();
|
|
977
|
+
const maxRowLength = set(out._columns.concat(x._columns)).length;
|
|
978
|
+
forEach(out._values, (row) => {
|
|
979
|
+
while (row.length < maxRowLength) {
|
|
980
|
+
row.push(void 0);
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
x.apply((row) => {
|
|
984
|
+
const rowCopy = row.copy();
|
|
985
|
+
const temp = [];
|
|
986
|
+
forEach(out._columns, (col) => {
|
|
987
|
+
const index = rowCopy._index.indexOf(col);
|
|
988
|
+
if (index > -1) {
|
|
989
|
+
temp.push(rowCopy._values[index]);
|
|
990
|
+
rowCopy._values.splice(index, 1);
|
|
991
|
+
rowCopy._index.splice(index, 1);
|
|
992
|
+
} else {
|
|
993
|
+
temp.push(void 0);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
out._values.push(temp.concat(rowCopy._values));
|
|
997
|
+
}, 1);
|
|
998
|
+
out._columns = out._columns.concat(
|
|
999
|
+
filter(x._columns, (c) => out._columns.indexOf(c) < 0)
|
|
1000
|
+
);
|
|
1001
|
+
while (out._index.length < out._values.length) {
|
|
1002
|
+
const newRowName = "row" + out._index.length;
|
|
1003
|
+
out._index.push(
|
|
1004
|
+
newRowName + (df._index.indexOf(newRowName) > -1 ? " (2)" : "")
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
return out;
|
|
1008
|
+
} else {
|
|
1009
|
+
const out = df.copy();
|
|
1010
|
+
forEach(out._index, (rowName, i) => {
|
|
1011
|
+
const xIndex = x._index.indexOf(rowName);
|
|
1012
|
+
if (xIndex > -1) {
|
|
1013
|
+
out._values[i] = out._values[i].concat(x._values[xIndex]);
|
|
1014
|
+
} else {
|
|
1015
|
+
out._values[i] = out._values[i].concat(ndarray(x.shape[1]));
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
forEach(x._index, (rowName, i) => {
|
|
1019
|
+
const outIndex = out._index.indexOf(rowName);
|
|
1020
|
+
if (outIndex < 0) {
|
|
1021
|
+
out._index.push(rowName);
|
|
1022
|
+
out._values.push(ndarray(out._columns.length).concat(x._values[i]));
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
out._columns = out._columns.concat(
|
|
1026
|
+
map(x._columns, (c) => c + (out._columns.indexOf(c) > -1 ? " (2)" : ""))
|
|
1027
|
+
);
|
|
1028
|
+
return out;
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
throw new MathError(
|
|
1032
|
+
"Only 1- or 2-dimensional arrays, Series, and DataFrames can be appended to a DataFrame!"
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-apply.mjs
|
|
1038
|
+
function dfApply(DataFrame2, Series2, df, fn, axis) {
|
|
1039
|
+
axis = axis || 0;
|
|
1040
|
+
assert(
|
|
1041
|
+
isFunction(fn),
|
|
1042
|
+
"The first parameter to the `apply` method must be a function."
|
|
1043
|
+
);
|
|
1044
|
+
assert(
|
|
1045
|
+
axis === 0 || axis === 1,
|
|
1046
|
+
"The second parameter to the `apply` method (the `axis`) must be 0 or 1."
|
|
1047
|
+
);
|
|
1048
|
+
if (axis === 0) {
|
|
1049
|
+
const temp = {};
|
|
1050
|
+
let shouldReturnADataFrame;
|
|
1051
|
+
forEach(df.columns, (colName, i) => {
|
|
1052
|
+
const series = new Series2(map(df.values, (row) => row[i]));
|
|
1053
|
+
series.name = colName;
|
|
1054
|
+
series.index = df.index;
|
|
1055
|
+
const value = fn(series, i, df);
|
|
1056
|
+
if (value instanceof Series2) {
|
|
1057
|
+
temp[colName] = value.values;
|
|
1058
|
+
} else {
|
|
1059
|
+
temp[colName] = value;
|
|
1060
|
+
}
|
|
1061
|
+
if (isUndefined(shouldReturnADataFrame)) {
|
|
1062
|
+
shouldReturnADataFrame = value instanceof Series2 || isArray(value);
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
if (shouldReturnADataFrame) {
|
|
1066
|
+
const out = new DataFrame2(temp);
|
|
1067
|
+
out.index = df.index;
|
|
1068
|
+
return out;
|
|
1069
|
+
} else {
|
|
1070
|
+
const out = new Series2(map(df.columns, (colName) => temp[colName]));
|
|
1071
|
+
out.index = df.columns;
|
|
1072
|
+
return out;
|
|
1073
|
+
}
|
|
1074
|
+
} else if (axis === 1) {
|
|
1075
|
+
let shouldReturnADataFrame;
|
|
1076
|
+
const temp = map(df.values, (row, i) => {
|
|
1077
|
+
const series = new Series2(row);
|
|
1078
|
+
series.name = df.index[i];
|
|
1079
|
+
series.index = df.columns;
|
|
1080
|
+
const value = fn(series, i, df);
|
|
1081
|
+
if (isUndefined(shouldReturnADataFrame)) {
|
|
1082
|
+
shouldReturnADataFrame = value instanceof Series2 || isArray(value);
|
|
1083
|
+
}
|
|
1084
|
+
if (value instanceof Series2) {
|
|
1085
|
+
return value.values;
|
|
1086
|
+
} else {
|
|
1087
|
+
return value;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
if (shouldReturnADataFrame) {
|
|
1091
|
+
const out = new DataFrame2(temp);
|
|
1092
|
+
out.index = df.index;
|
|
1093
|
+
out.columns = df.columns;
|
|
1094
|
+
return out;
|
|
1095
|
+
} else {
|
|
1096
|
+
const out = new Series2(temp);
|
|
1097
|
+
out.index = df.index;
|
|
1098
|
+
return out;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-string.mjs
|
|
1104
|
+
function isString(s2) {
|
|
1105
|
+
return typeof s2 === "string";
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-assign.mjs
|
|
1109
|
+
function dfAssign(DataFrame2, Series2, df, p1, p2) {
|
|
1110
|
+
const isDataFrame2 = (x) => x instanceof DataFrame2;
|
|
1111
|
+
const isSeries2 = (x) => x instanceof Series2;
|
|
1112
|
+
if (!isUndefined(p2)) {
|
|
1113
|
+
assert(
|
|
1114
|
+
isString(p1),
|
|
1115
|
+
"If passing two arguments into the `assign` method, then the first argument must be a string name!"
|
|
1116
|
+
);
|
|
1117
|
+
assert(
|
|
1118
|
+
isArray(p2) && !isJagged(p2) && shape(p2).length === 1,
|
|
1119
|
+
"If passing two arguments into the `assign` method, then the second argument must be a 1-dimensional array!"
|
|
1120
|
+
);
|
|
1121
|
+
const out = df.copy();
|
|
1122
|
+
if (out.columns.includes(p1)) {
|
|
1123
|
+
const index = out.columns.indexOf(p1);
|
|
1124
|
+
out.columns[index] = p1;
|
|
1125
|
+
forEach(out.values, (v, i) => v[index] = p2[i]);
|
|
1126
|
+
return out;
|
|
1127
|
+
} else {
|
|
1128
|
+
out._columns.push(p1);
|
|
1129
|
+
forEach(out._values, (v, i) => v.push(p2[i]));
|
|
1130
|
+
return out;
|
|
1131
|
+
}
|
|
1132
|
+
} else {
|
|
1133
|
+
if (isDataFrame2(p1)) {
|
|
1134
|
+
const out = df.copy();
|
|
1135
|
+
const outShape = out.shape;
|
|
1136
|
+
const p1Shape = p1.shape;
|
|
1137
|
+
for (let j = 0; j < p1Shape[1]; j++) {
|
|
1138
|
+
const col = p1.columns[j];
|
|
1139
|
+
const colNewIndex = out.columns.includes(col) ? out.columns.indexOf(col) : out.columns.length;
|
|
1140
|
+
if (!out.columns.includes(col)) {
|
|
1141
|
+
out._columns.push(col);
|
|
1142
|
+
}
|
|
1143
|
+
for (let i = 0; i < outShape[0]; i++) {
|
|
1144
|
+
out._values[i][colNewIndex] = p1._values[i][j];
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return out;
|
|
1148
|
+
} else if (isSeries2(p1)) {
|
|
1149
|
+
return df.assign(p1.name, p1.values);
|
|
1150
|
+
} else if (isObject(p1)) {
|
|
1151
|
+
return df.assign(new DataFrame2(p1));
|
|
1152
|
+
} else {
|
|
1153
|
+
throw new MathError(
|
|
1154
|
+
"You must pass a DataFrame, Series, or object into the `assign` method!"
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-copy.mjs
|
|
1161
|
+
function dfCopy(DataFrame2, df) {
|
|
1162
|
+
if (df.isEmpty) return new DataFrame2();
|
|
1163
|
+
const out = new DataFrame2(copy(df.values));
|
|
1164
|
+
out.columns = df.columns.slice();
|
|
1165
|
+
out.index = df.index.slice();
|
|
1166
|
+
return out;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop.mjs
|
|
1170
|
+
function dfDrop(DataFrame2, Series2, df, rows, cols) {
|
|
1171
|
+
if (isUndefined(rows)) rows = [];
|
|
1172
|
+
if (isUndefined(cols)) cols = [];
|
|
1173
|
+
if (isString(rows) || isNumber(rows)) rows = [rows];
|
|
1174
|
+
if (isString(cols) || isNumber(cols)) cols = [cols];
|
|
1175
|
+
assert(
|
|
1176
|
+
isArray(rows),
|
|
1177
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1178
|
+
);
|
|
1179
|
+
assert(
|
|
1180
|
+
isArray(cols),
|
|
1181
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1182
|
+
);
|
|
1183
|
+
assert(
|
|
1184
|
+
shape(rows).length === 1,
|
|
1185
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1186
|
+
);
|
|
1187
|
+
assert(
|
|
1188
|
+
shape(cols).length === 1,
|
|
1189
|
+
"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
|
|
1190
|
+
);
|
|
1191
|
+
let outIndex, outColumns;
|
|
1192
|
+
forEach(df.index, (row, i) => {
|
|
1193
|
+
if (rows.indexOf(row) < 0 && rows.indexOf(i) < 0) {
|
|
1194
|
+
if (!outIndex) outIndex = [];
|
|
1195
|
+
outIndex.push(row);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
forEach(df.columns, (col, i) => {
|
|
1199
|
+
if (cols.indexOf(col) < 0 && cols.indexOf(i) < 0) {
|
|
1200
|
+
if (!outColumns) outColumns = [];
|
|
1201
|
+
outColumns.push(col);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
let out = df.get(outIndex, outColumns);
|
|
1205
|
+
if (out instanceof Series2) {
|
|
1206
|
+
let temp = new DataFrame2();
|
|
1207
|
+
temp = temp.assign(out);
|
|
1208
|
+
if (df.index.indexOf(out.name) > -1) temp = temp.transpose();
|
|
1209
|
+
out = temp;
|
|
1210
|
+
}
|
|
1211
|
+
return out;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/is-integer.mjs
|
|
1215
|
+
function isInteger(x) {
|
|
1216
|
+
return isNumber(x) && (x >= 0 ? Math.floor(x) === x : Math.ceil(x) === x);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/is-whole-number.mjs
|
|
1220
|
+
function isWholeNumber(x) {
|
|
1221
|
+
return isInteger(x) && x >= 0;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-missing.mjs
|
|
1225
|
+
function dfDropMissing(DataFrame2, Series2, df, axis, condition, threshold) {
|
|
1226
|
+
axis = axis || 0;
|
|
1227
|
+
assert(
|
|
1228
|
+
axis === 0 || axis === 1,
|
|
1229
|
+
"The first parameter of the `dropMissing` method (the `axis`) must be 0 or 1."
|
|
1230
|
+
);
|
|
1231
|
+
threshold = threshold || 0;
|
|
1232
|
+
assert(
|
|
1233
|
+
isWholeNumber(threshold),
|
|
1234
|
+
"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)."
|
|
1235
|
+
);
|
|
1236
|
+
condition = threshold > 0 ? "none" : condition || "any";
|
|
1237
|
+
assert(
|
|
1238
|
+
condition === "any" || condition === "all" || condition === "none",
|
|
1239
|
+
"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)."
|
|
1240
|
+
);
|
|
1241
|
+
function helper4(values) {
|
|
1242
|
+
if (threshold > 0) {
|
|
1243
|
+
let count2 = 0;
|
|
1244
|
+
for (let i = 0; i < values.length; i++) {
|
|
1245
|
+
const value = values[i];
|
|
1246
|
+
if (isUndefined(value)) count2++;
|
|
1247
|
+
if (count2 >= threshold) return [];
|
|
1248
|
+
}
|
|
1249
|
+
} else if (condition === "any") {
|
|
1250
|
+
for (let i = 0; i < values.length; i++) {
|
|
1251
|
+
const value = values[i];
|
|
1252
|
+
if (isUndefined(value)) return [];
|
|
1253
|
+
}
|
|
1254
|
+
} else if (condition === "all") {
|
|
1255
|
+
for (let i = 0; i < values.length; i++) {
|
|
1256
|
+
const value = values[i];
|
|
1257
|
+
if (!isUndefined(value)) return values;
|
|
1258
|
+
}
|
|
1259
|
+
return [];
|
|
1260
|
+
}
|
|
1261
|
+
return values;
|
|
1262
|
+
}
|
|
1263
|
+
let out = df.copy();
|
|
1264
|
+
const tempID = Math.random().toString();
|
|
1265
|
+
if (axis === 0) {
|
|
1266
|
+
out = out.assign(tempID, out.index);
|
|
1267
|
+
const newValues = filter(map(out.values, helper4), (row) => row.length > 0);
|
|
1268
|
+
if (shape(newValues).length < 2) return new DataFrame2();
|
|
1269
|
+
out.values = newValues;
|
|
1270
|
+
let newIndex = out.get(null, tempID);
|
|
1271
|
+
if (isUndefined(newIndex)) return new DataFrame2();
|
|
1272
|
+
if (isString(newIndex)) newIndex = [newIndex];
|
|
1273
|
+
if (newIndex instanceof Series2) newIndex = newIndex.values;
|
|
1274
|
+
out.index = newIndex;
|
|
1275
|
+
out = out.drop(null, tempID);
|
|
1276
|
+
} else if (axis === 1) {
|
|
1277
|
+
const temp = {};
|
|
1278
|
+
forEach(out.columns, (colName, i) => {
|
|
1279
|
+
const values = map(out.values, (row) => row[i]);
|
|
1280
|
+
const newValues = helper4(values);
|
|
1281
|
+
if (newValues.length > 0) {
|
|
1282
|
+
temp[colName] = newValues;
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
if (Object.keys(temp).length + Object.getOwnPropertySymbols(temp).length === 0) {
|
|
1286
|
+
return new DataFrame2();
|
|
1287
|
+
}
|
|
1288
|
+
const newOut = new DataFrame2(temp);
|
|
1289
|
+
newOut.index = out.index;
|
|
1290
|
+
return newOut;
|
|
1291
|
+
}
|
|
1292
|
+
return out;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/drop-nan.mjs
|
|
1296
|
+
function dropNaN(x) {
|
|
1297
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
1298
|
+
return x.dropNaN(...Object.values(arguments).slice(1));
|
|
1299
|
+
}
|
|
1300
|
+
assert(
|
|
1301
|
+
isArray(x),
|
|
1302
|
+
"The `dropNaN` function only works on arrays, Series, and DataFrames!"
|
|
1303
|
+
);
|
|
1304
|
+
const out = [];
|
|
1305
|
+
forEach(x, (v) => {
|
|
1306
|
+
try {
|
|
1307
|
+
return out.push(dropNaN(v));
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
if (isNumber(v)) {
|
|
1310
|
+
return out.push(v);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
return out;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-nan.mjs
|
|
1318
|
+
function dfDropNaN(DataFrame2, df, axis, condition, threshold) {
|
|
1319
|
+
axis = axis || 0;
|
|
1320
|
+
assert(
|
|
1321
|
+
axis === 0 || axis === 1,
|
|
1322
|
+
"The first parameter of the `dropNaN` method (the `axis`) must be 0 or 1."
|
|
1323
|
+
);
|
|
1324
|
+
threshold = threshold || 0;
|
|
1325
|
+
assert(
|
|
1326
|
+
isWholeNumber(threshold),
|
|
1327
|
+
"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)."
|
|
1328
|
+
);
|
|
1329
|
+
condition = threshold > 0 ? "none" : condition || "any";
|
|
1330
|
+
assert(
|
|
1331
|
+
condition === "any" || condition === "all" || condition === "none",
|
|
1332
|
+
"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)."
|
|
1333
|
+
);
|
|
1334
|
+
function helper4(values) {
|
|
1335
|
+
const numericalValues = dropNaN(values);
|
|
1336
|
+
if (threshold > 0) return values.length - numericalValues.length < threshold;
|
|
1337
|
+
if (condition === "any") return numericalValues.length === values.length;
|
|
1338
|
+
if (condition === "all") return numericalValues.length > 0;
|
|
1339
|
+
return true;
|
|
1340
|
+
}
|
|
1341
|
+
const out = df.copy();
|
|
1342
|
+
if (axis === 0) {
|
|
1343
|
+
const rowsToKeep = filter(out.index, (row) => {
|
|
1344
|
+
const values = out.get(row, null).values;
|
|
1345
|
+
return helper4(values);
|
|
1346
|
+
});
|
|
1347
|
+
if (rowsToKeep.length > 0) return out.get(rowsToKeep, null);
|
|
1348
|
+
else return new DataFrame2();
|
|
1349
|
+
} else if (axis === 1) {
|
|
1350
|
+
const colsToKeep = filter(out.columns, (col) => {
|
|
1351
|
+
const values = out.get(null, col).values;
|
|
1352
|
+
return helper4(values);
|
|
1353
|
+
});
|
|
1354
|
+
if (colsToKeep.length > 0) return out.get(null, colsToKeep);
|
|
1355
|
+
else return new DataFrame2();
|
|
1356
|
+
}
|
|
1357
|
+
return out;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-filter.mjs
|
|
1361
|
+
function arrayToObject(x) {
|
|
1362
|
+
const out = {};
|
|
1363
|
+
forEach(flatten(x), (value, i) => {
|
|
1364
|
+
out[value] = i;
|
|
1365
|
+
});
|
|
1366
|
+
return out;
|
|
1367
|
+
}
|
|
1368
|
+
function undoArrayToObject(obj) {
|
|
1369
|
+
return Object.keys(obj).concat(Object.getOwnPropertySymbols(obj)).sort((a, b) => obj[a] - obj[b]);
|
|
1370
|
+
}
|
|
1371
|
+
function dfFilter(DataFrame2, Series2, df, fn, axis) {
|
|
1372
|
+
assert(
|
|
1373
|
+
isFunction(fn),
|
|
1374
|
+
"The `filter` method takes a single parameter: a function that is used to filter the values."
|
|
1375
|
+
);
|
|
1376
|
+
if (isUndefined(axis)) axis = 0;
|
|
1377
|
+
assert(
|
|
1378
|
+
axis === 0 || axis === 1,
|
|
1379
|
+
"The `axis` parameter to the `filter` method must be 0 or 1."
|
|
1380
|
+
);
|
|
1381
|
+
let out = df.copy();
|
|
1382
|
+
if (out.isEmpty) return out;
|
|
1383
|
+
const index = arrayToObject(out.index);
|
|
1384
|
+
const columns = arrayToObject(out.columns);
|
|
1385
|
+
if (axis === 0) {
|
|
1386
|
+
let count2 = 0;
|
|
1387
|
+
const newValues = filter(out.values, (row, i) => {
|
|
1388
|
+
const series = new Series2(row);
|
|
1389
|
+
series.name = df.index[i];
|
|
1390
|
+
series.index = df.columns;
|
|
1391
|
+
const shouldKeep = fn(series, i, df);
|
|
1392
|
+
if (shouldKeep) {
|
|
1393
|
+
count2++;
|
|
1394
|
+
} else {
|
|
1395
|
+
delete index[out.index[i]];
|
|
1396
|
+
}
|
|
1397
|
+
return shouldKeep;
|
|
1398
|
+
});
|
|
1399
|
+
if (count2 === 0) {
|
|
1400
|
+
return new DataFrame2();
|
|
1401
|
+
}
|
|
1402
|
+
if (count2 === 1) {
|
|
1403
|
+
const temp = new Series2(newValues[0]);
|
|
1404
|
+
temp.name = undoArrayToObject(index)[0];
|
|
1405
|
+
temp.index = undoArrayToObject(columns);
|
|
1406
|
+
return temp;
|
|
1407
|
+
}
|
|
1408
|
+
out.values = newValues;
|
|
1409
|
+
out.index = undoArrayToObject(index);
|
|
1410
|
+
} else if (axis === 1) {
|
|
1411
|
+
out = out.transpose();
|
|
1412
|
+
let count2 = 0;
|
|
1413
|
+
const newValues = filter(out.values, (row, i) => {
|
|
1414
|
+
const series = new Series2(row);
|
|
1415
|
+
series.name = df.columns[i];
|
|
1416
|
+
series.index = df.index;
|
|
1417
|
+
const shouldKeep = fn(series, i, df);
|
|
1418
|
+
if (shouldKeep) {
|
|
1419
|
+
count2++;
|
|
1420
|
+
} else {
|
|
1421
|
+
delete columns[out.index[i]];
|
|
1422
|
+
}
|
|
1423
|
+
return shouldKeep;
|
|
1424
|
+
});
|
|
1425
|
+
if (count2 === 0) {
|
|
1426
|
+
return new DataFrame2();
|
|
1427
|
+
}
|
|
1428
|
+
if (count2 === 1) {
|
|
1429
|
+
const temp = new Series2(newValues[0]);
|
|
1430
|
+
temp.name = undoArrayToObject(columns)[0];
|
|
1431
|
+
temp.index = undoArrayToObject(index);
|
|
1432
|
+
return temp;
|
|
1433
|
+
}
|
|
1434
|
+
out.values = newValues;
|
|
1435
|
+
out.index = undoArrayToObject(columns);
|
|
1436
|
+
out = out.transpose();
|
|
1437
|
+
}
|
|
1438
|
+
return out;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-get.mjs
|
|
1442
|
+
function dfGet(df, rows, cols) {
|
|
1443
|
+
if (isString(rows) || isNumber(rows)) rows = [rows];
|
|
1444
|
+
if (isString(cols) || isNumber(cols)) cols = [cols];
|
|
1445
|
+
for (const i in rows) {
|
|
1446
|
+
if (typeof rows[i] === "bigint") {
|
|
1447
|
+
rows[i] = Number(rows[i]);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
for (const i in cols) {
|
|
1451
|
+
if (typeof cols[i] === "bigint") {
|
|
1452
|
+
cols[i] = Number(cols[i]);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
const types = set(map((rows || []).concat(cols || []), (v) => typeof v));
|
|
1456
|
+
assert(
|
|
1457
|
+
types.length <= 2,
|
|
1458
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1459
|
+
);
|
|
1460
|
+
if (types.length === 1) {
|
|
1461
|
+
assert(
|
|
1462
|
+
types[0] === "string" || types[0] === "number",
|
|
1463
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
if (types.length === 2) {
|
|
1467
|
+
assert(
|
|
1468
|
+
types.indexOf("string") > -1,
|
|
1469
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1470
|
+
);
|
|
1471
|
+
assert(
|
|
1472
|
+
types.indexOf("number") > -1,
|
|
1473
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
if (!isUndefined(rows)) {
|
|
1477
|
+
rows = map(rows, (r) => {
|
|
1478
|
+
if (isString(r)) {
|
|
1479
|
+
assert(df.index.indexOf(r) > -1, `Row "${r}" does not exist!`);
|
|
1480
|
+
return r;
|
|
1481
|
+
}
|
|
1482
|
+
if (isNumber(r)) {
|
|
1483
|
+
assert(r >= 0, `Index ${r} is out of bounds!`);
|
|
1484
|
+
assert(Math.floor(r) === r, `Row numbers must be integers!`);
|
|
1485
|
+
assert(r < df.index.length, `Index ${r} is out of bounds!`);
|
|
1486
|
+
return df.index[r];
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
if (!isUndefined(cols)) {
|
|
1491
|
+
cols = map(cols, (c) => {
|
|
1492
|
+
if (isString(c)) {
|
|
1493
|
+
assert(df.columns.indexOf(c) > -1, `Column "${c}" does not exist!`);
|
|
1494
|
+
return c;
|
|
1495
|
+
}
|
|
1496
|
+
if (isNumber(c)) {
|
|
1497
|
+
assert(c >= 0, `Column ${c} is out of bounds!`);
|
|
1498
|
+
assert(Math.floor(c) === c, `Column numbers must be integers!`);
|
|
1499
|
+
assert(c < df.columns.length, `Column ${c} is out of bounds!`);
|
|
1500
|
+
return df.columns[c];
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
return df.getSubsetByNames(rows, cols);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/sort.mjs
|
|
1508
|
+
function alphaSort(a, b) {
|
|
1509
|
+
try {
|
|
1510
|
+
if (a < b) return -1;
|
|
1511
|
+
if (a > b) return 1;
|
|
1512
|
+
return 0;
|
|
1513
|
+
} catch (e) {
|
|
1514
|
+
a = typeof a === "object" && a !== null ? JSON.stringify(a) : a.toString();
|
|
1515
|
+
b = typeof b === "object" && b !== null ? JSON.stringify(b) : b.toString();
|
|
1516
|
+
if (a < b) return -1;
|
|
1517
|
+
if (a > b) return 1;
|
|
1518
|
+
return 0;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
function sort(arr, fn) {
|
|
1522
|
+
if (isUndefined(fn)) fn = alphaSort;
|
|
1523
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1524
|
+
return arr.sort(...Object.values(arguments).slice(1));
|
|
1525
|
+
}
|
|
1526
|
+
assert(
|
|
1527
|
+
isArray(arr),
|
|
1528
|
+
"The `sort` function only works on arrays, Series, and DataFrames!"
|
|
1529
|
+
);
|
|
1530
|
+
assert(
|
|
1531
|
+
isFunction(fn),
|
|
1532
|
+
"The second parameter of the `sort` function must be a comparison function!"
|
|
1533
|
+
);
|
|
1534
|
+
const out = arr.slice();
|
|
1535
|
+
out.sort(fn);
|
|
1536
|
+
return out;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-dummies.mjs
|
|
1540
|
+
function camelify(text) {
|
|
1541
|
+
const temp = text.toLowerCase();
|
|
1542
|
+
let out = "";
|
|
1543
|
+
for (let i = 0; i < temp.length; i++) {
|
|
1544
|
+
const char = temp[i];
|
|
1545
|
+
if (char.match(/[a-z0-9]/g)) {
|
|
1546
|
+
out += char;
|
|
1547
|
+
} else {
|
|
1548
|
+
out += " ";
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
const words = filter(out.split(" "), (word) => word.length > 0);
|
|
1552
|
+
return words[0] + map(
|
|
1553
|
+
words.slice(1),
|
|
1554
|
+
(word) => word[0].toUpperCase() + word.substring(1)
|
|
1555
|
+
).join("");
|
|
1556
|
+
}
|
|
1557
|
+
function dfGetDummies(DataFrame2, df, columns) {
|
|
1558
|
+
if (isUndefined(columns)) {
|
|
1559
|
+
columns = df.columns;
|
|
1560
|
+
} else if (isString(columns)) {
|
|
1561
|
+
columns = [columns];
|
|
1562
|
+
}
|
|
1563
|
+
const temp = {};
|
|
1564
|
+
forEach(columns, (col) => {
|
|
1565
|
+
assert(
|
|
1566
|
+
isString(col),
|
|
1567
|
+
"You must pass either a string or a one-dimensional array of strings into the `getDummies` (AKA `oneHotEncode`) method!"
|
|
1568
|
+
);
|
|
1569
|
+
const colIndex = df.columns.indexOf(col);
|
|
1570
|
+
assert(
|
|
1571
|
+
colIndex > -1,
|
|
1572
|
+
`The given DataFrame does not have a column called "${col}"!`
|
|
1573
|
+
);
|
|
1574
|
+
const values = map(df.values, (row) => row[colIndex]);
|
|
1575
|
+
const valuesSet = sort(set(values));
|
|
1576
|
+
forEach(values, (value) => {
|
|
1577
|
+
forEach(valuesSet, (orig) => {
|
|
1578
|
+
const colName = col + "_" + camelify(orig.toString());
|
|
1579
|
+
if (!temp[colName]) {
|
|
1580
|
+
temp[colName] = [];
|
|
1581
|
+
}
|
|
1582
|
+
if (value === orig) {
|
|
1583
|
+
temp[colName].push(1);
|
|
1584
|
+
} else {
|
|
1585
|
+
temp[colName].push(0);
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
});
|
|
1590
|
+
const out = new DataFrame2(temp);
|
|
1591
|
+
out.index = df.index;
|
|
1592
|
+
return out;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-indices.mjs
|
|
1596
|
+
function dfGetSubsetByIndices(df, rowIndices, colIndices) {
|
|
1597
|
+
const dataShape = df.shape;
|
|
1598
|
+
if (isUndefined(rowIndices)) rowIndices = range(0, dataShape[0]).toArray();
|
|
1599
|
+
if (isUndefined(colIndices)) colIndices = range(0, dataShape[1]).toArray();
|
|
1600
|
+
if (isNumber(rowIndices)) rowIndices = [rowIndices];
|
|
1601
|
+
if (isNumber(colIndices)) colIndices = [colIndices];
|
|
1602
|
+
assert(
|
|
1603
|
+
isArray(rowIndices) && isArray(colIndices),
|
|
1604
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1605
|
+
);
|
|
1606
|
+
assert(
|
|
1607
|
+
shape(rowIndices).length === 1 && shape(colIndices).length === 1,
|
|
1608
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1609
|
+
);
|
|
1610
|
+
assert(
|
|
1611
|
+
rowIndices.length > 0,
|
|
1612
|
+
"The `rowIndices` array must contain at least one index."
|
|
1613
|
+
);
|
|
1614
|
+
assert(
|
|
1615
|
+
colIndices.length > 0,
|
|
1616
|
+
"The `colIndices` array must contain at least one index."
|
|
1617
|
+
);
|
|
1618
|
+
forEach(rowIndices, (rowIndex) => {
|
|
1619
|
+
assert(
|
|
1620
|
+
isWholeNumber(rowIndex),
|
|
1621
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1622
|
+
);
|
|
1623
|
+
assert(
|
|
1624
|
+
rowIndex < df.index.length,
|
|
1625
|
+
`The row index ${rowIndex} is out of bounds.`
|
|
1626
|
+
);
|
|
1627
|
+
});
|
|
1628
|
+
forEach(colIndices, (colIndex) => {
|
|
1629
|
+
assert(
|
|
1630
|
+
isWholeNumber(colIndex),
|
|
1631
|
+
"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
|
|
1632
|
+
);
|
|
1633
|
+
assert(
|
|
1634
|
+
colIndex < df.columns.length,
|
|
1635
|
+
`The column index ${colIndex} is out of bounds.`
|
|
1636
|
+
);
|
|
1637
|
+
});
|
|
1638
|
+
const rows = map(rowIndices, (i) => df.index[i]);
|
|
1639
|
+
const cols = map(colIndices, (i) => df.columns[i]);
|
|
1640
|
+
return df.getSubsetByNames(rows, cols);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-names.mjs
|
|
1644
|
+
function dfGetSubsetByNames(DataFrame2, Series2, df, rows, cols) {
|
|
1645
|
+
if (isUndefined(rows)) rows = df.index;
|
|
1646
|
+
if (isUndefined(cols)) cols = df.columns;
|
|
1647
|
+
if (isString(rows)) rows = [rows];
|
|
1648
|
+
if (isString(cols)) cols = [cols];
|
|
1649
|
+
assert(
|
|
1650
|
+
isArray(rows) && isArray(cols),
|
|
1651
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1652
|
+
);
|
|
1653
|
+
assert(
|
|
1654
|
+
shape(rows).length === 1 && shape(cols).length === 1,
|
|
1655
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1656
|
+
);
|
|
1657
|
+
assert(
|
|
1658
|
+
rows.length > 0,
|
|
1659
|
+
"The `rows` array must contain at least one row name."
|
|
1660
|
+
);
|
|
1661
|
+
assert(
|
|
1662
|
+
cols.length > 0,
|
|
1663
|
+
"The `cols` array must contain at least one column name."
|
|
1664
|
+
);
|
|
1665
|
+
forEach(rows, (row) => {
|
|
1666
|
+
assert(
|
|
1667
|
+
isString(row),
|
|
1668
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1669
|
+
);
|
|
1670
|
+
assert(
|
|
1671
|
+
df.index.indexOf(row) > -1,
|
|
1672
|
+
`The row name "${row}" does not exist in the list of rows.`
|
|
1673
|
+
);
|
|
1674
|
+
});
|
|
1675
|
+
forEach(cols, (col) => {
|
|
1676
|
+
assert(
|
|
1677
|
+
isString(col),
|
|
1678
|
+
"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
|
|
1679
|
+
);
|
|
1680
|
+
assert(
|
|
1681
|
+
df.columns.indexOf(col) > -1,
|
|
1682
|
+
`The column name "${col}" does not exist in the list of columns.`
|
|
1683
|
+
);
|
|
1684
|
+
});
|
|
1685
|
+
const values = map(rows, (row) => {
|
|
1686
|
+
return map(cols, (col) => {
|
|
1687
|
+
return df.values[df.index.indexOf(row)][df.columns.indexOf(col)];
|
|
1688
|
+
});
|
|
1689
|
+
});
|
|
1690
|
+
if (rows.length === 1 && cols.length === 1) {
|
|
1691
|
+
return values[0][0];
|
|
1692
|
+
}
|
|
1693
|
+
if (rows.length === 1) {
|
|
1694
|
+
const out2 = new Series2(values[0]);
|
|
1695
|
+
out2.name = rows[0];
|
|
1696
|
+
out2.index = cols;
|
|
1697
|
+
return out2;
|
|
1698
|
+
}
|
|
1699
|
+
if (cols.length === 1) {
|
|
1700
|
+
const out2 = new Series2(map(values, (v) => v[0]));
|
|
1701
|
+
out2.name = cols[0];
|
|
1702
|
+
out2.index = rows;
|
|
1703
|
+
return out2;
|
|
1704
|
+
}
|
|
1705
|
+
const out = new DataFrame2(values);
|
|
1706
|
+
out.columns = cols;
|
|
1707
|
+
out.index = rows;
|
|
1708
|
+
return out;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-print.mjs
|
|
1712
|
+
function dfPrint(DataFrame2, Series2, df) {
|
|
1713
|
+
function truncate(s2, maxLength2) {
|
|
1714
|
+
if (isString(s2)) {
|
|
1715
|
+
if (s2.length > maxLength2) {
|
|
1716
|
+
return s2.substring(0, maxLength2 - 3) + "...";
|
|
1717
|
+
} else {
|
|
1718
|
+
return s2;
|
|
1719
|
+
}
|
|
1720
|
+
} else {
|
|
1721
|
+
return s2;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (df.isEmpty) {
|
|
1725
|
+
console.table({});
|
|
1726
|
+
console.log("Shape:", [0, 0], "\n");
|
|
1727
|
+
return df;
|
|
1728
|
+
}
|
|
1729
|
+
const maxRows = typeof window === "undefined" ? 20 : 10;
|
|
1730
|
+
const halfMaxRows = Math.floor(maxRows / 2);
|
|
1731
|
+
const maxColumns = 4;
|
|
1732
|
+
const halfMaxColumns = Math.floor(maxColumns / 2);
|
|
1733
|
+
const tempRows = maxRows > df.index.length ? null : range(0, halfMaxRows).toArray().concat(
|
|
1734
|
+
range(df.index.length - halfMaxRows, df.index.length).toArray()
|
|
1735
|
+
);
|
|
1736
|
+
const tempColumns = maxColumns > df.columns.length ? null : range(0, halfMaxColumns).toArray().concat(
|
|
1737
|
+
range(
|
|
1738
|
+
df.columns.length - halfMaxColumns,
|
|
1739
|
+
df.columns.length
|
|
1740
|
+
).toArray()
|
|
1741
|
+
);
|
|
1742
|
+
let temp = df.get(tempRows, tempColumns);
|
|
1743
|
+
if (temp instanceof Series2) {
|
|
1744
|
+
if (df.shape[0] === 1) {
|
|
1745
|
+
temp = new DataFrame2([temp.values]);
|
|
1746
|
+
temp.index = df.index;
|
|
1747
|
+
temp.columns = new Series2(df.columns).get(tempColumns).values;
|
|
1748
|
+
} else if (df.shape[1] === 1) {
|
|
1749
|
+
temp = new DataFrame2([temp.values]).transpose();
|
|
1750
|
+
temp.index = new Series2(df.index).get(tempRows).values;
|
|
1751
|
+
temp.columns = df.columns;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
if (maxRows <= df.index.length) {
|
|
1755
|
+
temp._index.splice(halfMaxRows, 0, "...");
|
|
1756
|
+
temp._values.splice(
|
|
1757
|
+
halfMaxRows,
|
|
1758
|
+
0,
|
|
1759
|
+
range(0, temp.columns.length).map(() => "...")
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
if (maxColumns <= df.columns.length) {
|
|
1763
|
+
temp._columns.splice(halfMaxColumns, 0, "...");
|
|
1764
|
+
temp._values = map(temp._values, (row) => {
|
|
1765
|
+
row.splice(halfMaxColumns, 0, "...");
|
|
1766
|
+
return row;
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
const maxLength = 28;
|
|
1770
|
+
if (temp instanceof Series2) {
|
|
1771
|
+
temp.values = map(temp.values, (value) => truncate(value, maxLength));
|
|
1772
|
+
temp.name = truncate(temp.name, maxLength);
|
|
1773
|
+
temp.index = map(temp.index, (row) => truncate(row, maxLength));
|
|
1774
|
+
} else {
|
|
1775
|
+
temp.values = map(temp.values, (row) => {
|
|
1776
|
+
return map(row, (value) => truncate(value, maxLength));
|
|
1777
|
+
});
|
|
1778
|
+
temp.columns = map(temp.columns, (col) => truncate(col, maxLength));
|
|
1779
|
+
temp.index = map(temp.index, (row) => truncate(row, maxLength));
|
|
1780
|
+
}
|
|
1781
|
+
console.table(temp.toDetailedObject());
|
|
1782
|
+
console.log("Shape:", df.shape, "\n");
|
|
1783
|
+
return df;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-reset-index.mjs
|
|
1787
|
+
function dfResetIndex(df, shouldSkipCopying) {
|
|
1788
|
+
const out = shouldSkipCopying ? df : df.copy();
|
|
1789
|
+
const n = (out.index.length - 1).toString().length;
|
|
1790
|
+
out.index = range(0, df.shape[0]).map((i) => {
|
|
1791
|
+
return "row" + i.toString().padStart(n, "0");
|
|
1792
|
+
});
|
|
1793
|
+
return out;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/product.mjs
|
|
1797
|
+
function product(arr, shouldDropNaNs) {
|
|
1798
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1799
|
+
return product(arr.values, shouldDropNaNs);
|
|
1800
|
+
}
|
|
1801
|
+
assert(
|
|
1802
|
+
isArray(arr),
|
|
1803
|
+
"The `product` function only works on arrays, Series, and DataFrames!"
|
|
1804
|
+
);
|
|
1805
|
+
try {
|
|
1806
|
+
if (arr.length === 0) return NaN;
|
|
1807
|
+
const temp = flatten(arr);
|
|
1808
|
+
let resultShouldBeABigInt = false;
|
|
1809
|
+
let out = 1;
|
|
1810
|
+
for (let v of temp) {
|
|
1811
|
+
if (!isNumber(v)) {
|
|
1812
|
+
if (shouldDropNaNs) {
|
|
1813
|
+
v = 1;
|
|
1814
|
+
} else {
|
|
1815
|
+
return NaN;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
if (typeof v === "bigint") {
|
|
1819
|
+
resultShouldBeABigInt = true;
|
|
1820
|
+
v = Number(v);
|
|
1821
|
+
}
|
|
1822
|
+
out *= v;
|
|
1823
|
+
}
|
|
1824
|
+
if (resultShouldBeABigInt) {
|
|
1825
|
+
try {
|
|
1826
|
+
return BigInt(out);
|
|
1827
|
+
} catch (e) {
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
return out;
|
|
1831
|
+
} catch (e) {
|
|
1832
|
+
return NaN;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/is-natural-number.mjs
|
|
1837
|
+
function isNaturalNumber(x) {
|
|
1838
|
+
return isInteger(x) && x > 0;
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/reshape.mjs
|
|
1842
|
+
function reshape(x, newShape) {
|
|
1843
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
1844
|
+
return reshape(x.values, newShape);
|
|
1845
|
+
}
|
|
1846
|
+
assert(
|
|
1847
|
+
isArray(x),
|
|
1848
|
+
"The first argument passed into the `reshape` function must be an array!"
|
|
1849
|
+
);
|
|
1850
|
+
if (isNumber(newShape)) newShape = [newShape];
|
|
1851
|
+
assert(
|
|
1852
|
+
isArray(newShape),
|
|
1853
|
+
"The second argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1854
|
+
);
|
|
1855
|
+
assert(
|
|
1856
|
+
shape(newShape).length === 1,
|
|
1857
|
+
"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1858
|
+
);
|
|
1859
|
+
newShape = map(newShape, (v) => {
|
|
1860
|
+
if (typeof v === "bigint") {
|
|
1861
|
+
v = Number(v);
|
|
1862
|
+
}
|
|
1863
|
+
assert(
|
|
1864
|
+
isNaturalNumber(v),
|
|
1865
|
+
"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
|
|
1866
|
+
);
|
|
1867
|
+
return Number(v);
|
|
1868
|
+
});
|
|
1869
|
+
if (newShape.length === 0) {
|
|
1870
|
+
return flatten(x);
|
|
1871
|
+
}
|
|
1872
|
+
const temp = flatten(x);
|
|
1873
|
+
if (newShape.length === 1 && newShape[0] === temp.length) {
|
|
1874
|
+
return temp;
|
|
1875
|
+
}
|
|
1876
|
+
assert(
|
|
1877
|
+
product(newShape) === temp.length,
|
|
1878
|
+
"The new shape doesn't match the number of values available in `x` (the first argument passed into the `reshape` function)!"
|
|
1879
|
+
);
|
|
1880
|
+
const out = [];
|
|
1881
|
+
const step = Math.floor(temp.length / newShape[0]);
|
|
1882
|
+
for (let i = 0; i < newShape[0]; i++) {
|
|
1883
|
+
const row = temp.slice(i * step, (i + 1) * step);
|
|
1884
|
+
out.push(reshape(row, newShape.slice(1)));
|
|
1885
|
+
}
|
|
1886
|
+
return out;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/random.mjs
|
|
1890
|
+
var MAX = Math.pow(2, 64);
|
|
1891
|
+
var s = [];
|
|
1892
|
+
seed(Math.floor(Math.random() * MAX));
|
|
1893
|
+
function splitmix64(state, n) {
|
|
1894
|
+
state = uint(state);
|
|
1895
|
+
function helper4() {
|
|
1896
|
+
state += uint("0x9e3779b97f4a7c15");
|
|
1897
|
+
let z = copy(state);
|
|
1898
|
+
z = (z ^ z >> BigInt(30)) * uint("0xbf58476d1ce4e5b9");
|
|
1899
|
+
z = (z ^ z >> BigInt(27)) * uint("0x94d049bb133111eb");
|
|
1900
|
+
return z ^ z >> BigInt(31);
|
|
1901
|
+
}
|
|
1902
|
+
const out = [];
|
|
1903
|
+
for (let i = 0; i < n; i++) out.push(helper4());
|
|
1904
|
+
return out;
|
|
1905
|
+
}
|
|
1906
|
+
function uint(x) {
|
|
1907
|
+
return BigInt.asUintN(64, BigInt(x));
|
|
1908
|
+
}
|
|
1909
|
+
function rotl(x, k) {
|
|
1910
|
+
x = uint(x);
|
|
1911
|
+
k = BigInt(k);
|
|
1912
|
+
return uint(uint(x << k) | uint(x >> uint(BigInt(64) - k)));
|
|
1913
|
+
}
|
|
1914
|
+
function seed(val) {
|
|
1915
|
+
if (typeof val === "bigint") {
|
|
1916
|
+
val = Number(val);
|
|
1917
|
+
}
|
|
1918
|
+
if (!isUndefined(val)) {
|
|
1919
|
+
assert(
|
|
1920
|
+
isNumber(val),
|
|
1921
|
+
"If passing a value into the `seed` function, then that value must be an integer!"
|
|
1922
|
+
);
|
|
1923
|
+
const temp = splitmix64(Math.floor(val), 4);
|
|
1924
|
+
s[0] = temp[0];
|
|
1925
|
+
s[1] = temp[1];
|
|
1926
|
+
s[2] = temp[2];
|
|
1927
|
+
s[3] = temp[3];
|
|
1928
|
+
} else {
|
|
1929
|
+
return copy(s);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
function next() {
|
|
1933
|
+
const result = uint(rotl(s[0] + s[3], 23) + s[0]);
|
|
1934
|
+
const t = uint(s[1] << BigInt(17));
|
|
1935
|
+
s[2] = uint(s[2] ^ s[0]);
|
|
1936
|
+
s[3] = uint(s[3] ^ s[1]);
|
|
1937
|
+
s[1] = uint(s[1] ^ s[2]);
|
|
1938
|
+
s[0] = uint(s[0] ^ s[3]);
|
|
1939
|
+
s[2] = uint(s[2] ^ t);
|
|
1940
|
+
s[3] = rotl(s[3], 45);
|
|
1941
|
+
return Math.floor(Number(result)) / MAX;
|
|
1942
|
+
}
|
|
1943
|
+
function random(shape2) {
|
|
1944
|
+
if (isUndefined(shape2)) return next();
|
|
1945
|
+
if (!isArray(shape2)) shape2 = [shape2];
|
|
1946
|
+
return reshape(map(ndarray(product(shape2)), next), shape2);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/shuffle.mjs
|
|
1950
|
+
function shuffle(arr) {
|
|
1951
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
1952
|
+
return arr.shuffle(...Object.values(arguments).slice(1));
|
|
1953
|
+
}
|
|
1954
|
+
assert(
|
|
1955
|
+
isArray(arr),
|
|
1956
|
+
"The `shuffle` function only works on arrays, Series, and DataFrames!"
|
|
1957
|
+
);
|
|
1958
|
+
const out = [];
|
|
1959
|
+
const temp = arr.slice();
|
|
1960
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1961
|
+
const index = Math.floor(random() * temp.length);
|
|
1962
|
+
out.push(temp.splice(index, 1)[0]);
|
|
1963
|
+
}
|
|
1964
|
+
return out;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-shuffle.mjs
|
|
1968
|
+
function dfShuffle(df, axis) {
|
|
1969
|
+
if (isUndefined(axis)) axis = 0;
|
|
1970
|
+
assert(
|
|
1971
|
+
axis === 0 || axis === 1,
|
|
1972
|
+
"The `axis` parameter to the `shuffle` must be 0, 1, or undefined."
|
|
1973
|
+
);
|
|
1974
|
+
return df.get(
|
|
1975
|
+
axis === 0 ? shuffle(df.index) : null,
|
|
1976
|
+
axis === 1 ? shuffle(df.columns) : null
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/is-boolean.mjs
|
|
1981
|
+
function isBoolean(x) {
|
|
1982
|
+
return typeof x === "boolean";
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-sort.mjs
|
|
1986
|
+
function dfSort(df, a, b) {
|
|
1987
|
+
if (isFunction(a)) {
|
|
1988
|
+
return dfSortByFunction(df, a, b);
|
|
1989
|
+
} else {
|
|
1990
|
+
return dfSortByColumns(df, a, b);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function dfSortByFunction(df, fn, axis) {
|
|
1994
|
+
axis = isUndefined(axis) ? 0 : axis;
|
|
1995
|
+
assert(
|
|
1996
|
+
isFunction(fn),
|
|
1997
|
+
"When sorting a DataFrame using a function, the first argument to the `sort` method must be a function!"
|
|
1998
|
+
);
|
|
1999
|
+
assert(
|
|
2000
|
+
isNumber(axis),
|
|
2001
|
+
"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."
|
|
2002
|
+
);
|
|
2003
|
+
if (axis === 0) {
|
|
2004
|
+
const index = sort(df.index, (a, b) => {
|
|
2005
|
+
return fn(df.get(a, null), df.get(b, null));
|
|
2006
|
+
});
|
|
2007
|
+
return df.get(index, null);
|
|
2008
|
+
} else {
|
|
2009
|
+
const columns = sort(df.columns, (a, b) => {
|
|
2010
|
+
return fn(df.get(null, a), df.get(null, b));
|
|
2011
|
+
});
|
|
2012
|
+
return df.get(null, columns);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
function dfSortByColumns(df, cols, directions) {
|
|
2016
|
+
let out = df.copy();
|
|
2017
|
+
const indexID = random().toString();
|
|
2018
|
+
out = out.assign(indexID, out.index);
|
|
2019
|
+
if (isUndefined(cols)) {
|
|
2020
|
+
cols = [indexID];
|
|
2021
|
+
directions = [true];
|
|
2022
|
+
}
|
|
2023
|
+
if (isNumber(cols) || isString(cols)) {
|
|
2024
|
+
cols = [cols];
|
|
2025
|
+
if (isBoolean(directions) || isString(directions)) directions = [directions];
|
|
2026
|
+
}
|
|
2027
|
+
assert(
|
|
2028
|
+
isArray(cols),
|
|
2029
|
+
"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."
|
|
2030
|
+
);
|
|
2031
|
+
assert(
|
|
2032
|
+
shape(cols).length === 1,
|
|
2033
|
+
"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."
|
|
2034
|
+
);
|
|
2035
|
+
if (isUndefined(directions)) {
|
|
2036
|
+
directions = range(0, cols.length).map(() => true);
|
|
2037
|
+
}
|
|
2038
|
+
assert(
|
|
2039
|
+
isArray(directions),
|
|
2040
|
+
"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."
|
|
2041
|
+
);
|
|
2042
|
+
assert(
|
|
2043
|
+
shape(directions).length === 1,
|
|
2044
|
+
"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."
|
|
2045
|
+
);
|
|
2046
|
+
assert(
|
|
2047
|
+
cols.length === directions.length,
|
|
2048
|
+
"The arrays passed into the `sort` method must be equal in length."
|
|
2049
|
+
);
|
|
2050
|
+
cols = map(cols, (col) => {
|
|
2051
|
+
assert(
|
|
2052
|
+
isString(col) || isNumber(col),
|
|
2053
|
+
"Column references can either be column names (as strings) or column indices (as whole numbers)."
|
|
2054
|
+
);
|
|
2055
|
+
if (isString(col)) {
|
|
2056
|
+
const index = out.columns.indexOf(col);
|
|
2057
|
+
assert(index > -1, `The column "${col}" does not exist!`);
|
|
2058
|
+
return index;
|
|
2059
|
+
}
|
|
2060
|
+
if (isNumber(col)) {
|
|
2061
|
+
assert(isWholeNumber(col), "Column indices must be whole numbers!");
|
|
2062
|
+
assert(col < out.columns.length, `The index ${col} is out of bounds!`);
|
|
2063
|
+
return col;
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
directions = map(directions, (dir) => {
|
|
2067
|
+
assert(
|
|
2068
|
+
isString(dir) || isBoolean(dir),
|
|
2069
|
+
"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
|
|
2070
|
+
);
|
|
2071
|
+
if (isString(dir)) {
|
|
2072
|
+
const value = dir.trim().toLowerCase();
|
|
2073
|
+
assert(
|
|
2074
|
+
value === "ascending" || value === "descending",
|
|
2075
|
+
"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
|
|
2076
|
+
);
|
|
2077
|
+
return value === "ascending";
|
|
2078
|
+
}
|
|
2079
|
+
if (isBoolean(dir)) {
|
|
2080
|
+
return dir;
|
|
2081
|
+
}
|
|
2082
|
+
});
|
|
2083
|
+
out.values = sort(out.values, (a, b) => {
|
|
2084
|
+
let counter = 0;
|
|
2085
|
+
while (a[cols[counter]] === b[cols[counter]] && counter < cols.length) {
|
|
2086
|
+
counter++;
|
|
2087
|
+
}
|
|
2088
|
+
const isAscending = directions[counter];
|
|
2089
|
+
if (a[cols[counter]] === b[cols[counter]]) return 0;
|
|
2090
|
+
if (a[cols[counter]] < b[cols[counter]]) return isAscending ? -1 : 1;
|
|
2091
|
+
if (a[cols[counter]] > b[cols[counter]]) return isAscending ? 1 : -1;
|
|
2092
|
+
});
|
|
2093
|
+
const indexNumber = out.columns.indexOf(indexID);
|
|
2094
|
+
out.index = map(out.values, (row) => row[indexNumber]);
|
|
2095
|
+
out = out.dropColumns(indexID);
|
|
2096
|
+
return out;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-detailed-object.mjs
|
|
2100
|
+
function dfToDetailedObject(df, axis) {
|
|
2101
|
+
if (isUndefined(axis)) {
|
|
2102
|
+
axis = 0;
|
|
2103
|
+
} else {
|
|
2104
|
+
assert(
|
|
2105
|
+
axis === 0 || axis === 1,
|
|
2106
|
+
"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."
|
|
2107
|
+
);
|
|
2108
|
+
}
|
|
2109
|
+
const out = {};
|
|
2110
|
+
if (axis === 0) {
|
|
2111
|
+
forEach(df.index, (rowName, i) => {
|
|
2112
|
+
const temp = {};
|
|
2113
|
+
forEach(df.columns, (colName, j) => {
|
|
2114
|
+
temp[colName] = df.values[i][j];
|
|
2115
|
+
});
|
|
2116
|
+
out[rowName] = temp;
|
|
2117
|
+
});
|
|
2118
|
+
} else {
|
|
2119
|
+
forEach(df.columns, (colName, j) => {
|
|
2120
|
+
const temp = {};
|
|
2121
|
+
forEach(df.index, (rowName, i) => {
|
|
2122
|
+
temp[rowName] = df.values[i][j];
|
|
2123
|
+
});
|
|
2124
|
+
out[colName] = temp;
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
return out;
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json-string.mjs
|
|
2131
|
+
function dfToJSONString(df, axis) {
|
|
2132
|
+
return JSON.stringify(df.toObject(axis));
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json.mjs
|
|
2136
|
+
async function dfToJSON(df, axis) {
|
|
2137
|
+
return JSON.parse(dfToJSONString(df, axis));
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-object.mjs
|
|
2141
|
+
function dfToObject(df) {
|
|
2142
|
+
const out = {};
|
|
2143
|
+
forEach(df.columns, (col) => {
|
|
2144
|
+
out[col] = df.get(col).values;
|
|
2145
|
+
});
|
|
2146
|
+
return out;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/reverse.mjs
|
|
2150
|
+
function reverse(arr) {
|
|
2151
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
2152
|
+
const out2 = arr.copy();
|
|
2153
|
+
out2.values = reverse(out2.values);
|
|
2154
|
+
out2.index = reverse(out2.index);
|
|
2155
|
+
return out2;
|
|
2156
|
+
}
|
|
2157
|
+
assert(
|
|
2158
|
+
isArray(arr),
|
|
2159
|
+
"The `reverse` function only works on arrays, Series, and DataFrames!"
|
|
2160
|
+
);
|
|
2161
|
+
const out = [];
|
|
2162
|
+
for (let i = arr.length - 1; i >= 0; i--) out.push(arr[i]);
|
|
2163
|
+
return out;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/transpose.mjs
|
|
2167
|
+
function transpose(arr) {
|
|
2168
|
+
if (isDataFrame(arr) || isSeries(arr)) {
|
|
2169
|
+
return arr.transpose();
|
|
2170
|
+
}
|
|
2171
|
+
assert(
|
|
2172
|
+
isArray(arr),
|
|
2173
|
+
"The `transpose` function only works on arrays, Series, and DataFrames!"
|
|
2174
|
+
);
|
|
2175
|
+
const theShape = shape(arr);
|
|
2176
|
+
assert(
|
|
2177
|
+
theShape.length <= 2,
|
|
2178
|
+
"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!"
|
|
2179
|
+
);
|
|
2180
|
+
if (theShape.length === 1) {
|
|
2181
|
+
return reverse(arr);
|
|
2182
|
+
} else if (theShape.length === 2) {
|
|
2183
|
+
const out = ndarray(reverse(theShape));
|
|
2184
|
+
for (let row = 0; row < theShape[0]; row++) {
|
|
2185
|
+
for (let col = 0; col < theShape[1]; col++) {
|
|
2186
|
+
out[col][row] = arr[row][col];
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return out;
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-append.mjs
|
|
2194
|
+
function seriesAppend(Series2, series, x) {
|
|
2195
|
+
if (isSeries(x)) {
|
|
2196
|
+
return new Series2(series.values.concat(x.values));
|
|
2197
|
+
}
|
|
2198
|
+
if (isArray(x)) {
|
|
2199
|
+
const xShape = shape(x);
|
|
2200
|
+
assert(
|
|
2201
|
+
xShape.length === 1 && !isNested(xShape),
|
|
2202
|
+
"Only vectors can be appended to Series!"
|
|
2203
|
+
);
|
|
2204
|
+
const out = series.copy();
|
|
2205
|
+
forEach(x, (v, i) => {
|
|
2206
|
+
out._values.push(v);
|
|
2207
|
+
out._index.push("item" + (series.values.length + i));
|
|
2208
|
+
});
|
|
2209
|
+
return out;
|
|
2210
|
+
}
|
|
2211
|
+
return seriesAppend(series, [x]);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-apply.mjs
|
|
2215
|
+
function seriesApply(series, fn) {
|
|
2216
|
+
assert(
|
|
2217
|
+
isFunction(fn),
|
|
2218
|
+
"The parameter to the `apply` method must be a function."
|
|
2219
|
+
);
|
|
2220
|
+
const out = series.copy();
|
|
2221
|
+
out._values = map(out._values, (v, i) => fn(v, i));
|
|
2222
|
+
return out;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-drop-missing.mjs
|
|
2226
|
+
function seriesDropMissing(series) {
|
|
2227
|
+
const out = series.copy();
|
|
2228
|
+
const outIndex = [];
|
|
2229
|
+
out._values = filter(out.values, (v, i) => {
|
|
2230
|
+
if (isUndefined(v)) {
|
|
2231
|
+
return false;
|
|
2232
|
+
} else {
|
|
2233
|
+
outIndex.push(out.index[i]);
|
|
2234
|
+
return true;
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
out._index = outIndex;
|
|
2238
|
+
return out;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-drop-nan.mjs
|
|
2242
|
+
function seriesDropNaN(Series2, series) {
|
|
2243
|
+
const index = [];
|
|
2244
|
+
const values = [];
|
|
2245
|
+
forEach(series.values, (value, i) => {
|
|
2246
|
+
if (isNumber(value)) {
|
|
2247
|
+
values.push(value);
|
|
2248
|
+
index.push(series.index[i]);
|
|
2249
|
+
}
|
|
2250
|
+
});
|
|
2251
|
+
const out = new Series2(values);
|
|
2252
|
+
out.name = series.name;
|
|
2253
|
+
out.index = index;
|
|
2254
|
+
return out;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-filter.mjs
|
|
2258
|
+
function seriesFilter(Series2, series, fn) {
|
|
2259
|
+
let out = series.copy();
|
|
2260
|
+
const index = copy(out.index);
|
|
2261
|
+
const indicesToRemove = [];
|
|
2262
|
+
const newValues = filter(out.values, (value, i) => {
|
|
2263
|
+
const shouldKeep = fn(value, i, out.values);
|
|
2264
|
+
if (!shouldKeep) indicesToRemove.push(out.index[i]);
|
|
2265
|
+
return shouldKeep;
|
|
2266
|
+
});
|
|
2267
|
+
forEach(indicesToRemove, (i) => {
|
|
2268
|
+
index.splice(index.indexOf(i), 1);
|
|
2269
|
+
});
|
|
2270
|
+
if (newValues.length === 0) {
|
|
2271
|
+
out = new Series2();
|
|
2272
|
+
out.name = series.name;
|
|
2273
|
+
return out;
|
|
2274
|
+
}
|
|
2275
|
+
out.values = newValues;
|
|
2276
|
+
out.index = index;
|
|
2277
|
+
return out;
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-get.mjs
|
|
2281
|
+
function seriesGet(series, indices) {
|
|
2282
|
+
if (isString(indices) || isNumber(indices)) indices = [indices];
|
|
2283
|
+
for (const i in indices) {
|
|
2284
|
+
if (typeof indices[i] === "bigint") {
|
|
2285
|
+
indices[i] = Number(indices[i]);
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
const types = set(map(indices || [], (v) => typeof v));
|
|
2289
|
+
assert(
|
|
2290
|
+
types.length <= 2,
|
|
2291
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2292
|
+
);
|
|
2293
|
+
if (types.length === 1) {
|
|
2294
|
+
assert(
|
|
2295
|
+
types[0] === "string" || types[0] === "number",
|
|
2296
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
if (types.length === 2) {
|
|
2300
|
+
assert(
|
|
2301
|
+
types.indexOf("string") > -1,
|
|
2302
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2303
|
+
);
|
|
2304
|
+
assert(
|
|
2305
|
+
types.indexOf("number") > -1,
|
|
2306
|
+
"Only whole numbers and/or strings are allowed in `get` arrays!"
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
if (!isUndefined(indices)) {
|
|
2310
|
+
indices = map(indices, (i) => {
|
|
2311
|
+
if (typeof i === "string") {
|
|
2312
|
+
assert(series.index.indexOf(i) > -1, `Index "${i}" does not exist!`);
|
|
2313
|
+
return i;
|
|
2314
|
+
}
|
|
2315
|
+
if (typeof i === "number") {
|
|
2316
|
+
assert(i >= 0, `Index ${i} is out of bounds!`);
|
|
2317
|
+
assert(Math.floor(i) === i, `Indices must be integers!`);
|
|
2318
|
+
assert(i < series.index.length, `Index ${i} is out of bounds!`);
|
|
2319
|
+
return series.index[i];
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
return series.getSubsetByNames(indices);
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-indices.mjs
|
|
2327
|
+
function seriesGetSubsetByIndices(series, indices) {
|
|
2328
|
+
const dataShape = series.shape;
|
|
2329
|
+
if (isUndefined(indices)) indices = range(0, dataShape[0]).toArray();
|
|
2330
|
+
assert(
|
|
2331
|
+
isArray(indices),
|
|
2332
|
+
"The `indices` array must be 1-dimensional array of whole numbers."
|
|
2333
|
+
);
|
|
2334
|
+
assert(
|
|
2335
|
+
shape(indices).length === 1,
|
|
2336
|
+
"The `indices` array must be a 1-dimensional array of whole numbers."
|
|
2337
|
+
);
|
|
2338
|
+
assert(
|
|
2339
|
+
indices.length > 0,
|
|
2340
|
+
"The `indices` array must contain at least one index."
|
|
2341
|
+
);
|
|
2342
|
+
forEach(indices, (index) => {
|
|
2343
|
+
assert(
|
|
2344
|
+
isWholeNumber(index),
|
|
2345
|
+
"The `indices` array must be a 1-dimensional array of whole numbers."
|
|
2346
|
+
);
|
|
2347
|
+
assert(
|
|
2348
|
+
index < series.index.length,
|
|
2349
|
+
`The row index ${index} is out of bounds.`
|
|
2350
|
+
);
|
|
2351
|
+
});
|
|
2352
|
+
const rows = map(indices, (i) => series.index[i]);
|
|
2353
|
+
return series.getSubsetByNames(rows);
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-names.mjs
|
|
2357
|
+
function seriesGetSubsetByNames(Series2, series, indices) {
|
|
2358
|
+
if (isUndefined(indices)) indices = series.index;
|
|
2359
|
+
assert(
|
|
2360
|
+
isArray(indices),
|
|
2361
|
+
"The `indices` array must be a 1-dimensional array of strings."
|
|
2362
|
+
);
|
|
2363
|
+
assert(
|
|
2364
|
+
shape(indices).length === 1,
|
|
2365
|
+
"The `indices` array must be a 1-dimensional array of strings."
|
|
2366
|
+
);
|
|
2367
|
+
assert(
|
|
2368
|
+
indices.length > 0,
|
|
2369
|
+
"The `indices` array must contain at least one index name."
|
|
2370
|
+
);
|
|
2371
|
+
forEach(indices, (name) => {
|
|
2372
|
+
assert(isString(name), "The `indices` array must contain only strings.");
|
|
2373
|
+
assert(
|
|
2374
|
+
series.index.indexOf(name) > -1,
|
|
2375
|
+
`The name "${name}" does not exist in the index.`
|
|
2376
|
+
);
|
|
2377
|
+
});
|
|
2378
|
+
const values = map(indices, (name) => {
|
|
2379
|
+
return series.values[series.index.indexOf(name)];
|
|
2380
|
+
});
|
|
2381
|
+
if (values.length === 1) return values[0];
|
|
2382
|
+
const out = new Series2(values);
|
|
2383
|
+
out.index = indices;
|
|
2384
|
+
out.name = series.name;
|
|
2385
|
+
return out;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-print.mjs
|
|
2389
|
+
function seriesPrint(series) {
|
|
2390
|
+
let temp = series.copy();
|
|
2391
|
+
const maxRows = typeof window === "undefined" ? 20 : 10;
|
|
2392
|
+
if (temp.index.length > maxRows) {
|
|
2393
|
+
temp = temp.get(
|
|
2394
|
+
range(0, maxRows / 2).toArray().concat(
|
|
2395
|
+
range(temp.index.length - maxRows / 2, temp.index.length).toArray()
|
|
2396
|
+
)
|
|
2397
|
+
);
|
|
2398
|
+
const tempIndex = copy(temp.index);
|
|
2399
|
+
tempIndex.splice(Math.floor(tempIndex.length / 2), 0, "...");
|
|
2400
|
+
temp.values.push("...");
|
|
2401
|
+
temp.index.push("...");
|
|
2402
|
+
temp = temp.get(tempIndex);
|
|
2403
|
+
}
|
|
2404
|
+
const out = {};
|
|
2405
|
+
forEach(temp.values, (value, i) => {
|
|
2406
|
+
const obj = {};
|
|
2407
|
+
obj[temp.name] = value;
|
|
2408
|
+
out[temp.index[i]] = obj;
|
|
2409
|
+
});
|
|
2410
|
+
console.table(out);
|
|
2411
|
+
console.log("Shape:", series.shape, "\n");
|
|
2412
|
+
return series;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-shuffle.mjs
|
|
2416
|
+
function seriesShuffle(series) {
|
|
2417
|
+
const out = series.copy();
|
|
2418
|
+
return out.get(shuffle(out.index));
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-sort.mjs
|
|
2422
|
+
function seriesSort(Series2, series, fn) {
|
|
2423
|
+
fn = fn || ((a, b) => a < b ? -1 : 1);
|
|
2424
|
+
assert(
|
|
2425
|
+
isUndefined(fn) || isFunction(fn),
|
|
2426
|
+
"You must pass undefined, null, or a comparison function as the second argument to the `sort` method!"
|
|
2427
|
+
);
|
|
2428
|
+
const pairs = transpose([series.values, series.index]);
|
|
2429
|
+
const temp = sort(pairs, (aPair, bPair) => {
|
|
2430
|
+
return fn(aPair[0], bPair[0]);
|
|
2431
|
+
});
|
|
2432
|
+
const newValues = [];
|
|
2433
|
+
const newIndex = [];
|
|
2434
|
+
forEach(temp, (pair) => {
|
|
2435
|
+
newValues.push(pair[0]);
|
|
2436
|
+
newIndex.push(pair[1]);
|
|
2437
|
+
});
|
|
2438
|
+
const out = new Series2();
|
|
2439
|
+
out._values = newValues;
|
|
2440
|
+
out._index = newIndex;
|
|
2441
|
+
out.name = series.name;
|
|
2442
|
+
return out;
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-sort-by-index.mjs
|
|
2446
|
+
function seriesSortByIndex(Series2, series) {
|
|
2447
|
+
let temp = transpose([series.values, series.index]);
|
|
2448
|
+
temp = transpose(
|
|
2449
|
+
sort(temp, (a, b) => {
|
|
2450
|
+
if (a[1] === b[1]) return 0;
|
|
2451
|
+
if (a[1] < b[1]) return -1;
|
|
2452
|
+
if (a[1] > b[1]) return 1;
|
|
2453
|
+
})
|
|
2454
|
+
);
|
|
2455
|
+
const out = new Series2(temp[0]);
|
|
2456
|
+
out.index = temp[1];
|
|
2457
|
+
out.name = series.name;
|
|
2458
|
+
return out;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/series-to-object.mjs
|
|
2462
|
+
function seriesToObject(series) {
|
|
2463
|
+
const out = {};
|
|
2464
|
+
out[series.name] = {};
|
|
2465
|
+
forEach(series.index, (index, i) => {
|
|
2466
|
+
out[series.name][index] = series.values[i];
|
|
2467
|
+
});
|
|
2468
|
+
return out;
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/series/index.mjs
|
|
2472
|
+
var SERIES_SYMBOL = Symbol.for("@jrc03c/js-math-tools/series");
|
|
2473
|
+
function createSeriesClass(DataFrame2) {
|
|
2474
|
+
class Series2 {
|
|
2475
|
+
static [Symbol.hasInstance](x) {
|
|
2476
|
+
try {
|
|
2477
|
+
return !!x._symbol && x._symbol === SERIES_SYMBOL;
|
|
2478
|
+
} catch (e) {
|
|
2479
|
+
return false;
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
constructor(data) {
|
|
2483
|
+
this.name = "data";
|
|
2484
|
+
Object.defineProperty(this, "_symbol", {
|
|
2485
|
+
configurable: false,
|
|
2486
|
+
enumerable: false,
|
|
2487
|
+
writable: false,
|
|
2488
|
+
value: SERIES_SYMBOL
|
|
2489
|
+
});
|
|
2490
|
+
Object.defineProperty(this, "_values", {
|
|
2491
|
+
value: [],
|
|
2492
|
+
configurable: true,
|
|
2493
|
+
enumerable: false,
|
|
2494
|
+
writable: true
|
|
2495
|
+
});
|
|
2496
|
+
Object.defineProperty(this, "values", {
|
|
2497
|
+
configurable: true,
|
|
2498
|
+
enumerable: true,
|
|
2499
|
+
get() {
|
|
2500
|
+
return this._values;
|
|
2501
|
+
},
|
|
2502
|
+
set(x) {
|
|
2503
|
+
assert(isArray(x), "The new values must be a 1-dimensional array!");
|
|
2504
|
+
const dataShape = shape(x);
|
|
2505
|
+
assert(
|
|
2506
|
+
dataShape.length === 1,
|
|
2507
|
+
"The new array of values must be 1-dimensional!"
|
|
2508
|
+
);
|
|
2509
|
+
if (dataShape[0] < this._index.length) {
|
|
2510
|
+
this._index = this._index.slice(0, dataShape[0]);
|
|
2511
|
+
} else if (dataShape[0] > this._index.length) {
|
|
2512
|
+
const n = (x.length - 1).toString().length;
|
|
2513
|
+
this._index = this._index.concat(
|
|
2514
|
+
range(this._index.length, dataShape[0]).map((i) => {
|
|
2515
|
+
return "item" + i.toString().padStart(n, "0");
|
|
2516
|
+
})
|
|
2517
|
+
);
|
|
2518
|
+
}
|
|
2519
|
+
this._values = x;
|
|
2520
|
+
}
|
|
2521
|
+
});
|
|
2522
|
+
Object.defineProperty(this, "_index", {
|
|
2523
|
+
value: [],
|
|
2524
|
+
configurable: true,
|
|
2525
|
+
enumerable: false,
|
|
2526
|
+
writable: true
|
|
2527
|
+
});
|
|
2528
|
+
Object.defineProperty(this, "index", {
|
|
2529
|
+
configurable: true,
|
|
2530
|
+
enumerable: true,
|
|
2531
|
+
get() {
|
|
2532
|
+
return this._index;
|
|
2533
|
+
},
|
|
2534
|
+
set(x) {
|
|
2535
|
+
assert(
|
|
2536
|
+
isArray(x),
|
|
2537
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2538
|
+
);
|
|
2539
|
+
assert(
|
|
2540
|
+
x.length === this.shape[0],
|
|
2541
|
+
"The new index must be the same length as the old index!"
|
|
2542
|
+
);
|
|
2543
|
+
assert(
|
|
2544
|
+
shape(x).length === 1,
|
|
2545
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2546
|
+
);
|
|
2547
|
+
forEach(x, (value) => {
|
|
2548
|
+
assert(isString(value), "All of the row names must be strings!");
|
|
2549
|
+
});
|
|
2550
|
+
this._index = x;
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
if (data) {
|
|
2554
|
+
if (data instanceof Series2) {
|
|
2555
|
+
this.name = data.name;
|
|
2556
|
+
this.values = copy(data.values);
|
|
2557
|
+
this.index = copy(data.index);
|
|
2558
|
+
} else if (isArray(data)) {
|
|
2559
|
+
const dataShape = shape(data);
|
|
2560
|
+
assert(
|
|
2561
|
+
dataShape.length === 1,
|
|
2562
|
+
"When passing an array into the constructor of a Series, the array must be 1-dimensional!"
|
|
2563
|
+
);
|
|
2564
|
+
this.values = data;
|
|
2565
|
+
} else if (data instanceof Object) {
|
|
2566
|
+
const keys = map(
|
|
2567
|
+
Object.keys(data).concat(Object.getOwnPropertySymbols(data)),
|
|
2568
|
+
(v) => v.toString()
|
|
2569
|
+
);
|
|
2570
|
+
assert(
|
|
2571
|
+
keys.length === 1,
|
|
2572
|
+
"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!"
|
|
2573
|
+
);
|
|
2574
|
+
const name = keys[0];
|
|
2575
|
+
const values = data[name];
|
|
2576
|
+
assert(
|
|
2577
|
+
shape(values).length === 1,
|
|
2578
|
+
"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!"
|
|
2579
|
+
);
|
|
2580
|
+
this.name = name;
|
|
2581
|
+
this.values = values.slice();
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
get shape() {
|
|
2586
|
+
return shape(this.values);
|
|
2587
|
+
}
|
|
2588
|
+
get length() {
|
|
2589
|
+
return this.shape[0];
|
|
2590
|
+
}
|
|
2591
|
+
get isEmpty() {
|
|
2592
|
+
return filter(this.values, (v) => !isUndefined(v)).length === 0;
|
|
2593
|
+
}
|
|
2594
|
+
clear() {
|
|
2595
|
+
const out = this.copy();
|
|
2596
|
+
forEach(out.values, (v, i) => {
|
|
2597
|
+
out.values[i] = void 0;
|
|
2598
|
+
});
|
|
2599
|
+
return out;
|
|
2600
|
+
}
|
|
2601
|
+
get(indices) {
|
|
2602
|
+
return seriesGet(this, indices);
|
|
2603
|
+
}
|
|
2604
|
+
getSubsetByNames(indices) {
|
|
2605
|
+
return seriesGetSubsetByNames(Series2, this, indices);
|
|
2606
|
+
}
|
|
2607
|
+
getSubsetByIndices(indices) {
|
|
2608
|
+
return seriesGetSubsetByIndices(this, indices);
|
|
2609
|
+
}
|
|
2610
|
+
loc(indices) {
|
|
2611
|
+
return this.getSubsetByNames(indices);
|
|
2612
|
+
}
|
|
2613
|
+
iloc(indices) {
|
|
2614
|
+
return this.getSubsetByIndices(indices);
|
|
2615
|
+
}
|
|
2616
|
+
reverse() {
|
|
2617
|
+
const out = new Series2(reverse(this.values));
|
|
2618
|
+
out.index = reverse(this.index);
|
|
2619
|
+
out.name = this.name;
|
|
2620
|
+
return out;
|
|
2621
|
+
}
|
|
2622
|
+
resetIndex() {
|
|
2623
|
+
const out = this.copy();
|
|
2624
|
+
const n = (out.index.length - 1).toString().length;
|
|
2625
|
+
out.index = range(0, this.shape[0]).map((i) => {
|
|
2626
|
+
return "item" + i.toString().padStart(n, "0");
|
|
2627
|
+
});
|
|
2628
|
+
return out;
|
|
2629
|
+
}
|
|
2630
|
+
copy() {
|
|
2631
|
+
const out = new Series2();
|
|
2632
|
+
out._values = copy(this.values);
|
|
2633
|
+
out._index = copy(this.index);
|
|
2634
|
+
out.name = this.name;
|
|
2635
|
+
return out;
|
|
2636
|
+
}
|
|
2637
|
+
append(x) {
|
|
2638
|
+
return seriesAppend(Series2, this, x);
|
|
2639
|
+
}
|
|
2640
|
+
apply(fn) {
|
|
2641
|
+
return seriesApply(this, fn);
|
|
2642
|
+
}
|
|
2643
|
+
concat(x) {
|
|
2644
|
+
return this.append(x);
|
|
2645
|
+
}
|
|
2646
|
+
dropMissing(condition, threshold) {
|
|
2647
|
+
return seriesDropMissing(this, condition, threshold);
|
|
2648
|
+
}
|
|
2649
|
+
dropNaN() {
|
|
2650
|
+
return seriesDropNaN(Series2, this);
|
|
2651
|
+
}
|
|
2652
|
+
toObject() {
|
|
2653
|
+
return seriesToObject(this);
|
|
2654
|
+
}
|
|
2655
|
+
print() {
|
|
2656
|
+
return seriesPrint(this);
|
|
2657
|
+
}
|
|
2658
|
+
shuffle() {
|
|
2659
|
+
return seriesShuffle(this);
|
|
2660
|
+
}
|
|
2661
|
+
sort(direction) {
|
|
2662
|
+
return seriesSort(Series2, this, direction);
|
|
2663
|
+
}
|
|
2664
|
+
sortByIndex() {
|
|
2665
|
+
return seriesSortByIndex(Series2, this);
|
|
2666
|
+
}
|
|
2667
|
+
filter(fn) {
|
|
2668
|
+
return seriesFilter(Series2, this, fn);
|
|
2669
|
+
}
|
|
2670
|
+
toDataFrame() {
|
|
2671
|
+
const out = new DataFrame2(transpose([this.values]));
|
|
2672
|
+
out.columns = [this.name];
|
|
2673
|
+
out.index = this.index;
|
|
2674
|
+
return out;
|
|
2675
|
+
}
|
|
2676
|
+
transpose() {
|
|
2677
|
+
const out = this.copy();
|
|
2678
|
+
out.values = reverse(out.values);
|
|
2679
|
+
out.index = reverse(out.index);
|
|
2680
|
+
return out;
|
|
2681
|
+
}
|
|
2682
|
+
getDummies() {
|
|
2683
|
+
return this.toDataFrame().getDummies();
|
|
2684
|
+
}
|
|
2685
|
+
oneHotEncode() {
|
|
2686
|
+
return this.getDummies();
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
return Series2;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/dataframe/index.mjs
|
|
2693
|
+
var DATAFRAME_SYMBOL = Symbol.for("@jrc03c/js-math-tools/dataframe");
|
|
2694
|
+
function makeKey3(n) {
|
|
2695
|
+
const alpha = "abcdefghijklmnopqrstuvwxyz1234567890";
|
|
2696
|
+
let out = "";
|
|
2697
|
+
for (let i = 0; i < n; i++) out += alpha[Math.floor(random() * alpha.length)];
|
|
2698
|
+
return out;
|
|
2699
|
+
}
|
|
2700
|
+
var DataFrame = class _DataFrame {
|
|
2701
|
+
static [Symbol.hasInstance](x) {
|
|
2702
|
+
try {
|
|
2703
|
+
return !!x._symbol && x._symbol === DATAFRAME_SYMBOL;
|
|
2704
|
+
} catch (e) {
|
|
2705
|
+
return false;
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
constructor(data) {
|
|
2709
|
+
Object.defineProperty(this, "_symbol", {
|
|
2710
|
+
configurable: false,
|
|
2711
|
+
enumerable: false,
|
|
2712
|
+
writable: false,
|
|
2713
|
+
value: DATAFRAME_SYMBOL
|
|
2714
|
+
});
|
|
2715
|
+
Object.defineProperty(this, "_values", {
|
|
2716
|
+
value: [],
|
|
2717
|
+
configurable: true,
|
|
2718
|
+
enumerable: false,
|
|
2719
|
+
writable: true
|
|
2720
|
+
});
|
|
2721
|
+
Object.defineProperty(this, "values", {
|
|
2722
|
+
configurable: true,
|
|
2723
|
+
enumerable: true,
|
|
2724
|
+
get() {
|
|
2725
|
+
if (this._values.length === 0 || !isUndefined(this._values[0]) && this._values[0].length === 0) {
|
|
2726
|
+
return [[]];
|
|
2727
|
+
}
|
|
2728
|
+
return this._values;
|
|
2729
|
+
},
|
|
2730
|
+
set(x) {
|
|
2731
|
+
assert(isArray(x), "The new values must be a 2-dimensional array!");
|
|
2732
|
+
const dataShape = shape(x);
|
|
2733
|
+
assert(
|
|
2734
|
+
dataShape.length === 2,
|
|
2735
|
+
"The new array of values must be 2-dimensional!"
|
|
2736
|
+
);
|
|
2737
|
+
if (dataShape[0] < this._index.length) {
|
|
2738
|
+
this._index = this._index.slice(0, dataShape[0]);
|
|
2739
|
+
} else if (dataShape[0] > this._index.length) {
|
|
2740
|
+
const n = (dataShape[0] - 1).toString().length;
|
|
2741
|
+
this._index = this._index.concat(
|
|
2742
|
+
range(this._index.length, dataShape[0]).map((i) => {
|
|
2743
|
+
return "row" + i.toString().padStart(n, "0");
|
|
2744
|
+
})
|
|
2745
|
+
);
|
|
2746
|
+
}
|
|
2747
|
+
if (dataShape[1] < this._columns.length) {
|
|
2748
|
+
this._columns = this._columns.slice(0, dataShape[1]);
|
|
2749
|
+
} else if (dataShape[1] > this._columns.length) {
|
|
2750
|
+
const n = (dataShape[1] - 1).toString().length;
|
|
2751
|
+
this._columns = this._columns.concat(
|
|
2752
|
+
range(this._columns.length, dataShape[1]).map((i) => {
|
|
2753
|
+
return "col" + i.toString().padStart(n, "0");
|
|
2754
|
+
})
|
|
2755
|
+
);
|
|
2756
|
+
}
|
|
2757
|
+
this._values = x;
|
|
2758
|
+
}
|
|
2759
|
+
});
|
|
2760
|
+
Object.defineProperty(this, "_columns", {
|
|
2761
|
+
value: [],
|
|
2762
|
+
configurable: true,
|
|
2763
|
+
enumerable: false,
|
|
2764
|
+
writable: true
|
|
2765
|
+
});
|
|
2766
|
+
Object.defineProperty(this, "columns", {
|
|
2767
|
+
configurable: true,
|
|
2768
|
+
enumerable: true,
|
|
2769
|
+
get() {
|
|
2770
|
+
return this._columns;
|
|
2771
|
+
},
|
|
2772
|
+
set(x) {
|
|
2773
|
+
assert(
|
|
2774
|
+
isArray(x),
|
|
2775
|
+
"The new columns list must be a 1-dimensional array of strings!"
|
|
2776
|
+
);
|
|
2777
|
+
assert(
|
|
2778
|
+
this.isEmpty || x.length === this.shape[1],
|
|
2779
|
+
"The new columns list must be the same length as the old columns list!"
|
|
2780
|
+
);
|
|
2781
|
+
assert(
|
|
2782
|
+
shape(x).length === 1,
|
|
2783
|
+
"The new columns list must be a 1-dimensional array of strings!"
|
|
2784
|
+
);
|
|
2785
|
+
x = map(x, (v) => {
|
|
2786
|
+
if (typeof v !== "string") {
|
|
2787
|
+
v = JSON.stringify(v) || v.toString();
|
|
2788
|
+
}
|
|
2789
|
+
if (v.trim().length === 0) {
|
|
2790
|
+
return "untitled_" + makeKey3(8);
|
|
2791
|
+
}
|
|
2792
|
+
return v.trim();
|
|
2793
|
+
});
|
|
2794
|
+
const counts = (() => {
|
|
2795
|
+
const temp = count(x);
|
|
2796
|
+
const out = {};
|
|
2797
|
+
forEach(temp.values, (v) => {
|
|
2798
|
+
out[v] = temp.get(v);
|
|
2799
|
+
});
|
|
2800
|
+
return out;
|
|
2801
|
+
})();
|
|
2802
|
+
x = map(x, (v) => {
|
|
2803
|
+
if (counts[v] > 1) {
|
|
2804
|
+
return v + "_" + makeKey3(8);
|
|
2805
|
+
}
|
|
2806
|
+
return v;
|
|
2807
|
+
});
|
|
2808
|
+
this._columns = x;
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
Object.defineProperty(this, "_index", {
|
|
2812
|
+
value: [],
|
|
2813
|
+
configurable: true,
|
|
2814
|
+
enumerable: false,
|
|
2815
|
+
writable: true
|
|
2816
|
+
});
|
|
2817
|
+
Object.defineProperty(this, "index", {
|
|
2818
|
+
configurable: true,
|
|
2819
|
+
enumerable: true,
|
|
2820
|
+
get() {
|
|
2821
|
+
return this._index;
|
|
2822
|
+
},
|
|
2823
|
+
set(x) {
|
|
2824
|
+
assert(
|
|
2825
|
+
isArray(x),
|
|
2826
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2827
|
+
);
|
|
2828
|
+
assert(
|
|
2829
|
+
this.isEmpty || x.length === this.shape[0],
|
|
2830
|
+
"The new index must be the same length as the old index!"
|
|
2831
|
+
);
|
|
2832
|
+
assert(
|
|
2833
|
+
shape(x).length === 1,
|
|
2834
|
+
"The new index must be a 1-dimensional array of strings!"
|
|
2835
|
+
);
|
|
2836
|
+
x = map(x, (v) => {
|
|
2837
|
+
if (typeof v !== "string") {
|
|
2838
|
+
v = JSON.stringify(v) || v.toString();
|
|
2839
|
+
}
|
|
2840
|
+
if (v.trim().length === 0) {
|
|
2841
|
+
return "untitled_" + makeKey3(8);
|
|
2842
|
+
}
|
|
2843
|
+
return v.trim();
|
|
2844
|
+
});
|
|
2845
|
+
const counts = (() => {
|
|
2846
|
+
const temp = count(x);
|
|
2847
|
+
const out = {};
|
|
2848
|
+
forEach(temp.values, (v) => {
|
|
2849
|
+
out[v] = temp.get(v);
|
|
2850
|
+
});
|
|
2851
|
+
return out;
|
|
2852
|
+
})();
|
|
2853
|
+
x = map(x, (v) => {
|
|
2854
|
+
if (counts[v] > 1) {
|
|
2855
|
+
return v + "_" + makeKey3(8);
|
|
2856
|
+
}
|
|
2857
|
+
return v;
|
|
2858
|
+
});
|
|
2859
|
+
this._index = x;
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
2862
|
+
assert(
|
|
2863
|
+
isUndefined(data) || isObject(data) || isArray(data),
|
|
2864
|
+
"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."
|
|
2865
|
+
);
|
|
2866
|
+
if (data) {
|
|
2867
|
+
if (data instanceof _DataFrame) {
|
|
2868
|
+
this.values = copy(data.values);
|
|
2869
|
+
this.columns = copy(data.columns);
|
|
2870
|
+
this.index = copy(data.index);
|
|
2871
|
+
} else if (isArray(data)) {
|
|
2872
|
+
const dataShape = shape(data);
|
|
2873
|
+
assert(
|
|
2874
|
+
dataShape.length === 2,
|
|
2875
|
+
"The `data` array passed into the constructor of a DataFrame must be 2-dimensional!"
|
|
2876
|
+
);
|
|
2877
|
+
assert(
|
|
2878
|
+
!isJagged(data),
|
|
2879
|
+
"The 2-dimensional array passed into the constructor of a DataFrame must not contain sub-arrays (i.e., rows) of different lengths!"
|
|
2880
|
+
);
|
|
2881
|
+
this.values = data;
|
|
2882
|
+
} else {
|
|
2883
|
+
this._columns = map(
|
|
2884
|
+
Object.keys(data).concat(Object.getOwnPropertySymbols(data)),
|
|
2885
|
+
(v) => v.toString()
|
|
2886
|
+
);
|
|
2887
|
+
const temp = [];
|
|
2888
|
+
let lastColName = null;
|
|
2889
|
+
let lastColLength = null;
|
|
2890
|
+
forEach(this._columns, (col) => {
|
|
2891
|
+
if (isUndefined(lastColLength)) {
|
|
2892
|
+
lastColName = col;
|
|
2893
|
+
lastColLength = data[col].length;
|
|
2894
|
+
}
|
|
2895
|
+
assert(
|
|
2896
|
+
data[col].length === lastColLength,
|
|
2897
|
+
`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.`
|
|
2898
|
+
);
|
|
2899
|
+
lastColLength = data[col].length;
|
|
2900
|
+
const values = data[col];
|
|
2901
|
+
temp.push(values);
|
|
2902
|
+
});
|
|
2903
|
+
this._values = transpose(temp);
|
|
2904
|
+
const dataShape = shape(this.values);
|
|
2905
|
+
const n = (dataShape[0] - 1).toString().length;
|
|
2906
|
+
this._index = range(0, dataShape[0]).map((i) => {
|
|
2907
|
+
return "row" + i.toString().padStart(n, "0");
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
get shape() {
|
|
2913
|
+
return shape(this.values);
|
|
2914
|
+
}
|
|
2915
|
+
get length() {
|
|
2916
|
+
return this.shape[0];
|
|
2917
|
+
}
|
|
2918
|
+
get width() {
|
|
2919
|
+
return this.shape[1];
|
|
2920
|
+
}
|
|
2921
|
+
get rows() {
|
|
2922
|
+
return this.index;
|
|
2923
|
+
}
|
|
2924
|
+
set rows(rows) {
|
|
2925
|
+
this.index = rows;
|
|
2926
|
+
}
|
|
2927
|
+
get isEmpty() {
|
|
2928
|
+
return this.values.length === 0 || this.values.every((row) => row.length === 0);
|
|
2929
|
+
}
|
|
2930
|
+
clear() {
|
|
2931
|
+
const out = new _DataFrame(ndarray(this.shape));
|
|
2932
|
+
out.columns = this.columns.slice();
|
|
2933
|
+
out.index = this.index.slice();
|
|
2934
|
+
return out;
|
|
2935
|
+
}
|
|
2936
|
+
get(rows, cols) {
|
|
2937
|
+
if (arguments.length === 0) {
|
|
2938
|
+
return this;
|
|
2939
|
+
}
|
|
2940
|
+
if (arguments.length === 1) {
|
|
2941
|
+
try {
|
|
2942
|
+
return this.get(null, rows);
|
|
2943
|
+
} catch (e) {
|
|
2944
|
+
return this.get(rows, null);
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
return dfGet(this, rows, cols);
|
|
2948
|
+
}
|
|
2949
|
+
getSubsetByNames(rows, cols) {
|
|
2950
|
+
return dfGetSubsetByNames(_DataFrame, Series, this, rows, cols);
|
|
2951
|
+
}
|
|
2952
|
+
getSubsetByIndices(rowIndices, colIndices) {
|
|
2953
|
+
return dfGetSubsetByIndices(this, rowIndices, colIndices);
|
|
2954
|
+
}
|
|
2955
|
+
getDummies(columns) {
|
|
2956
|
+
return dfGetDummies(_DataFrame, this, columns);
|
|
2957
|
+
}
|
|
2958
|
+
oneHotEncode(columns) {
|
|
2959
|
+
return dfGetDummies(_DataFrame, this, columns);
|
|
2960
|
+
}
|
|
2961
|
+
transpose() {
|
|
2962
|
+
const out = new _DataFrame(transpose(this.values));
|
|
2963
|
+
out.columns = this.index.slice();
|
|
2964
|
+
out.index = this.columns.slice();
|
|
2965
|
+
return out;
|
|
2966
|
+
}
|
|
2967
|
+
get T() {
|
|
2968
|
+
return this.transpose();
|
|
2969
|
+
}
|
|
2970
|
+
resetIndex(shouldSkipCopying) {
|
|
2971
|
+
return dfResetIndex(this, shouldSkipCopying);
|
|
2972
|
+
}
|
|
2973
|
+
copy() {
|
|
2974
|
+
return dfCopy(_DataFrame, this);
|
|
2975
|
+
}
|
|
2976
|
+
assign(p1, p2) {
|
|
2977
|
+
return dfAssign(_DataFrame, Series, this, p1, p2);
|
|
2978
|
+
}
|
|
2979
|
+
apply(fn, axis) {
|
|
2980
|
+
return dfApply(_DataFrame, Series, this, fn, axis);
|
|
2981
|
+
}
|
|
2982
|
+
dropMissing(axis, condition, threshold) {
|
|
2983
|
+
return dfDropMissing(_DataFrame, Series, this, axis, condition, threshold);
|
|
2984
|
+
}
|
|
2985
|
+
dropNaN(axis, condition, threshold) {
|
|
2986
|
+
return dfDropNaN(_DataFrame, this, axis, condition, threshold);
|
|
2987
|
+
}
|
|
2988
|
+
drop(rows, cols) {
|
|
2989
|
+
return dfDrop(_DataFrame, Series, this, rows, cols);
|
|
2990
|
+
}
|
|
2991
|
+
dropColumns(columns) {
|
|
2992
|
+
return this.drop(null, columns);
|
|
2993
|
+
}
|
|
2994
|
+
dropRows(rows) {
|
|
2995
|
+
return this.drop(rows, null);
|
|
2996
|
+
}
|
|
2997
|
+
toDetailedObject(axis) {
|
|
2998
|
+
return dfToDetailedObject(this, axis);
|
|
2999
|
+
}
|
|
3000
|
+
toObject() {
|
|
3001
|
+
return dfToObject(this);
|
|
3002
|
+
}
|
|
3003
|
+
toJSONString(axis) {
|
|
3004
|
+
return dfToJSONString(this, axis);
|
|
3005
|
+
}
|
|
3006
|
+
saveAsJSON(filename, axis) {
|
|
3007
|
+
return dfToJSON(this, filename, axis);
|
|
3008
|
+
}
|
|
3009
|
+
print() {
|
|
3010
|
+
return dfPrint(_DataFrame, Series, this);
|
|
3011
|
+
}
|
|
3012
|
+
sort(cols, directions) {
|
|
3013
|
+
return dfSort(this, cols, directions);
|
|
3014
|
+
}
|
|
3015
|
+
sortByIndex() {
|
|
3016
|
+
return this.sort();
|
|
3017
|
+
}
|
|
3018
|
+
filter(fn, axis) {
|
|
3019
|
+
return dfFilter(_DataFrame, Series, this, fn, axis);
|
|
3020
|
+
}
|
|
3021
|
+
shuffle(axis) {
|
|
3022
|
+
return dfShuffle(this, axis);
|
|
3023
|
+
}
|
|
3024
|
+
append(x, axis) {
|
|
3025
|
+
return dfAppend(this, x, axis);
|
|
3026
|
+
}
|
|
3027
|
+
concat(x, axis) {
|
|
3028
|
+
return this.append(x, axis);
|
|
3029
|
+
}
|
|
3030
|
+
join(x, axis) {
|
|
3031
|
+
return this.append(x, axis);
|
|
3032
|
+
}
|
|
3033
|
+
toString() {
|
|
3034
|
+
return JSON.stringify(this);
|
|
3035
|
+
}
|
|
3036
|
+
};
|
|
3037
|
+
var Series = createSeriesClass(DataFrame);
|
|
3038
|
+
|
|
3039
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/max.mjs
|
|
3040
|
+
function max(arr, shouldDropNaNs) {
|
|
3041
|
+
return stats(arr, { shouldDropNaNs }).max;
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/vectorize.mjs
|
|
3045
|
+
function vectorize(fn) {
|
|
3046
|
+
assert(
|
|
3047
|
+
isFunction(fn),
|
|
3048
|
+
"You must pass a function into the `vectorize` function!"
|
|
3049
|
+
);
|
|
3050
|
+
return function helper4() {
|
|
3051
|
+
let hasSeries, hasDataFrames;
|
|
3052
|
+
const series = [];
|
|
3053
|
+
const dataframes = [];
|
|
3054
|
+
const childArrays = map(
|
|
3055
|
+
filter(Object.keys(arguments), (key) => {
|
|
3056
|
+
const arg = arguments[key];
|
|
3057
|
+
if (isArray(arg)) {
|
|
3058
|
+
return true;
|
|
3059
|
+
} else if (isSeries(arg)) {
|
|
3060
|
+
hasSeries = true;
|
|
3061
|
+
series.push(arg);
|
|
3062
|
+
return true;
|
|
3063
|
+
} else if (isDataFrame(arg)) {
|
|
3064
|
+
hasDataFrames = true;
|
|
3065
|
+
dataframes.push(arg);
|
|
3066
|
+
return true;
|
|
3067
|
+
} else {
|
|
3068
|
+
return false;
|
|
3069
|
+
}
|
|
3070
|
+
}),
|
|
3071
|
+
(key) => arguments[key]
|
|
3072
|
+
);
|
|
3073
|
+
forEach(childArrays.slice(0, -1), (s2, i) => {
|
|
3074
|
+
assert(
|
|
3075
|
+
isEqual(
|
|
3076
|
+
isArray(s2) ? shape(s2) : s2.shape,
|
|
3077
|
+
isArray(childArrays[i + 1]) ? shape(childArrays[i + 1]) : childArrays[i + 1].shape
|
|
3078
|
+
),
|
|
3079
|
+
`When passing multiple arrays into the \`${fn.name}\` function, all of the arrays must have the same shape!`
|
|
3080
|
+
);
|
|
3081
|
+
});
|
|
3082
|
+
if (childArrays.length > 0) {
|
|
3083
|
+
const maxLength = max(
|
|
3084
|
+
map(childArrays, (a) => a.length ? a.length : a.values.length)
|
|
3085
|
+
);
|
|
3086
|
+
const out = range(0, maxLength).map((i) => {
|
|
3087
|
+
const args = map(Object.keys(arguments), (key) => {
|
|
3088
|
+
if (isArray(arguments[key])) {
|
|
3089
|
+
return arguments[key][i];
|
|
3090
|
+
} else if (isSeries(arguments[key])) {
|
|
3091
|
+
return arguments[key].values[i];
|
|
3092
|
+
} else if (isDataFrame(arguments[key])) {
|
|
3093
|
+
return arguments[key].values[i];
|
|
3094
|
+
} else {
|
|
3095
|
+
return arguments[key];
|
|
3096
|
+
}
|
|
3097
|
+
});
|
|
3098
|
+
return helper4(...args);
|
|
3099
|
+
});
|
|
3100
|
+
if (hasDataFrames) {
|
|
3101
|
+
try {
|
|
3102
|
+
if (dataframes.length === 1 && isEqual(shape(dataframes[0]), shape(out))) {
|
|
3103
|
+
const temp = new DataFrame(out);
|
|
3104
|
+
temp.index = dataframes[0].index.slice();
|
|
3105
|
+
temp.columns = dataframes[0].columns.slice();
|
|
3106
|
+
return temp;
|
|
3107
|
+
} else {
|
|
3108
|
+
return new DataFrame(out);
|
|
3109
|
+
}
|
|
3110
|
+
} catch (e) {
|
|
3111
|
+
return out;
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
if (hasSeries) {
|
|
3115
|
+
try {
|
|
3116
|
+
if (series.length === 1 && series[0].length === out.length) {
|
|
3117
|
+
const temp = new Series(out);
|
|
3118
|
+
temp.name = series[0].name;
|
|
3119
|
+
temp.index = series[0].index.slice();
|
|
3120
|
+
return temp;
|
|
3121
|
+
} else {
|
|
3122
|
+
return new Series(out);
|
|
3123
|
+
}
|
|
3124
|
+
} catch (e) {
|
|
3125
|
+
return out;
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
return out;
|
|
3129
|
+
} else {
|
|
3130
|
+
return fn(...arguments);
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/abs.mjs
|
|
3136
|
+
function abs(x) {
|
|
3137
|
+
try {
|
|
3138
|
+
if (!isNumber(x)) return NaN;
|
|
3139
|
+
if (typeof x === "bigint") {
|
|
3140
|
+
return x < 0 ? -x : x;
|
|
3141
|
+
} else {
|
|
3142
|
+
return Math.abs(x);
|
|
3143
|
+
}
|
|
3144
|
+
} catch (e) {
|
|
3145
|
+
return NaN;
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
var vabs = vectorize(abs);
|
|
3149
|
+
|
|
3150
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/add.mjs
|
|
3151
|
+
function add() {
|
|
3152
|
+
try {
|
|
3153
|
+
let out = 0;
|
|
3154
|
+
let resultShouldBeABigInt = false;
|
|
3155
|
+
const x = Object.values(arguments);
|
|
3156
|
+
for (let v of x) {
|
|
3157
|
+
if (!isNumber(v)) return NaN;
|
|
3158
|
+
if (typeof v === "bigint") {
|
|
3159
|
+
resultShouldBeABigInt = true;
|
|
3160
|
+
v = Number(v);
|
|
3161
|
+
}
|
|
3162
|
+
out += v;
|
|
3163
|
+
}
|
|
3164
|
+
if (resultShouldBeABigInt) {
|
|
3165
|
+
try {
|
|
3166
|
+
return BigInt(out);
|
|
3167
|
+
} catch (e) {
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
return out;
|
|
3171
|
+
} catch (e) {
|
|
3172
|
+
return NaN;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
var vadd = vectorize(add);
|
|
3176
|
+
|
|
3177
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/apply.mjs
|
|
3178
|
+
function apply(x, fn) {
|
|
3179
|
+
try {
|
|
3180
|
+
return fn(x);
|
|
3181
|
+
} catch (e) {
|
|
3182
|
+
return NaN;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
var vapply = vectorize(apply);
|
|
3186
|
+
|
|
3187
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/arccos.mjs
|
|
3188
|
+
function arccos(x) {
|
|
3189
|
+
try {
|
|
3190
|
+
if (!isNumber(x)) return NaN;
|
|
3191
|
+
if (typeof x === "bigint") {
|
|
3192
|
+
x = Number(x);
|
|
3193
|
+
}
|
|
3194
|
+
return Math.acos(x);
|
|
3195
|
+
} catch (e) {
|
|
3196
|
+
return NaN;
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
var varccos = vectorize(arccos);
|
|
3200
|
+
|
|
3201
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/arcsin.mjs
|
|
3202
|
+
function arcsin(x) {
|
|
3203
|
+
try {
|
|
3204
|
+
if (!isNumber(x)) return NaN;
|
|
3205
|
+
if (typeof x === "bigint") {
|
|
3206
|
+
x = Number(x);
|
|
3207
|
+
}
|
|
3208
|
+
return Math.asin(x);
|
|
3209
|
+
} catch (e) {
|
|
3210
|
+
return NaN;
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
var varcsin = vectorize(arcsin);
|
|
3214
|
+
|
|
3215
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/arctan.mjs
|
|
3216
|
+
function arctan(x) {
|
|
3217
|
+
try {
|
|
3218
|
+
if (!isNumber(x)) return NaN;
|
|
3219
|
+
if (typeof x === "bigint") {
|
|
3220
|
+
x = Number(x);
|
|
3221
|
+
}
|
|
3222
|
+
return Math.atan(x);
|
|
3223
|
+
} catch (e) {
|
|
3224
|
+
return NaN;
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
var varctan = vectorize(arctan);
|
|
3228
|
+
|
|
3229
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/ceil.mjs
|
|
3230
|
+
function ceil(x) {
|
|
3231
|
+
try {
|
|
3232
|
+
if (!isNumber(x)) return NaN;
|
|
3233
|
+
if (typeof x === "bigint") return x;
|
|
3234
|
+
return Math.ceil(x);
|
|
3235
|
+
} catch (e) {
|
|
3236
|
+
return NaN;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
var vceil = vectorize(ceil);
|
|
3240
|
+
|
|
3241
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/chop.mjs
|
|
3242
|
+
function chop(x, threshold) {
|
|
3243
|
+
try {
|
|
3244
|
+
if (!isNumber(x)) return NaN;
|
|
3245
|
+
if (typeof x === "bigint") return x;
|
|
3246
|
+
if (isUndefined(threshold)) {
|
|
3247
|
+
threshold = 1e-10;
|
|
3248
|
+
} else if (!isNumber(threshold)) {
|
|
3249
|
+
return NaN;
|
|
3250
|
+
}
|
|
3251
|
+
return vabs(x) < threshold ? 0 : x;
|
|
3252
|
+
} catch (e) {
|
|
3253
|
+
return NaN;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
var vchop = vectorize(chop);
|
|
3257
|
+
|
|
3258
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/int.mjs
|
|
3259
|
+
function int(x) {
|
|
3260
|
+
if (isDataFrame(x) || isSeries(x)) {
|
|
3261
|
+
const out = x.copy();
|
|
3262
|
+
out.values = int(out.values);
|
|
3263
|
+
return out;
|
|
3264
|
+
}
|
|
3265
|
+
if (isArray(x)) {
|
|
3266
|
+
return map(x, (v) => int(v));
|
|
3267
|
+
} else {
|
|
3268
|
+
try {
|
|
3269
|
+
const out = JSON.parse(x);
|
|
3270
|
+
if (isNumber(out)) {
|
|
3271
|
+
return typeof out === "bigint" ? Number(out) : out >= 0 ? Math.floor(out) : Math.ceil(out);
|
|
3272
|
+
}
|
|
3273
|
+
return NaN;
|
|
3274
|
+
} catch (e) {
|
|
3275
|
+
return NaN;
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
var vint = vectorize(int);
|
|
3280
|
+
|
|
3281
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/clamp.mjs
|
|
3282
|
+
function clamp(x, a, b) {
|
|
3283
|
+
try {
|
|
3284
|
+
if (!isNumber(x)) return NaN;
|
|
3285
|
+
if (!isNumber(a)) return NaN;
|
|
3286
|
+
if (!isNumber(b)) return NaN;
|
|
3287
|
+
if (typeof x === "bigint") {
|
|
3288
|
+
return BigInt(clamp(vint(x), a, b));
|
|
3289
|
+
}
|
|
3290
|
+
if (x < a) return a;
|
|
3291
|
+
if (x > b) return b;
|
|
3292
|
+
return x;
|
|
3293
|
+
} catch (e) {
|
|
3294
|
+
return NaN;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
var vclamp = vectorize(clamp);
|
|
3298
|
+
|
|
3299
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/cos.mjs
|
|
3300
|
+
function cos(x) {
|
|
3301
|
+
try {
|
|
3302
|
+
if (!isNumber(x)) return NaN;
|
|
3303
|
+
if (typeof x === "bigint") {
|
|
3304
|
+
x = Number(x);
|
|
3305
|
+
}
|
|
3306
|
+
return Math.cos(x);
|
|
3307
|
+
} catch (e) {
|
|
3308
|
+
return NaN;
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
var vcos = vectorize(cos);
|
|
3312
|
+
|
|
3313
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/helpers/data-types.mjs
|
|
3314
|
+
var dataTypes = Object.freeze({
|
|
3315
|
+
boolean: "boolean",
|
|
3316
|
+
date: "date",
|
|
3317
|
+
null: "null",
|
|
3318
|
+
number: "number",
|
|
3319
|
+
object: "object",
|
|
3320
|
+
string: "string"
|
|
3321
|
+
});
|
|
3322
|
+
|
|
3323
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/pow.mjs
|
|
3324
|
+
function pow(x, p) {
|
|
3325
|
+
try {
|
|
3326
|
+
if (!isNumber(x)) return NaN;
|
|
3327
|
+
if (!isNumber(p)) return NaN;
|
|
3328
|
+
if (typeof x === "bigint" || typeof p === "bigint") {
|
|
3329
|
+
const out = pow(Number(x), Number(p));
|
|
3330
|
+
try {
|
|
3331
|
+
return BigInt(out);
|
|
3332
|
+
} catch (e) {
|
|
3333
|
+
return out;
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
return Math.pow(x, p);
|
|
3337
|
+
} catch (e) {
|
|
3338
|
+
return NaN;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
var vpow = vectorize(pow);
|
|
3342
|
+
|
|
3343
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/sqrt.mjs
|
|
3344
|
+
function sqrt(x) {
|
|
3345
|
+
try {
|
|
3346
|
+
if (!isNumber(x)) return NaN;
|
|
3347
|
+
if (typeof x === "bigint") {
|
|
3348
|
+
const out = sqrt(Number(x));
|
|
3349
|
+
try {
|
|
3350
|
+
return BigInt(out);
|
|
3351
|
+
} catch (e) {
|
|
3352
|
+
return out;
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
return Math.sqrt(x);
|
|
3356
|
+
} catch (e) {
|
|
3357
|
+
return NaN;
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
var vsqrt = vectorize(sqrt);
|
|
3361
|
+
|
|
3362
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/multiply.mjs
|
|
3363
|
+
function multiply() {
|
|
3364
|
+
try {
|
|
3365
|
+
const x = Object.values(arguments);
|
|
3366
|
+
if (x.length === 0) return NaN;
|
|
3367
|
+
let resultShouldBeABigInt = false;
|
|
3368
|
+
let out = 1;
|
|
3369
|
+
for (let v of x) {
|
|
3370
|
+
if (!isNumber(v)) return NaN;
|
|
3371
|
+
if (typeof v === "bigint") {
|
|
3372
|
+
resultShouldBeABigInt = true;
|
|
3373
|
+
v = Number(v);
|
|
3374
|
+
}
|
|
3375
|
+
out *= v;
|
|
3376
|
+
}
|
|
3377
|
+
if (resultShouldBeABigInt) {
|
|
3378
|
+
try {
|
|
3379
|
+
return BigInt(out);
|
|
3380
|
+
} catch (e) {
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
return out;
|
|
3384
|
+
} catch (e) {
|
|
3385
|
+
return NaN;
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
var vmultiply = vectorize(multiply);
|
|
3389
|
+
|
|
3390
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/exp.mjs
|
|
3391
|
+
function exp(x) {
|
|
3392
|
+
try {
|
|
3393
|
+
if (!isNumber(x)) return NaN;
|
|
3394
|
+
if (typeof x === "bigint") {
|
|
3395
|
+
if (x === 0n) {
|
|
3396
|
+
return 1n;
|
|
3397
|
+
} else {
|
|
3398
|
+
x = Number(x);
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
return Math.exp(x);
|
|
3402
|
+
} catch (e) {
|
|
3403
|
+
return NaN;
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
var vexp = vectorize(exp);
|
|
3407
|
+
|
|
3408
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/factorial.mjs
|
|
3409
|
+
function factorial(n) {
|
|
3410
|
+
try {
|
|
3411
|
+
if (typeof n === "bigint") {
|
|
3412
|
+
return BigInt(factorial(vint(n)));
|
|
3413
|
+
}
|
|
3414
|
+
if (n !== vint(n)) return NaN;
|
|
3415
|
+
if (n <= 1) return 1;
|
|
3416
|
+
return n * factorial(n - 1);
|
|
3417
|
+
} catch (e) {
|
|
3418
|
+
return NaN;
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
var vfactorial = vectorize(factorial);
|
|
3422
|
+
|
|
3423
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/float.mjs
|
|
3424
|
+
function float(x) {
|
|
3425
|
+
try {
|
|
3426
|
+
if (x === "Infinity") {
|
|
3427
|
+
return Infinity;
|
|
3428
|
+
}
|
|
3429
|
+
if (x === "-Infinity") {
|
|
3430
|
+
return -Infinity;
|
|
3431
|
+
}
|
|
3432
|
+
const out = JSON.parse(x);
|
|
3433
|
+
if (isNumber(out)) return out;
|
|
3434
|
+
return NaN;
|
|
3435
|
+
} catch (e) {
|
|
3436
|
+
return NaN;
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
var vfloat = vectorize(float);
|
|
3440
|
+
|
|
3441
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/floor.mjs
|
|
3442
|
+
function floor(x) {
|
|
3443
|
+
try {
|
|
3444
|
+
if (!isNumber(x)) return NaN;
|
|
3445
|
+
if (typeof x === "bigint") {
|
|
3446
|
+
return x;
|
|
3447
|
+
}
|
|
3448
|
+
return Math.floor(x);
|
|
3449
|
+
} catch (e) {
|
|
3450
|
+
return NaN;
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
var vfloor = vectorize(floor);
|
|
3454
|
+
|
|
3455
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/lerp.mjs
|
|
3456
|
+
function lerp(a, b, f) {
|
|
3457
|
+
try {
|
|
3458
|
+
if (!isNumber(a)) return NaN;
|
|
3459
|
+
if (!isNumber(b)) return NaN;
|
|
3460
|
+
if (!isNumber(f)) return NaN;
|
|
3461
|
+
if (typeof a === "bigint" || typeof b === "bigint") {
|
|
3462
|
+
const out = lerp(Number(a), Number(b), f);
|
|
3463
|
+
try {
|
|
3464
|
+
return BigInt(out);
|
|
3465
|
+
} catch (e) {
|
|
3466
|
+
return out;
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
return f * (b - a) + a;
|
|
3470
|
+
} catch (e) {
|
|
3471
|
+
return NaN;
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
var vlerp = vectorize(lerp);
|
|
3475
|
+
|
|
3476
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/log.mjs
|
|
3477
|
+
function log(x, base) {
|
|
3478
|
+
try {
|
|
3479
|
+
base = isUndefined(base) ? Math.E : base;
|
|
3480
|
+
if (!isNumber(x)) return NaN;
|
|
3481
|
+
if (!isNumber(base)) return NaN;
|
|
3482
|
+
if (typeof x === "bigint" || typeof base === "bigint") {
|
|
3483
|
+
const out = log(Number(x), Number(base));
|
|
3484
|
+
try {
|
|
3485
|
+
return BigInt(out);
|
|
3486
|
+
} catch (e) {
|
|
3487
|
+
return out;
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
return Math.log(x) / Math.log(base);
|
|
3491
|
+
} catch (e) {
|
|
3492
|
+
return NaN;
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
var vlog = vectorize(log);
|
|
3496
|
+
|
|
3497
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/mod.mjs
|
|
3498
|
+
function mod(a, b) {
|
|
3499
|
+
try {
|
|
3500
|
+
if (!isNumber(a)) return NaN;
|
|
3501
|
+
if (!isNumber(b)) return NaN;
|
|
3502
|
+
if (typeof a === "bigint" || typeof b === "bigint") {
|
|
3503
|
+
const out = mod(Number(a), Number(b));
|
|
3504
|
+
try {
|
|
3505
|
+
return BigInt(out);
|
|
3506
|
+
} catch (e) {
|
|
3507
|
+
return out;
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
return a % b;
|
|
3511
|
+
} catch (e) {
|
|
3512
|
+
return NaN;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
var vmod = vectorize(mod);
|
|
3516
|
+
|
|
3517
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/remap.mjs
|
|
3518
|
+
var helper3 = vectorize((x, a, b, c, d) => {
|
|
3519
|
+
try {
|
|
3520
|
+
let resultShouldBeABigInt = false;
|
|
3521
|
+
for (const v of [x, a, b, c, d]) {
|
|
3522
|
+
if (!isNumber(v)) {
|
|
3523
|
+
return NaN;
|
|
3524
|
+
}
|
|
3525
|
+
if (typeof v === "bigint") {
|
|
3526
|
+
resultShouldBeABigInt = true;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
if (resultShouldBeABigInt) {
|
|
3530
|
+
x = Number(x);
|
|
3531
|
+
a = Number(a);
|
|
3532
|
+
b = Number(b);
|
|
3533
|
+
c = Number(c);
|
|
3534
|
+
d = Number(d);
|
|
3535
|
+
}
|
|
3536
|
+
const num = (d - c) * (x - a);
|
|
3537
|
+
const den = b - a;
|
|
3538
|
+
if (den === 0) return NaN;
|
|
3539
|
+
const out = num / den + c;
|
|
3540
|
+
if (resultShouldBeABigInt) {
|
|
3541
|
+
try {
|
|
3542
|
+
return BigInt(out);
|
|
3543
|
+
} catch (e) {
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
return out;
|
|
3547
|
+
} catch (e) {
|
|
3548
|
+
return NaN;
|
|
3549
|
+
}
|
|
3550
|
+
});
|
|
3551
|
+
|
|
3552
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/round.mjs
|
|
3553
|
+
function round(x) {
|
|
3554
|
+
try {
|
|
3555
|
+
if (!isNumber(x)) return NaN;
|
|
3556
|
+
if (typeof x === "bigint") return x;
|
|
3557
|
+
return Math.round(x);
|
|
3558
|
+
} catch (e) {
|
|
3559
|
+
return NaN;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
var vround = vectorize(round);
|
|
3563
|
+
|
|
3564
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/sign.mjs
|
|
3565
|
+
function sign(x) {
|
|
3566
|
+
try {
|
|
3567
|
+
if (!isNumber(x)) return NaN;
|
|
3568
|
+
if (typeof x === "bigint") return BigInt(sign(Number(x)));
|
|
3569
|
+
if (x < 0) return -1;
|
|
3570
|
+
if (x > 0) return 1;
|
|
3571
|
+
return 0;
|
|
3572
|
+
} catch (e) {
|
|
3573
|
+
return NaN;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
var vsign = vectorize(sign);
|
|
3577
|
+
|
|
3578
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/sin.mjs
|
|
3579
|
+
function sin(x) {
|
|
3580
|
+
try {
|
|
3581
|
+
if (!isNumber(x)) return NaN;
|
|
3582
|
+
if (typeof x === "bigint") {
|
|
3583
|
+
x = Number(x);
|
|
3584
|
+
}
|
|
3585
|
+
return Math.sin(x);
|
|
3586
|
+
} catch (e) {
|
|
3587
|
+
return NaN;
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
var vsin = vectorize(sin);
|
|
3591
|
+
|
|
3592
|
+
// node_modules/.pnpm/@jrc03c+js-math-tools@0.0.104/node_modules/@jrc03c/js-math-tools/src/tan.mjs
|
|
3593
|
+
function tan(x) {
|
|
3594
|
+
try {
|
|
3595
|
+
if (!isNumber(x)) return NaN;
|
|
3596
|
+
if (typeof x === "bigint") {
|
|
3597
|
+
x = Number(x);
|
|
3598
|
+
}
|
|
3599
|
+
return Math.tan(x);
|
|
3600
|
+
} catch (e) {
|
|
3601
|
+
return NaN;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
var vtan = vectorize(tan);
|
|
3605
|
+
|
|
3606
|
+
// src/index.mjs
|
|
3607
|
+
var Data = (() => {
|
|
3608
|
+
const SECRET = Math.random();
|
|
3609
|
+
class Data2 {
|
|
3610
|
+
static new(data, shouldIncludeAllProperties) {
|
|
3611
|
+
data = data || {};
|
|
3612
|
+
if (typeof data !== "object") {
|
|
3613
|
+
throw new Error(
|
|
3614
|
+
"The value passed into the `Data` constructor must be an object (or undefined)!"
|
|
3615
|
+
);
|
|
3616
|
+
}
|
|
3617
|
+
const out = new this(SECRET);
|
|
3618
|
+
const keys = shouldIncludeAllProperties ? Object.keys(data).concat(Object.getOwnPropertySymbols(data)) : Object.keys(out).concat(Object.getOwnPropertySymbols(out));
|
|
3619
|
+
for (let i = 0; i < keys.length; i++) {
|
|
3620
|
+
const key = keys[i];
|
|
3621
|
+
out[key] = copy(data[key]) ?? out[key];
|
|
3622
|
+
}
|
|
3623
|
+
return out;
|
|
3624
|
+
}
|
|
3625
|
+
constructor(v) {
|
|
3626
|
+
if (v !== SECRET) {
|
|
3627
|
+
throw new Error(
|
|
3628
|
+
`New \`${this.constructor.name}\` instances must be created using the \`${this.constructor.name}.new\` static method!`
|
|
3629
|
+
);
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
return Data2;
|
|
3634
|
+
})();
|
|
3635
|
+
|
|
3636
|
+
// src/iife.mjs
|
|
3637
|
+
globalThis.Data = Data;
|
|
3638
|
+
})();
|